wxruby 1.9.1-i386-mswin32 → 1.9.2-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,8 +15,6 @@ end
15
15
  include Wx
16
16
 
17
17
  # menu items
18
- Caret_Quit = ID_EXIT
19
- Caret_About = ID_ABOUT
20
18
  Caret_set_blink_time = 3
21
19
  Caret_Move = 4
22
20
 
@@ -27,26 +25,22 @@ Caret_Text = 1000
27
25
  # MyCanvas is a canvas on which you can type
28
26
  class MyCanvas < ScrolledWindow
29
27
  def initialize(parent)
30
- super(parent, -1,
31
- DEFAULT_POSITION, DEFAULT_SIZE,
32
- SUNKEN_BORDER )
28
+ super(parent, :style => SUNKEN_BORDER)
33
29
 
34
- set_background_colour(WHITE)
30
+ self.background_colour = WHITE
35
31
 
36
32
  @font = Font.new(12, FONTFAMILY_TELETYPE,
37
33
  FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL)
38
34
 
39
- @x_caret = @y_caret =
40
- @x_chars = @y_chars = 0
41
-
35
+ @x_caret = @y_caret = @x_chars = @y_chars = 0
42
36
  @x_margin = @y_margin = 5
43
37
  @text = nil
44
38
 
45
39
  create_caret
46
40
 
47
- evt_paint {on_paint}
48
- evt_size {|event| on_size(event)}
49
- evt_char {|event| on_char(event)}
41
+ evt_paint :on_paint
42
+ evt_size :on_size
43
+ evt_char :on_char
50
44
  end
51
45
 
52
46
  def [](x,y)
@@ -108,14 +102,14 @@ class MyCanvas < ScrolledWindow
108
102
 
109
103
  def create_caret
110
104
  paint do | dc |
111
- dc.set_font(@font)
112
- @height_char = dc.get_char_height
113
- @width_char = dc.get_char_width
105
+ dc.font = @font
106
+ @height_char = dc.char_height
107
+ @width_char = dc.char_width
114
108
 
115
- caret = Caret.new(self, Size.new(@width_char, @height_char))
116
- set_caret(caret)
109
+ my_caret = Caret.new(self, Size.new(@width_char, @height_char))
110
+ self.caret = my_caret
117
111
 
118
- caret.move(Point.new(@x_margin, @y_margin))
112
+ caret.move [ @x_margin, @y_margin ]
119
113
  caret.show
120
114
  end
121
115
  end
@@ -130,13 +124,13 @@ class MyCanvas < ScrolledWindow
130
124
  def do_move_caret
131
125
  log_status("Caret is at (%d, %d)", @x_caret, @y_caret)
132
126
 
133
- get_caret.move_xy(@x_margin + @x_caret * @width_char,
134
- @y_margin + @y_caret * @height_char)
127
+ caret.move_xy( @x_margin + @x_caret * @width_char,
128
+ @y_margin + @y_caret * @height_char)
135
129
  end
136
130
 
137
131
  def on_size(event)
138
- @x_chars = (event.get_size.x - 2*@x_margin) / @width_char
139
- @y_chars = (event.get_size.y - 2*@y_margin) / @height_char
132
+ @x_chars = (event.size.x - 2 * @x_margin) / @width_char
133
+ @y_chars = (event.size.y - 2 * @y_margin) / @height_char
140
134
  if @x_chars <= 0
141
135
  @x_chars = 1
142
136
  end
@@ -152,17 +146,15 @@ class MyCanvas < ScrolledWindow
152
146
 
153
147
  @text = " " * @x_chars * @y_chars
154
148
 
155
- frame = get_parent
156
- if frame && frame.get_status_bar
149
+ if parent && parent.status_bar
157
150
  msg = sprintf("Panel size is (%d, %d)", @x_chars, @y_chars)
158
- frame.set_status_text(msg, 1)
159
- frame.refresh
151
+ parent.set_status_text(msg, 1)
152
+ parent.refresh
160
153
  end
161
154
  event.skip
162
155
  end
163
156
 
