Class: Cosmos::ScriptRunnerFrame

Inherits:
Qt::Widget
  • Object
show all
Defined in:
lib/cosmos/tools/script_runner/script_runner_frame.rb

Overview

Frame within ScriptRunner and TestRunner that handles instrumenting the script and running it. This includes handling all the user interation and how to run, step, pause, and stop a script.

Constant Summary collapse

CMD_KEYWORDS =
%w(cmd cmd_no_range_check cmd_no_hazardous_check cmd_no_checks)
TLM_KEYWORDS =
%w(tlm tlm_raw tlm_formatted tlm_with_units limits_enabled? \
enable_limits disable_limits wait_tolerance wait_tolerance_raw \
check_tolerance check_tolerance_raw wait_check_tolerance \
wait_check_tolerance_raw)
SET_TLM_KEYWORDS =
%w(set_tlm set_tlm_raw override_tlm_raw normalize_tlm_raw)
CHECK_KEYWORDS =
%w(check check_raw wait wait_raw wait_check wait_check_raw)
INSTANCE_VARS =
%w(__return_val close_on_complete error eval_error filename instrumented_script \
line_number line_offset saved_instance saved_run_thread text text_binding uncaught_exception)
@@instance =
nil
@@run_thread =
nil
@@breakpoints =
{}
@@step_mode =
false
@@line_delay =
0.1
@@instrumented_cache =
{}
@@file_cache =
{}
@@output_thread =
nil
@@limits_monitor_thread =
nil
@@pause_on_error =
true
@@monitor_limits =
false
@@pause_on_red =
false
@@show_backtrace =
false
@@error =
nil
@@output_sleeper =
Sleeper.new
@@limits_sleeper =
Sleeper.new
@@cancel_output =
false
@@cancel_limits =
false
@@file_number =
1
@@default_font =
Cosmos.get_default_font

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, default_tab_text = 'Untitled') ⇒ ScriptRunnerFrame

Returns a new instance of ScriptRunnerFrame.



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
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 134

def initialize(parent, default_tab_text = 'Untitled')
  super(parent)
  @default_tab_text = '  ' + default_tab_text + '  '
  # Keep track of whether this frame has been fully initialized
  @initialized = false
  @debug_frame = nil

  # Keep track of a unique file number so we can differentiate untitled tabs
  @file_number = @@file_number
  @@file_number +=1
  @filename = ''

  @layout = Qt::VBoxLayout.new
  @layout.setContentsMargins(0,0,0,0)

  # Add Realtime Button Bar
  @realtime_button_bar = RealtimeButtonBar.new(self)
  @realtime_button_bar.state = 'Stopped'
  @realtime_button_bar.step_callback = method(:handle_step_button)
  @realtime_button_bar.start_callback = method(:handle_start_go_button)
  @realtime_button_bar.pause_callback = method(:handle_pause_retry_button)
  @realtime_button_bar.stop_callback  = method(:handle_stop_button)
  @layout.addWidget(@realtime_button_bar)

  # Create shortcuts to activate the RealtimeButtonBar actions
  step = Qt::Shortcut.new(Qt::KeySequence.new(Qt::Key_F10), self)
  self.connect(step, SIGNAL('activated()')) { handle_step_button() }
  start_go = Qt::Shortcut.new(Qt::KeySequence.new(Qt::Key_F5), self)
  self.connect(start_go, SIGNAL('activated()')) { handle_start_go_button() }
  pause_retry = Qt::Shortcut.new(Qt::KeySequence.new(Qt::Key_F6), self)
  self.connect(pause_retry, SIGNAL('activated()')) { handle_pause_retry_button() }
  stop = Qt::Shortcut.new(Qt::KeySequence.new(Qt::Key_F7), self)
  self.connect(stop, SIGNAL('activated()')) { handle_stop_button() }

  # Create a splitter to hold the script text area and the script output text area.
  @splitter = Qt::Splitter.new(Qt::Vertical, self)
  @layout.addWidget(@splitter)
  @top_widget = Qt::Widget.new(@splitter)
  @top_widget.setContentsMargins(0,0,0,0)
  @top_frame = Qt::VBoxLayout.new(@top_widget)
  @top_frame.setContentsMargins(0,0,0,0)

  # Add Initial Text Window
  @script = create_ruby_editor()
  @script.filename = unique_filename()
  @script.connect(SIGNAL('modificationChanged(bool)')) do |changed|
    emit modificationChanged(changed)
  end
  @top_frame.addWidget(@script)

  # Set self as the gui window to allow prompts and other popups to appear
  set_cmd_tlm_gui_window(self)

  # Add change handlers
  connect(@script,
          SIGNAL('undoAvailable(bool)'),
          self,
          SLOT('undo_available(bool)'))

  # Add Output Text
  @bottom_frame = Qt::Widget.new
  @bottom_layout = Qt::VBoxLayout.new
  @bottom_layout.setContentsMargins(0,0,0,0)
  @bottom_layout_label = Qt::Label.new("Script Output:")
  @bottom_layout.addWidget(@bottom_layout_label)
  @output = Qt::PlainTextEdit.new
  @output.setReadOnly(true)
  @output.setMaximumBlockCount(100)
  @bottom_layout.addWidget(@output)
  @bottom_frame.setLayout(@bottom_layout)
  @splitter.addWidget(@bottom_frame)
  @splitter.setStretchFactor(0,10)
  @splitter.setStretchFactor(1,1)

  setLayout(@layout)

  # Configure Variables
  @line_offset = 0
  @output_io = StringIO.new('', 'r+')
  @output_io_mutex = Mutex.new
  @change_callback = nil
  @run_callback = nil
  @stop_callback = nil
  @error_callback = nil
  @pause_callback = nil
  @allow_start = true
  @continue_after_error = true
  @debug_text = nil
  @debug_history = []
  @debug_code_completion = nil
  @top_level_instrumented_cache = nil
  @output_time = Time.now.sys
  initialize_variables()

  # Redirect $stdout and $stderr
  redirect_io()

  # Create Tabbook
  @tab_book = Qt::TabWidget.new
  @tab_book_shown = false

  @find_dialog = nil
  @replace_dialog = nil

  mark_breakpoints(@script.filename)
