Top Level Namespace
Defined Under Namespace
Modules: DialogBindSystemSounds
Instance Method Summary collapse
-
#guidirectoryselect(title = 'DialogBind') ⇒ String
Shows system-native directory selection dialog.
-
#guierror(text, title = 'DialogBind') ⇒ Boolean
Shows an error message box with only single OK button.
-
#guifileselect(filter = [], title = 'DialogBind') ⇒ String
Shows system-native file selection dialog.
-
#guigets(text = 'Type something:', title = 'DialogBind') ⇒ String
Shows an input box with the specified text.
-
#guilicense(file, title = 'DialogBind') ⇒ Boolean
Shows a message box containing the license agreement that is stored in the specified file.
-
#guinotify(text, title = 'DialogBind', sound = DialogBindSystemSounds::Success) ⇒ Boolean
Shows a notification in system tray or a message box, depending on operating system notifications support.
-
#guiputs(text, title = 'DialogBind') ⇒ Boolean
Shows a simple message box (or information message box when using Zenity backend).
-
#guiselect(entries, text = 'Choose one of the items below:', title = 'DialogBind') ⇒ String
Shows either a message box with buttons matching the items specified in the array “entries“ or a list message box.
-
#guisound(sound_v) ⇒ Object
Plays the default system sounds.
-
#guiyesno(text, title = 'DialogBind') ⇒ Boolean
Shows a question message box with “Yes” and “No” buttons.
Instance Method Details
#guidirectoryselect(title = 'DialogBind') ⇒ String
Shows system-native directory selection dialog.
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
# File 'lib/dialogbind.rb', line 544 def guidirectoryselect(title='DialogBind') if $dialogbind_dialog_backend == 'macos' then return macopen(title, [], true) elsif $dialogbind_dialog_backend == 'kdialog' then if kdialog({ 'title' => title, 'getexistingdirectory' => [] }, true) == false then return '' end return File.read('/tmp/kdialog.sock').gsub("\n", "") elsif $dialogbind_dialog_backend == 'zenity' then zenity({ 'title' => title, 'file-selection' => nil, 'directory' => nil, ' > /tmp/zenity.sock 2>/dev/null' => nil }) return File.read('/tmp/zenity.sock').gsub("\n", "") elsif $dialogbind_dialog_backend == 'win32' then return win32_vbbrowseforfolder(title).gsub("\\", '/') else raise 'The selected backend does not support directory selection dialog boxes.' end return '' end |
#guierror(text, title = 'DialogBind') ⇒ Boolean
Shows an error message box with only single OK button.
296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/dialogbind.rb', line 296 def guierror(text, title='DialogBind') if $dialogbind_dialog_backend == 'zenity' then return zenity('error' => nil, 'title' => title, 'text' => text) elsif $dialogbind_dialog_backend == 'macos' then return macdialog(text, [ 'OK' ], 'dialog', true) elsif $dialogbind_dialog_backend == 'kdialog' then return kdialog({ 'title' => title, 'error' => text }) elsif $dialogbind_dialog_backend == 'win32' then return win32_msgbox(text, title, 16) else raise 'The selected backend does not support question message boxes.' end return false end |
#guifileselect(filter = [], title = 'DialogBind') ⇒ String
Shows system-native file selection dialog. Currently does not work on Windows.
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'lib/dialogbind.rb', line 520 def guifileselect(filter=[], title='DialogBind') if $dialogbind_dialog_backend == 'macos' then return macopen(title, filter, false) elsif $dialogbind_dialog_backend == 'kdialog' then if kdialog({ 'title' => title, 'getopenfilename' => [] }, true) == false then return '' end return File.read('/tmp/kdialog.sock').gsub("\n", "") elsif $dialogbind_dialog_backend == 'zenity' then zenity({ 'title' => title, 'file-selection' => nil, '%' => zenityfilter(filter), ' > /tmp/zenity.sock 2>/dev/null' => nil }) return File.read('/tmp/zenity.sock').gsub("\n", "") elsif $dialogbind_dialog_backend == 'win32' then return win32_activexopen(title) else raise 'The selected backend does not support file selection dialog boxes.' return '' end return '' end |
#guigets(text = 'Type something:', title = 'DialogBind') ⇒ String
Shows an input box with the specified text.
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/dialogbind.rb', line 568 def guigets(text='Type something:', title='DialogBind') if $dialogbind_dialog_backend == 'macos' then return macentry(text) elsif $dialogbind_dialog_backend == 'kdialog' then kdialog({ 'title' => title, 'inputbox' => [ text, '' ] }, true) return File.read('/tmp/kdialog.sock').gsub("\n", "") elsif $dialogbind_dialog_backend == 'zenity' then zenity({ 'title' => title, 'entry' => nil, 'text' => text, ' > /tmp/zenity.sock 2>/dev/null' => nil }) return File.read('/tmp/zenity.sock').gsub("\n", "") elsif $dialogbind_dialog_backend == 'win32' then return win32_vbinputbox(text) else raise 'The selected backend does not support input boxes.' return '' end return '' end |
#guilicense(file, title = 'DialogBind') ⇒ Boolean
Shows a message box containing the license agreement that is stored in the specified file.
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/dialogbind.rb', line 316 def guilicense(file, title='DialogBind') if File.exists?(file) == false then guierror('File "' + file + '" does not exist.', title) return false end if $dialogbind_dialog_backend == 'zenity' then return zenity({ 'text-info' => nil, 'title' => title, 'filename' => file, 'checkbox' => 'I have read and accepted the terms of the license agreement.' }) elsif $dialogbind_dialog_backend == 'macos' then macdialog('Right now, the license agreement will be shown in TextEdit. Close TextEdit using Command-Q to continue,', ['OK']) system('open -e "' + file.gsub('"', "\\\"") + '"') return guiyesno('Do you accept the terms of the license agreement?', title) elsif $dialogbind_dialog_backend == 'win32' then retv_msgbox = win32_msgbox("Do you accept the terms of the license agreement below?\n\n" + File.read(file), title, 36) return (retv_msgbox == 6) elsif $dialogbind_dialog_backend == 'kdialog' then kdialog({ 'textbox' => file, 'title' => title }) if kdialog({ 'yesno' => 'Do you accept the terms of the license agreement?', 'title' => title }) then return true end return false else raise 'The selected backend does not support license message boxes.' return false end return false end |
#guinotify(text, title = 'DialogBind', sound = DialogBindSystemSounds::Success) ⇒ Boolean
Shows a notification in system tray or a message box, depending on operating system notifications support.
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
# File 'lib/dialogbind.rb', line 591 def guinotify(text, title='DialogBind', sound=DialogBindSystemSounds::Success) if $dialogbind_dialog_backend != 'win32' && $dialogbind_dialog_backend != 'kdialog' then guisound(sound) end if $dialogbind_dialog_backend == 'macos' then return macdialog(text, [], 'notification', false, false, title) elsif $dialogbind_dialog_backend == 'kdialog' then return kdialog({ 'title' => title, 'passivepopup' => [ text, 10 ] }) elsif $dialogbind_dialog_backend == 'zenity' then return zenity({ 'title' => title, 'notification' => nil, 'text' => text }) else return guiputs(text, title) end return false end |
#guiputs(text, title = 'DialogBind') ⇒ Boolean
Shows a simple message box (or information message box when using Zenity backend).
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/dialogbind.rb', line 246 def guiputs(text, title='DialogBind') if $dialogbind_dialog_backend == 'zenity' then return zenity({ 'info' => nil, 'title' => title, 'text' => text }) elsif $dialogbind_dialog_backend == 'macos' then return macdialog(text) elsif $dialogbind_dialog_backend == 'kdialog' then return kdialog({ 'title' => title, 'msgbox' => text }) elsif $dialogbind_dialog_backend == 'win32' then win32_msgbox(text, title, 0) return true else puts title + ': ' + text return true end return false end |
#guiselect(entries, text = 'Choose one of the items below:', title = 'DialogBind') ⇒ String
Shows either a message box with buttons matching the items specified in the array “entries“ or a list message box.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/dialogbind.rb', line 360 def guiselect(entries, text='Choose one of the items below:', title='DialogBind') if $dialogbind_dialog_backend == 'zenity' then array_of_items = [] item_count_zenity = 0 entries.each do |item| array_of_items.push(item_count_zenity) array_of_items.push(item) item_count_zenity += 1 end if zenity({'list' => nil, 'radiolist' => nil, 'text' => text, 'print-column' => 'ALL', 'column' => '#', 'column%' => 'Items', '' => array_of_items, ' > /tmp/zenity.sock 2>/dev/null' => nil }) then return File.read('/tmp/zenity.sock').gsub("\n", "") else return nil end elsif $dialogbind_dialog_backend == 'kdialog' then list_args = [ text ] item_count = 0 entries.each do |list_item| list_args.push(item_count) list_args.push(list_item) list_args.push('-') item_count += 1 end if kdialog({ 'title' => title, 'radiolist' => list_args,}, true) == false then return nil end item_index = File.read('/tmp/kdialog.sock').gsub("\n", "").to_i if item_index > entries.length then return '' end return entries[item_index].clone elsif $dialogbind_dialog_backend == 'macos' then if entries.include? 'false' then raise 'The list of items to present to the user cannot contain the words "true" or "false" without additional punctuation due to limitations of AppleScript that is called from Ruby on macOS to display dialogs.' end return macselect(entries, text) elsif $dialogbind_dialog_backend == 'win32' then combined_msg = text.clone count = 0 entries.each do |entry_item| combined_msg += "\r\n" + count.to_s + '. ' + entry_item.to_s count += 1 end combined_msg += "\r\n" + " (To select one of the items above, enter the matching number before the dot)" entered_id = win32_vbinputbox(combined_msg).to_i if entered_id > entries.length then return '' end return entries[entered_id].clone else raise 'The selected backend does not support license message boxes.' return false end return nil end |
#guisound(sound_v) ⇒ Object
Plays the default system sounds.
DialogBindSystemSounds::Error and DialogBindSystemSounds::Attention. Specifying DialogBindSystemSounds::None will do nothing.
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/dialogbind.rb', line 472 def guisound(sound_v) if sound_v == DialogBindSystemSounds::None then return end if $dialogbind_dialog_backend != 'macos' && $dialogbind_dialog_backend != 'win32' then linuxsound(sound_v) return end constant_sound_success = '/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/burn complete.aif' constant_sound_error = '/System/Library/Sounds/Funk.aiff' constant_sound_attention = '/System/Library/PrivateFrameworks/FindMyDevic.framework/Versions/A/Resources/fmd_sound.aiff' if File.exists?(constant_sound_attention) == false then constant_sound_attention = constant_sound_success end if File.exists?(constant_sound_success) == false then constant_sound_success = constant_sound_error end if $dialogbind_dialog_backend == 'win32' then constant_sound_success = 'c:/Windows/Media/tada.wav' constant_sound_error = 'c:/Windows/Media/Windows Error.wav' if File.exists?(constant_sound_error) == false then constant_sound_error = 'c:/Windows/Media/chord.wav' end constant_sound_attention = 'c:/Windows/Media/chimes.wav' end if sound_v == DialogBindSystemSounds::Success then nativesoundplay(constant_sound_success) elsif sound_v == DialogBindSystemSounds::Error then nativesoundplay(constant_sound_error) else nativesoundplay(constant_sound_attention) end end |
#guiyesno(text, title = 'DialogBind') ⇒ Boolean
Shows a question message box with “Yes” and “No” buttons.
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/dialogbind.rb', line 268 def guiyesno(text, title='DialogBind') if $dialogbind_dialog_backend == 'zenity' then return zenity('question' => nil, 'title' => title, 'text' => text) elsif $dialogbind_dialog_backend == 'macos' then macdialog(text, [ 'Yes', 'No' ], 'dialog', false, true) output = `#{$dialogbind_macos_script_cmd}`.gsub("\n", "") if output == nil || output.include?(':') == false then return false end if output.split(':')[1].downcase == 'yes' then return true end elsif $dialogbind_dialog_backend == 'kdialog' then return kdialog({ 'title' => title, 'yesno' => text }) elsif $dialogbind_dialog_backend == 'win32' then retv_msgbox = win32_msgbox(text, title, 36) return (retv_msgbox == 6) else raise 'The selected backend does not support question message boxes.' end return false end |