Class: AimsProject::GeometryEditor
- Inherits:
-
Wx::ScrolledWindow
- Object
- Wx::ScrolledWindow
- AimsProject::GeometryEditor
- Includes:
- Wx
- Defined in:
- lib/aims_project/geometry_editor.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#button_panel ⇒ Object
Returns the value of attribute button_panel.
-
#text_ctrl ⇒ Object
Returns the value of attribute text_ctrl.
Instance Method Summary collapse
-
#evaluate ⇒ Object
Apply the edits to the geometry_file and evaluate.
-
#get_contents ⇒ Object
Return the text contents of this control after evaluating it with ERB.
-
#initialize(app, window) ⇒ GeometryEditor
constructor
A new instance of GeometryEditor.
- #select_atom(atom) ⇒ Object
- #unit_cell=(uc) ⇒ Object
Constructor Details
#initialize(app, window) ⇒ 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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) = HBoxSizer.new @toggle_source = CheckBox.new(self, ID_ANY, "Source") basedir = File.dirname(__FILE__) arrow_icon = Image.new(File.join(basedir,"green_arrow.jpg"), BITMAP_TYPE_JPEG) = BitmapButton.new(self, :bitmap => arrow_icon.rescale(16,15).convert_to_bitmap,:style=>BU_EXACTFIT, :name => "evaluate") # error_icon = Image.new(File.join(basedir, "red_cross.jpeg"), BITMAP_TYPE_JPEG) # @clear_errors_button = BitmapButton.new(self, :bitmap => error_icon.rescale(16,15).convert_to_bitmap,:style=>BU_EXACTFIT, :name => "Clear Errors") .add_item(@toggle_source,1) .add_stretch_spacer .add_item(,3) evt_checkbox(@toggle_source) {|evt| if @toggle_source.is_checked @text_ctrl.set_read_only(false) @text_ctrl.set_text(@unit_cell.raw_input) else @text_ctrl.set_read_only(false) @text_ctrl.set_text(@unit_cell.input_geometry) @text_ctrl.set_read_only(true) end } sizer.add_item(, :flag => EXPAND) sizer.add_item(@text_ctrl, :proportion => 1, :flag => EXPAND | ALL, :border => 5) set_auto_layout(true) set_sizer(sizer) () {|event| self.evaluate } end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
6 7 8 |
# File 'lib/aims_project/geometry_editor.rb', line 6 def app @app end |
#button_panel ⇒ Object
Returns the value of attribute button_panel.
6 7 8 |
# File 'lib/aims_project/geometry_editor.rb', line 6 def end |
#text_ctrl ⇒ Object
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
#evaluate ⇒ Object
Apply the edits to the geometry_file and evaluate
62 63 64 65 66 67 68 69 70 |
# File 'lib/aims_project/geometry_editor.rb', line 62 def evaluate @unit_cell.raw_input = @text_ctrl.get_text begin @unit_cell.evaluate rescue # @button_pane.add_item(@clear_errors_button, 3) @text_ctrl.set_text($!. + $!.backtrace.join("\n")) end end |
#get_contents ⇒ Object
Return the text contents of this control after evaluating it with ERB
107 108 109 |
# File 'lib/aims_project/geometry_editor.rb', line 107 def get_contents ERB.new(@text_ctrl.get_value).result end |
#select_atom(atom) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/aims_project/geometry_editor.rb', line 87 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
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/aims_project/geometry_editor.rb', line 72 def unit_cell=(uc) @unit_cell = uc if @toggle_source.is_checked @text_ctrl.set_read_only(false) @text_ctrl.set_text(@unit_cell.raw_input) @text_ctrl.set_read_only(false) else @text_ctrl.set_read_only(false) @text_ctrl.set_text(@unit_cell.input_geometry) @text_ctrl.set_read_only(true) end end |