164
157
  def on_paint
165
- caret = get_caret
166
158
  if caret
167
159
  caret.hide
168
160
  end
@@ -180,7 +172,6 @@ class MyCanvas < ScrolledWindow
180
172
  if caret
181
173
  caret.show
182
174
  end
183
-
184
175
  end
185
176
 
186
177
  def on_char(event)
@@ -212,15 +203,14 @@ class MyCanvas < ScrolledWindow
212
203
  end
213
204
  do_move_caret
214
205
  end
215
-
216
206
  end
217
207
 
218
208
  class MyFrame < Frame
219
- def initialize(title,pos,size)
209
+ def initialize(title, pos, size)
220
210
  super(nil, -1, title, pos, size)
221
211
  # set the frame icon
222
212
  icon_file = File.join(File.dirname(__FILE__), 'mondrian.xpm')
223
- set_icon(Icon.new(icon_file, BITMAP_TYPE_XPM))
213
+ self.icon = Icon.new(icon_file, BITMAP_TYPE_XPM)
224
214
 
225
215
  # create a menu bar
226
216
  menu_file = Menu.new
@@ -228,16 +218,16 @@ class MyFrame < Frame
228
218
  menu_file.append(Caret_set_blink_time, "&Blink time...\tCtrl-B")
229
219
  menu_file.append(Caret_Move, "&Move caret\tCtrl-C")
230
220
  menu_file.append_separator
231
- menu_file.append(Caret_About, "&About...\tCtrl-A", "Show about dialog")
221
+ menu_file.append(Wx::ID_ABOUT, "&About...\tCtrl-A", "Show about dialog")
232
222
  menu_file.append_separator
233
- menu_file.append(Caret_Quit, "E&xit\tAlt-X", "Quit self program")
223
+ menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit self program")
234
224
 
235
225
  # now append the freshly created menu to the menu bar...
236
226
  menu_bar = MenuBar.new
237
227
  menu_bar.append(menu_file, "&File")
238
228
 
239
229
  # ... and attach self menu bar to the frame
240
- set_menu_bar(menu_bar)
230
+ self.menu_bar = menu_bar
241
231
 
242
232
  @canvas = MyCanvas.new(self)
243
233
 
@@ -247,12 +237,12 @@ class MyFrame < Frame
247
237
 
248
238
  # create a status bar just for fun (by default with 1 pane only)
249
239
  create_status_bar(2)
250
- set_status_text("Welcome to Windows!")
240
+ self.status_text = "Welcome to Windows!"
251
241
 
252
- evt_menu(Caret_Quit) {on_quit}
253
- evt_menu(Caret_About) {on_about}
254
- evt_menu(Caret_set_blink_time) {on_set_blink_time}
255
- evt_menu(Caret_Move) {on_caret_move}
242
+ evt_menu Wx::ID_EXIT, :on_quit
243
+ evt_menu Wx::ID_ABOUT, :on_about
244
+ evt_menu Caret_set_blink_time, :on_set_blink_time
245
+ evt_menu Caret_Move, :on_caret_move
256
246
  end
257
247
 
258
248
  def on_quit