end

Instance Attribute Details

#change_callbackObject

Returns the value of attribute change_callback.



96
97
98
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 96

def change_callback
  @change_callback
end

#continue_after_errorObject

Returns the value of attribute continue_after_error.



102
103
104
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 102

def continue_after_error
  @continue_after_error
end

#error_callbackObject

Returns the value of attribute error_callback.



99
100
101
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 99

def error_callback
  @error_callback
end

#exceptionsObject

Returns the value of attribute exceptions.



103
104
105
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 103

def exceptions
  @exceptions
end

#filenameObject

Returns the value of attribute filename.



101
102
103
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 101

def filename
  @filename
end

#inline_returnObject

Deprecated and unused - Here to prevent cache errors for old scripts



105
106
107
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 105

def inline_return
  @inline_return
end

#inline_return_paramsObject

Deprecated and unused - Here to prevent cache errors for old scripts



106
107
108
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 106

def inline_return_params
  @inline_return_params
end

#message_logObject (readonly)

Returns the value of attribute message_log.



107
108
109
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 107

def message_log
  @message_log
end

#pause_callbackObject

Returns the value of attribute pause_callback.



100
101
102
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 100

def pause_callback
  @pause_callback
end

#run_callbackObject

Returns the value of attribute run_callback.



97
98
99
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 97

def run_callback
  @run_callback
end

#scriptObject (readonly)

Returns the value of attribute script.



111
112
113
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 111

def script
  @script
end

#script_bindingObject

Returns the value of attribute script_binding.



104
105
106
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 104

def script_binding
  @script_binding
end

#script_classObject (readonly)

Returns the value of attribute script_class.



108
109
110
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 108

def script_class
  @script_class
end

#stdout_max_linesObject

Returns the value of attribute stdout_max_lines.



110
111
112
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 110

def stdout_max_lines
  @stdout_max_lines
end

#stop_callbackObject

Returns the value of attribute stop_callback.



98
99
100
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 98

def stop_callback
  @stop_callback
end

#top_level_instrumented_cacheObject (readonly)

Returns the value of attribute top_level_instrumented_cache.



109
110
111
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 109

def top_level_instrumented_cache
  @top_level_instrumented_cache
end

#use_instrumentationObject

Returns the value of attribute use_instrumentation.



95
96
97
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 95

def use_instrumentation
  @use_instrumentation
end

Class Method Details

.clear_breakpoint(filename, line_number) ⇒ Object



1064
1065
1066
1067
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1064

def self.clear_breakpoint(filename, line_number)
  @@breakpoints[filename] ||= {}
  @@breakpoints[filename].delete(line_number) if @@breakpoints[filename][line_number]
end

.clear_breakpoints(filename = nil) ⇒ Object



1069
1070
1071
1072
1073
1074
1075
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1069

def self.clear_breakpoints(filename = nil)
  if filename == nil or filename.empty?
    @@breakpoints = {}
  else
    @@breakpoints.delete(filename)
  end
end

.file_cacheObject



386
387
388
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 386

def self.file_cache
  @@file_cache
end

.file_cache=(value) ⇒ Object



390
391
392
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 390

def self.file_cache=(value)
  @@file_cache = value
end

.instanceObject



347
348
349
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 347

def self.instance
  @@instance
end

.instance=(value) ⇒ Object



351
352
353
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 351

def self.instance=(value)
  @@instance = value
end

.instrument_script(text, filename, mark_private = false) ⇒ Object



519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 519

def self.instrument_script(text, filename, mark_private = false)
  if filename and !filename.empty?
    @@file_cache[filename] = text.clone
  end

  ruby_lex_utils = RubyLexUtils.new
  instrumented_text = ''

  Qt.execute_in_main_thread(true) do
    window = Qt::CoreApplication.instance.activeWindow
    @cancel_instrumentation = false
    ProgressDialog.execute(window, # parent
                           "Instrumenting: #{File.basename(filename.to_s)}",
                           500,    # width
                           100,    # height
                           true,   # show overall progress
                           false,  # don't show step progress
                           false,  # don't show text
                           false,  # don't show done
                           true) do |progress_dialog| # show cancel
      progress_dialog.cancel_callback = lambda { |dialog| @cancel_instrumentation = true; [true, false] }
      progress_dialog.enable_cancel_button
      comments_removed_text = ruby_lex_utils.remove_comments(text)
      num_lines = comments_removed_text.num_lines.to_f
      num_lines = 1 if num_lines < 1
      instrumented_text =
        instrument_script_implementation(ruby_lex_utils,
                                         comments_removed_text,
                                         num_lines,
                                         progress_dialog,
                                         filename,
                                         mark_private)
      progress_dialog.close_done
    end
  end

  Kernel.raise StopScript if @cancel_instrumentation or ProgressDialog.canceled?
  instrumented_text
