Class: Cosmos::ScriptRunner
- Includes:
- ScriptAudit
- Defined in:
- lib/cosmos/tools/script_runner/script_runner.rb
Constant Summary collapse
- UNTITLED_TAB_TEXT =
' Untitled '
Class Method Summary collapse
Instance Method Summary collapse
-
#active_script_runner_frame ⇒ Object
Returns the script runner frame of the active tab.
-
#close_active_tab ⇒ Object
Closes the active tab.
- #closeEvent(event) ⇒ Object
- #context_menu(point) ⇒ Object
-
#create_tab(filename = '') ⇒ Object
Creates a new tab.
- #disable_menu_items ⇒ Object
-
#dragEnterEvent(event) ⇒ Object
Drag files into ScriptRunner support.
- #dragMoveEvent(event) ⇒ Object
- #dropEvent(event) ⇒ Object
- #enable_menu_items ⇒ Object
-
#file_close ⇒ Object
File->Close.
-
#file_new ⇒ Object
File->New.
-
#file_open(filename = nil) ⇒ Object
File->Open.
-
#file_options ⇒ Object
File->Options.
-
#file_reload ⇒ Object
File->Reload.
-
#file_save(save_as = false) ⇒ Object
File->Save and File->Save As.
- #handle_script_keypress(event) ⇒ Object
-
#handle_tab_change(index) ⇒ Object
Handle the user changing tabs.
-
#initialize(options) ⇒ ScriptRunner
constructor
A new instance of ScriptRunner.
- #initialize_actions ⇒ Object
- #initialize_central_widget ⇒ Object
- #initialize_menus ⇒ Object
-
#prompt_for_save_if_needed(message = 'Save?') ⇒ Object
Prompts for save if the current tab has been modified.
-
#prompt_for_save_if_needed_on_close ⇒ Object
Prompts the user that unsaved changes have been made before they close the app.
-
#run_callback(script_runner_frame = nil) ⇒ Object
This method disables things that you shouldn’t do while running.
-
#script_call_stack ⇒ Object
Script->Show Call Stack.
-
#script_log_message ⇒ Object
Script->Log Message to Script Log.
-
#script_set_status(message) ⇒ Object
Called by cosmos_script_module by the user calling the status_bar scripting method.
-
#script_toggle_debug ⇒ Object
Script->Toggle Debug.
-
#script_toggle_disconnect ⇒ Object
Script->Toggle Disconnect.
-
#script_view_instrumented ⇒ Object
Script->View Instrumented.
-
#search_text ⇒ Object
Called by the FindReplaceDialog to get the text to search.
-
#stop_callback(script_runner_frame = nil) ⇒ Object
This method reenables things after running.
- #undo_available(bool) ⇒ Object
-
#update_title ⇒ Object
Updates the title appropriately to show the tabs filename and modified status.
Methods included from ScriptAudit
Methods inherited from QtTool
#about, #complete_initialize, create_default_options, graceful_kill, #initialize_help_menu, post_options_parsed_hook, pre_window_new_hook, redirect_io, restore_io
Constructor Details
#initialize(options) ⇒ ScriptRunner
Returns a new instance of ScriptRunner.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 30 def initialize() # All code before super is executed twice in RubyQt Based classes super() # MUST BE FIRST Cosmos.load_cosmos_icon("script_runner.png") setAcceptDrops(true) # Allow dropping in files @config_file = .config_file @server_config_file = .server_config_file # Add procedures to search path System.paths['PROCEDURES'].each do |path| Cosmos.add_to_search_path(path) end initialize_actions() () () complete_initialize() # Load icons @running_icon = Cosmos.get_icon('running.png') @no_icon = Qt::Icon.new # Handle configuration filename = File.join(::Cosmos::USERPATH, %w(config tools script_runner), @config_file) if File.exist?(filename) ScriptRunnerConfig.new(filename) elsif @config_file != 'script_runner.txt' raise "Could not find config file #{filename}" end @procedure_dir = System.paths['PROCEDURES'][0] @debug = false # Create the initial tab(s) if ARGV.length == 0 create_tab() else ARGV.each {|argv_filename| create_tab(argv_filename)} end end |
Class Method Details
.run(option_parser = nil, options = nil) ⇒ Object
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 902 def self.run(option_parser = nil, = nil) Cosmos.catch_fatal_exception do unless option_parser and option_parser, = () .width = 750 .height = 600 .title = "Script Runner : Untitiled" .auto_size = false .config_file = "script_runner.txt" .server_config_file = CmdTlmServer::DEFAULT_CONFIG_FILE option_parser.separator "Script Runner Specific Options:" option_parser.on("-c", "--config FILE", "Use the specified configuration file") do |arg| .config_file = arg end option_parser.on("-s", "--server FILE", "Use the specified server configuration file for disconnect mode") do |arg| .server_config_file = arg end end super(option_parser, ) end end |
Instance Method Details
#active_script_runner_frame ⇒ Object
Returns the script runner frame of the active tab
813 814 815 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 813 def active_script_runner_frame @tab_book.currentTab end |
#close_active_tab ⇒ Object
Closes the active tab
849 850 851 852 853 854 855 856 857 858 859 860 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 849 def close_active_tab if @tab_book.count > 1 active_script_runner_frame(). tab_index = @tab_book.currentIndex @tab_book.removeTab(tab_index) if tab_index >= 1 @tab_book.setCurrentIndex(tab_index - 1) else @tab_book.setCurrentIndex(0) end end end |
#closeEvent(event) ⇒ Object
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 626 def closeEvent(event) if active_script_runner_frame().prompt_if_running_on_close() if prompt_for_save_if_needed_on_close() shutdown_cmd_tlm() @tab_book.tabs.each_with_index do |tab, index| tab. end super(event) else event.ignore() end else event.ignore() end end |
#context_menu(point) ⇒ Object
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 749 def (point) index = 0 @tab_book.tabBar.count.times do break if @tab_book.tabBar.tabRect(index).contains(point) index += 1 end return if (index == @tab_book.tabBar.count) # Bring the right clicked tab to the front @tab_book.setCurrentIndex(index) = Qt::Menu.new() new_action = Qt::Action.new(tr("&New"), self) new_action.statusTip = tr("Create a new script") new_action.connect(SIGNAL('triggered()')) { file_new() } .addAction(new_action) close_action = Qt::Action.new(tr("&Close"), self) close_action.statusTip = tr("Close the script") close_action.connect(SIGNAL('triggered()')) { file_close() } .addAction(close_action) save_action = Qt::Action.new(tr("&Save"), self) save_action.statusTip = tr("Save the script") save_action.connect(SIGNAL('triggered()')) { file_save(false) } .addAction(save_action) save_action = Qt::Action.new(tr("Save &As"), self) save_action.statusTip = tr("Save the script as") save_action.connect(SIGNAL('triggered()')) { file_save(true) } .addAction(save_action) .exec(@tab_book.mapToGlobal(point)) .dispose end |
#create_tab(filename = '') ⇒ Object
Creates a new tab
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 818 def create_tab(filename = '') if filename.empty? tab_item_name = UNTITLED_TAB_TEXT else tab_item_name = ' ' + File.basename(filename) + ' ' end script_runner_frame = ScriptRunnerFrame.new(self) script_runner_frame.toggle_debug(@debug) script_runner_frame.setContentsMargins(5,5,5,5) connect(script_runner_frame, SIGNAL('undoAvailable(bool)'), self, SLOT('undo_available(bool)')) script_runner_frame.run_callback = method(:run_callback) script_runner_frame.stop_callback = method(:stop_callback) script_runner_frame.set_text_from_file(filename) unless filename.empty? script_runner_frame.filename = filename # Register a keypress handler so we can Ctrl-Tab our way through the tabs script_runner_frame.key_press_callback = method(:handle_script_keypress) # Update the title if the frame changes so we can add/remove the asterix script_runner_frame.connect(SIGNAL('modificationChanged(bool)')) { update_title() } @tab_book.addTab(script_runner_frame, tab_item_name) @tab_book.setCurrentIndex(@tab_book.count-1) # index is 0 based # Set the focus on the input now that we've added the tab script_runner_frame.setFocus update_title() end |
#disable_menu_items ⇒ Object
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 699 def # Disable File Menu Items @file_new.setEnabled(false) @file_open.setEnabled(false) @file_close.setEnabled(false) @file_reload.setEnabled(false) @file_save.setEnabled(false) @file_save_as.setEnabled(false) .setEnabled(false) # Disable Edit Menu Items @edit_undo.setEnabled(false) @edit_redo.setEnabled(false) @edit_cut.setEnabled(false) @edit_copy.setEnabled(false) @edit_paste.setEnabled(false) @edit_select_all.setEnabled(false) @edit_comment.setEnabled(false) # Disable Script Menu Items @script_syntax_all.setEnabled(false) @script_syntax_lines.setEnabled(false) @script_mnemonic_all.setEnabled(false) @script_mnemonic_lines.setEnabled(false) @script_execute_lines.setEnabled(false) @script_execute_cursor.setEnabled(false) # Enable Script Runtime Items .setEnabled(true) @script_call_stack.setEnabled(true) end |
#dragEnterEvent(event) ⇒ Object
Drag files into ScriptRunner support
336 337 338 339 340 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 336 def dragEnterEvent(event) if event.mimeData.hasUrls event.acceptProposedAction(); end end |
#dragMoveEvent(event) ⇒ Object
342 343 344 345 346 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 342 def dragMoveEvent(event) if event.mimeData.hasUrls event.acceptProposedAction(); end end |
#dropEvent(event) ⇒ Object
348 349 350 351 352 353 354 355 356 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 348 def dropEvent(event) event.mimeData.urls.each do |url| filename = url.toLocalFile extension = File.extname(filename).to_s.downcase if extension == '.rb' or extension == '.txt' file_open(filename) end end end |
#enable_menu_items ⇒ Object
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 667 def # Enable File Menu Items @file_new.setEnabled(true) @file_open.setEnabled(true) @file_close.setEnabled(true) @file_reload.setEnabled(true) @file_save.setEnabled(true) @file_save_as.setEnabled(true) .setEnabled(true) # Enable Edit Menu Items @edit_undo.setEnabled(true) @edit_redo.setEnabled(true) @edit_cut.setEnabled(true) @edit_copy.setEnabled(true) @edit_paste.setEnabled(true) @edit_select_all.setEnabled(true) @edit_comment.setEnabled(true) # Enable Script Menu Items @script_syntax_all.setEnabled(true) @script_syntax_lines.setEnabled(true) @script_mnemonic_all.setEnabled(true) @script_mnemonic_lines.setEnabled(true) @script_execute_lines.setEnabled(true) @script_execute_cursor.setEnabled(true) # Disable Script Runtime Items' .setEnabled(false) @script_call_stack.setEnabled(false) end |
#file_close ⇒ Object
File->Close
462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 462 def file_close if prompt_for_save_if_needed('Save Current Script?') if @tab_book.count > 1 close_active_tab() else active_script_runner_frame(). @tab_book.setTabText(0, ' Untitled ') @tab_book.currentTab.clear end update_title() end end |
#file_new ⇒ Object
File->New
363 364 365 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 363 def file_new create_tab() end |
#file_open(filename = nil) ⇒ Object
File->Open
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 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 368 def file_open(filename = nil) if !filename filename = Qt::FileDialog.getOpenFileName(self, "Select Script", @procedure_dir) end unless filename.nil? || filename.empty? # If the user opens a file we already have open # just set the current tab to that file and return @tab_book.tabs.each_with_index do |tab, index| if tab.filename == filename @tab_book.setCurrentIndex(index) @tab_book.currentTab.set_text_from_file(filename) @tab_book.currentTab.filename = filename return end end if ((@tab_book.count == 1) && @tab_book.currentTab.filename.empty? && !@tab_book.currentTab.modified) # Active Tab is an unmodified Untitled so just open the file in it @tab_book.currentTab.set_text_from_file(filename) @tab_book.currentTab.filename = filename @tab_book.setTabText(@tab_book.currentIndex, File.basename(filename)) else create_tab(filename) end update_title() @procedure_dir = File.dirname(filename) @procedure_dir << '/' if @procedure_dir[-1..-1] != '/' and @procedure_dir[-1..-1] != '\\' end end |
#file_options ⇒ Object
File->Options
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 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 476 def dialog = Qt::Dialog.new(self) dialog.setWindowTitle('Script Runner Options') layout = Qt::VBoxLayout.new form = Qt::FormLayout.new box = Qt::DoubleSpinBox.new box.setRange(0, 60) box.setValue(ScriptRunnerFrame.line_delay) form.addRow(tr("&Delay between each script line:"), box) pause_on_error = Qt::CheckBox.new form.addRow(tr("&Pause on error:"), pause_on_error) monitor = Qt::CheckBox.new form.addRow(tr("&Monitor limits:"), monitor) if ScriptRunnerFrame.pause_on_error pause_on_error.setCheckState(Qt::Checked) else pause_on_error.setCheckState(Qt::Unchecked) end pause_on_red = Qt::CheckBox.new form.addRow(tr("Pause on &red limit:"), pause_on_red) if ScriptRunnerFrame.monitor_limits monitor.setCheckState(Qt::Checked) pause_on_red.setCheckState(Qt::Checked) if ScriptRunnerFrame.pause_on_red else pause_on_red.setEnabled(false) end monitor.connect(SIGNAL('stateChanged(int)')) do if monitor.isChecked() pause_on_red.setEnabled(true) else pause_on_red.setCheckState(Qt::Unchecked) pause_on_red.setEnabled(false) end end layout.addLayout(form) divider = Qt::Frame.new divider.setFrameStyle(Qt::Frame::HLine | Qt::Frame::Raised) divider.setLineWidth(1) layout.addWidget(divider) ok = Qt::PushButton.new('Ok') ok.setDefault(true) ok.connect(SIGNAL('clicked(bool)')) do ScriptRunnerFrame.line_delay = box.value ScriptRunnerFrame.pause_on_error = (pause_on_error.checkState == Qt::Checked) ScriptRunnerFrame.monitor_limits = (monitor.checkState == Qt::Checked) ScriptRunnerFrame.pause_on_red = (pause_on_red.checkState == Qt::Checked) dialog.accept end cancel = Qt::PushButton.new('Cancel') cancel.connect(SIGNAL('clicked(bool)')) { dialog.reject } = Qt::HBoxLayout.new .addWidget(ok) .addWidget(cancel) layout.addLayout() dialog.setLayout(layout) dialog.exec dialog.dispose end |
#file_reload ⇒ Object
File->Reload
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 402 def file_reload safe_to_continue = true if @tab_book.currentTab.modified case Qt::MessageBox.question(self, # parent 'Discard Changes?', # title 'Warning: Changes will be lost. Continue?', # text Qt::MessageBox::Yes | Qt::MessageBox::No, # buttons Qt::MessageBox::No) # default button when Qt::MessageBox::No safe_to_continue = false end end if safe_to_continue if active_script_runner_frame().filename.empty? active_script_runner_frame().set_text('') else active_script_runner_frame().set_text_from_file(active_script_runner_frame().filename) end @tab_book.currentTab.modified = false update_title() end end |
#file_save(save_as = false) ⇒ Object
File->Save and File->Save As
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 427 def file_save(save_as = false) saved = false filename = active_script_runner_frame().filename if filename.empty? filename = Qt::FileDialog::getSaveFileName(self, # parent 'Save As...', # caption @procedure_dir + '/procedure.rb', # dir 'Procedure Files (*.rb)') # filter elsif save_as filename = Qt::FileDialog::getSaveFileName(self, # parent 'Save As...', # caption filename, # dir 'Procedure Files (*.rb)') # filter end if not filename.nil? and not filename.empty? begin @tab_book.currentTab.filename = filename @tab_book.currentTab.modified = false @tab_book.setTabText(@tab_book.currentIndex, File.basename(filename)) active_script_runner_frame().filename = filename File.open(filename, "w") {|file| file.write(active_script_runner_frame().text)} saved = true update_title() statusBar.showMessage(tr("#{filename} saved")) @procedure_dir = File.dirname(filename) @procedure_dir << '/' if @procedure_dir[-1..-1] != '/' and @procedure_dir[-1..-1] != '\\' rescue => error statusBar.showMessage(tr("Error Saving Script : #{error.class} : #{error.message}")) end end return saved end |
#handle_script_keypress(event) ⇒ Object
736 737 738 739 740 741 742 743 744 745 746 747 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 736 def handle_script_keypress(event) update_title() if event.matches(Qt::KeySequence::NextChild) index = @tab_book.currentIndex + 1 index = 0 if index >= @tab_book.count @tab_book.setCurrentIndex(index) elsif event.matches(Qt::KeySequence::PreviousChild) index = @tab_book.currentIndex - 1 index = @tab_book.count - 1 if index < 0 @tab_book.setCurrentIndex(index) end end |
#handle_tab_change(index) ⇒ Object
Handle the user changing tabs
732 733 734 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 732 def handle_tab_change(index) update_title() end |
#initialize_actions ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 72 def initialize_actions super() # File actions @file_new = Qt::Action.new(Cosmos.get_icon('file.png'), tr('&New'), self) @file_new_keyseq = Qt::KeySequence.new(tr('Ctrl+N')) @file_new.shortcut = @file_new_keyseq @file_new.statusTip = tr('Start a new script') @file_new.connect(SIGNAL('triggered()')) { file_new() } @file_open = Qt::Action.new(Cosmos.get_icon('open.png'), tr('&Open'), self) @file_open_keyseq = Qt::KeySequence.new(tr('Ctrl+O')) @file_open.shortcut = @file_open_keyseq @file_open.statusTip = tr('Open a script') @file_open.connect(SIGNAL('triggered()')) { file_open() } @file_close = Qt::Action.new(tr('&Close'), self) @file_close_keyseq = Qt::KeySequence.new(tr('Ctrl+W')) @file_close.shortcut = @file_close_keyseq @file_close.statusTip = tr('Close the script') @file_close.connect(SIGNAL('triggered()')) { file_close() } @file_reload = Qt::Action.new(tr('&Reload'), self) @file_reload_keyseq = Qt::KeySequence.new(tr('Ctrl+R')) @file_reload.shortcut = @file_reload_keyseq @file_reload.statusTip = tr('Reload a script') @file_reload.connect(SIGNAL('triggered()')) { file_reload() } @file_save = Qt::Action.new(Cosmos.get_icon('save.png'), tr('&Save'), self) @file_save_keyseq = Qt::KeySequence.new(tr('Ctrl+S')) @file_save.shortcut = @file_save_keyseq @file_save.statusTip = tr('Save the script') @file_save.connect(SIGNAL('triggered()')) { file_save(false) } @file_save_as = Qt::Action.new(Cosmos.get_icon('save_as.png'), tr('Save &As'), self) @file_save_as.statusTip = tr('Save the script') @file_save_as.connect(SIGNAL('triggered()')) { file_save(true) } = Qt::Action.new(tr('O&ptions'), self) .statusTip = tr('Application Options') .connect(SIGNAL('triggered()')) { () } # Edit actions @edit_undo = Qt::Action.new(Cosmos.get_icon('undo.png'), tr('&Undo'), self) @edit_undo_keyseq = Qt::KeySequence.new(tr('Ctrl+Z')) @edit_undo.shortcut = @edit_undo_keyseq @edit_undo.statusTip = tr('Undo') @edit_undo.connect(SIGNAL('triggered()')) { active_script_runner_frame().undo } @edit_redo = Qt::Action.new(Cosmos.get_icon('redo.png'), tr('&Redo'), self) @edit_redo_keyseq = Qt::KeySequence.new(tr('Ctrl+Y')) @edit_redo.shortcut = @edit_redo_keyseq @edit_redo.statusTip = tr('Redo') @edit_redo.connect(SIGNAL('triggered()')) { active_script_runner_frame().redo } @edit_cut = Qt::Action.new(Cosmos.get_icon('cut.png'), tr('Cu&t'), self) @edit_cut_keyseq = Qt::KeySequence.new(tr('Ctrl+X')) @edit_cut.shortcut = @edit_cut_keyseq @edit_cut.statusTip = tr('Cut') @edit_cut.connect(SIGNAL('triggered()')) { active_script_runner_frame().cut } @edit_copy = Qt::Action.new(Cosmos.get_icon('copy.png'), tr('&Copy'), self) @edit_copy_keyseq = Qt::KeySequence.new(tr('Ctrl+C')) @edit_copy.shortcut = @edit_copy_keyseq @edit_copy.statusTip = tr('Copy') @edit_copy.connect(SIGNAL('triggered()')) { active_script_runner_frame().copy } @edit_paste = Qt::Action.new(tr('&Paste'), self) @edit_paste_keyseq = Qt::KeySequence.new(tr('Ctrl+V')) @edit_paste.shortcut = @edit_paste_keyseq @edit_paste.statusTip = tr('Paste') @edit_paste.connect(SIGNAL('triggered()')) { active_script_runner_frame().paste } @edit_select_all = Qt::Action.new(tr('Select &All'), self) @edit_select_all_keyseq = Qt::KeySequence.new(tr('Ctrl+A')) @edit_select_all.shortcut = @edit_select_all_keyseq @edit_select_all.statusTip = tr('Select All') @edit_select_all.connect(SIGNAL('triggered()')) { active_script_runner_frame().select_all } @edit_comment = Qt::Action.new(tr('Comment/Uncomment &Lines'), self) @edit_comment_keyseq = Qt::KeySequence.new(tr('Ctrl+K')) @edit_comment.shortcut = @edit_comment_keyseq @edit_comment.statusTip = tr('Comment/Uncomment Lines') @edit_comment.connect(SIGNAL('triggered()')) { active_script_runner_frame().comment_or_uncomment_lines } # Search Actions @search_find = Qt::Action.new(Cosmos.get_icon('search.png'), tr('&Find'), self) @search_find_keyseq = Qt::KeySequence.new(tr('Ctrl+F')) @search_find.shortcut = @search_find_keyseq @search_find.statusTip = tr('Find text') @search_find.connect(SIGNAL('triggered()')) do FindReplaceDialog.show_find(self) end @search_find_next = Qt::Action.new(tr('Find &Next'), self) @search_find_next_keyseq = Qt::KeySequence.new(tr('F3')) @search_find_next.shortcut = @search_find_next_keyseq @search_find_next.statusTip = tr('Find next instance') @search_find_next.connect(SIGNAL('triggered()')) do FindReplaceDialog.find_next(self) end @search_find_previous = Qt::Action.new(tr('Find &Previous'), self) @search_find_previous_keyseq = Qt::KeySequence.new(tr('Shift+F3')) @search_find_previous.shortcut = @search_find_previous_keyseq @search_find_previous.statusTip = tr('Find previous instance') @search_find_previous.connect(SIGNAL('triggered()')) do FindReplaceDialog.find_previous(self) end @search_replace = Qt::Action.new(tr('&Replace'), self) @search_replace_keyseq = Qt::KeySequence.new(tr('Ctrl+H')) @search_replace.shortcut = @search_replace_keyseq @search_replace.statusTip = tr('Replace') @search_replace.connect(SIGNAL('triggered()')) do FindReplaceDialog.show_replace(self) end # Script Actions @script_syntax_all = Qt::Action.new(tr('&Ruby Syntax Check'), self) @script_syntax_all.statusTip = tr('Check ruby syntax of this script') @script_syntax_all.connect(SIGNAL('triggered()')) do active_script_runner_frame().ruby_syntax_check_text() end @script_mnemonic_all = Qt::Action.new(tr('&Mnemonic Check'), self) @script_mnemonic_all.statusTip = tr('Check mnemonics of this script') @script_mnemonic_all.connect(SIGNAL('triggered()')) do active_script_runner_frame().mnemonic_check_text(active_script_runner_frame().text) end @script_execute_lines = Qt::Action.new(tr('&Execute Selected Lines'), self) @script_execute_lines.statusTip = tr('Execute selected lines') @script_execute_lines.connect(SIGNAL('triggered()')) { active_script_runner_frame().run_selection } @script_execute_cursor = Qt::Action.new(tr('E&xecute From Cursor'), self) @script_execute_cursor.statusTip = tr('Execute from cursor position') @script_execute_cursor.connect(SIGNAL('triggered()')) { active_script_runner_frame().run_from_cursor } @script_syntax_lines = Qt::Action.new(tr('Ruby &Syntax Check Selected Lines'), self) @script_syntax_lines.statusTip = tr('Check ruby syntax of selected lines') @script_syntax_lines.connect(SIGNAL('triggered()')) { active_script_runner_frame().ruby_syntax_check_selection } @script_mnemonic_lines = Qt::Action.new(tr('M&nemonic Check Selected Lines'), self) @script_mnemonic_lines.statusTip = tr('Check mnemonics of selected lines') @script_mnemonic_lines.connect(SIGNAL('triggered()')) { active_script_runner_frame().mnemonic_check_selection } @script_audit = Qt::Action.new(tr('&Generate Cmd/Tlm Audit'), self) @script_audit.statusTip = tr('Generate audit about commands sent and telemetry checked') @script_audit.connect(SIGNAL('triggered()')) { script_audit() } @script_instrumented = Qt::Action.new(tr('&View Instrumented Script'), self) @script_instrumented.statusTip = tr('View instrumented script') @script_instrumented.connect(SIGNAL('triggered()')) { script_view_instrumented() } = Qt::Action.new(tr('Log Message to Script Log'), self) .statusTip = tr('Log Message to Script Log') .connect(SIGNAL('triggered()')) { () } .setEnabled(false) @script_call_stack = Qt::Action.new(tr('Show Call Stack'), self) @script_call_stack.statusTip = tr('Show Call Stack') @script_call_stack.connect(SIGNAL('triggered()')) { script_call_stack() } @script_call_stack.setEnabled(false) @script_debug = Qt::Action.new(Cosmos.get_icon('bug.png'), tr('Toggle &Debug'), self) @script_debug_keyseq = Qt::KeySequence.new(tr('Ctrl+D')) @script_debug.shortcut = @script_debug_keyseq @script_debug.statusTip = tr('Toggle debug capabilities for the script') @script_debug.connect(SIGNAL('triggered()')) { script_toggle_debug() } @script_disconnect = Qt::Action.new(Cosmos.get_icon('disconnected.png'), tr('&Toggle Disconnect'), self) @script_disconnect_keyseq = Qt::KeySequence.new(tr('Ctrl+T')) @script_disconnect.shortcut = @script_disconnect_keyseq @script_disconnect.statusTip = tr('Toggle disconnect from the server') @script_disconnect.connect(SIGNAL('triggered()')) { script_toggle_disconnect() } end |
#initialize_central_widget ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 313 def # Create the central widget @tab_book = Qt::TabWidget.new @tab_book.setMovable(true) @tab_book.setContextMenuPolicy(Qt::CustomContextMenu) connect(@tab_book, SIGNAL('customContextMenuRequested(const QPoint&)'), self, SLOT('context_menu(const QPoint&)')) connect(@tab_book, SIGNAL('currentChanged(int)'), self, SLOT('handle_tab_change(int)')) setCentralWidget(@tab_book) # Display a blank message to force the statusBar to show statusBar.showMessage("") end |
#initialize_menus ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 250 def # File Menu = .addMenu(tr('&File')) .addAction(@file_new) .addAction(@file_open) .addAction(@file_close) .addAction(@file_reload) .addSeparator() .addAction(@file_save) .addAction(@file_save_as) .addSeparator() .addAction() .addSeparator() .addAction(@exit_action) # Edit Menu = .addMenu(tr('&Edit')) .addAction(@edit_undo) .addAction(@edit_redo) .addSeparator() .addAction(@edit_cut) .addAction(@edit_copy) .addAction(@edit_paste) .addSeparator() .addAction(@edit_select_all) .addSeparator() .addAction(@edit_comment) # Search Menu = .addMenu(tr('&Search')) .addAction(@search_find) .addAction(@search_find_next) .addAction(@search_find_previous) .addAction(@search_replace) # Script Menu = .addMenu(tr('Scrip&t')) .addAction(@script_syntax_all) .addAction(@script_syntax_lines) .addSeparator() .addAction(@script_mnemonic_all) .addAction(@script_mnemonic_lines) .addSeparator() .addAction(@script_execute_lines) .addAction(@script_execute_cursor) .addSeparator() .addAction(@script_audit) .addAction(@script_instrumented) .addSeparator() .addAction() .addAction(@script_call_stack) .addAction(@script_debug) .addAction(@script_disconnect) # Help Menu @about_string = "Script Runner allows the user to execute commands "\ "and take action on telemetry within a saveable script. "\ "It allows the full power of the Ruby programming language "\ "while defining several keywords to manipulate commands and telemetry in COSMOS.\n" () end |
#prompt_for_save_if_needed(message = 'Save?') ⇒ Object
Prompts for save if the current tab has been modified
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 863 def prompt_for_save_if_needed( = 'Save?') safe_to_continue = true if @tab_book.currentTab.modified case Qt::MessageBox.question( self, # parent 'Save?', # title , # text Qt::MessageBox::Yes | Qt::MessageBox::No | Qt::MessageBox::Cancel, # buttons Qt::MessageBox::Cancel) # default button when Qt::MessageBox::Cancel safe_to_continue = false when Qt::MessageBox::Yes saved = file_save(false) if not saved safe_to_continue = false end end end return safe_to_continue end |
#prompt_for_save_if_needed_on_close ⇒ Object
Prompts the user that unsaved changes have been made before they close the app
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 885 def prompt_for_save_if_needed_on_close safe_to_continue = true @tab_book.tabs.each_with_index do |tab, index| if tab.modified @tab_book.setCurrentIndex(index) if tab.filename.empty? = "Save changes to 'Untitled'?" else = "Save changes to '#{tab.filename}'?" end safe_to_continue = prompt_for_save_if_needed() #~ break unless safe_to_continue end end return safe_to_continue end |
#run_callback(script_runner_frame = nil) ⇒ Object
This method disables things that you shouldn’t do while running
643 644 645 646 647 648 649 650 651 652 653 654 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 643 def run_callback(script_runner_frame = nil) if script_runner_frame @tab_book.tabs.each_with_index do |tab, index| if tab != script_runner_frame @tab_book.setTabEnabled(index, false) else @tab_book.tabBar.setTabIcon(index, @running_icon) end end end () end |
#script_call_stack ⇒ Object
Script->Show Call Stack
593 594 595 596 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 593 def script_call_stack trace = active_script_runner_frame().current_backtrace ScrollTextDialog.new(self, 'Call Stack', trace.join("\n")) end |
#script_log_message ⇒ Object
Script->Log Message to Script Log
584 585 586 587 588 589 590 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 584 def = () if active_script_runner_frame().scriptrunner_puts 'User logged: ' + .to_s active_script_runner_frame().handle_output_io end end |
#script_set_status(message) ⇒ Object
Called by cosmos_script_module by the user calling the status_bar scripting method
792 793 794 795 796 797 798 799 800 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 792 def script_set_status() Qt.execute_in_main_thread(true) do # Check for self.disposed? to work around crash when using SimpleCov unless self.disposed? = statusBar() .showMessage() end end end |
#script_toggle_debug ⇒ Object
Script->Toggle Debug
599 600 601 602 603 604 605 606 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 599 def script_toggle_debug @debug = !@debug if @tab_book.count > 0 (0..(@tab_book.count - 1)).each do |index| @tab_book.tab(index).toggle_debug(@debug) end end end |
#script_toggle_disconnect ⇒ Object
Script->Toggle Disconnect
609 610 611 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 609 def script_toggle_disconnect @server_config_file = active_script_runner_frame().toggle_disconnect(@server_config_file) end |
#script_view_instrumented ⇒ Object
Script->View Instrumented
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 545 def script_view_instrumented begin instrumented_script = ScriptRunnerFrame.instrument_script(active_script_runner_frame().text, active_script_runner_frame().filename, true) rescue StopScript return end # Show Dialog box containing script code box = Qt::Dialog.new(self) box.setWindowTitle('Instrumented Script') text = Qt::PlainTextEdit.new text.setWordWrapMode(Qt::TextOption::NoWrap) text.setReadOnly(true) text.setPlainText(instrumented_script) layout = Qt::VBoxLayout.new layout.addWidget(text) ok = Qt::PushButton.new('OK') ok.setDefault(true) ok.connect(SIGNAL('clicked(bool)')) { box.accept } = Qt::HBoxLayout.new .addStretch .addWidget(ok) .addStretch layout.addLayout() box.setLayout(layout) box.setMinimumWidth([Qt::CoreApplication.instance.desktop.availableGeometry.width, text.document.size.width].min) screen_height = Qt::CoreApplication.instance.desktop.availableGeometry.height preferred_height = (text.document.size.height * text.fontMetrics.lineSpacing) + text.horizontalScrollBar.height + ok.sizeHint.height + (layout.spacing * 5) box.setMinimumHeight([screen_height, preferred_height].min) box.exec box.dispose end |
#search_text ⇒ Object
Called by the FindReplaceDialog to get the text to search
618 619 620 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 618 def search_text active_script_runner_frame().script end |
#stop_callback(script_runner_frame = nil) ⇒ Object
This method reenables things after running
657 658 659 660 661 662 663 664 665 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 657 def stop_callback(script_runner_frame = nil) if script_runner_frame @tab_book.tabs.each_with_index do |tab, index| @tab_book.setTabEnabled(index, true) @tab_book.tabBar.setTabIcon(index, @no_icon) end end () end |
#undo_available(bool) ⇒ Object
622 623 624 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 622 def undo_available(bool) update_title() end |
#update_title ⇒ Object
Updates the title appropriately to show the tabs filename and modified status
803 804 805 806 807 808 809 810 |
# File 'lib/cosmos/tools/script_runner/script_runner.rb', line 803 def update_title if @tab_book.currentTab.filename.empty? self.setWindowTitle("Script Runner : Untitled") else self.setWindowTitle("Script Runner : #{@tab_book.currentTab.filename}") end self.setWindowTitle(self.windowTitle << '*') if @tab_book.currentTab.modified end |