@@ -0,0 +1,81 @@
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
+
16
+ # This simple sample demonstrates how to use Ruby 1.8's lightweight
17
+ # (green) threads to execute non-GUI code in parallel with a wxRuby
18
+ # GUI. This strategy is useful in a number of situations:
19
+ #
20
+ # * To keep the GUI responsive whilst computationally intensive
21
+ # operations are carried out in the background
22
+ # * To keep the GUI responsive while waiting for networking operations
23
+ # to complete
24
+ #
25
+ # The basic problem is that, as with other Ruby GUI toolkits, non-GUI
26
+ # threads will not, by default, get allocated time to run while Ruby is
27
+ # busy in Wx code - the main wxRuby event loop. Strategies to deal with
28
+ # this include using non-blocking IO, and, more generically, using
29
+ # wxRuby's Timer class to explicitly allocate time for non-GUI threads
30
+ # to run. The latter technique is shown here.
31
+
32
+ # This frame shows a set of progress bars which monitor progress of
33
+ # long-running tasks. In this example, this long-running task is
34
+ # emulated by simply sleep-ing for random periods, but could equally be
35
+ # downloading from a socket or parsing a file.
36
+ class ProgressFrame < Wx::Frame
37
+ STEPS = 20
38
+ def initialize
39
+ super(nil, :title => 'Threading demo')
40
+ @gauges = []
41
+ panel = Wx::Panel.new(self)
42
+ sizer = Wx::BoxSizer.new(Wx::VERTICAL)
43
+ # show ten gauges
44
+ 10.times do
45
+ gauge = Wx::Gauge.new(panel, :range => STEPS)
46
+ # For each gauge, start a new thread in which the task runs
47
+ Thread.new do
48
+ # The long-running task
49
+ STEPS.times do | i |
50
+ sleep rand(100) / 50.0
51
+ # Update the main GUI
52
+ gauge.value = i + 1
53
+ end
54
+ end
55
+ @gauges << gauge
56
+ sizer.add(gauge, 0, Wx::GROW|Wx::ALL, 2)
57
+ end
58
+ panel.sizer = sizer
59
+ sizer.fit(panel)
60
+ end
61
+ end
62
+
63
+ # This app class creates a frame, and, importantly, a timer to allow
64
+ class GaugeApp < Wx::App
65
+ # Get a guaranteed-unique id
66
+ THREAD_TIMER_ID = Wx::ID_HIGHEST + 1
67
+ def on_init
68
+ # Create a global application timer
69
+ t = Wx::Timer.new(self, THREAD_TIMER_ID)
70
+ # When the timer "ticks", switch control to other ruby threads
71
+ evt_timer(THREAD_TIMER_ID) { Thread.pass }
72
+ # Start the timer to run every 1/40 second (25ms); higher values
73
+ # will make the other threads run more often, but will eventually
74
+ # degrade the responsiveness of the GUI.
75
+ t.start(25)
76
+ prog = ProgressFrame.new
77
+ prog.show
78
+ end
79
+ end
80
+
81
+ GaugeApp.new.main_loop
@@ -14,42 +14,41 @@ rescue LoadError => no_wx_err
14
14
  end
15
15
 
16
16
  class MyFrame < Wx::Frame
17
- def initialize(title, pos, size, style = Wx::DEFAULT_FRAME_STYLE)
18
- super(nil, -1, title, pos, size, style)
17
+ def initialize(title, pos, size)
18
+ super(nil, :title => title, :position => pos, :size => size)
19
19
 
20
-
21
- menuFile = Wx::Menu.new()
22
- helpMenu = Wx::Menu.new()
20
+ menuFile = Wx::Menu.new
21
+ helpMenu = Wx::Menu.new
23
22
  helpMenu.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
24
23
  menuFile.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
25
- menuBar = Wx::MenuBar.new()
24
+ menuBar = Wx::MenuBar.new
26
25
  menuBar.append(menuFile, "&File")
27
26
  menuBar.append(helpMenu, "&Help")
28
- set_menu_bar(menuBar)
29
-
30
- create_status_bar(2)
31
- set_status_text("Welcome to wxRuby!")
32
- s = Wx::StaticText.new(self, -1, 'The Wizard has completed')
27
+ self.menu_bar = menuBar
33
28
 
29
+ create_status_bar(1)
30
+ self.status_text = "Welcome to wxRuby!"
31
+ s = Wx::StaticText.new(self, :label => 'The Wizard has completed')
32
+ evt_menu Wx::ID_EXIT, :on_quit
33
+ evt_menu Wx::ID_ABOUT, :on_about
34
34
 
35
- evt_menu(Wx::ID_EXIT) { on_quit }
36
- evt_menu(Wx::ID_ABOUT) { on_about }
37
- w = Wx::Wizard.new(self, -1, 'The WxRuby Wizard')
35
+ w = Wx::Wizard.new(self, :title => 'The WxRuby Wizard')
38
36
  p1 = Wx::WizardPageSimple.new(w)
