Class: QDA::GUI::ScriptWindow

Inherits:
WorkAreaWindow show all
Defined in:
lib/weft/wxgui/inspectors/script.rb

Constant Summary

Constants inherited from WorkAreaWindow

WorkAreaWindow::W_WINDOW_DEF_SIZE

Instance Method Summary collapse

Methods inherited from WorkAreaWindow

#active?, #layout, #layout=

Constructor Details

#initialize(obj, app, workarea, layout) ⇒ ScriptWindow

Returns a new instance of ScriptWindow.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/weft/wxgui/inspectors/script.rb', line 3

def initialize(obj, app, workarea, layout)
  super(workarea, "Script #{obj.dbid}", nil)
  @app = app
  code = ''
  sizer = Wx::BoxSizer.new(Wx::VERTICAL)
  @code = Wx::TextCtrl.new(self, -1, code, Wx::DEFAULT_POSITION, 
                            Wx::DEFAULT_SIZE, Wx::TE_MULTILINE)
  sizer.add(@code, 2, Wx::GROW|Wx::ALL, 5)

  button = Wx::Button.new(self, -1, 'Run')
  button.evt_button(button.get_id) { | e | on_run(e) }
  sizer.add(button, 0, Wx::ALL, 5)

  @output  = Wx::TextCtrl.new(self, -1, '', Wx::DEFAULT_POSITION, 
                               Wx::DEFAULT_SIZE, 
                               Wx::TE_MULTILINE|Wx::TE_READONLY)
  sizer.add(@output, 2, Wx::GROW|Wx::ALL, 5)
  self.sizer = sizer
end

Instance Method Details

#on_run(e) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/weft/wxgui/inspectors/script.rb', line 23

def on_run(e)
  $stdout = result = StringIO.new()
  @app.instance_eval( @code.get_value() )
  # STDERR.puts result.inspect()
  result.rewind()
  @output.value = result.read()
  $stdout = STDOUT
rescue Exception => err
  @output.value = err
  @output.value += err.backtrace.join("\n")
end