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,723 @@
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
+
11
+ require 'wx'
12
+
13
+
14
+ include Wx
15
+
16
+ DIALOGS_CHOOSE_COLOUR = 1
17
+ DIALOGS_CHOOSE_COLOUR_GENERIC = 2
18
+ DIALOGS_CHOOSE_FONT = 3
19
+ DIALOGS_CHOOSE_FONT_GENERIC = 4
20
+ DIALOGS_MESSAGE_BOX = 5
21
+ DIALOGS_SINGLE_CHOICE = 6
22
+ DIALOGS_MULTI_CHOICE = 7
23
+ DIALOGS_TEXT_ENTRY = 8
24
+ DIALOGS_PASSWORD_ENTRY = 9
25
+ DIALOGS_FILE_OPEN = 10
26
+ DIALOGS_FILE_OPEN2 = 11
27
+ DIALOGS_FILES_OPEN = 12
28
+ DIALOGS_FILE_SAVE = 13
29
+ DIALOGS_DIR_CHOOSE = 14
30
+ DIALOGS_GENERIC_DIR_CHOOSE = 15
31
+ DIALOGS_TIP = 16
32
+ DIALOGS_NUM_ENTRY = 17
33
+ DIALOGS_LOG_DIALOG = 18
34
+ DIALOGS_MODAL = 19
35
+ DIALOGS_MODELESS = 20
36
+ DIALOGS_MODELESS_BTN = 21
37
+ DIALOGS_PROGRESS = 22
38
+ DIALOGS_BUSYINFO = 23
39
+ DIALOGS_FIND = 24
40
+ DIALOGS_REPLACE = 25
41
+
42
+ $my_canvas = nil
43
+
44
+ class MyModalDialog < Dialog
45
+ def initialize(parent)
46
+ super(parent, -1, "Modal dialog")
47
+
48
+ sizer_top = BoxSizer.new(HORIZONTAL)
49
+
50
+ @btn_focused = Button.new(self, -1, "Default button")
51
+ @btn_delete = Button.new(self, -1, "&Delete button")
52
+ btn_ok = Button.new(self, ID_CANCEL, "&Close")
53
+ sizer_top.add(@btn_focused, 0, ALIGN_CENTER | ALL, 5)
54
+ sizer_top.add(@btn_delete, 0, ALIGN_CENTER | ALL, 5)
55
+ sizer_top.add(btn_ok, 0, ALIGN_CENTER | ALL, 5)
56
+
57
+ set_auto_layout(true)
58
+ set_sizer(sizer_top)
59
+
60
+ sizer_top.set_size_hints(self)
61
+ sizer_top.fit(self)
62
+
63
+ @btn_focused.set_focus()
64
+ @btn_focused.set_default()
65
+
66
+ evt_button(-1) {|event| on_button(event) }
67
+ end
68
+
69
+ def on_button(event)
70
+ id = event.get_id
71
+
72
+ if id == @btn_delete.get_id
73
+ @btn_focused.destroy
74
+ @btn_focused = nil
75
+
76
+ @btn_delete.disable()
77
+ elsif @btn_focused && id == @btn_focused.get_id
78
+ get_text_from_user("Dummy prompt", "Modal dialog called from dialog",
79
+ "", self)
80
+ else
81
+ event.skip()
82
+ end
83
+ end
84
+ end
85
+
86
+
87
+ class MyModelessDialog < Dialog
88
+ def initialize(parent)
89
+ super(parent, -1, "Modeless dialog")
90
+
91
+ sizer_top = BoxSizer.new(VERTICAL)
92
+
93
+ btn = Button.new(self, DIALOGS_MODELESS_BTN, "Press me")
94
+ check = CheckBox.new(self, -1, "Should be disabled")
95
+ check.disable()
96
+
97
+ sizer_top.add(btn, 1, EXPAND | ALL, 5)
98
+ sizer_top.add(check, 1, EXPAND | ALL, 5)
99
+
100
+ set_auto_layout(true)
101
+ set_sizer(sizer_top)
102
+
103
+ sizer_top.set_size_hints(self)
104
+ sizer_top.fit(self)
105
+
106
+ evt_button(DIALOGS_MODELESS_BTN) {|event| on_button(event) }
107
+
108
+ evt_close() {|event| on_close(event) }
109
+
110
+ end
111
+
112
+ def on_button(event)
113
+ message_box("Button pressed in modeless dialog", "Info",
114
+ OK | ICON_INFORMATION, self)
115
+ end
116
+
117
+ def on_close(event)
118
+ if event.can_veto()
119
+ message_box("Use the menu item to close self dialog",
120
+ "Modeless dialog",
121
+ OK | ICON_INFORMATION, self)
122
+
123
+ event.veto()
124
+ end
125
+ end
126
+ end
127
+
128
+
129
+ class MyCanvas < ScrolledWindow
130
+ def initialize(parent)
131
+ super(parent,-1,DEFAULT_POSITION,DEFAULT_SIZE, NO_FULL_REPAINT_ON_RESIZE)
132
+ evt_paint { |event| on_paint(event) }
133
+ end
134
+
135
+ def clear
136
+
137
+ end
138
+
139
+ def on_paint(event)
140
+ paint do |dc|
141
+ dc.set_text_foreground( get_app.canvas_text_colour )
142
+ dc.set_font( get_app.canvas_font )
143
+ dc.draw_text("Windows common dialogs test application", 10, 10)
144
+ end
145
+ end
146
+ end
147
+
148
+ class MyFrame < Frame
149
+ def initialize(parent,
150
+ title,
151
+ pos,
152
+ size)
153
+ super(parent, -1, title, pos, size)
154
+
155
+ @dialog = nil
156
+
157
+ @dlg_find = nil
158
+ @dlg_replace = nil
159
+
160
+ @find_data = FindReplaceData.new
161
+
162
+ @ext_def = ""
163
+ @index = -1
164
+
165
+ @max = 10
166
+
167
+ create_status_bar()
168
+
169
+ evt_menu(DIALOGS_CHOOSE_COLOUR) {|event| on_choose_colour(event) }
170
+ evt_menu(DIALOGS_CHOOSE_FONT) {|event| on_choose_font(event) }
171
+ evt_menu(DIALOGS_LOG_DIALOG) {|event| on_log_dialog(event) }
172
+ evt_menu(DIALOGS_MESSAGE_BOX) {|event| on_message_box(event) }
173
+ evt_menu(DIALOGS_TEXT_ENTRY) {|event| on_text_entry(event) }
174
+ evt_menu(DIALOGS_PASSWORD_ENTRY) {|event| on_password_entry(event) }
175
+ evt_menu(DIALOGS_NUM_ENTRY) {|event| on_numeric_entry(event) }
176
+ evt_menu(DIALOGS_SINGLE_CHOICE) {|event| on_single_choice(event) }
177
+ evt_menu(DIALOGS_MULTI_CHOICE) {|event| on_multi_choice(event) }
178
+ evt_menu(DIALOGS_FILE_OPEN) {|event| on_file_open(event) }
179
+ evt_menu(DIALOGS_FILE_OPEN2) {|event| on_file_open2(event) }
180
+ evt_menu(DIALOGS_FILES_OPEN) {|event| on_files_open(event) }
181
+ evt_menu(DIALOGS_FILE_SAVE) {|event| on_file_save(event) }
182
+ evt_menu(DIALOGS_DIR_CHOOSE) {|event| on_dir_choose(event) }
183
+ evt_menu(DIALOGS_MODAL) {|event| on_modal_dlg(event) }
184
+ evt_menu(DIALOGS_MODELESS) {|event| on_modeless_dlg(event) }
185
+ evt_menu(DIALOGS_TIP) {|event| on_show_tip(event) }
186
+ evt_menu(DIALOGS_PROGRESS) {|event| on_show_progress(event) }
187
+ evt_menu(DIALOGS_BUSYINFO) {|event| on_show_busy_info(event) }
188
+ evt_menu(DIALOGS_FIND) {|event| on_show_find_dialog(event) }
189
+ evt_menu(DIALOGS_REPLACE) {|event| on_show_replace_dialog(event) }
190
+ evt_find(-1) {|event| on_find_dialog(event) }
191
+ evt_find_next(-1) {|event| on_find_dialog(event) }
192
+ evt_find_replace(-1) {|event| on_find_dialog(event) }
193
+ evt_find_replace_all(-1) {|event| on_find_dialog(event) }
194
+ evt_find_close(-1) {|event| on_find_dialog(event) }
195
+ evt_menu(ID_EXIT) {|event| on_exit(event) }
196
+
197
+ end
198
+
199
+ def on_choose_colour(event)
200
+
201
+ col = $my_canvas.get_background_colour()
202
+
203
+ data = ColourData.new
204
+ data.set_colour(col)
205
+ data.set_choose_full(true)
206
+ for i in 0 ... 16
207
+ colour = Colour.new(i*16, i*16, i*16)
208
+ data.set_custom_colour(i, colour)
209
+ end
210
+
211
+ dialog = ColourDialog.new(self, data)
212
+ dialog.set_title("Choose the background colour (not OS X)")
213
+ if dialog.show_modal() == ID_OK
214
+ retData = dialog.get_colour_data()
215
+ col = retData.get_colour()
216
+ $my_canvas.set_background_colour(col)
217
+ #$my_canvas.clear()
218
+ $my_canvas.refresh()
219
+ end
220
+ end
221
+
222
+
223
+ def on_choose_font(event)
224
+ data = FontData.new
225
+ data.set_initial_font(Wx::get_app.canvas_font)
226
+ data.set_colour(Wx::get_app.canvas_text_colour)
227
+
228
+ dialog = FontDialog.new(self, data)
229
+
230
+ if dialog.show_modal() == ID_OK
231
+ ret_data = dialog.get_font_data()
232
+ Wx::get_app.canvas_font = ret_data.get_chosen_font()
233
+ Wx::get_app.canvas_text_colour = ret_data.get_colour()
234
+ font = ret_data.get_chosen_font
235
+ msg = "Font = %s, %i pt" % [ font.get_face_name,
236
+ font.get_point_size ]
237
+ dialog2 = MessageDialog.new(self, msg, "Got font")
238
+ dialog2.show_modal()
239
+ # $my_canvas.refresh()
240
+ end
241
+ #else: cancelled by the user, don't change the font
242
+ end
243
+
244
+
245
+ def on_log_dialog(event)
246
+
247
+ # calling yield() (as ~BusyCursor does) shouldn't result in messages
248
+ # being flushed -- test it
249
+
250
+ BusyCursor.busy() do
251
+
252
+ log_message("This is some message - everything is ok so far.")
253
+ log_message("Another message...\n... self one is on multiple lines")
254
+ log_warning("And then something went wrong!")
255
+
256
+ # and if ~BusyCursor doesn't do it, then call it manually
257
+ Wx::get_app.yield()
258
+
259
+ log_error("Intermediary error handler decided to abort.")
260
+ log_error("DEMO: The top level caller detected an unrecoverable error.")
261
+
262
+ Log::flush_active()
263
+
264
+ log_message("And this is the same dialog but with only one message.")
265
+ end
266
+ end
267
+
268
+ def on_message_box(event)
269
+
270
+ dialog = MessageDialog.new(nil, "This is a message box\nA long, long string to test out the message box properly",
271
+ "Message box text", NO_DEFAULT|YES_NO|CANCEL|ICON_INFORMATION)
272
+
273
+ case dialog.show_modal()
274
+ when ID_YES
275
+ log_status("You pressed \"Yes\"")
276
+ when ID_NO
277
+ log_status("You pressed \"No\"")
278
+ when ID_CANCEL
279
+ log_status("You pressed \"Cancel\"")
280
+ else
281
+ log_error("Unexpected MessageDialog return code!")
282
+ end
283
+ end
284
+
285
+
286
+ def on_numeric_entry(event)
287
+
288
+ res = get_number_from_user( "This is some text, actually a lot of text.\n" +
289
+ "Even two rows of text.",
290
+ "Enter a number:", "Numeric input test",
291
+ 50, 0, 100, self )
292
+
293
+ if res == -1
294
+ msg = "Invalid number entered or dialog cancelled."
295
+ icon = ICON_HAND
296
+ else
297
+ msg = sprintf("You've entered %d", res )
298
+ icon = ICON_INFORMATION
299
+ end
300
+
301
+ message_box(msg, "Numeric test result", OK | icon, self)
302
+ end
303
+
304
+ def on_password_entry(event)
305
+
306
+ pwd = get_password_from_user("Enter password:",
307
+ "Password entry dialog",
308
+ "", self)
309
+ if pwd
310
+ message_box(sprintf("Your password is '%s'", pwd),
311
+ "Got password", OK | ICON_INFORMATION, self)
312
+ end
313
+ end
314
+
315
+
316
+ def on_text_entry(event)
317
+
318
+ dialog = TextEntryDialog.new(self,
319
+ "This is a small sample\n" +
320
+ "A long, long string to test out the text entrybox",
321
+ "Please enter a string",
322
+ "Default value",
323
+ OK | CANCEL)
324
+
325
+ if dialog.show_modal() == ID_OK
326
+ dialog2 = MessageDialog.new(self, dialog.get_value(), "Got string")
327
+ dialog2.show_modal()
328
+ end
329
+ end
330
+
331
+ def on_single_choice(event)
332
+
333
+ choices = ["One", "Two", "Three", "Four", "Five"]
334
+
335
+ dialog = SingleChoiceDialog.new(self,
336
+ "This is a small sample\n" +
337
+ "A single-choice convenience dialog",
338
+ "Please select a value",
339
+ choices, nil, OK | CANCEL)
340
+
341
+ dialog.set_selection(2)
342
+
343
+ if dialog.show_modal() == ID_OK
344
+ dialog2 = MessageDialog.new(self, dialog.get_string_selection(), "Got string")
345
+ dialog2.show_modal()
346
+ end
347
+ end
348
+
349
+
350
+ def on_multi_choice(event)
351
+
352
+ choices = [
353
+ "One", "Two", "Three", "Four", "Five",
354
+ "Six", "Seven", "Eight", "Nine", "Ten",
355
+ "Eleven", "Twelve", "Seventeen"]
356
+
357
+ selections = get_multiple_choices("This is a small sample\n" +
358
+ "A multi-choice convenience dialog",
359
+ "Please select a value",
360
+ choices,
361
+ self)
362
+ if selections
363
+ msg = sprintf("You selected %d items:\n", selections.length)
364
+ for n in 0 ... selections.length
365
+ msg += sprintf("\t%d: %d (%s)\n", n, selections[n],
366
+ choices[selections[n]])
367
+ end
368
+ log_message(msg)
369
+ end
370
+ #else: cancelled or nothing selected
371
+ end
372
+
373
+
374
+ def on_file_open(event)
375
+
376
+ dialog = FileDialog.new(
377
+ self,
378
+ "Testing open file dialog",
379
+ "",
380
+ "",
381
+ "C++ files (*.h;*.cpp)|*.h;*.cpp"
382
+ )
383
+
384
+ dialog.set_directory(get_home_dir())
385
+
386
+ if dialog.show_modal() == ID_OK
387
+ info = sprintf("Full file name: %s\n" +
388
+ "Path: %s\n" +
389
+ "Name: %s",
390
+ dialog.get_path(),
391
+ dialog.get_directory(),
392
+ dialog.get_filename())
393
+ dialog2 = MessageDialog.new(self, info, "Selected file")
394
+ dialog2.show_modal()
395
+ end
396
+ end
397
+
398
+
399
+ # this shows how to take advantage of specifying a default extension in the
400
+ # call to FileSelector: it is remembered after each new call and the next
401
+ # one will use it by default
402
+ def on_file_open2(event)
403
+
404
+ path = file_selector(
405
+ "Select the file to load",
406
+ "", "",
407
+ @ext_def,
408
+ "Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*",
409
+ CHANGE_DIR,
410
+ self
411
+ )
412
+
413
+ if path == nil
414
+ return nil
415
+ end
416
+
417
+ # it is just a sample, would use SplitPath in real program
418
+ @ext_def = path[/[^\.]*$/]
419
+
420
+ log_message("You selected the file '%s', remembered extension '%s'",
421
+ path, @ext_def)
422
+ end
423
+
424
+
425
+ def on_files_open(event)
426
+
427
+ dialog = FileDialog.new(self, "Testing open multiple file dialog",
428
+ "", "", FILE_SELECTOR_DEFAULT_WILDCARD_STR,
429
+ MULTIPLE)
430
+
431
+ if dialog.show_modal() == ID_OK
432
+
433
+ paths = dialog.get_paths()
434
+ filenames = dialog.get_filenames()
435
+
436
+ count = paths.length
437
+ msg = ""
438
+ for n in 0 ... count
439
+ s = sprintf("File %d: %s (%s)\n",
440
+ n, paths[n], filenames[n])
441
+ msg += s
442
+ end
443
+
444
+ dialog2 = MessageDialog.new(self, msg, "Selected files")
445
+ dialog2.show_modal()
446
+ end
447
+ end
448
+
449
+
450
+ def on_file_save(event)
451
+
452
+ dialog = FileDialog.new(self,
453
+ "Testing save file dialog",
454
+ "",
455
+ "myletter.doc",
456
+ "Text files (*.txt)|*.txt|Document files (*.doc)|*.doc",
457
+ SAVE|OVERWRITE_PROMPT)
458
+
459
+ dialog.set_filter_index(1)
460
+
461
+ if dialog.show_modal() == ID_OK
462
+
463
+ log_message("%s, filter %d",
464
+ dialog.get_path(), dialog.get_filter_index())
465
+ end
466
+ end
467
+
468
+ def on_dir_choose(event)
469
+
470
+ # pass some initial dir to DirDialog
471
+ dir_home = get_home_dir()
472
+
473
+ dialog = DirDialog.new(self, "Testing directory picker", dir_home)
474
+
475
+ if dialog.show_modal() == ID_OK
476
+ log_message("Selected path: %s", dialog.get_path())
477
+ end
478
+ end
479
+
480
+
481
+ def on_modal_dlg(event)
482
+ dlg = MyModalDialog.new(self)
483
+ dlg.show_modal()
484
+ end
485
+
486
+ def on_modeless_dlg(event)
487
+ show = get_menu_bar().is_checked(event.get_id())
488
+ if show
489
+ if !@dialog
490
+ @dialog = MyModelessDialog.new(self)
491
+ end
492
+ @dialog.show(true)
493
+ else # hide
494
+ @dialog.hide()
495
+ end
496
+ end
497
+
498
+
499
+ def on_show_tip(event)
500
+
501
+ if @index == -1
502
+ @index = rand(5)
503
+ end
504
+
505
+ tip_src = File.join( File.dirname(__FILE__), 'tips.txt')
506
+ tip_provider = create_file_tip_provider(tip_src, @index)
507
+
508
+ show_at_startup = show_tip(self, tip_provider)
509
+
510
+ if show_at_startup
511
+ message_box("Will show tips on startup", "Tips dialog",
512
+ OK | ICON_INFORMATION, self)
513
+ end
514
+
515
+ @index = tip_provider.get_current_tip()
516
+
517
+ end
518
+
519
+ def on_exit(event)
520
+ close(true)
521
+ end
522
+
523
+
524
+ def on_show_progress(event)
525
+
526
+ dialog = ProgressDialog.new("Progress dialog example",
527
+ "An informative message",
528
+ @max, # range
529
+ self, # parent
530
+ PD_CAN_ABORT|PD_APP_MODAL|
531
+ PD_ELAPSED_TIME|PD_ESTIMATED_TIME|
532
+ PD_REMAINING_TIME)
533
+
534
+ cont = true
535
+ for i in 0 .. @max
536
+ sleep(1)
537
+ if i == @max
538
+ cont = dialog.update(i, "That's all, folks!")
539
+ elsif i == @max / 2
540
+ cont = dialog.update(i, "Only a half left (very long message)!")
541
+ else
542
+ cont = dialog.update(i)
543
+ end
544
+
545
+ if !cont
546
+ if message_box("Do you really want to cancel?",
547
+ "Progress dialog question", # caption
548
+ YES_NO | ICON_QUESTION) == YES
549
+ dialog.end_modal(ID_CANCEL)
550
+ break
551
+ end
552
+ dialog.resume()
553
+ end
554
+ end
555
+
556
+
557
+ if !cont
558
+ log_status("Progress dialog aborted!")
559
+ else
560
+ log_status("Countdown from %d finished", @max)
561
+ end
562
+ end
563
+
564
+ def on_show_busy_info(event)
565
+ WindowDisabler.disable(self) do
566
+ info = BusyInfo.busy("Working, please wait...", self) do
567
+
568
+ for i in 0 ... 18
569
+ Wx::get_app.yield()
570
+ end
571
+ sleep(2)
572
+ end
573
+ end
574
+ end
575
+
576
+ def on_show_replace_dialog(event)
577
+
578
+ if @dlg_replace
579
+ #@dlg_replace.destroy
580
+ @dlg_replace = nil
581
+ else
582
+ @dlg_replace = FindReplaceDialog.new(
583
+ self,
584
+ @find_data,
585
+ "Find and replace dialog",
586
+ FR_REPLACEDIALOG
587
+ )
588
+
589
+ @dlg_replace.show(true)
590
+ end
591
+ end
592
+
593
+ def on_show_find_dialog(event)
594
+
595
+ if @dlg_find
596
+ @dlg_find.destroy
597
+ @dlg_find = nil
598
+ else
599
+ @dlg_find = FindReplaceDialog.new(
600
+ self,
601
+ @find_data,
602
+ "Find dialog", # just for testing
603
+ FR_NOWHOLEWORD
604
+ )
605
+
606
+ @dlg_find.show(true)
607
+ end
608
+ end
609
+
610
+ def decode_find_dialog_event_flags(flags)
611
+ str = ""
612
+ str << ((flags & FR_DOWN) != 0 ? "down" : "up") << ", " \
613
+ << ((flags & FR_WHOLEWORD) != 0 ? "whole words only, " : "") \
614
+ << ((flags & FR_MATCHCASE) != 0 ? "" : "not ") \
615
+ << "case sensitive"
616
+
617
+ return str
618
+ end
619
+
620
+ def on_find_dialog(event)
621
+
622
+ type = event.get_event_type()
623
+
624
+ if type == EVT_COMMAND_FIND || type == EVT_COMMAND_FIND_NEXT
625
+ log_message("Find %s'%s' (flags: %s)",
626
+ type == EVT_COMMAND_FIND_NEXT ? "next " : "",
627
+ event.get_find_string(),
628
+ decode_find_dialog_event_flags(event.get_flags()))
629
+ elsif type == EVT_COMMAND_FIND_REPLACE || type == EVT_COMMAND_FIND_REPLACE_ALL
630
+ log_message("Replace %s'%s' with '%s' (flags: %s)",
631
+ type == EVT_COMMAND_FIND_REPLACE_ALL ? "all " : "",
632
+ event.get_find_string(),
633
+ event.get_replace_string(),
634
+ decode_find_dialog_event_flags(event.get_flags()))
635
+ elsif type == EVT_COMMAND_FIND_CLOSE
636
+ dlg = event.get_dialog()
637
+ if dlg == @dlg_find
638
+ txt = "Find"
639
+ id_menu = DIALOGS_FIND
640
+ @dlg_find = nil
641
+ elsif dlg == @dlg_replace
642
+ txt = "Replace"
643
+ id_menu = DIALOGS_REPLACE
644
+ @dlg_replace = nil
645
+ else
646
+ txt = "Unknown"
647
+ id_menu = -1
648
+ log_error("unexpected event")
649
+ end
650
+
651
+ log_message("%s dialog is being closed.", txt)
652
+
653
+ if id_menu != -1
654
+ get_menu_bar().check(id_menu, false)
655
+ end
656
+
657
+ dlg.destroy()
658
+ else
659
+ log_error("Unknown find dialog event!")
660
+ end
661
+ end
662
+
663
+ end
664
+
665
+
666
+ class MyApp < App
667
+ attr_accessor :canvas_text_colour, :canvas_font
668
+
669
+ def on_init()
670
+ self.canvas_text_colour = Wx::Colour.new("BLACK")
671
+ self.canvas_font = Wx::NORMAL_FONT
672
+ # Create the main frame window
673
+ frame = MyFrame.new(nil, "Windows dialogs example",
674
+ Point.new(20, 20), Size.new(400, 300))
675
+
676
+ # Make a menubar
677
+ file_menu = Menu.new
678
+
679
+ file_menu.append(DIALOGS_CHOOSE_COLOUR, "&Choose colour")
680
+ file_menu.append_separator()
681
+ file_menu.append(DIALOGS_CHOOSE_FONT, "Choose &font")
682
+ file_menu.append_separator()
683
+ file_menu.append(DIALOGS_LOG_DIALOG, "&Log dialog\tCtrl-L")
684
+ file_menu.append(DIALOGS_MESSAGE_BOX, "&Message box\tCtrl-M")
685
+ file_menu.append(DIALOGS_TEXT_ENTRY, "Text &entry\tCtrl-E")
686
+ file_menu.append(DIALOGS_PASSWORD_ENTRY, "&Password entry\tCtrl-P")
687
+ file_menu.append(DIALOGS_NUM_ENTRY, "&Numeric entry\tCtrl-N")
688
+ file_menu.append(DIALOGS_SINGLE_CHOICE, "&Single choice\tCtrl-C")
689
+ file_menu.append(DIALOGS_MULTI_CHOICE, "M&ultiple choice\tCtrl-U")
690
+ file_menu.append_separator()
691
+ file_menu.append(DIALOGS_TIP, "&Tip of the day\tCtrl-T")
692
+ file_menu.append_separator()
693
+ file_menu.append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O")
694
+ file_menu.append(DIALOGS_FILE_OPEN2, "&Second open file\tCtrl-2")
695
+ file_menu.append(DIALOGS_FILES_OPEN, "Open &files\tShift-Ctrl-O")
696
+ file_menu.append(DIALOGS_FILE_SAVE, "Sa&ve file\tCtrl-S")
697
+ file_menu.append(DIALOGS_DIR_CHOOSE, "&Choose a directory\tCtrl-D")
698
+ file_menu.append(DIALOGS_PROGRESS, "Pro&gress dialog\tCtrl-G")
699
+ file_menu.append(DIALOGS_BUSYINFO, "&Busy info dialog\tCtrl-B")
700
+ file_menu.append(DIALOGS_FIND, "&Find dialog\tCtrl-F", "", ITEM_CHECK)
701
+ file_menu.append(DIALOGS_REPLACE, "Find and &replace dialog\tShift-Ctrl-F", "", ITEM_CHECK)
702
+ file_menu.append_separator()
703
+ file_menu.append(DIALOGS_MODAL, "Mo&dal dialog\tCtrl-W")
704
+ file_menu.append(DIALOGS_MODELESS, "Modeless &dialog\tCtrl-Z", "", ITEM_CHECK)
705
+ file_menu.append_separator()
706
+ file_menu.append(ID_EXIT, "E&xit\tAlt-X")
707
+ menu_bar = MenuBar.new
708
+ menu_bar.append(file_menu, "&File")
709
+ frame.set_menu_bar(menu_bar)
710
+
711
+ $my_canvas = MyCanvas.new(frame)
712
+ $my_canvas.set_background_colour(WHITE)
713
+
714
+ frame.centre(BOTH)
715
+
716
+ # Show the frame
717
+ frame.show()
718
+ end
719
+ end
720
+
721
+ app = MyApp.new()
722
+ app.main_loop()
723
+