39
- s = Wx::StaticText.new(p1, -1, 'This is the first page')
37
+ s = Wx::StaticText.new(p1, :label => 'This is the first page')
38
+
40
39
  p2 = Wx::WizardPageSimple.new(w, p1)
41
40
  p1.set_next(p2)
42
- s = Wx::StaticText.new(p2, -1, 'This is the second page')
41
+ s = Wx::StaticText.new(p2, :label => 'This is the second page')
42
+
43
43
  p3 = Wx::WizardPageSimple.new(w, p2)
44
44
  p2.set_next(p3)
45
- s = Wx::StaticText.new(p3, -1, 'This is the final page')
46
-
47
- evt_wizard_page_changed(w.get_id) { p "page changed" }
48
- evt_wizard_page_changing(w.get_id) { p "page changing" }
49
- evt_wizard_help(w.get_id) { p "wizard help" }
50
- evt_wizard_cancel(w.get_id) { p "wizard cancelled" }
51
- evt_wizard_finished(w.get_id) { p "wizard finished" }
45
+ s = Wx::StaticText.new(p3, :label => 'This is the final page')
52
46
 
47
+ evt_wizard_page_changed(w) { p "page changed" }
48
+ evt_wizard_page_changing(w) { p "page changing" }
49
+ evt_wizard_help(w) { p "wizard help" }
50
+ evt_wizard_cancel(w) { p "wizard cancelled" }
51
+ evt_wizard_finished(w) { p "wizard finished" }
53
52
 
54
53
  w.run_wizard(p1)
55
54
  end
@@ -70,7 +69,6 @@ class RbApp < Wx::App
70
69
  frame = MyFrame.new("Wizard wxRuby App",
71
70
  Wx::Point.new(50, 50),
72
71
  Wx::Size.new(450, 340))
73
-
74
72
  frame.show(true)
75
73
 
76
74
  end
data/samples/html/html.rb CHANGED
@@ -78,9 +78,9 @@ class MyHtmlWindow < Wx::HtmlWindow
78
78
 
79
79
  def on_cell_mouse_hover(cell, x, y)
80
80
  if link = cell.get_link
81
- get_related_frame.set_status_text(link.get_href)
81
+ related_frame.status_text = link.get_href, 1
82
82
  else
83
- get_related_frame.set_status_text('')
83
+ related_frame.status_text = ''
84
84
  end
85
85
  end
86
86
  end
@@ -95,8 +95,8 @@ class HtmlFrame < Wx::Frame
95
95
  super(nil, -1, title, pos, size, style)
96
96
  setup_menus
97
97
  setup_panel
98
- create_status_bar(2)
99
- set_status_text("Welcome to wxRuby!")
98
+ create_status_bar
99
+ self.status_text = "Welcome to wxRuby!"
100
100
  end
101
101
 
102
102
  def setup_panel
@@ -127,6 +127,7 @@ class HtmlFrame < Wx::Frame
127
127
  # in the correct platform-specific place
128
128
  menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
129
129
  menu_file.append(Wx::ID_OPEN, "&Open File...\tCtrl-O", "Open File")
130
+ menu_file.append(Wx::ID_HIGHEST + 1, "&Open URL...\tCtrl-U", "Open URL")
130
131
  menu_file.append(Wx::ID_PRINT, "&Print...\tCtrl-P", "Print")
131
132
 
132
133
  menu_file.append(Wx::ID_PREVIEW, "&Preview...\tCtrl-Shift-P",
@@ -137,13 +138,14 @@ class HtmlFrame < Wx::Frame
137
138
  menu_bar.append(menu_file, "&File")
138
139
  menu_bar.append(menu_help, "&Help")
139
140
  # Assign the menus to this frame
140
- set_menu_bar(menu_bar)
141
+ self.menu_bar = menu_bar
141
142
  # handle menu events
142
- evt_menu(Wx::ID_OPEN) { on_open_file }
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 }
143
+ evt_menu Wx::ID_OPEN, :on_open_file
144
+ evt_menu Wx::ID_HIGHEST + 1, :on_open_url
145
+ evt_menu Wx::ID_PRINT, :on_print
146
+ evt_menu Wx::ID_PREVIEW, :on_preview
147
+ evt_menu Wx::ID_EXIT, :on_quit
148
+ evt_menu Wx::ID_ABOUT, :on_about
147
149
  end