end

.instrument_script_implementation(ruby_lex_utils, comments_removed_text, num_lines, progress_dialog, filename, mark_private = false) ⇒ Object



559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 559

def self.instrument_script_implementation(ruby_lex_utils,
                                          comments_removed_text,
                                          num_lines,
                                          progress_dialog,
                                          filename,
                                          mark_private = false)
  if mark_private
    instrumented_text = 'private; '
  else
    instrumented_text = ''
  end

  ruby_lex_utils.each_lexed_segment(comments_removed_text) do |segment, instrumentable, inside_begin, line_no|
    return nil if @cancel_instrumentation
    instrumented_line = ''
    if instrumentable
      # Add a newline if it's empty to ensure the instrumented code has
      # the same number of lines as the original script. Note that the
      # segment could have originally had comments but they were stripped in
      # ruby_lex_utils.remove_comments
      if segment.strip.empty?
        instrumented_text << "\n"
        next
      end

      # Create a variable to hold the segment's return value
      instrumented_line << "__return_val = nil; "

      # If not inside a begin block then create one to catch exceptions
      unless inside_begin
        instrumented_line << 'begin; '
      end

      # Add preline instrumentation
      instrumented_line << "ScriptRunnerFrame.instance.script_binding = binding(); "\
        "ScriptRunnerFrame.instance.pre_line_instrumentation('#{filename}', #{line_no}); "

      # Add the actual line
      instrumented_line << "__return_val = begin; "
      instrumented_line << segment
      instrumented_line.chomp!

      # Add postline instrumentation
      instrumented_line << " end; ScriptRunnerFrame.instance.post_line_instrumentation('#{filename}', #{line_no}); "

      # Complete begin block to catch exceptions
      unless inside_begin
        instrumented_line << "rescue Exception => eval_error; "\
        "retry if ScriptRunnerFrame.instance.exception_instrumentation(eval_error, '#{filename}', #{line_no}); end; "
      end

      instrumented_line << " __return_val\n"
    else
      unless segment =~ /^\s*end\s*$/ or segment =~ /^\s*when .*$/
        num_left_brackets = segment.count('{')
        num_right_brackets = segment.count('}')
        num_left_square_brackets = segment.count('[')
        num_right_square_brackets = segment.count(']')

        if (num_right_brackets > num_left_brackets) ||
          (num_right_square_brackets > num_left_square_brackets)
          instrumented_line = segment
        else
          instrumented_line = "ScriptRunnerFrame.instance.pre_line_instrumentation('#{filename}', #{line_no}); " + segment
        end
      else
        instrumented_line = segment
      end
    end

    instrumented_text << instrumented_line

    progress_dialog.set_overall_progress(line_no / num_lines) if progress_dialog and line_no
  end
  instrumented_text
end

.instrumented_cacheObject



378
379
380
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 378

def self.instrumented_cache
  @@instrumented_cache
end

.instrumented_cache=(value) ⇒ Object



382
383
384
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 382

def self.instrumented_cache=(value)
  @@instrumented_cache = value
end

.line_delayObject



370
371
372
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 370

def self.line_delay
  @@line_delay
end

.line_delay=(value) ⇒ Object



374
375
376
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 374

def self.line_delay=(value)
  @@line_delay = value
end

.monitor_limitsObject



402
403
404
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 402

def self.monitor_limits
  @@monitor_limits
end

.monitor_limits=(value) ⇒ Object



406
407
408
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 406

def self.monitor_limits=(value)
  @@monitor_limits = value
end

.pause_on_errorObject



394
395
396
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 394

def self.pause_on_error
  @@pause_on_error
end

.pause_on_error=(value) ⇒ Object



398
399
400
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 398

def self.pause_on_error=(value)
  @@pause_on_error = value
end

.pause_on_redObject



410
411
412
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 410

def self.pause_on_red
  @@pause_on_red
end

.pause_on_red=(value) ⇒ Object



414
415
416
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 414

def self.pause_on_red=(value)
  @@pause_on_red = value
end

.running?Boolean

Returns:

  • (Boolean)


452
453
454
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 452

def self.running?
  if @@run_thread then true else false end
end

.set_breakpoint(filename, line_number) ⇒ Object



1059
1060
1061
1062
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1059

def self.set_breakpoint(filename, line_number)
  @@breakpoints[filename] ||= {}
  @@breakpoints[filename][line_number] = true
end

.show_backtraceObject



418
419
420
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 418

def self.show_backtrace
  @@show_backtrace
end

.show_backtrace=(value) ⇒ Object



422
423
424
425
426
427
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 422

def self.show_backtrace=(value)
  @@show_backtrace = value
  if @@show_backtrace and @@error
    puts Time.now.sys.formatted + " (SCRIPTRUNNER): "  + "Most recent exception:\n" + @@error.formatted
  end
end

.step_modeObject



355
356
357
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 355

def self.step_mode
  @@step_mode
end

.step_mode=(value) ⇒ Object



359
360
361
362
363
364
365
366
367
368
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 359

def self.step_mode=(value)
  @@step_mode = value
  if self.instance
    if value
      self.instance.pause
    else
      self.instance.go
    end
  end
end

.stop!Object



480
481
482
483
484
485
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 480

def self.stop!
  if @@run_thread
    Cosmos.kill_thread(nil, @@run_thread)
    @@run_thread = nil
  end
end

Instance Method Details

#active_script_highlight(color) ⇒ Object



