wxruby 1.9.6-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/LICENSE +53 -0
  2. data/README +297 -0
  3. data/lib/wx/accessors.rb +52 -0
  4. data/lib/wx/classes/acceleratortable.rb +28 -0
  5. data/lib/wx/classes/animation.rb +18 -0
  6. data/lib/wx/classes/app.rb +45 -0
  7. data/lib/wx/classes/artprovider.rb +31 -0
  8. data/lib/wx/classes/bitmap.rb +28 -0
  9. data/lib/wx/classes/busycursor.rb +12 -0
  10. data/lib/wx/classes/checklistbox.rb +45 -0
  11. data/lib/wx/classes/choice.rb +4 -0
  12. data/lib/wx/classes/clientdc.rb +13 -0
  13. data/lib/wx/classes/clipboard.rb +16 -0
  14. data/lib/wx/classes/colour.rb +47 -0
  15. data/lib/wx/classes/combobox.rb +4 -0
  16. data/lib/wx/classes/commandevent.rb +7 -0
  17. data/lib/wx/classes/controlwithitems.rb +10 -0
  18. data/lib/wx/classes/dc.rb +57 -0
  19. data/lib/wx/classes/event.rb +5 -0
  20. data/lib/wx/classes/evthandler.rb +921 -0
  21. data/lib/wx/classes/font.rb +118 -0
  22. data/lib/wx/classes/functions.rb +44 -0
  23. data/lib/wx/classes/gauge.rb +12 -0
  24. data/lib/wx/classes/grid.rb +138 -0
  25. data/lib/wx/classes/helpcontroller.rb +5 -0
  26. data/lib/wx/classes/htmlhelpcontroller.rb +5 -0
  27. data/lib/wx/classes/htmlwindow.rb +14 -0
  28. data/lib/wx/classes/icon.rb +21 -0
  29. data/lib/wx/classes/iconbundle.rb +3 -0
  30. data/lib/wx/classes/image.rb +31 -0
  31. data/lib/wx/classes/imagelist.rb +3 -0
  32. data/lib/wx/classes/listbox.rb +4 -0
  33. data/lib/wx/classes/listctrl.rb +21 -0
  34. data/lib/wx/classes/locale.rb +28 -0
  35. data/lib/wx/classes/mediactrl.rb +22 -0
  36. data/lib/wx/classes/menu.rb +62 -0
  37. data/lib/wx/classes/menuitem.rb +7 -0
  38. data/lib/wx/classes/object.rb +7 -0
  39. data/lib/wx/classes/paintdc.rb +12 -0
  40. data/lib/wx/classes/point.rb +48 -0
  41. data/lib/wx/classes/previewframe.rb +13 -0
  42. data/lib/wx/classes/rect.rb +10 -0
  43. data/lib/wx/classes/size.rb +49 -0
  44. data/lib/wx/classes/sound.rb +23 -0
  45. data/lib/wx/classes/styledtextctrl.rb +92 -0
  46. data/lib/wx/classes/textctrl.rb +14 -0
  47. data/lib/wx/classes/texturlevent.rb +6 -0
  48. data/lib/wx/classes/timer.rb +94 -0
  49. data/lib/wx/classes/toolbartool.rb +4 -0
  50. data/lib/wx/classes/treectrl.rb +44 -0
  51. data/lib/wx/classes/window.rb +82 -0
  52. data/lib/wx/classes/xmlresource.rb +37 -0
  53. data/lib/wx/keyword_ctors.rb +222 -0
  54. data/lib/wx/keyword_defs.rb +492 -0
  55. data/lib/wx/version.rb +3 -0
  56. data/lib/wx.rb +42 -0
  57. data/lib/wxruby2.so +0 -0
  58. data/samples/SAMPLES-LICENSE.TXT +18 -0
  59. data/samples/aui/aui.rb +1356 -0
  60. data/samples/bigdemo/About.rbw +39 -0
  61. data/samples/bigdemo/ColorPanel.rbw +23 -0
  62. data/samples/bigdemo/GridSimple.rbw +78 -0
  63. data/samples/bigdemo/MDIDemo.rbw +57 -0
  64. data/samples/bigdemo/PopupMenu.rbw +149 -0
  65. data/samples/bigdemo/ShapedWindow.rbw +131 -0
  66. data/samples/bigdemo/Sizers.rbw +543 -0
  67. data/samples/bigdemo/bigdemo.rb +823 -0
  68. data/samples/bigdemo/demoTemplate.rbw +33 -0
  69. data/samples/bigdemo/helpfile.htb +0 -0
  70. data/samples/bigdemo/icons/Test 015.jpg +0 -0
  71. data/samples/bigdemo/icons/Test 015.png +0 -0
  72. data/samples/bigdemo/icons/choice.bmp +0 -0
  73. data/samples/bigdemo/icons/choice.xpm +27 -0
  74. data/samples/bigdemo/icons/combo.bmp +0 -0
  75. data/samples/bigdemo/icons/combo.xpm +27 -0
  76. data/samples/bigdemo/icons/copy.xpm +25 -0
  77. data/samples/bigdemo/icons/cut.xpm +24 -0
  78. data/samples/bigdemo/icons/gauge.bmp +0 -0
  79. data/samples/bigdemo/icons/gauge.xpm +27 -0
  80. data/samples/bigdemo/icons/help.xpm +25 -0
  81. data/samples/bigdemo/icons/list.bmp +0 -0
  82. data/samples/bigdemo/icons/list.xpm +27 -0
  83. data/samples/bigdemo/icons/mondrian.ico +0 -0
  84. data/samples/bigdemo/icons/mondrian.xpm +44 -0
  85. data/samples/bigdemo/icons/new.xpm +24 -0
  86. data/samples/bigdemo/icons/ogl.ico +0 -0
  87. data/samples/bigdemo/icons/ogl.xpm +45 -0
  88. data/samples/bigdemo/icons/open.xpm +26 -0
  89. data/samples/bigdemo/icons/paste.bmp +0 -0
  90. data/samples/bigdemo/icons/paste.xpm +38 -0
  91. data/samples/bigdemo/icons/pointy.png +0 -0
  92. data/samples/bigdemo/icons/preview.xpm +26 -0
  93. data/samples/bigdemo/icons/print.xpm +26 -0
  94. data/samples/bigdemo/icons/radio.bmp +0 -0
  95. data/samples/bigdemo/icons/radio.xpm +27 -0
  96. data/samples/bigdemo/icons/robert.xpm +415 -0
  97. data/samples/bigdemo/icons/ruby.png +0 -0
  98. data/samples/bigdemo/icons/sashtest.ico +0 -0
  99. data/samples/bigdemo/icons/save.xpm +25 -0
  100. data/samples/bigdemo/icons/smiles.bmp +0 -0
  101. data/samples/bigdemo/icons/smiles.xpm +39 -0
  102. data/samples/bigdemo/icons/smiley.ico +0 -0
  103. data/samples/bigdemo/icons/smiley.xpm +42 -0
  104. data/samples/bigdemo/icons/stattext.xpm +24 -0
  105. data/samples/bigdemo/icons/test2.bmp +0 -0
  106. data/samples/bigdemo/icons/test2.png +0 -0
  107. data/samples/bigdemo/icons/test2.xpm +79 -0
  108. data/samples/bigdemo/icons/text.bmp +0 -0
  109. data/samples/bigdemo/icons/text.xpm +27 -0
  110. data/samples/bigdemo/icons/tog1.bmp +0 -0
  111. data/samples/bigdemo/icons/tog1.xpm +38 -0
  112. data/samples/bigdemo/icons/tog2.bmp +0 -0
  113. data/samples/bigdemo/icons/tog2.xpm +38 -0
  114. data/samples/bigdemo/icons/wxwin.ico +0 -0
  115. data/samples/bigdemo/icons/wxwin16x16.png +0 -0
  116. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -0
  117. data/samples/bigdemo/icons/wxwin32x32.png +0 -0
  118. data/samples/bigdemo/icons/wxwin48x48.png +0 -0
  119. data/samples/bigdemo/run.rb +90 -0
  120. data/samples/bigdemo/tips.txt +7 -0
  121. data/samples/bigdemo/utils.rb +12 -0
  122. data/samples/bigdemo/wxArtProvider.rbw +281 -0
  123. data/samples/bigdemo/wxBitmapButton.rbw +65 -0
  124. data/samples/bigdemo/wxButton.rbw +64 -0
  125. data/samples/bigdemo/wxCalendarCtrl.rbw +60 -0
  126. data/samples/bigdemo/wxCheckBox.rbw +50 -0
  127. data/samples/bigdemo/wxCheckListBox.rbw +75 -0
  128. data/samples/bigdemo/wxChoice.rbw +47 -0
  129. data/samples/bigdemo/wxChoicebook.rbw +78 -0
  130. data/samples/bigdemo/wxColourDialog.rbw +31 -0
  131. data/samples/bigdemo/wxComboBox.rbw +77 -0
  132. data/samples/bigdemo/wxCursor.rbw +136 -0
  133. data/samples/bigdemo/wxDialog.rbw +74 -0
  134. data/samples/bigdemo/wxDirDialog.rbw +29 -0
  135. data/samples/bigdemo/wxDragImage.rbw +70 -0
  136. data/samples/bigdemo/wxFileDialog.rbw +37 -0
  137. data/samples/bigdemo/wxFileDialog_Save.rbw +35 -0
  138. data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -0
  139. data/samples/bigdemo/wxFontDialog.rbw +173 -0
  140. data/samples/bigdemo/wxFrame.rbw +53 -0
  141. data/samples/bigdemo/wxGauge.rbw +71 -0
  142. data/samples/bigdemo/wxGenericDirCtrl.rbw +74 -0
  143. data/samples/bigdemo/wxGrid.rbw +66 -0
  144. data/samples/bigdemo/wxHtmlHelpController.rbw +52 -0
  145. data/samples/bigdemo/wxListBox.rbw +140 -0
  146. data/samples/bigdemo/wxListCtrl_virtual.rbw +107 -0
  147. data/samples/bigdemo/wxMDIWindows.rbw +50 -0
  148. data/samples/bigdemo/wxMenu.rbw +236 -0
  149. data/samples/bigdemo/wxMessageDialog.rbw +27 -0
  150. data/samples/bigdemo/wxMiniFrame.rbw +70 -0
  151. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -0
  152. data/samples/bigdemo/wxNotebook.rbw +136 -0
  153. data/samples/bigdemo/wxProgressDialog.rbw +43 -0
  154. data/samples/bigdemo/wxRadioBox.rbw +72 -0
  155. data/samples/bigdemo/wxRadioButton.rbw +125 -0
  156. data/samples/bigdemo/wxSashWindow.rbw +141 -0
  157. data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -0
  158. data/samples/bigdemo/wxScrolledWindow.rbw +199 -0
  159. data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -0
  160. data/samples/bigdemo/wxSlider.rbw +42 -0
  161. data/samples/bigdemo/wxSpinButton.rbw +50 -0
  162. data/samples/bigdemo/wxSpinCtrl.rbw +51 -0
  163. data/samples/bigdemo/wxSplitterWindow.rbw +63 -0
  164. data/samples/bigdemo/wxStaticBitmap.rbw +51 -0
  165. data/samples/bigdemo/wxStaticText.rbw +55 -0
  166. data/samples/bigdemo/wxStatusBar.rbw +126 -0
  167. data/samples/bigdemo/wxTextCtrl.rbw +149 -0
  168. data/samples/bigdemo/wxTextEntryDialog.rbw +31 -0
  169. data/samples/bigdemo/wxToggleButton.rbw +49 -0
  170. data/samples/bigdemo/wxToolBar.rbw +131 -0
  171. data/samples/bigdemo/wxTreeCtrl.rbw +190 -0
  172. data/samples/calendar/calendar.rb +271 -0
  173. data/samples/caret/caret.rb +282 -0
  174. data/samples/caret/mondrian.xpm +44 -0
  175. data/samples/controls/controls.rb +1136 -0
  176. data/samples/controls/get_item_sample.rb +87 -0
  177. data/samples/controls/icons/choice.xpm +27 -0
  178. data/samples/controls/icons/combo.xpm +27 -0
  179. data/samples/controls/icons/gauge.xpm +27 -0
  180. data/samples/controls/icons/list.xpm +27 -0
  181. data/samples/controls/icons/radio.xpm +27 -0
  182. data/samples/controls/icons/stattext.xpm +24 -0
  183. data/samples/controls/icons/text.xpm +27 -0
  184. data/samples/controls/mondrian.ico +0 -0
  185. data/samples/controls/mondrian.xpm +44 -0
  186. data/samples/controls/test2.bmp +0 -0
  187. data/samples/dialogs/dialogs.rb +723 -0
  188. data/samples/dialogs/tips.txt +18 -0
  189. data/samples/drawing/graphics_drawing.rb +235 -0
  190. data/samples/drawing/images.rb +37 -0
  191. data/samples/drawing/paperclip.png +0 -0
  192. data/samples/etc/activation.rb +102 -0
  193. data/samples/etc/choice.rb +67 -0
  194. data/samples/etc/miniframe.rb +79 -0
  195. data/samples/etc/sash.rb +130 -0
  196. data/samples/etc/scrollwin.rb +110 -0
  197. data/samples/etc/system_settings.rb +252 -0
  198. data/samples/etc/threaded.rb +72 -0
  199. data/samples/etc/wizard.rb +74 -0
  200. data/samples/event/event.rb +182 -0
  201. data/samples/grid/grid.rb +198 -0
  202. data/samples/grid/gridtablebase.rb +134 -0
  203. data/samples/html/html.rb +262 -0
  204. data/samples/listbook/listbook.rb +174 -0
  205. data/samples/listbook/listbook.xrc +370 -0
  206. data/samples/mdi/mdi.rb +82 -0
  207. data/samples/media/mediactrl.rb +167 -0
  208. data/samples/minimal/minimal.rb +77 -0
  209. data/samples/minimal/mondrian.ico +0 -0
  210. data/samples/minimal/mondrian.png +0 -0
  211. data/samples/minimal/nothing.rb +16 -0
  212. data/samples/opengl/cube.rb +117 -0
  213. data/samples/printing/mondrian.ico +0 -0
  214. data/samples/printing/mondrian.xpm +44 -0
  215. data/samples/printing/printing.rb +310 -0
  216. data/samples/sockets/SocketPackets.rb +27 -0
  217. data/samples/sockets/res/message-new.png +0 -0
  218. data/samples/sockets/res/user.png +0 -0
  219. data/samples/sockets/wxClient.rb +395 -0
  220. data/samples/sockets/wxServer.rb +422 -0
  221. data/samples/sockets/wxSocketGUI.rb +97 -0
  222. data/samples/text/mondrian.ico +0 -0
  223. data/samples/text/mondrian.xpm +44 -0
  224. data/samples/text/scintilla.rb +169 -0
  225. data/samples/text/textctrl.rb +113 -0
  226. data/samples/text/unicode.rb +242 -0
  227. data/samples/text/utf8.txt +15 -0
  228. data/samples/treectrl/icon1.xpm +79 -0
  229. data/samples/treectrl/icon2.xpm +53 -0
  230. data/samples/treectrl/icon3.xpm +79 -0
  231. data/samples/treectrl/icon4.xpm +43 -0
  232. data/samples/treectrl/icon5.xpm +79 -0
  233. data/samples/treectrl/treectrl.rb +1174 -0
  234. data/samples/xrc/samples.xrc +46 -0
  235. data/samples/xrc/xrc_sample.rb +96 -0
  236. metadata +313 -0
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+ require 'wx'
9
+
10
+ class GridFrame < Wx::Frame
11
+
12
+ def initialize(parent, id = -1, title = "MyFrame",
13
+ pos = Wx::DEFAULT_POSITION,
14
+ size = Wx::DEFAULT_SIZE,
15
+ style = Wx::DEFAULT_FRAME_STYLE)
16
+
17
+ super(parent, id, title, pos, size, style)
18
+ sizer = Wx::BoxSizer.new(Wx::VERTICAL)
19
+ create_status_bar()
20
+ set_status_text(Wx::VERSION_STRING)
21
+
22
+ # panel = Wx::Panel.new(self)
23
+ sel_menu = Wx::Menu.new
24
+ sel_menu.append(1002, 'Select all', 'Select all')
25
+ evt_menu(1002) { @grid.select_all }
26
+ sel_menu.append(1003, 'Select row 2', 'Select row 2')
27
+ evt_menu(1003) { @grid.select_row(1) }
28
+ sel_menu.append(1004, 'Select column 4', 'Select col 4')
29
+ evt_menu(1004) { @grid.select_col(3) }
30
+ sel_menu.append(1005, 'Select block', 'Select block')
31
+ evt_menu(1005) { @grid.select_block(1, 1, 6, 3) }
32
+ menu_bar = Wx::MenuBar.new
33
+ menu_bar.append(sel_menu, 'Select')
34
+ set_menu_bar(menu_bar)
35
+
36
+ make_grid(self)
37
+ sizer.add(@grid, 1, Wx::ALL|Wx::GROW, 4)
38
+ set_sizer(sizer)
39
+
40
+ evt_grid_cell_left_click() do |evt|
41
+ set_status_text("#{evt.get_row} x #{evt.get_col} is clicked")
42
+ evt.skip
43
+ end
44
+
45
+ evt_grid_cell_right_click() do |evt|
46
+ set_status_text("#{evt.get_row} x #{evt.get_col} is right clicked")
47
+ evt.skip
48
+ end
49
+
50
+ evt_grid_cell_left_dclick() do |evt|
51
+ set_status_text("#{evt.get_row} x #{evt.get_col} is double clicked")
52
+ evt.skip
53
+ end
54
+
55
+ evt_grid_cell_right_dclick() do |evt|
56
+ set_status_text("#{evt.get_row} x #{evt.get_col} is right double clicked")
57
+ evt.skip
58
+ end
59
+
60
+ evt_grid_label_left_click() do |evt|
61
+ set_status_text("#{evt.get_row} x #{evt.get_col} label is clicked")
62
+ evt.skip
63
+ end
64
+
65
+ evt_grid_label_right_click() do |evt|
66
+ set_status_text("#{evt.get_row} x #{evt.get_col} label is right clicked")
67
+ evt.skip
68
+ end
69
+
70
+ evt_grid_label_left_dclick() do |evt|
71
+ set_status_text("#{evt.get_row} x #{evt.get_col} labelis double clicked")
72
+ evt.skip
73
+ end
74
+
75
+ evt_grid_label_right_dclick() do |evt|
76
+ set_status_text("#{evt.get_row} x #{evt.get_col} label is right double clicked")
77
+ evt.skip
78
+ end
79
+
80
+ evt_grid_select_cell() do |evt|
81
+ set_status_text("#{evt.get_row} x #{evt.get_col} cell is selected")
82
+ evt.skip
83
+ end
84
+
85
+ evt_grid_row_size do |evt|
86
+ set_status_text("Row #{evt.get_row_or_col} size changed")
87
+ evt.skip
88
+ end
89
+
90
+ evt_grid_col_size do |evt|
91
+ set_status_text("Column #{evt.get_row_or_col} size changed")
92
+ evt.skip
93
+ end
94
+
95
+ evt_grid_editor_shown do |evt|
96
+ set_status_text("Begin editing")
97
+ evt.skip
98
+ end
99
+
100
+ evt_grid_editor_hidden do |evt|
101
+ set_status_text("End editing")
102
+ evt.skip
103
+ end
104
+
105
+ evt_grid_range_select do |evt|
106
+ top = evt.get_top_left_coords
107
+ bottom = evt.get_bottom_right_coords
108
+ set_status_text("[ #{top[0].to_s} x #{top[1].to_s} ] to [ #{bottom[0].to_s} x #{bottom[1].to_s} ] is selected")
109
+ end
110
+
111
+ evt_grid_editor_created do |evt|
112
+ set_status_text("Control #{evt.get_control} created")
113
+ evt.skip
114
+ end
115
+
116
+ evt_grid_cell_change() do |evt|
117
+ set_status_text("Cell #{evt.get_row} x #{evt.get_col} has changed")
118
+ end
119
+ end
120
+
121
+ # Create a wxGrid object
122
+ def make_grid(panel)
123
+ @grid = Wx::Grid.new(panel, -1)
124
+
125
+ # Then we call CreateGrid to set the dimensions of the grid
126
+ # (11 rows and 12 columns in this example)
127
+ @grid.create_grid( 20, 12 )
128
+ @grid.set_default_cell_background_colour(Wx::WHITE)
129
+ # We can set the sizes of individual rows and columns
130
+ # in pixels, and the label value string
131
+ @grid.set_row_size( 0, 60 )
132
+ @grid.set_row_label_value( 0, "Row1" )
133
+ @grid.set_row_label_alignment(Wx::ALIGN_CENTRE, Wx::ALIGN_CENTRE)
134
+
135
+ @grid.set_col_size( 0, 120 )
136
+ @grid.set_col_label_value( 0, "Col1" )
137
+ @grid.set_col_label_alignment(Wx::ALIGN_CENTRE, Wx::ALIGN_CENTRE)
138
+
139
+ # And set grid cell contents as strings
140
+ @grid.set_cell_value( 0, 0, "wxGrid is good" )
141
+
142
+ # We can specify that some cells are read-only
143
+ @grid.set_cell_value( 0, 2, "Read-only" )
144
+ @grid.set_read_only( 0, 2 )
145
+
146
+ # Colours can be specified for grid cell contents
147
+ @grid.set_cell_value(1, 1, "white on red")
148
+ @grid.set_cell_text_colour(1, 1, Wx::WHITE)
149
+ @grid.set_cell_background_colour(1, 1, Wx::RED)
150
+
151
+ # We can specify the some cells will store numeric
152
+ # values rather than strings. Here we set grid column 6
153
+ # to hold floating point values displayed with width
154
+ # of 2 and precision of 2. The column is highlighted in light grey
155
+ cell_attr = Wx::GridCellAttr.new
156
+ cell_attr.set_background_colour( Wx::LIGHT_GREY )
157
+ cell_attr.set_renderer( Wx::GridCellFloatRenderer.new(2, 2) )
158
+
159
+ @grid.set_col_attr(5, cell_attr)
160
+ @grid.set_cell_value(0, 5, "3.1415")
161
+ @grid.set_cell_value(0, 6,
162
+ "The whole column to the left uses float format")
163
+
164
+ # Custom Editors Can be used
165
+ editor = Wx::GridCellNumberEditor.new(5, 20)
166
+ @grid.set_cell_value(3, 1, 'Number editor below')
167
+ @grid.set_cell_editor(4, 1, editor)
168
+
169
+ editor = Wx::GridCellFloatEditor.new(4, 2)
170
+ @grid.set_cell_value(3, 2, 'Float editor below')
171
+ @grid.set_cell_editor(4, 2, editor)
172
+
173
+ editor = Wx::GridCellChoiceEditor.new(['foo', 'bar', 'baz'])
174
+ @grid.set_cell_value(3, 3, 'Choice editor below')
175
+ @grid.set_cell_editor(4, 3, editor)
176
+
177
+ @grid.auto_size_row(3, true)
178
+
179
+ # Display of cells can be customised
180
+ @grid.set_cell_editor(6, 0, Wx::GridCellBoolEditor.new)
181
+ @grid.set_cell_renderer(6, 0, Wx::GridCellBoolRenderer.new)
182
+ @grid.set_cell_value(6, 1, 'Cell to the left displayed as boolean')
183
+ end
184
+
185
+ end
186
+
187
+ class GridApp < Wx::App
188
+ def on_init
189
+ frame = GridFrame.new(nil, -1, "Grid Sample",
190
+ Wx::Point.new(10, 100),
191
+ Wx::Size.new(630,400))
192
+
193
+ set_top_window(frame)
194
+ frame.show()
195
+ end
196
+ end
197
+
198
+ GridApp.new.main_loop()
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+ require 'wx'
9
+
10
+ # GridTableBase is an alternative way to provide data to a Wx::Grid. A
11
+ # subclass of Wx::GridTableBase is created which is reqiured to provide
12
+ # methods to report the total size of the Grid in rows and columns, and
13
+ # the contents and style of individual cells.
14
+ #
15
+ # Then, when creating the Grid, instead of calling create_grid and
16
+ # set_value to populate it, the GridTableBase-derived class is
17
+ # associated with the Grid, and provides these functions (see below)
18
+ #
19
+ # This approach is typically useful for dealing with very large sets of
20
+ # data, as each cell's value is only requested as it becomes visible.v
21
+ class MyGridTable < Wx::GridTableBase
22
+ attr_reader :cols, :rows
23
+ def initialize(rows, cols)
24
+ super()
25
+ @rows = rows
26
+ @cols = cols
27
+ @val = 'a'
28
+ end
29
+
30
+ # Firstly, a GridTableBase must indicate the size of the grid in
31
+ # terms of rows ...
32
+ def get_number_rows
33
+ @rows
34
+ end
35
+
36
+ # ... and columns
37
+ def get_number_cols
38
+ @cols
39
+ end
40
+
41
+ # Most importantly, it should be able to return any given cell's
42
+ # contents, given its row and column reference
43
+ def get_value(row, col)
44
+ "#{@val} - #{row}"
45
+ end
46
+
47
+ # It should also return the attributes that should apply to any given
48
+ # cell; this example give alternate rows red text letters
49
+ def get_attr(row, col, attr_kind)
50
+ attr = Wx::GridCellAttr.new
51
+ if (row % 2).zero?
52
+ attr.text_colour = Wx::RED
53
+ end
54
+ attr
55
+ end
56
+
57
+ # It should indicate whether any given cell is empty
58
+ def is_empty_cell(row, col)
59
+ false
60
+ end
61
+
62
+ # It may also provide labels for the columns and rows
63
+ def get_col_label_value(col)
64
+ "Col: #{col}"
65
+ end
66
+
67
+ # If the Grid is to support write as well as read operations,
68
+ # set_value should also be implemented. In this case, the change is
69
+ # merely echoed back and doesn't alter the underlying value; a real
70
+ # implementation could, for example, write back to a database
71
+ def set_value(x, y, val)
72
+ puts "Changing the value of cell (#{x}, #{y}) to '#{val}'"
73
+ end
74
+ end
75
+
76
+ # A derivative class illustrating that it is possible to change
77
+ # parameters of the GridTable and have the main control update.
78
+ class MyMutableGridTable < MyGridTable
79
+ def increment_value
80
+ @val = @val.succ
81
+ end
82
+ end
83
+
84
+
85
+ class GridFrame < Wx::Frame
86
+ def initialize()
87
+ super(nil, :title => 'GridTableBase demo')
88
+ main_sizer = Wx::BoxSizer.new(Wx::VERTICAL)
89
+ # Create a grid and associate an instance of the GridTable as the
90
+ # data provider for the grid
91
+ @grid = Wx::Grid.new(self)
92
+ @grid.table = MyMutableGridTable.new(10, 10)
93
+
94
+ main_sizer.add(@grid, 1, Wx::EXPAND|Wx::ALL, 5)
95
+
96
+ # Add some buttons that can change the contents
97
+ butt_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
98
+
99
+ butt_1 = Wx::Button.new(self, :label => "Add row")
100
+ # When resizing the grid to have a new number of rows or columns,
101
+ # need to allocate a new grid table source
102
+ evt_button(butt_1) do
103
+ @grid.table = MyMutableGridTable.new( @grid.table.rows + 1,
104
+ @grid.table.cols)
105
+ @grid.refresh
106
+ end
107
+ butt_sizer.add(butt_1)
108
+
109
+ butt_2 = Wx::Button.new(self, :label => "Add column")
110
+ evt_button(butt_2) do
111
+ @grid.table = MyMutableGridTable.new( @grid.table.rows,
112
+ @grid.table.cols + 1)
113
+ @grid.refresh
114
+ end
115
+ butt_sizer.add(butt_2)
116
+
117
+ # For other changes, can just change a value in the existing
118
+ # GridTable
119
+ butt_3 = Wx::Button.new(self, :label => "Increment letter")
120
+ evt_button(butt_3) do
121
+ @grid.table.increment_value
122
+ @grid.refresh
123
+ end
124
+ butt_sizer.add(butt_3)
125
+
126
+ main_sizer.add(butt_sizer, 0, Wx::EXPAND|Wx::ALL, 5)
127
+ self.sizer = main_sizer
128
+ end
129
+ end
130
+
131
+ Wx::App.run do
132
+ GridFrame.new.show
133
+ end
134
+
@@ -0,0 +1,262 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+ require 'wx'
9
+
10
+ require 'net/http'
11
+ require 'uri'
12
+
13
+ class MyHtmlWindow < Wx::HtmlWindow
14
+ attr_reader :html_src
15
+ def initialize(*args)
16
+ super
17
+ evt_html_link_clicked self, :on_link_clicked
18
+ evt_html_cell_hover self, :on_hover
19
+ end
20
+
21
+ def load_page_from_uri(uri)
22
+ case uri
23
+ when URI::HTTP
24
+ Wx::BusyCursor.busy do
25
+ begin
26
+ res = Net::HTTP.start(uri.host, uri.port) do | http |
27
+ http.get(uri.path)
28
+ end
29
+ @loaded_uri = uri
30
+ set_page(res.body)
31
+ rescue => err
32
+ msg = "Could not load page:\n#{err}"
33
+ Wx::MessageDialog.new(nil, msg, 'Error loading page',
34
+ Wx::OK|Wx::ICON_ERROR).show_modal
35
+ return ''
36
+ end
37
+ end
38
+ return @loaded_uri
39
+ when URI::Generic
40
+ if @loaded_uri and @loaded_uri.kind_of?(URI::HTTP)
41
+ return load_page_from_uri( @loaded_uri.merge(uri) )
42
+ elsif @loaded_uri # current viewing a file
43
+ if uri.to_s =~ /^\//
44
+ return load_file(uri.path)
45
+ elsif not uri.path.empty?
46
+ local_file = File.join( File.dirname(@loaded_uri.path), uri.path)
47
+ return load_file( local_file )
48
+ end
49
+ end
50
+ end
51
+
52
+ dlg = Wx::MessageDialog.new(nil, "Can't load link",
53
+ "Unable to load the link #{uri}",
54
+ Wx::ICON_ERROR)
55
+ dlg.show_modal
56
+ end
57
+
58
+ def load_file(file)
59
+ @loaded_uri = URI.parse("file:////" + file)
60
+ super file
61
+ @loaded_uri
62
+ end
63
+
64
+ def set_page(html)
65
+ super html
66
+ @html_src = html
67
+ related_frame.addr_bar.value = @loaded_uri.to_s
68
+ end
69
+
70
+ def on_link_clicked(event)
71
+ href = event.link_info.href
72
+ return if href =~ /^#/
73
+ link_uri = URI.parse(href)
74
+ @loaded_uri = load_page_from_uri(link_uri)
75
+ end
76
+
77
+ def on_hover(event)
78
+ if link = event.cell.link
79
+ related_frame.set_status_text(link.href)
80
+ else
81
+ related_frame.status_text = ''
82
+ end
83
+ end
84
+ end
85
+
86
+ # The frame or self-contained window for this application
87
+ class HtmlFrame < Wx::Frame
88
+ attr_reader :html_win, :addr_bar
89
+
90
+ def initialize(title, pos, size, style = Wx::DEFAULT_FRAME_STYLE)
91
+ # A main application frame has no parent (nil)
92
+ # -1 means this frame will be supplied a default id
93
+ super(nil, -1, title, pos, size, style)
94
+ setup_menus
95
+ setup_panel
96
+ create_status_bar
97
+ self.status_text = "Welcome to wxRuby!"
98
+ end
99
+
100
+ def setup_panel
101
+ panel = Wx::Panel.new(self, -1)
102
+
103
+ sizer = Wx::BoxSizer.new(Wx::VERTICAL)
104
+ top_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
105
+
106
+ @go_butt = Wx::StaticText.new(panel, -1, 'Location:')
107
+ top_sizer.add(@go_butt, 0, Wx::ALL, 4)
108
+ @addr_bar = Wx::TextCtrl.new(panel, -1, 'HOME', Wx::DEFAULT_POSITION,
109
+ Wx::DEFAULT_SIZE, Wx::TE_READONLY)
110
+ top_sizer.add(@addr_bar, 1, Wx::ALL, 4)
111
+ sizer.add(top_sizer, 0, Wx::EXPAND|Wx::TOP|Wx::BOTTOM, 4)
112
+
113
+ @html_win = MyHtmlWindow.new(panel, -1)
114
+ @html_win.set_related_frame(self, 'HTML Window: %s')
115
+
116
+ @html_win.set_page(DATA.read)
117
+ sizer.add(@html_win, 1, Wx::ALL|Wx::GROW, 4)
118
+ panel.set_sizer(sizer)
119
+ end
120
+
121
+ def setup_menus
122
+ menu_file = Wx::Menu.new()
123
+ menu_help = Wx::Menu.new()
124
+ # Using Wx::ID_ABOUT default id means the menu item will be placed
125
+ # in the correct platform-specific place
126
+ menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
127
+ menu_file.append(Wx::ID_OPEN, "&Open File...\tCtrl-O", "Open File")
128
+ menu_file.append(Wx::ID_HIGHEST + 1, "&Open URL...\tCtrl-U", "Open URL")
129
+ menu_file.append(Wx::ID_PRINT, "&Print...\tCtrl-P", "Print")
130
+
131
+ menu_file.append(Wx::ID_PREVIEW, "&Preview...\tCtrl-Shift-P",
132
+ "Print Preview")
133
+ menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
134
+
135
+ menu_bar = Wx::MenuBar.new()
136
+ menu_bar.append(menu_file, "&File")
137
+ menu_bar.append(menu_help, "&Help")
138
+ # Assign the menus to this frame
139
+ self.menu_bar = menu_bar
140
+ # handle menu events
141
+ evt_menu Wx::ID_OPEN, :on_open_file
142
+ evt_menu Wx::ID_HIGHEST + 1, :on_open_url
143
+ evt_menu Wx::ID_PRINT, :on_print
144
+ evt_menu Wx::ID_PREVIEW, :on_preview
145
+ evt_menu Wx::ID_EXIT, :on_quit
146
+ evt_menu Wx::ID_ABOUT, :on_about
147
+ end
148
+
149
+ # end the application
150
+ def on_quit
151
+ close
152
+ end
153
+
154
+ def on_open_file
155
+ f_dlg = Wx::FileDialog.new(self, "Open an HTML file", "", "",
156
+ "HTML files (*.html;*.htm)|*.html;*.htm)",
157
+ Wx::OPEN)
158
+ if not f_dlg.show_modal == Wx::ID_OK
159
+ return
160
+ end
161
+ html_file = f_dlg.get_path
162
+ if html_file.index("\\")
163
+ html_file = html_file.split("\\").join("/")
164
+ end
165
+ @html_win.load_file(html_file)
166
+ end
167
+
168
+ def on_open_url
169
+ url = Wx::get_text_from_user('Enter URL to open', 'Enter URL')
170
+ if not url.empty?
171
+ uri = URI.parse(url)
172
+ uri.path = '/' if uri.path.empty?
173
+ @html_win.load_page_from_uri(uri)
174
+ end
175
+ end
176
+
177
+ # show an 'About' dialog
178
+ def on_about
179
+ msg = sprintf("This is the About dialog of the HTML sample.\n" \
180
+ "Welcome to wxRuby, version %s", Wx::WXRUBY_VERSION)
181
+
182
+ # create a simple message dialog with OK button
183
+ about_dlg = Wx::MessageDialog.new( self, msg, 'About WxRuby HTML',
184
+ Wx::OK|Wx::ICON_INFORMATION )
185
+ about_dlg.show_modal()
186
+ about_dlg.destroy()
187
+ end
188
+
189
+ def on_preview
190
+ print = Wx::HtmlEasyPrinting.new('Print HTML', self)
191
+ print.preview_text(@html_win.html_src)
192
+ end
193
+
194
+ def on_print
195
+ print = Wx::HtmlEasyPrinting.new('Print HTML', self)
196
+ print.print_text(@html_win.html_src)
197
+ end
198
+
199
+ # utility function to find an icon relative to this ruby script
200
+ def local_icon_file(icon_name)
201
+ File.join( File.dirname(__FILE__), icon_name)
202
+ end
203
+ end
204
+
205
+ # Wx::App is the container class for any wxruby app - only a single
206
+ # instance is required
207
+ class HtmlApp < Wx::App
208
+ def on_init
209
+ frame = HtmlFrame.new("Minimal wxRuby App",
210
+ Wx::Point.new(50, 50),
211
+ Wx::Size.new(450, 340))
212
+ set_app_name('HtmlDemo')
213
+ # required
214
+ frame.show()
215
+ end
216
+ end
217
+
218
+ # Create an instance ...
219
+ app = HtmlApp.new
220
+ # ... and run the application
221
+ app.main_loop()
222
+
223
+ __END__
224
+ <html>
225
+ <head>
226
+ <title>WxRuby HTML Demo</title>
227
+ </head>
228
+
229
+ <body bgcolor="#ffffff">
230
+ <h1>The HtmlWindow widget</h1>
231
+ <p>This is a very simple demonstration of
232
+ <strong>Wx::HtmlWindow</strong>, a control for displaying hypertext. The
233
+ control understands most HTML tags, including links, tables, images,
234
+ lists and the venerable FONT tag. It does not know about CSS or
235
+ Javascript; it is not really intended for building a general-purpose
236
+ web browser.</p>
237
+ <h2>This demo</h2>
238
+ <p>In this demo you can open local files for viewing (by choosing the
239
+ File / Open). If you have an internet connection http:// links will be
240
+ downloaded as well. Its features are otherwise limited - for example,
241
+ this example doesn't know about HTML anchor targets, because it has
242
+ over-ridden default link handling to show how to subclass and
243
+ specialise HtmlWindow in Ruby.</a>
244
+ <h2>Html Easy Printing</h2>
245
+ <p>A useful feature included with WxRuby is a simple interface for
246
+ printing HTML. You can see this in action by choosing 'Print' or
247
+ 'Preview' from the File menu.</p>
248
+ <h3>Further information</h3>
249
+ <p>Here's a table with some links</p>
250
+ <table border="1">
251
+ <tr>
252
+ <td>WxRuby online documentation</td>
253
+ <td><a href="http://wxruby.rubyforge.org/doc/">http://wxruby.rubyforge.org/doc/</a></td>
254
+ </tr>
255
+ <tr>
256
+ <td>WxRuby Wiki</td>
257
+ <td><a href="http://wxruby.rubyforge.org/wiki/wiki.pl">http://wxruby.rubyforge.org/wiki/wiki.pl</a></td>
258
+ </tr>
259
+ </table>
260
+
261
+ </body>
262
+ </html>