nobody at rubyforge.org
2007-Feb-14 20:07 UTC
[Wxruby-development] [875] trunk/wxruby2/samples: Add expanded grid sample
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:'':'';} #msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[875] trunk/wxruby2/samples: Add expanded grid sample</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>875</dd> <dt>Author</dt> <dd>brokentoy</dd> <dt>Date</dt> <dd>2007-02-14 15:07:21 -0500 (Wed, 14 Feb 2007)</dd> </dl> <h3>Log Message</h3> <pre>Add expanded grid sample</pre> <h3>Added Paths</h3> <ul> <li>trunk/wxruby2/samples/grid/</li> <li><a href="#trunkwxruby2samplesgridgridrb">trunk/wxruby2/samples/grid/grid.rb</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="trunkwxruby2samplesgridgridrb"></a> <div class="addfile"><h4>Added: trunk/wxruby2/samples/grid/grid.rb (0 => 875)</h4> <pre class="diff"><span> <span class="info">--- trunk/wxruby2/samples/grid/grid.rb         (rev 0) +++ trunk/wxruby2/samples/grid/grid.rb        2007-02-14 20:07:21 UTC (rev 875) </span><span class="lines">@@ -0,0 +1,200 @@ </span><ins>+begin + require ''wx'' +rescue LoadError => no_wx_err + begin + require ''rubygems'' + load ''wx'' + rescue + raise no_wx_err + end +end + + +class GridFrame < Wx::Frame + + def initialize(parent, id = -1, title = "MyFrame", + pos = Wx::DEFAULT_POSITION, + size = Wx::DEFAULT_SIZE, + style = Wx::DEFAULT_FRAME_STYLE) + + super(parent, id, title, pos, size, style) + sizer = Wx::BoxSizer.new(Wx::VERTICAL) + create_status_bar() + set_status_text(Wx::VERSION_STRING) + + # panel = Wx::Panel.new(self) + sel_menu = Wx::Menu.new + sel_menu.append(1002, ''Select all'', ''Select all'') + evt_menu(1002) { @grid.select_all } + sel_menu.append(1003, ''Select row 2'', ''Select row 2'') + evt_menu(1003) { @grid.select_row(1) } + sel_menu.append(1004, ''Select column 4'', ''Select col 4'') + evt_menu(1004) { @grid.select_col(3) } + sel_menu.append(1005, ''Select block'', ''Select block'') + evt_menu(1005) { @grid.select_block(1, 1, 6, 3) } + menu_bar = Wx::MenuBar.new + menu_bar.append(sel_menu, ''Select'') + set_menu_bar(menu_bar) + + make_grid(self) + sizer.add(@grid, 1, Wx::ALL|Wx::GROW, 4) + set_sizer(sizer) + + evt_grid_cell_left_click() do |evt| + set_status_text("#{evt.get_row} x #{evt.get_col} is clicked") + evt.skip + end + + evt_grid_cell_right_click() do |evt| + set_status_text("#{evt.get_row} x #{evt.get_col} is right clicked") + evt.skip + end + + evt_grid_cell_left_dclick() do |evt| + set_status_text("#{evt.get_row} x #{evt.get_col} is double clicked") + evt.skip + end + + evt_grid_cell_right_dclick() do |evt| + set_status_text("#{evt.get_row} x #{evt.get_col} is right double clicked") + evt.skip + end + + evt_grid_label_left_click() do |evt| + set_status_text("#{evt.get_row} x #{evt.get_col} label is clicked") + evt.skip + end + + evt_grid_label_right_click() do |evt| + set_status_text("#{evt.get_row} x #{evt.get_col} label is right clicked") + evt.skip + end + + evt_grid_label_left_dclick() do |evt| + set_status_text("#{evt.get_row} x #{evt.get_col} labelis double clicked") + evt.skip + end + + evt_grid_label_right_dclick() do |evt| + set_status_text("#{evt.get_row} x #{evt.get_col} label is right double clicked") + evt.skip + end + + evt_grid_select_cell() do |evt| + set_status_text("#{evt.get_row} x #{evt.get_col} cell is selected") + evt.skip + end + + evt_grid_row_size do |evt| + set_status_text("Row #{evt.get_row_or_col} size changed") + evt.skip + end + + evt_grid_col_size do |evt| + set_status_text("Column #{evt.get_row_or_col} size changed") + evt.skip + end + + evt_grid_editor_shown do |evt| + set_status_text("Begin editing") + evt.skip + end + + evt_grid_editor_hidden do |evt| + set_status_text("End editing") + evt.skip + end + + evt_grid_range_select do |evt| + top = evt.get_top_left_coords + bottom = evt.get_bottom_right_coords + set_status_text("[ #{top[0].to_s} x #{top[1].to_s} ] to [ #{bottom[0].to_s} x #{bottom[1].to_s} ] is selected") + end + + evt_grid_editor_created do |evt| + set_status_text("Control #{evt.get_control} created") + evt.skip + end + + evt_grid_cell_change() do |evt| + set_status_text("Cell #{evt.get_row} x #{evt.get_col} has changed") + end + end + + # Create a wxGrid object + def make_grid(panel) + @grid = Wx::Grid.new(panel, -1) + + # Then we call CreateGrid to set the dimensions of the grid + # (11 rows and 12 columns in this example) + @grid.create_grid( 20, 12 ) + @grid.set_default_cell_background_colour(Wx::WHITE) + # We can set the sizes of individual rows and columns + # in pixels, and the label value string + @grid.set_row_size( 0, 60 ) + @grid.set_row_label_value( 0, "Row1" ) + @grid.set_row_label_alignment(Wx::ALIGN_CENTRE, Wx::ALIGN_CENTRE) + + @grid.set_col_size( 0, 120 ) + @grid.set_col_label_value( 0, "Col1" ) + @grid.set_col_label_alignment(Wx::ALIGN_CENTRE, Wx::ALIGN_CENTRE) + + # And set grid cell contents as strings + @grid.set_cell_value( 0, 0, "wxGrid is good" ) + + # We can specify that some cells are read-only + @grid.set_cell_value( 0, 2, "Read-only" ) + @grid.set_read_only( 0, 2 ) + + # Colours can be specified for grid cell contents + @grid.set_cell_value(1, 1, "white on red") + @grid.set_cell_text_colour(1, 1, Wx::WHITE) + @grid.set_cell_background_colour(1, 1, Wx::RED) + + # We can specify the some cells will store numeric + # values rather than strings. Here we set grid column 6 + # to hold floating point values displayed with width + # of 2 and precision of 2. The column is highlighted in light grey + cell_attr = Wx::GridCellAttr.new + cell_attr.set_background_colour( Wx::LIGHT_GREY ) + cell_attr.set_renderer( Wx::GridCellFloatRenderer.new(2, 2) ) + + @grid.set_col_attr(5, cell_attr) + @grid.set_cell_value(0, 5, "3.1415") + @grid.set_cell_value(0, 6, + "The whole column to the left uses float format") + + # Custom Editors Can be used + editor = Wx::GridCellNumberEditor.new(5, 20) + @grid.set_cell_value(3, 1, ''Number editor below'') + @grid.set_cell_editor(4, 1, editor) + + editor = Wx::GridCellFloatEditor.new(4, 2) + @grid.set_cell_value(3, 2, ''Float editor below'') + @grid.set_cell_editor(4, 2, editor) + + editor = Wx::GridCellChoiceEditor.new([''foo'', ''bar'', ''baz'']) + @grid.set_cell_value(3, 3, ''Choice editor below'') + @grid.set_cell_editor(4, 3, editor) + + @grid.auto_size_row(3, true) + + # Display of cells can be customised + @grid.set_cell_renderer(6, 0, Wx::GridCellBoolRenderer.new) + @grid.set_cell_value(6, 1, ''Cell to the left displayed as boolean'') + end + +end + +class GridApp < Wx::App + def on_init + frame = GridFrame.new(nil, -1, "Grid Sample", + Wx::Point.new(10, 100), + Wx::Size.new(630,400)) + + set_top_window(frame) + frame.show() + end +end + +GridApp.new.main_loop() </ins></span></pre> </div> </div> </body> </html>
Seemingly Similar Threads
- [903] branches/wxruby2/wxwidgets_282/samples: Added #!/usr/bin/env ruby to the grid sample.
- Scrolling to the bottom of a Grid
- [861] trunk/wxruby2/doc/textile/grid.txtl: Added missing methods listing section
- [ wxruby-Bugs-16848 ] segfault on Grid#set_cell_value
- Text of Status Bar always disappear