326
327
328
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 326

def active_script_highlight(color)
  Qt.execute_in_main_thread { @active_script.highlight_line(color) }
end

#allow_start=(value) ⇒ Object



330
331
332
333
334
335
336
337
338
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 330

def allow_start=(value)
  @allow_start = value
  if @allow_start
    @realtime_button_bar.start_button.setEnabled(true)
  elsif not running?
    @realtime_button_bar.start_button.setEnabled(false)
    @script.setReadOnly(true)
  end
end

#breakpoint_cleared(line) ⇒ Object



735
736
737
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 735

def breakpoint_cleared(line)
  ScriptRunnerFrame.clear_breakpoint(current_tab_filename(), line)
end

#breakpoint_set(line) ⇒ Object

Implement the breakpoint callbacks from the RubyEditor



722
723
724
725
726
727
728
729
730
731
732
733
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 722

def breakpoint_set(line)
  # Check for blank and comment lines which can't have a breakpoint.
  # There are other un-instrumentable lines which don't support breakpoints
  # but this is the most common and is an easy check.
  # Note: line is 1 based but @script.get_line is zero based so subtract 1
  text = @active_script.get_line(line - 1)
  if text && (text.strip.empty? || text.strip[0] == '#')
    @active_script.clear_breakpoint(line) # Immediately clear it
  else
    ScriptRunnerFrame.set_breakpoint(current_tab_filename(), line)
  end
end

#breakpoints_clearedObject



739
740
741
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 739

def breakpoints_cleared
  ScriptRunnerFrame.clear_breakpoints(current_tab_filename())
end

#clearObject



340
341
342
343
344
345
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 340

def clear
  self.set_text('')
  self.filename = ''
  @script.filename = unique_filename()
  self.modified = false
end

#clear_breakpointsObject



1077
1078
1079
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1077

def clear_breakpoints
  ScriptRunnerFrame.clear_breakpoints(unique_filename())
end

#comment_or_uncomment_linesObject



770
771
772
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 770

def comment_or_uncomment_lines
  @script.comment_or_uncomment_lines unless running?()
end

#copyObject



758
759
760
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 758

def copy
  @script.copy unless running?()
end

#create_ruby_editorObject



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
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 257

def create_ruby_editor
  # Add Initial Text Window
  script = RubyEditor.new(self, @@default_font)
  script.enable_breakpoints = true if @debug_frame
  connect(script,
          SIGNAL('breakpoint_set(int)'),
          self,
          SLOT('breakpoint_set(int)'))
  connect(script,
          SIGNAL('breakpoint_cleared(int)'),
          self,
          SLOT('breakpoint_cleared(int)'))
  connect(script,
          SIGNAL('breakpoints_cleared()'),
          self,
          SLOT('breakpoints_cleared()'))
  script.connect(SIGNAL('font_changed(QFont)')) do |font|
    # Remember changed fonts for future tabs
    @@default_font = font
  end

  # Add right click menu
  script.setContextMenuPolicy(Qt::CustomContextMenu)
  connect(script,
          SIGNAL('customContextMenuRequested(const QPoint&)'),
          self,
          SLOT('context_menu(const QPoint&)'))

  return script
end

#current_backtraceObject



1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1209

def current_backtrace
  trace = []
  Qt.execute_in_main_thread(true) do
    if @@run_thread
      temp_trace = @@run_thread.backtrace
      cosmos_lib = Regexp.new(File.join(Cosmos::PATH, 'lib'))
      temp_trace.each do |line|
        next if line =~ cosmos_lib
        trace << line
      end
    end
  end
  trace
end

#current_tab_filenameObject



249
250
251
252
253
254
255
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 249

def current_tab_filename
  if @tab_book_shown
    return @tab_book.widget(@tab_book.currentIndex).filename
  else
    return @script.filename
  end
end

#cutObject



754
755
756
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 754

def cut
  @script.cut unless running?()
end

#disable_retryObject



499
500
501
502
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 499

def disable_retry
  @realtime_button_bar.start_button.setText('Skip')
  @realtime_button_bar.pause_button.setDisabled(true)
end

#enable_retryObject



504
505
506
507
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 504

def enable_retry
  @realtime_button_bar.start_button.setText('Go')
  @realtime_button_bar.pause_button.setDisabled(false)
end

#exception_instrumentation(error, filename, line_number) ⇒ Object



678
679
680
681
682
683
684
685
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 678

def exception_instrumentation(error, filename, line_number)
  if error.class == StopScript || error.class == SkipTestCase || !@use_instrumentation
    Kernel.raise error
  elsif !error.eql?(@@error)
    line_number = line_number + @line_offset if @active_script.object_id == @script.object_id
    handle_exception(error, false, filename, line_number)
  end
end

#goObject



460
461
462
463
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 460

def go
  @go    = true
  @pause = false unless @@step_mode
end

#go?Boolean

Returns:

  • (Boolean)


465
466
467
468
469
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 465

def go?
  temp = @go
  @go = false
  temp
end

#graceful_killObject



1284
1285
1286
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1284

def graceful_kill
  # Just to avoid warning
end

#handle_output_io(filename = @current_filename, line_number = @current_line_number) ⇒ Object



1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1228

