wxruby 1.9.2-i386-mswin32 → 1.9.3-i386-mswin32

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