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 |
# 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 main_sizer.add(@grid, 1, Wx::GROW|Wx::ALL, 4) # 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) 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
91 92 93 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 91 def associated_subscribers() [ @drop_down ] end |
#count_method=(new_method) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 120 def count_method=(new_method) if new_method != @count_method @cr.count_method = new_method @count_method = new_method refresh() end end |
#object ⇒ Object
87 88 89 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 87 def object() @cr end |
#on_add_col(e) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 128 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
136 137 138 139 140 141 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 136 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
173 174 175 176 177 178 179 180 181 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 173 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
111 112 113 114 115 116 117 118 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 111 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
97 98 99 100 101 102 103 104 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 97 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
143 144 145 146 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 143 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.
150 151 152 153 154 155 156 157 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 150 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.
161 162 163 164 165 166 167 168 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 161 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
219 220 221 222 223 224 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 219 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
226 227 228 229 230 231 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 226 def receive_category_deleted(cat) deleted = nil deleted = @cr.remove_col(cat) deleted = @cr.remove_row(cat) refresh() if deleted end |
#refresh ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 183 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 |