def handle_output_io(filename = @current_filename, line_number = @current_line_number)
  @output_time = Time.now.sys
  Qt.execute_in_main_thread(true) do
    if @output_io.string[-1..-1] == "\n"
      time_formatted = Time.now.sys.formatted
      lines_to_write = ''
      out_line_number = line_number.to_s
      out_filename = File.basename(filename) if filename

      # Build each line to write
      string = @output_io.string.clone
      @output_io.string = @output_io.string[string.length..-1]
      line_count = 0
      string.each_line do |out_line|
        color = nil
        if out_line[0..1] == '20' and out_line[10] == ' ' and out_line[23..24] == ' ('
          line_to_write = out_line
        else
          if filename
            line_to_write = time_formatted + " (#{out_filename}:#{out_line_number}): "  + out_line
          else
            line_to_write = time_formatted + " (SCRIPTRUNNER): "  + out_line
            color = Cosmos::BLUE
          end
        end
        @output.add_formatted_text(line_to_write, color)
        lines_to_write << line_to_write

        line_count += 1
        if line_count > @stdout_max_lines
          out_line = "ERROR: Too much written to stdout.  Truncating output to #{@stdout_max_lines} lines.\n"
          if filename
            line_to_write = time_formatted + " (#{out_filename}:#{out_line_number}): "  + out_line
          else
            line_to_write = time_formatted + " (SCRIPTRUNNER): "  + out_line
          end
          @output.addText(line_to_write, Cosmos::RED)
          lines_to_write << line_to_write
          break
        end
      end # string.each_line

      # Actually add to the GUI
      @output.flush

      # Add to the message log
      if @filename.empty?
        @message_log ||= MessageLog.new("sr_untitled")
      else
        @message_log ||= MessageLog.new("sr_#{File.basename(@filename).split('.')[0]}")
      end
      @message_log.write(lines_to_write)
    end
  end
end

#hide_debugObject



1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1032

def hide_debug
  # Since we're disabling debug, clear the breakpoints and disable them
  ScriptRunnerFrame.clear_breakpoints()
  @script.clear_breakpoints
  @script.enable_breakpoints = false
  if @tab_book_shown
    if @tab_book.count > 0
      (0..(@tab_book.count - 1)).each do |index|
        @tab_book.widget(index).enable_breakpoints = false
      end
    end
  end
  @realtime_button_bar.step_button.setHidden(true)
  # Remove the debug frame
  @bottom_frame.layout.takeAt(@bottom_frame.layout.count - 1) if @debug_frame
  @debug_frame.removeAll
  @debug_frame.dispose
  @debug_frame = nil

  # If step mode was previously active then pause the script so it doesn't
  # just take off when we end the debugging session
  if @@step_mode
    pause()
    @@step_mode = false
  end
end

#mnemonic_check_selectionObject



864
865
866
867
868
869
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 864

def mnemonic_check_selection
  unless self.class.running?()
    selection = @script.selected_lines
    mnemonic_check_text(selection, @script.selection_start_line+1) if selection
  end
end

#mnemonic_check_text(text, start_line_number = 1) ⇒ Object



871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 871