148
150
 
149
151
  # end the application
@@ -153,16 +155,27 @@ class HtmlFrame < Wx::Frame
153
155
 
154
156
  def on_open_file
155
157
  f_dlg = Wx::FileDialog.new(self, "Open an HTML file", "", "",
156
- "HTML files (*.html;*.htm)|.html;.htm)",
158
+ "HTML files (*.html;*.htm)|*.html;*.htm)",
157
159
  Wx::OPEN)
158
160
  if not f_dlg.show_modal == Wx::ID_OK
159
161
  return
160
162
  end
161
163
  html_file = f_dlg.get_path
162
-
164
+ if html_file.index("\\")
165
+ html_file = html_file.split("\\").join("/")
166
+ end
163
167
  @html_win.load_file(html_file)
164
168
  end
165
169
 
170
+ def on_open_url
171
+ url = Wx::get_text_from_user('Enter URL to open', 'Enter URL')
172
+ if not url.empty?
173
+ uri = URI.parse(url)
174
+ uri.path = '/' if uri.path.empty?
175
+ @html_win.load_page_from_uri(uri)
176
+ end
177
+ end
178
+
166
179
  # show an 'About' dialog
167
180
  def on_about
168
181
  msg = sprintf("This is the About dialog of the HTML sample.\n" \
@@ -13,69 +13,66 @@ rescue LoadError => no_wx_err
13
13
  end
14
14
  end
15
15
 
16
- # This sample demonstrates the use of the listbook class.
17
- # NB: This sample doesn't currently work on Linux (21/08/2006)
18
-
19
-
20
-
21
16
  #
22
17
  # Basic Frame Class. This creates the dialog window
23
18
  #
24
19
  class SimpleFrame < Wx::Frame
25
20
 
26
- FILE_DIALOG, FILE_ABOUT, FILE_QUIT = [0,Wx::ID_ABOUT,Wx::ID_EXIT]
27
-
28
- def initialize(parent)
29
- # To load a layout defined in XRC into a Ruby subclass of Frame,
30
- # first call the empty constructor. All the details of size,
31
- # title, position and so on are loaded from the XRC by the call to
32
- # load_frame_subclass. Using a non-empty constructor will cause
33
- # errors on GTK.
34
- super()
35
- $xml.load_frame_subclass(self,nil,'ID_FRAME')
21
+ FILE_DIALOG, FILE_ABOUT, FILE_QUIT = [0,Wx::ID_ABOUT,Wx::ID_EXIT]
22
+
23
+ def initialize(parent)
24
+ # To load a layout defined in XRC into a Ruby subclass of Frame,
25
+ # first call the empty constructor. All the details of size,
26
+ # title, position and so on are loaded from the XRC by the call to
27
+ # load_frame_subclass. Using a non-empty constructor will cause
28
+ # errors on GTK.
29
+ super()
30
+ $xml.load_frame_subclass(self,nil,'ID_FRAME')
36
31
 
37
- # Create a new menu
38
- bar = Wx::MenuBar.new
39
- menu = Wx::Menu.new
32
+ # Create a new menu
33
+ bar = Wx::MenuBar.new
34
+ menu = Wx::Menu.new
40
35
  menu.append(FILE_ABOUT,"About...")
41
36
  menu.append_separator
42
- menu.append(FILE_QUIT,"Quit")
43
- bar.append(menu,"File")
44
-
45
- set_menu_bar(bar)
46
-
47
- # Assign the menu events
37
+ menu.append(FILE_QUIT,"Quit")
38
+ bar.append(menu,"File")
39
+
40
+ set_menu_bar(bar)
41
+
42
+ # Assign the menu events
48
43
  evt_menu(FILE_ABOUT) do
49
- Wx::message_box("wxRuby Listbook sample\nby Sean Long", "About Listbook", Wx::OK | Wx::ICON_INFORMATION, self)
44
+ Wx::message_box("wxRuby Listbook sample\nby Sean Long", "About Listbook", Wx::OK | Wx::ICON_INFORMATION, self)
50
45
  end
51
- evt_menu(FILE_QUIT) do
52
- Wx::get_app.exit_main_loop()
53
- end
54
- evt_close() do
55
- Wx::get_app.exit_main_loop()
56
- end
46
+ evt_menu(FILE_QUIT) do
47
+ Wx::get_app.exit_main_loop()
48
+ end
49
+ evt_close() do
50
+ Wx::get_app.exit_main_loop()
51
+ end
57
52
 
58
53
  # Variables not in tabs
59
- @listbook = Wx::Window.find_window_by_id(Wx::xrcid('ID_LISTBOOK'),self)
60
- @text_output = Wx::Window.find_window_by_id(Wx::xrcid('ID_ORDER_TEXTCTRL'),self)
54
+ @listbook = xrcid_to_window('ID_LISTBOOK')
55
+ @text_output = xrcid_to_window('ID_ORDER_TEXTCTRL')
61
56
 
62
57
  # Variables for widgets in Pizza tab
63
- @pizza_size = Wx::Window.find_window_by_id(Wx::xrcid('ID_PIZZA_SIZE_CHOICE'),self)
64
- @pizza_crust = Wx::Window.find_window_by_id(Wx::xrcid('ID_PIZZA_CRUST_CHOICE'),self)
65
- @pizza_sauce = Wx::Window.find_window_by_id(Wx::xrcid('ID_PIZZA_SAUCE_CHOICE'),self)
66
- @pizza_cheese = Wx::Window.find_window_by_id(Wx::xrcid('ID_PIZZA_CHEESE_CHOICE'),self)
58
+ @pizza_size = xrcid_to_window('ID_PIZZA_SIZE_CHOICE')
59
+ @pizza_crust = xrcid_to_window('ID_PIZZA_CRUST_CHOICE')
60
+ @pizza_sauce = xrcid_to_window('ID_PIZZA_SAUCE_CHOICE')
61
+ @pizza_cheese = xrcid_to_window('ID_PIZZA_CHEESE_CHOICE')
67
62
  @pizza_toppings = []
68
63
  3.times do |i|
69
- @pizza_toppings << Wx::Window.find_window_by_id(Wx::xrcid("ID_PIZZA_TOPPING_#{i+1}_CHOICE"),self)
64
+ @pizza_toppings << xrcid_to_window("ID_PIZZA_TOPPING_#{i+1}_CHOICE")
70
65
  end
71
66
 
72
67
  # fill in toppings
73
- toppings = ['pepperoni','sausage','itallian sausage','olives','mushrooms','artichoke','extra cheese','']
68
+ toppings = ['pepperoni','sausage','italian sausage','olives',
69
+ 'mushrooms','artichoke','extra cheese','']
74
70
  toppings.each do |top_name|
75
71
  @pizza_toppings.each do |top_obj|
76
72
  top_obj.append(top_name)
77
73
  end
78
74
  end
75
+
79
76
  index = 0
80
77
  @pizza_toppings.each do |obj|
81
78
  obj.set_selection(index)
@@ -83,11 +80,10 @@ class SimpleFrame < Wx::Frame
83
80
  end
84
81
 
85
82
  # Events for pizza tab
86
- evt_button(Wx::xrcid('ID_PIZZA_BUTTON')) do |event|
83
+ evt_button( Wx::xrcid('ID_PIZZA_BUTTON') ) do |event|
87
84
  #get selections and add to order
88
85
  order_string = @text_output.get_value
89
86
  if order_string != "" then order_string << "\n" end
90
-
91
87
  order_string << "One #{@pizza_size.get_string_selection} pizza with:\n"
92
88
  order_string << @pizza_crust.get_string_selection + " crust" + "\n"
93
89
  order_string << @pizza_sauce.get_string_selection + " sauce" +"\n"
@@ -99,8 +95,8 @@ class SimpleFrame < Wx::Frame
99
95
 
100
96
 
101
97
  # Variables for widgets in Drink tab
102
- @drink_size = Wx::Window.find_window_by_id(Wx::xrcid('ID_DRINK_SIZE_CHOICE'),self)
103
- @drink_type = Wx::Window.find_window_by_id(Wx::xrcid('ID_DRINK_TYPE_CHOICE'),self)
98
+ @drink_size = xrcid_to_window('ID_DRINK_SIZE_CHOICE')
99
+ @drink_type = xrcid_to_window('ID_DRINK_TYPE_CHOICE')
104
100
 
105
101
  # Events for drink tab
106
102
  evt_button(Wx::xrcid('ID_DRINK_BUTTON')) do |event|
@@ -114,11 +110,12 @@ class SimpleFrame < Wx::Frame
114
110
  end
115
111
 
116
112
  # Variables for widgets in Ice Cream tab
117
- @ice_cream_size = Wx::Window.find_window_by_id(Wx::xrcid('ID_ICE_CREAM_SIZE_CHOICE'),self)
118
- @ice_cream_type = Wx::Window.find_window_by_id(Wx::xrcid('ID_ICE_CREAM_TYPE_CHOICE'),self)
113
+ @ice_cream_size = xrcid_to_window('ID_ICE_CREAM_SIZE_CHOICE')
114
+ @ice_cream_type = xrcid_to_window('ID_ICE_CREAM_TYPE_CHOICE')
119
115
  @ice_cream_toppings = []
120
116
  4.times do |i|
121
- @ice_cream_toppings << Wx::Window.find_window_by_id(Wx::xrcid("ID_ICE_CREAM_TOPPING_#{i+1}_CHOICE"),self)
117
+ @ice_cream_toppings <<
118
+ xrcid_to_window("ID_ICE_CREAM_TOPPING_#{i+1}_CHOICE")
122
119
  end
123
120
 
124
121
  toppings = ['','m&m\'s','chocolate chips','fudge','nuts','cherry','whip cream']
@@ -146,10 +143,15 @@ class SimpleFrame < Wx::Frame
146
143
  order_string = @text_output.get_value
147
144
  order_string << "moved to tab = #{@listbook.get_page_text(tab_number)} \n"
148
145
  @text_output.set_value(order_string)
149
- end
150
-
146
+ end
147
+ end
148
+
149
+ # Converts a XRCID id - as used in wxWidget's XML format - into the
150
+ # correct ruby window
151
+ def xrcid_to_window(xrc_id)
152
+ Wx::Window.find_window_by_id(Wx::xrcid(xrc_id), self)
151
153
  end
152
-
154
+
153
155
  end
154
156
 
155
157
  #
@@ -157,27 +159,23 @@ end
157
159
  #
158
160
  class XrcApp < Wx::App
159
161
 
160
- def on_init
161
- #
162
- # Create a resource handler
163
- #
164
- $xml = Wx::XmlResource.get();
165
- $xml.init_all_handlers();
162
+ def on_init
163
+ # Create a resource handler
164
+ $xml = Wx::XmlResource.get();
165
+ $xml.init_all_handlers();
166
166
 
167
- # Load a resource file from the script's directory
168
- xrc_file = File.join( File.dirname( __FILE__ ), 'listbook.xrc' )
167
+ # Load a resource file from the script's directory
168
+ xrc_file = File.join( File.dirname( __FILE__ ), 'listbook.xrc' )
169
169
 
170
- $xml.load(xrc_file)
170
+ $xml.load(xrc_file)
171
171
 
172
- #
173
- # Show the main frame.
174
- #
175
- $main = SimpleFrame.new(self)
176
- $main.show(true)
177
-
178
- end
179
172
 
173
+ # Show the main frame.
174
+ $main = SimpleFrame.new(self)
175
+ $main.show(true)
176
+
177
+ end
180
178
  end
181
-
182
-
179
+
180
+
183
181
  XrcApp.new().main_loop()