Class: QDA::GUI::CodeReviewWindow
- Inherits:
-
WorkAreaWindow
- Object
- WorkAreaWindow
- QDA::GUI::CodeReviewWindow
- Includes:
- Subscriber
- Defined in:
- lib/weft/wxgui/inspectors/codereview.rb
Constant Summary collapse
- W_WINDOW_DEF_SIZE =
[ 0.8, 0.6 ]
- BASE_COLOUR =
Wx::Colour.new(255, 255, 255)
- HIGHLIGHT_COLOUR =
Wx::Colour.new(255, 0, 0)
- GRID_COLOUR =
Wx::Colour.new(223, 223, 233)
- METHOD_MAPPING =
{ 'Number of documents' => :num_of_docs, 'Number of passages' => :num_of_codes, 'Number of characters' => :num_of_chars }
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #associated_subscribers ⇒ Object
- #count_method=(new_method) ⇒ Object
-
#initialize(obj, weft_client, workarea, layout) ⇒ CodeReviewWindow
constructor
A new instance of CodeReviewWindow.
- #object ⇒ Object
- #on_add_col(e) ⇒ Object
-
#on_add_row(e) ⇒ Object
add an item to the CodeReview.
- #on_cell_dclicked(e) ⇒ Object
- #on_change_method(e) ⇒ Object
-
#on_label_clicked(e) ⇒ Object
set the currently highlighted row or column as the current item in the dropdown.
- #on_remove(e) ⇒ Object
-
#on_remove_col(e) ⇒ Object
handler for removing a row, as selected in drop-down.
-
#on_remove_row(e) ⇒ Object
handler for removing a row, as selected in drop-down.
- #receive_category_changed(cat) ⇒ Object
- #receive_category_deleted(cat) ⇒ Object
- #refresh ⇒ Object
Methods included from Subscriber
Methods inherited from WorkAreaWindow
#active?, #layout, #layout=, #on_focus
Constructor Details
#initialize(obj, weft_client, workarea, layout) ⇒ CodeReviewWindow
Returns a new instance of CodeReviewWindow.
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 10 def initialize(obj, weft_client, workarea, layout) super(workarea, "Code Review #{obj.dbid}", nil) @client = weft_client @cr = obj @cr.count_method = @count_method = :num_of_docs main_sizer = Wx::BoxSizer.new(Wx::VERTICAL) panel = Wx::Panel.new(self) @grid = Wx::Grid.new(panel, -1, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::SIMPLE_BORDER) @grid.create_grid( 12, 6 ) @grid.set_row_label_size(160) @grid.set_grid_line_colour(GRID_COLOUR) @grid.enable_editing(false) 0.upto(5) { | i | @grid.set_col_label_value(i, '') } 0.upto(11) { | i | @grid.set_row_label_value(i, '') } evt_grid_label_left_click() { | evt | on_label_clicked(evt) } evt_grid_cell_left_dclick() { | evt | on_cell_dclicked(evt) } # the controls panel # butt_panel = Wx::Panel.new(panel, -1) butt_box_label = Wx::StaticBox.new(panel, -1, 'Select categories') bott_sizer = Wx::StaticBoxSizer.new(butt_box_label, Wx::HORIZONTAL) @drop_down = CategoryDropDown.new(@client, panel) bott_sizer.add(@drop_down, 3, Wx::ALL, 4) = Wx::Button.new(panel, -1, 'Add as row') .(.get_id) { | e | on_add_row(e) } bott_sizer.add(, 1, Wx::ALL, 4) = Wx::Button.new(panel, -1, 'Add as column') .(.get_id) { | e | on_add_col(e) } bott_sizer.add(, 1, Wx::ALL, 4) = Wx::Button.new(panel, -1, 'Remove') .(.get_id) { | e | on_remove(e) } bott_sizer.add(, 1, Wx::ALL, 4) # button = Wx::Button.new(butt_panel, -1, 'Remove column') # button.evt_button(button.get_id) { | e | on_remove_col(e) } # bott_sizer.add(button, 1, Wx::ALL, 4) # butt_panel.set_sizer(bott_sizer) main_sizer.add(bott_sizer, 0, Wx::GROW|Wx::ADJUST_MINSIZE|Wx::ALL, 4) # the numbers row num_box_label = Wx::StaticBox.new(panel, -1, Lang::DISPLAY_OPTIONS_LABEL) num_sizer = Wx::StaticBoxSizer.new(num_box_label, Wx::HORIZONTAL) # num_cbox = Wx::CheckBox.new(num_panel, -1, 'Show numbers') # num_sizer.add( Wx::StaticText.new(panel, -1, 'Count what?'), # 0, Wx::ALL|Wx::ALIGN_RIGHT, 4) @num_list = Wx::Choice.new(panel, -1) @num_list.append('Number of documents') @num_list.append('Number of passages') @num_list.append('Number of characters') @num_list.selection = 0 evt_choice( @num_list.get_id() ) { | e | on_change_method(e) } num_sizer.add(@num_list, 0, Wx::ALL, 4) main_sizer.add( num_sizer, 0, Wx::GROW|Wx::ADJUST_MINSIZE|Wx::ALL, 4) main_sizer.add(@grid, 1, Wx::GROW|Wx::ALL, 4) panel.set_sizer(main_sizer) main_sizer.set_size_hints(panel) self.icon = client.fetch_icon("codereview") subscribe(client, :category_deleted, :category_changed) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 9 def client @client end |
Instance Method Details
#associated_subscribers ⇒ Object
93 94 95 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 93 def associated_subscribers() [ @drop_down ] end |
#count_method=(new_method) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 122 def count_method=(new_method) if new_method != @count_method @cr.count_method = new_method @count_method = new_method refresh() end end |
#object ⇒ Object
89 90 91 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 89 def object() @cr end |
#on_add_col(e) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 130 def on_add_col(e) category = @drop_down.current_category return unless @cr.add_col(category) @grid.append_cols(1) if @cr.number_cols >= @grid.number_cols refresh() end |
#on_add_row(e) ⇒ Object
add an item to the CodeReview
138 139 140 141 142 143 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 138 def on_add_row(e) category = @drop_down.current_category return unless @cr.add_row(category) @grid.append_rows(1) if @cr.number_rows >= @grid.number_rows refresh() end |
#on_cell_dclicked(e) ⇒ Object
175 176 177 178 179 180 181 182 183 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 175 def on_cell_dclicked(e) q = @cr.to_query(@client.app, e.get_row, e.get_col) if q q_id = @client.app.get_preference('NextQuery') || 1 @client.app.save_preference('NextQuery', q_id + 1) q.dbid = q_id @workarea.launch_window(QueryWindow, q) end end |
#on_change_method(e) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 113 def on_change_method(e) sel = @num_list.get_string_selection() method = METHOD_MAPPING[ sel ] unless method raise RuntimeError.new("Unexpected selection #{sel}") end self.count_method = method end |
#on_label_clicked(e) ⇒ Object
set the currently highlighted row or column as the current item in the dropdown
99 100 101 102 103 104 105 106 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 99 def on_label_clicked(e) if row = e.row and row >= 0 and @cr.rows[row] @drop_down.receive_focus_category( @cr.rows[row] ) end if col = e.col and col >= 0 and @cr.cols[col] @drop_down.receive_focus_category( @cr.cols[col] ) end end |
#on_remove(e) ⇒ Object
145 146 147 148 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 145 def on_remove(e) on_remove_col(e) on_remove_row(e) end |
#on_remove_col(e) ⇒ Object
handler for removing a row, as selected in drop-down. Will remove the item from the underlying CodeReview, and redraw grid.
152 153 154 155 156 157 158 159 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 152 def on_remove_col(e) category = @drop_down.current_category if idx = @cr.remove_col(category) @grid.delete_cols(idx, 1) @grid.append_cols(1) refresh() end end |
#on_remove_row(e) ⇒ Object
handler for removing a row, as selected in drop-down. Will remove the item from the underlying CodeReview, and redraw grid.
163 164 165 166 167 168 169 170 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 163 def on_remove_row(e) category = @drop_down.current_category if idx = @cr.remove_row(category) @grid.delete_rows(idx, 1) @grid.append_rows(1) refresh() end end |
#receive_category_changed(cat) ⇒ Object
221 222 223 224 225 226 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 221 def receive_category_changed(cat) changed = nil changed = @cr.update_col(cat) changed = @cr.update_row(cat) refresh() if changed end |
#receive_category_deleted(cat) ⇒ Object
228 229 230 231 232 233 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 228 def receive_category_deleted(cat) deleted = nil deleted = @cr.remove_col(cat) deleted = @cr.remove_row(cat) refresh() if deleted end |
#refresh ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 185 def refresh() @grid.clear_grid() max = @cr.max() @cr.each_cell_value() do | x, y, val | @grid.set_cell_value(x, y, val.to_s) tint = BASE_COLOUR.mix( HIGHLIGHT_COLOUR, max, val) @grid.set_cell_background_colour(x, y, tint) end update_row_labels() update_col_labels() end |