def mnemonic_check_text(text, start_line_number = 1)
  results = []
  line_number = start_line_number
  text.each_line do |line|
    if line =~ /\(/
      result = nil
      keyword = line.split('(')[0].split[-1]
      if CMD_KEYWORDS.include? keyword
        result = mnemonic_check_cmd_line(keyword, line_number, line)
      elsif TLM_KEYWORDS.include? keyword
        result = mnemonic_check_tlm_line(keyword, line_number, line)
      elsif SET_TLM_KEYWORDS.include? keyword
        result = mnemonic_check_set_tlm_line(keyword, line_number, line)
      elsif CHECK_KEYWORDS.include? keyword
        result = mnemonic_check_check_line(keyword, line_number, line)
      end
      results << result if result
    end
    line_number += 1
  end

  if results.empty?
    Qt::MessageBox.information(self,
                               'Mnemonic Check Successful',
                               'Mnemonic Check Found No Errors')
  else
    dialog = Qt::Dialog.new(self) do |box|
      box.setWindowTitle('Mnemonic Check Failed')
      text = Qt::PlainTextEdit.new
      text.setReadOnly(true)
      text.setPlainText(results.join("\n"))
      frame = Qt::VBoxLayout.new(box)
      ok = Qt::PushButton.new('Ok')
      ok.setDefault(true)
      ok.connect(SIGNAL('clicked(bool)')) { box.accept }
      frame.addWidget(text)
      frame.addWidget(ok)
    end
    dialog.exec
    dialog.dispose
  end
end

#modifiedObject



310
311
312
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 310

def modified
  @script.document.isModified()
end

#modified=(bool) ⇒ Object



314
315
316
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 314

def modified=(bool)
  @script.document.setModified(bool)
end

#pasteObject



762
763
764
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 762

def paste
  @script.paste unless running?()
end

#pauseObject



471
472
473
474
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 471

def pause
  @pause = true
  @go    = false
end

#pause?Boolean

Returns:

  • (Boolean)


476
477
478
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 476

def pause?
  @pause
end

#perform_breakpoint(filename, line_number) ⇒ Object



692
693
694
695
696
697
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 692

def perform_breakpoint(filename, line_number)
  mark_breakpoint()
  scriptrunner_puts "Hit Breakpoint at #{filename}:#{line_number}"
  handle_output_io(filename, line_number)
  wait_for_go_or_stop()
end

#perform_pauseObject



687
688
689
690
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 687

def perform_pause
  mark_paused()
  wait_for_go_or_stop()
end

#post_line_instrumentation(filename, line_number) ⇒ Object



671
672
673
674
675
676
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 671

def post_line_instrumentation(filename, line_number)
  if @use_instrumentation
    line_number = line_number + @line_offset if @active_script.object_id == @script.object_id
    handle_output_io(filename, line_number)
  end
end

#pre_line_instrumentation(filename, line_number) ⇒ Object



636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 636

def pre_line_instrumentation(filename, line_number)
  @current_filename = filename
  @current_line_number = line_number
  if @use_instrumentation
    # Clear go
    @go = false

    # Handle stopping mid-script if necessary
    Kernel.raise StopScript if @stop

    # Handle needing to change tabs
    handle_potential_tab_change(filename)

    # Adjust line number for offset in main script
    line_number = line_number + @line_offset if @active_script.object_id == @script.object_id
    detail_string = nil
    if filename
      detail_string = File.basename(filename) << ':' << line_number.to_s
    end
    Logger.detail_string = detail_string

    # Highlight the line that is about to run
    Qt.execute_in_main_thread(true) do
      @active_script.center_line(line_number)
      @active_script.highlight_line
    end

    # Handle pausing the script
    handle_pause(filename, line_number)

    # Handle delay between lines
    handle_line_delay()
  end
end

#prompt_if_running_on_closeObject

Prompts the user that a script is running before they close the app



700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 700

def prompt_if_running_on_close
  safe_to_continue = true
  if running?
    case Qt::MessageBox.warning(
      self,      # parent
      'Warning', # title
      'A Script is Running! Close Anyways?', # text
      Qt::MessageBox::Yes | Qt::MessageBox::No, # buttons
      Qt::MessageBox::No) # default button
    when Qt::MessageBox::Yes
      safe_to_continue = true
      ScriptRunnerFrame.stop!
    else
      safe_to_continue = false
    end
  end
  return safe_to_continue
end

#redoObject



750
751
752
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 750

def redo
  @script.redo unless running?()
end

#retry_neededObject



495
496
497
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 495

def retry_needed
  @retry_needed = true
end

#retry_needed?Boolean

Returns:

  • (Boolean)


491
492
493
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 491

def retry_needed?
  @retry_needed
end

#ruby_syntax_check_selectionObject



829
830
831
832
833
834
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 829

def ruby_syntax_check_selection
  unless self.class.running?()
    selection = @script.selected_lines
    ruby_syntax_check_text(selection) if selection
  end
end

#ruby_syntax_check_text(selection = nil) ⇒ Object



836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 836

def ruby_syntax_check_text(selection = nil)
  unless self.class.running?()
    selection = text() unless selection
    check_process = IO.popen("ruby -c -rubygems 2>&1", 'r+')
    check_process.write("require 'cosmos'; require 'cosmos/script'; " + selection)
    check_process.close_write
    results = check_process.gets
    check_process.close
    if results
      if results =~ /Syntax OK/
        Qt::MessageBox.information(self, 'Syntax Check Successful', results)
      else
        # Results is a string like this: ":2: syntax error ..."
        # Normally the procedure comes before the first colon but since we
        # are writing to the process this is blank so we throw it away
        _, line_no, error = results.split(':')
        Qt::MessageBox.warning(self,
                               'Syntax Check Failed',
                               "Error on line #{line_no}: #{error.strip}")
      end
    else
      Qt::MessageBox.critical(self,
                              'Syntax Check Exception',
                              'Ruby syntax check unexpectedly returned nil')
    end
  end
end

#runObject



509
510
511
512
513
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 509

def run
  unless self.class.running?()
    run_text(@script.toPlainText)
  end
end

#run_and_close_on_complete(text_binding = nil) ⇒ Object



515
516
517
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 515

def run_and_close_on_complete(text_binding = nil)
  run_text(@script.toPlainText, 0, text_binding, true)
end

#run_from_cursorObject



819
820
821
822
823
824
825
826
827
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 819

def run_from_cursor
  unless self.class.running?()
    line_number = @script.selection_start_line
    text = @script.toPlainText.split("\n")[line_number..-1].join("\n")
    scriptrunner_puts "Running script from line #{line_number}: #{File.basename(@filename)}"
    handle_output_io()
    run_text(text, line_number)
  end
end

#run_selectionObject

Implement Script functionality in the frame (run selection, run from cursor, etc



792
793
794
795
796
797
798
799
800
801
802
803
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 792

def run_selection
  unless self.class.running?()
    selection = @script.selected_lines
    if selection
      start_line_number = @script.selection_start_line
      end_line_number   = @script.selection_end_line
      scriptrunner_puts "Running script lines #{start_line_number+1}-#{end_line_number+1}: #{File.basename(@filename)}"
      handle_output_io()
      run_text(selection, start_line_number)
    end
  end
end

#run_selection_while_pausedObject



805
806
807
808
809
810
811
812
813
814
815
816
817
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 805

def run_selection_while_paused
  current_script = @tab_book.widget(@tab_book.currentIndex)
  selection = current_script.selected_lines
  if selection
    start_line_number = current_script.selection_start_line
    end_line_number   = current_script.selection_end_line
    scriptrunner_puts "Debug: Running selected lines #{start_line_number+1}-#{end_line_number+1}: #{@tab_book.tabText(@tab_book.currentIndex)}"
    handle_output_io()
    dialog = ScriptRunnerDialog.new(self, 'Executing Selected Lines While Paused')
    dialog.execute_text_and_close_on_complete(selection, @script_binding)
    handle_output_io()
  end
end

#running?Boolean

Returns:

  • (Boolean)


456
457
458
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 456

def running?
  if @@instance == self and ScriptRunnerFrame.running?() then true else false end
end

#scriptrunner_puts(string) ⇒ Object



1224
1225
1226
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1224

def scriptrunner_puts(string)
  puts Time.now.sys.formatted + " (SCRIPTRUNNER): "  + string
end

#select_allObject



766
767
768
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 766

def select_all
  @script.select_all unless running?()
end

#select_tab_and_destroy_tabs_after_index(index) ⇒ Object



1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1081

def select_tab_and_destroy_tabs_after_index(index)
  Qt.execute_in_main_thread(true) do
    if @tab_book_shown
      @tab_book.setCurrentIndex(index)
      @active_script = @tab_book.widget(@tab_book.currentIndex)

      first_to_remove = index + 1
      last_to_remove  = @call_stack.length - 1

      last_to_remove.downto(first_to_remove) do |tab_index|
        tab = @tab_book.widget(tab_index)
        @tab_book.removeTab(tab_index)
        tab.dispose
      end

      @call_stack = @call_stack[0..index]
      @current_file = @call_stack[index]
    end
  end
end

#set_text(text, filename = '') ⇒ Object



433
434
435
436
437
438
439
440
441
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 433

def set_text(text, filename = '')
  unless running?()
    @script.setPlainText(text)
    @script.stop_highlight
    @filename = filename
    @script.filename = unique_filename()
    mark_breakpoints(@script.filename)
  end
end

#set_text_from_file(filename) ⇒ Object



443
444
445
446
447
448
449
450
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 443

def set_text_from_file(filename)
  unless running?()
    @@file_cache[filename] = nil
    @@breakpoints[filename] = nil
    load_file_into_script(filename)
    @filename = filename
  end
end

#setFocusObject



322
323
324
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 322

def setFocus
  @script.setFocus
end

#show_debugObject



937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 937

def show_debug
  unless @debug_frame
    @realtime_button_bar.step_button.setHidden(false)
    @script.enable_breakpoints = true
    if @tab_book_shown
      if @tab_book.count > 0
        (0..(@tab_book.count - 1)).each do |index|
          @tab_book.widget(index).enable_breakpoints = true
        end
      end
    end

    @debug_frame = Qt::HBoxLayout.new
    @debug_frame.setContentsMargins(0,0,0,0)
    @debug_frame_label = Qt::Label.new("Debug:")
    @debug_frame.addWidget(@debug_frame_label)
    @debug_text = CompletionLineEdit.new(self)
    @debug_text.setFocus(Qt::OtherFocusReason)
    @debug_text.connect(SIGNAL('key_pressed(QKeyEvent*)')) do |event|
      case event.key
      when Qt::Key_Return, Qt::Key_Enter
        begin
          debug_text = @debug_text.toPlainText
          @debug_history.unshift(debug_text)
          @debug_history_index = 0
          @debug_text.setPlainText('')
          scriptrunner_puts "Debug: #{debug_text}"
          handle_output_io()
          if not running?
            # Capture STDOUT and STDERR
            $stdout.add_stream(@output_io)
            $stderr.add_stream(@output_io)
          end

          if @script_binding
            # Check for accessing an instance variable or local
            if debug_text =~ /^@\S+$/ || @script_binding.local_variables.include?(debug_text.to_sym)
              debug_text = "puts #{debug_text}" # Automatically add puts to print it
            end
            eval(debug_text, @script_binding, 'debug', 1)
          else
            Object.class_eval(debug_text, 'debug', 1)
          end
          handle_output_io()
        rescue Exception => error
          if error.class == DRb::DRbConnError
            Logger.error("Error Connecting to Command and Telemetry Server")
          else
            Logger.error(error.class.to_s.split('::')[-1] + ' : ' + error.message)
          end
          handle_output_io()
        ensure
          if not running?
            # Capture STDOUT and STDERR
            $stdout.remove_stream(@output_io)
            $stderr.remove_stream(@output_io)
          end
        end
      when Qt::Key_Up
        if @debug_history.length > 0
          @debug_text.setPlainText(@debug_history[@debug_history_index])
          @debug_history_index += 1
          if @debug_history_index == @debug_history.length
            @debug_history_index = @debug_history.length-1
          end
        end
      when Qt::Key_Down
        if @debug_history.length > 0
          @debug_text.setPlainText(@debug_history[@debug_history_index])
          @debug_history_index -= 1
          @debug_history_index = 0 if @debug_history_index < 0
        end
      when Qt::Key_Escape
        @debug_text.setPlainText("")
      end
    end
    @debug_frame.addWidget(@debug_text)

    @locals_button = Qt::PushButton.new('Locals')
    @locals_button.connect(SIGNAL('clicked(bool)')) do
      next unless @script_binding
      @locals_button.setEnabled(false)
      vars = @script_binding.local_variables.map(&:to_s)
      puts "Locals: #{vars.reject {|x| INSTANCE_VARS.include?(x)}.sort.join(', ')}"
      while @output_io.string[-1..-1] == "\n"
        Qt::CoreApplication.processEvents()
      end
      @locals_button.setEnabled(true)
    end
    @debug_frame.addWidget(@locals_button)

    @bottom_frame.layout.addLayout(@debug_frame)
  end
end

#stop?Boolean

Returns:

  • (Boolean)


487
488
489
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 487

def stop?
  @stop
end

#stop_message_logObject



288
289
290
291
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 288

def stop_message_log
  @message_log.stop if @message_log
  @message_log = nil
end

#textObject



429
430
431
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 429

def text
  @script.toPlainText.gsub("\r", '')
end

#toggle_debug(debug = nil) ⇒ Object

Implement the debug capability



917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 917

def toggle_debug(debug = nil)
  if debug.nil?
    if @debug_frame
      hide_debug()
    else
      show_debug()
    end
  else
    if debug
      if !@debug_frame
        show_debug()
      end
    else
      if @debug_frame
        hide_debug()
      end
    end
  end
end

#toggle_disconnect(config_file, ask_for_config_file = true) ⇒ Object



1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 1102

def toggle_disconnect(config_file, ask_for_config_file = true)
  dialog = Qt::Dialog.new(self, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
  dialog.setWindowTitle("Disconnect Settings")
  dialog_layout = Qt::VBoxLayout.new
  dialog_layout.addWidget(Qt::Label.new("Targets checked will be disconnected."))

  all_targets = {}
  set_clear_layout = Qt::HBoxLayout.new
  check_all = Qt::PushButton.new("Check All")
  check_all.setAutoDefault(false)
  check_all.setDefault(false)
  check_all.connect(SIGNAL('clicked()')) do
    all_targets.each do |target, checkbox|
      checkbox.setChecked(true)
    end
  end
  set_clear_layout.addWidget(check_all)
  clear_all = Qt::PushButton.new("Clear All")
  clear_all.connect(SIGNAL('clicked()')) do
    all_targets.each do |target, checkbox|
      checkbox.setChecked(false)
    end
  end
  set_clear_layout.addWidget(clear_all)
  dialog_layout.addLayout(set_clear_layout)

  scroll = Qt::ScrollArea.new
  target_widget = Qt::Widget.new
  scroll.setWidget(target_widget)
  target_layout = Qt::VBoxLayout.new(target_widget)
  target_layout.setSizeConstraint(Qt::Layout::SetMinAndMaxSize)
  scroll.setSizePolicy(Qt::SizePolicy::Preferred, Qt::SizePolicy::Expanding)
  scroll.setWidgetResizable(true)

  existing = get_disconnected_targets()
  System.targets.keys.each do |target|
    check_layout = Qt::HBoxLayout.new
    check_label = Qt::CheckboxLabel.new(target)
    checkbox = Qt::CheckBox.new
    all_targets[target] = checkbox
    if existing
      checkbox.setChecked(existing && existing.include?(target))
    else
      checkbox.setChecked(true)
    end
    check_label.setCheckbox(checkbox)
    check_layout.addWidget(checkbox)
    check_layout.addWidget(check_label)
    check_layout.addStretch
    target_layout.addLayout(check_layout)
  end
  dialog_layout.addWidget(scroll)

  if ask_for_config_file
    chooser = FileChooser.new(self, "Config File", config_file, 'Select',
                              File.dirname(config_file))
    chooser.callback = lambda do |filename|
      chooser.filename = filename
    end
    dialog_layout.addWidget(chooser)
  end

  button_layout = Qt::HBoxLayout.new
  ok = Qt::PushButton.new("Ok")
  ok.setAutoDefault(true)
  ok.setDefault(true)
  targets = []
  ok.connect(SIGNAL('clicked()')) do
    all_targets.each do |target, checkbox|
      targets << target if checkbox.isChecked
    end
    dialog.accept()
  end
  button_layout.addWidget(ok)
  cancel = Qt::PushButton.new("Cancel")
  cancel.connect(SIGNAL('clicked()')) do
    dialog.reject()
  end
  button_layout.addWidget(cancel)
  dialog_layout.addLayout(button_layout)

  dialog.setLayout(dialog_layout)
  my_parent = self.parent
  while my_parent.parent
    my_parent = my_parent.parent
  end
  if dialog.exec == Qt::Dialog::Accepted
    if targets.empty?
      clear_disconnected_targets()
      my_parent.statusBar.showMessage("")
      self.setPalette(Qt::Palette.new(Cosmos::DEFAULT_PALETTE))
    else
      config_file = chooser.filename
      my_parent.statusBar.showMessage("Targets disconnected: #{targets.join(" ")}")
      self.setPalette(Qt::Palette.new(Cosmos::RED_PALETTE))
      Splash.execute(self) do |splash|
        ConfigParser.splash = splash
        splash.message = "Initializing Command and Telemetry Server"
        set_disconnected_targets(targets, targets.length == all_targets.length, config_file)
        ConfigParser.splash = nil
      end
    end
  end
  dialog.dispose
  config_file
end

#undoObject

Implement edit functionality in the frame (cut, copy, paste, etc)



746
747
748
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 746

def undo
  @script.undo unless running?()
end

#undo_available(bool) ⇒ Object



318
319
320
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 318

def undo_available(bool)
  emit undoAvailable(bool)
end

#unique_filenameObject



241
242
243
244
245
246
247
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 241

def unique_filename
  if @filename and !@filename.empty?
    return @filename
  else
    return @default_tab_text.strip + @file_number.to_s
  end
end

#zoom_defaultObject



784
785
786
787
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 784

def zoom_default
  # @active_script since this can be used while running
  @active_script.zoom_default
end

#zoom_inObject



774
775
776
777
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 774

def zoom_in
  # @active_script since this can be used while running
  @active_script.zoom_in
end

#zoom_outObject



779
780
781
782
# File 'lib/cosmos/tools/script_runner/script_runner_frame.rb', line 779

def zoom_out
  # @active_script since this can be used while running
  @active_script.zoom_out
end