Class: AimsProject::GeometryEditor

Inherits:
Wx::ScrolledWindow
  • Object
show all
Includes:
Wx
Defined in:
lib/aims_project/geometry_editor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, window) ⇒ GeometryEditor

Returns a new instance of GeometryEditor.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/aims_project/geometry_editor.rb', line 10

def initialize(app, window)
  
  super(window)

  @app = app
  
  sizer = BoxSizer.new(VERTICAL)

  @text_ctrl = StyledTextCtrl.new(self)
  # @text_ctrl.set_sel_background(true, Colour.new("wheat"))
  
  # Create the button panel (A toolbar for the top of this panel)
  @button_panel = HBoxSizer.new
  
  basedir = File.dirname(__FILE__)
  arrow_icon = Image.new(File.join(basedir,"green_arrow.jpg"), BITMAP_TYPE_JPEG)
  @eval_button = BitmapButton.new(self, :bitmap => arrow_icon.rescale(16,15).convert_to_bitmap,:style=>BU_EXACTFIT, :name => "evaluate")
  
  @button_panel.add_item(@eval_button,3)
      
  sizer.add_item(@button_panel, :flag => EXPAND)
  sizer.add_item(@text_ctrl, :proportion => 1, :flag => EXPAND | ALL, :border => 5)

  set_auto_layout(true)
  set_sizer(sizer)
  
  evt_button(@eval_button) {|event|
      self.evaluate
  }

end

Instance Attribute Details

#appObject

Returns the value of attribute app.



6
7
8
# File 'lib/aims_project/geometry_editor.rb', line 6

def app
  @app
end

#button_panelObject

Returns the value of attribute button_panel.



6
7
8
# File 'lib/aims_project/geometry_editor.rb', line 6

def button_panel
  @button_panel
end

#text_ctrlObject

Returns the value of attribute text_ctrl.



6
7
8
# File 'lib/aims_project/geometry_editor.rb', line 6

def text_ctrl
  @text_ctrl
end

Instance Method Details

#evaluateObject

Apply the edits to the geometry_file and evaluate



43
44
45
46
47
48
49
50
51
52
# File 'lib/aims_project/geometry_editor.rb', line 43

def evaluate
  
  @unit_cell.raw_input = @text_ctrl.get_text
  begin
    @unit_cell.evaluate    
  rescue 
    # @button_pane.add_item(@clear_errors_button, 3)
    @app.display_exception($!)
  end
end

#get_contentsObject

Return the text contents of this control after evaluating it with ERB



79
80
81
# File 'lib/aims_project/geometry_editor.rb', line 79

def get_contents
  ERB.new(@text_ctrl.get_value).result
end

#select_atom(atom) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/aims_project/geometry_editor.rb', line 59

def select_atom(atom)
  selectionStyle = Wx::RichTextAttr.new(Wx::BLACK, Wx::Colour.new("YELLOW"))
  
  pattern = atom.format_geometry_in
  puts "GeometryEditor.select_atom: pattern=#{pattern}"

  matchdata = self.text_ctrl.get_text.match(pattern)
  if matchdata
    lineStart = matchdata.begin(0)
    lineEnd = matchdata.end(0)
    # self.text_ctrl.set_style(lineStart...lineEnd, selectionStyle)
    self.text_ctrl.goto_pos(lineStart)
    self.text_ctrl.set_selection_start(lineStart)
    self.text_ctrl.set_selection_end(lineEnd)
  end
end

#unit_cell=(uc) ⇒ Object



54
55
56
57
# File 'lib/aims_project/geometry_editor.rb', line 54

def unit_cell=(uc)
  @unit_cell = uc
  @text_ctrl.set_text(@unit_cell.input_geometry)      
end