Class: QDA::GUI::CodeReviewWindow
- Inherits:
-
WorkAreaWindow
- Object
- Wx::MDIChildFrame
- 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 Method Summary collapse
- #associated_subscribers ⇒ Object
- #calculate_col(i) ⇒ Object
- #calculate_row(i) ⇒ Object
- #count_method=(method) ⇒ Object
-
#initialize(obj, app, workarea, layout) ⇒ CodeReviewWindow
constructor
A new instance of CodeReviewWindow.
- #on_add_col(e) ⇒ Object
- #on_add_row(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
removes the selected category from both rows and colums.
- #on_remove_col(e) ⇒ Object
- #on_remove_row(e) ⇒ Object
- #receive_category_changed(cat) ⇒ Object
- #receive_category_deleted(cat) ⇒ Object
- #recolour_table ⇒ Object
- #remove_col(idx) ⇒ Object
- #remove_row(idx) ⇒ Object
- #update_cell(x, y) ⇒ Object
- #update_col_labels ⇒ Object
- #update_row_labels ⇒ Object
Methods included from Subscriber
Methods inherited from WorkAreaWindow
Constructor Details
#initialize(obj, app, 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 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 10 def initialize(obj, app, workarea, layout) super(workarea, "Code Review #{obj.dbid}", nil) @cols, @rows, @contents = [], [], [] @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) } # 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(app, 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) subscribe(:category_deleted, :category_changed) end |
Instance Method Details
#associated_subscribers ⇒ Object
85 86 87 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 85 def associated_subscribers() [ @drop_down ] end |
#calculate_col(i) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 137 def calculate_col(i) col = @cols[i] @rows.each_with_index do | row_cat, j | @contents[j][i] = row_cat.codes.dup.join(col.codes) update_cell(j, i) end end |
#calculate_row(i) ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 162 def calculate_row(i) row = @rows[i] @cols.each_with_index do | col_cat, j | @contents[i][j] = col_cat.codes.dup.join(row.codes) update_cell(i, j) end end |
#count_method=(method) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 114 def count_method=(method) if method != @count_method @count_method = method 0.upto(@rows.length - 1) { | i | calculate_row(i) } recolour_table() end end |
#on_add_col(e) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 122 def on_add_col(e) category = @drop_down.current_category return false unless category return false if @cols.include?(category) @cols.push(category) @grid.append_cols(1) if @cols.length > @grid.number_cols col = @cols.length - 1 @grid.set_col_label_value( col, category.name ) # @grid.set_col_format_number( col ) calculate_col(col) recolour_table() end |
#on_add_row(e) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 145 def on_add_row(e) category = @drop_down.current_category return false unless category # don't add twice return false if @rows.include?(category) @rows.push(category) @grid.append_rows(1) if @rows.length > @grid.number_rows row = @rows.length - 1 @grid.set_row_label_value( row, category.name ) @contents[row] = [] # @grid.set_row_format_number( row ) calculate_row(row) recolour_table() end |
#on_change_method(e) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 105 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
91 92 93 94 95 96 97 98 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 91 def on_label_clicked(e) if row = e.row and row >= 0 and @rows[row] @drop_down.receive_focus_category( @rows[row] ) end if col = e.col and col >= 0 and @cols[col] @drop_down.receive_focus_category( @cols[col] ) end end |
#on_remove(e) ⇒ Object
removes the selected category from both rows and colums
171 172 173 174 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 171 def on_remove(e) on_remove_col(e) on_remove_row(e) end |
#on_remove_col(e) ⇒ Object
176 177 178 179 180 181 182 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 176 def on_remove_col(e) category = @drop_down.current_category return false unless category return false unless idx = @cols.index(category) remove_col(idx) recolour_table() end |
#on_remove_row(e) ⇒ Object
192 193 194 195 196 197 198 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 192 def on_remove_row(e) category = @drop_down.current_category return false unless category return false unless idx = @rows.index(category) remove_row(idx) recolour_table() end |
#receive_category_changed(cat) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 249 def receive_category_changed(cat) if idx = @cols.index(cat) @cols[idx] = cat calculate_col(idx) end if idx = @rows.index(cat) @rows[idx] = cat calculate_row(idx) end recolour_table() end |
#receive_category_deleted(cat) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 263 def receive_category_deleted(cat) if idx = @cols.index(cat) remove_col(idx) end if idx = @rows.index(cat) remove_row(idx) end recolour_table() end |
#recolour_table ⇒ Object
238 239 240 241 242 243 244 245 246 247 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 238 def recolour_table() max = @contents.flatten.collect { | x | x.send(@count_method) }.max @contents.each_with_index do | row_items, row | row_items.each_with_index do | code_table, col | clr = BASE_COLOUR.mix( HIGHLIGHT_COLOUR, max, code_table.send(@count_method)) @grid.set_cell_background_colour(row, col, clr) end end end |
#remove_col(idx) ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 184 def remove_col(idx) @cols.delete_at(idx) @contents.each { | row | row.delete_at(idx) } @grid.delete_cols(idx, 1) @grid.append_cols(1) update_col_labels() end |
#remove_row(idx) ⇒ Object
200 201 202 203 204 205 206 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 200 def remove_row(idx) @rows.delete_at(idx) @contents.delete_at(idx) @grid.delete_rows(idx, 1) @grid.append_rows(1) update_row_labels() end |
#update_cell(x, y) ⇒ Object
208 209 210 211 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 208 def update_cell(x, y) content = @contents[x][y].send(@count_method) @grid.set_cell_value( x, y, content.to_s ) end |
#update_col_labels ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 213 def update_col_labels() @cols.each_with_index do | c, i | @grid.set_col_label_value(i, c.name) end # check if we need to clean up deleted and now empty row labels # at the end - Wx 2.4.2 doesn't seem to do this automatically @grid.set_col_label_value(@cols.length, '') return if @cols.length == @grid.number_cols() for empty in ( @cols.length ... @grid.number_cols() ) @grid.set_col_label_value(empty, '') end end |
#update_row_labels ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/weft/wxgui/inspectors/codereview.rb', line 226 def update_row_labels() @rows.each_with_index do | c, i | @grid.set_row_label_value(i, c.name) end # check if we need to clean up deleted and now empty row labels # at the end - Wx 2.4.2 doesn't seem to do this automatically return if @rows.length == @grid.number_rows() for empty in ( @rows.length ... @grid.number_rows() ) @grid.set_row_label_value(empty, '') end end |