wxruby 1.9.3-i386-mswin32 → 1.9.4-i386-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. data/LICENSE +53 -53
  2. data/README +299 -299
  3. data/lib/wx/classes/evthandler.rb +9 -0
  4. data/lib/wx/classes/timer.rb +25 -0
  5. data/lib/wx/version.rb +1 -1
  6. data/lib/wx.rb +42 -42
  7. data/lib/wxruby2.exp +0 -0
  8. data/lib/wxruby2.lib +0 -0
  9. data/lib/wxruby2.so +0 -0
  10. data/samples/SAMPLES-LICENSE.TXT +17 -17
  11. data/samples/bigdemo/About.rbw +39 -39
  12. data/samples/bigdemo/ColorPanel.rbw +25 -25
  13. data/samples/bigdemo/GridSimple.rbw +80 -80
  14. data/samples/bigdemo/MDIDemo.rbw +59 -59
  15. data/samples/bigdemo/PopupMenu.rbw +151 -151
  16. data/samples/bigdemo/Sizers.rbw +545 -545
  17. data/samples/bigdemo/bigdemo.rb +826 -826
  18. data/samples/bigdemo/demoTemplate.rbw +37 -37
  19. data/samples/bigdemo/icons/choice.xpm +27 -27
  20. data/samples/bigdemo/icons/combo.xpm +27 -27
  21. data/samples/bigdemo/icons/copy.xpm +25 -25
  22. data/samples/bigdemo/icons/cut.xpm +24 -24
  23. data/samples/bigdemo/icons/gauge.xpm +27 -27
  24. data/samples/bigdemo/icons/help.xpm +25 -25
  25. data/samples/bigdemo/icons/list.xpm +27 -27
  26. data/samples/bigdemo/icons/mondrian.xpm +44 -44
  27. data/samples/bigdemo/icons/new.xpm +24 -24
  28. data/samples/bigdemo/icons/ogl.ico +0 -0
  29. data/samples/bigdemo/icons/ogl.xpm +45 -45
  30. data/samples/bigdemo/icons/open.xpm +26 -26
  31. data/samples/bigdemo/icons/paste.xpm +38 -38
  32. data/samples/bigdemo/icons/preview.xpm +26 -26
  33. data/samples/bigdemo/icons/print.xpm +26 -26
  34. data/samples/bigdemo/icons/radio.xpm +27 -27
  35. data/samples/bigdemo/icons/robert.xpm +415 -415
  36. data/samples/bigdemo/icons/save.xpm +25 -25
  37. data/samples/bigdemo/icons/smiles.xpm +39 -39
  38. data/samples/bigdemo/icons/smiley.xpm +42 -42
  39. data/samples/bigdemo/icons/stattext.xpm +24 -24
  40. data/samples/bigdemo/icons/test2.bmp +0 -0
  41. data/samples/bigdemo/icons/test2.xpm +79 -79
  42. data/samples/bigdemo/icons/text.xpm +27 -27
  43. data/samples/bigdemo/icons/tog1.xpm +38 -38
  44. data/samples/bigdemo/icons/tog2.xpm +38 -38
  45. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -25
  46. data/samples/bigdemo/tips.txt +7 -7
  47. data/samples/bigdemo/utils.rb +11 -11
  48. data/samples/bigdemo/wxButton.rbw +66 -66
  49. data/samples/bigdemo/wxCalendarCtrl.rbw +72 -72
  50. data/samples/bigdemo/wxCheckBox.rbw +52 -52
  51. data/samples/bigdemo/wxCheckListBox.rbw +77 -77
  52. data/samples/bigdemo/wxChoice.rbw +49 -49
  53. data/samples/bigdemo/wxColourDialog.rbw +34 -34
  54. data/samples/bigdemo/wxComboBox.rbw +79 -79
  55. data/samples/bigdemo/wxDialog.rbw +92 -92
  56. data/samples/bigdemo/wxDirDialog.rbw +32 -32
  57. data/samples/bigdemo/wxFileDialog.rbw +39 -39
  58. data/samples/bigdemo/wxFileDialog_Save.rbw +38 -38
  59. data/samples/bigdemo/wxFindReplaceDialog.rbw +85 -85
  60. data/samples/bigdemo/wxFontDialog.rbw +176 -176
  61. data/samples/bigdemo/wxFrame.rbw +55 -55
  62. data/samples/bigdemo/wxGauge.rbw +73 -73
  63. data/samples/bigdemo/wxGrid.rbw +68 -68
  64. data/samples/bigdemo/wxListBox.rbw +142 -142
  65. data/samples/bigdemo/wxListCtrl_virtual.rbw +109 -109
  66. data/samples/bigdemo/wxMDIWindows.rbw +52 -52
  67. data/samples/bigdemo/wxMenu.rbw +238 -238
  68. data/samples/bigdemo/wxMessageDialog.rbw +30 -30
  69. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +34 -34
  70. data/samples/bigdemo/wxNotebook.rbw +138 -138
  71. data/samples/bigdemo/wxProgressDialog.rbw +45 -45
  72. data/samples/bigdemo/wxRadioBox.rbw +74 -74
  73. data/samples/bigdemo/wxRadioButton.rbw +127 -127
  74. data/samples/bigdemo/wxScrolledMessageDialog.rbw +59 -59
  75. data/samples/bigdemo/wxScrolledWindow.rbw +201 -201
  76. data/samples/bigdemo/wxSingleChoiceDialog.rbw +35 -35
  77. data/samples/bigdemo/wxSlider.rbw +44 -44
  78. data/samples/bigdemo/wxSpinButton.rbw +52 -52
  79. data/samples/bigdemo/wxSpinCtrl.rbw +53 -53
  80. data/samples/bigdemo/wxSplitterWindow.rbw +65 -65
  81. data/samples/bigdemo/wxStaticBitmap.rbw +53 -53
  82. data/samples/bigdemo/wxStaticText.rbw +57 -57
  83. data/samples/bigdemo/wxStatusBar.rbw +128 -128
  84. data/samples/bigdemo/wxTextCtrl.rbw +151 -151
  85. data/samples/bigdemo/wxTextEntryDialog.rbw +34 -34
  86. data/samples/bigdemo/wxToggleButton.rbw +51 -51
  87. data/samples/bigdemo/wxToolBar.rbw +133 -133
  88. data/samples/bigdemo/wxTreeCtrl.rbw +192 -192
  89. data/samples/calendar/calendar.rb +275 -275
  90. data/samples/caret/caret.rb +286 -286
  91. data/samples/caret/mondrian.xpm +44 -44
  92. data/samples/controls/controls.rb +1140 -1140
  93. data/samples/controls/get_item_sample.rb +87 -87
  94. data/samples/controls/icons/choice.xpm +27 -27
  95. data/samples/controls/icons/combo.xpm +27 -27
  96. data/samples/controls/icons/gauge.xpm +27 -27
  97. data/samples/controls/icons/list.xpm +27 -27
  98. data/samples/controls/icons/radio.xpm +27 -27
  99. data/samples/controls/icons/stattext.xpm +24 -24
  100. data/samples/controls/icons/text.xpm +27 -27
  101. data/samples/controls/mondrian.xpm +44 -44
  102. data/samples/dialogs/dialogs.rb +724 -724
  103. data/samples/dialogs/tips.txt +18 -18
  104. data/samples/drawing/graphics_drawing.rb +22 -18
  105. data/samples/drawing/images.rb +48 -48
  106. data/samples/etc/activation.rb +108 -108
  107. data/samples/etc/choice.rb +72 -72
  108. data/samples/etc/miniframe.rb +84 -84
  109. data/samples/etc/sash.rb +135 -135
  110. data/samples/etc/scrollwin.rb +116 -116
  111. data/samples/etc/system_settings.rb +258 -258
  112. data/samples/etc/threaded.rb +5 -8
  113. data/samples/etc/wizard.rb +79 -79
  114. data/samples/html/html.rb +14 -10
  115. data/samples/listbook/listbook.rb +181 -181
  116. data/samples/listbook/listbook.xrc +370 -370
  117. data/samples/mdi/mdi.rb +87 -87
  118. data/samples/minimal/minimal.rb +85 -85
  119. data/samples/minimal/nothing.rb +21 -21
  120. data/samples/text/textctrl.rb +124 -124
  121. data/samples/text/unicode.rb +238 -238
  122. data/samples/text/utf8.txt +14 -14
  123. data/samples/treectrl/treectrl.rb +1180 -1180
  124. data/samples/xrc/samples.xrc +46 -46
  125. data/samples/xrc/xrc_sample.rb +107 -107
  126. metadata +3 -3
@@ -1,79 +1,79 @@
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
- class MyFrame < Wx::Frame
17
- def initialize(title, pos, size)
18
- super(nil, :title => title, :position => pos, :size => size)
19
-
20
- menuFile = Wx::Menu.new
21
- helpMenu = Wx::Menu.new
22
- helpMenu.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
23
- menuFile.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
24
- menuBar = Wx::MenuBar.new
25
- menuBar.append(menuFile, "&File")
26
- menuBar.append(helpMenu, "&Help")
27
- self.menu_bar = menuBar
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
-
35
- w = Wx::Wizard.new(self, :title => 'The WxRuby Wizard')
36
- p1 = Wx::WizardPageSimple.new(w)
37
- s = Wx::StaticText.new(p1, :label => 'This is the first page')
38
-
39
- p2 = Wx::WizardPageSimple.new(w, p1)
40
- p1.set_next(p2)
41
- s = Wx::StaticText.new(p2, :label => 'This is the second page')
42
-
43
- p3 = Wx::WizardPageSimple.new(w, p2)
44
- p2.set_next(p3)
45
- s = Wx::StaticText.new(p3, :label => 'This is the final page')
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" }
52
-
53
- w.run_wizard(p1)
54
- end
55
-
56
- def on_quit
57
- close(true)
58
- end
59
-
60
- def on_about
61
- msg = sprintf("This is the About dialog of the wizard sample.\n" \
62
- "Welcome to %s", Wx::VERSION_STRING)
63
- Wx::message_box(msg, "About Wizard", Wx::OK|Wx::ICON_INFORMATION, self)
64
- end
65
- end
66
-
67
- class RbApp < Wx::App
68
- def on_init
69
- frame = MyFrame.new("Wizard wxRuby App",
70
- Wx::Point.new(50, 50),
71
- Wx::Size.new(450, 340))
72
- frame.show(true)
73
-
74
- end
75
- end
76
-
77
- app = RbApp.new
78
- app.main_loop()
79
-
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
+ class MyFrame < Wx::Frame
17
+ def initialize(title, pos, size)
18
+ super(nil, :title => title, :position => pos, :size => size)
19
+
20
+ menuFile = Wx::Menu.new
21
+ helpMenu = Wx::Menu.new
22
+ helpMenu.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
23
+ menuFile.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
24
+ menuBar = Wx::MenuBar.new
25
+ menuBar.append(menuFile, "&File")
26
+ menuBar.append(helpMenu, "&Help")
27
+ self.menu_bar = menuBar
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
+
35
+ w = Wx::Wizard.new(self, :title => 'The WxRuby Wizard')
36
+ p1 = Wx::WizardPageSimple.new(w)
37
+ s = Wx::StaticText.new(p1, :label => 'This is the first page')
38
+
39
+ p2 = Wx::WizardPageSimple.new(w, p1)
40
+ p1.set_next(p2)
41
+ s = Wx::StaticText.new(p2, :label => 'This is the second page')
42
+
43
+ p3 = Wx::WizardPageSimple.new(w, p2)
44
+ p2.set_next(p3)
45
+ s = Wx::StaticText.new(p3, :label => 'This is the final page')
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" }
52
+
53
+ w.run_wizard(p1)
54
+ end
55
+
56
+ def on_quit
57
+ close(true)
58
+ end
59
+
60
+ def on_about
61
+ msg = sprintf("This is the About dialog of the wizard sample.\n" \
62
+ "Welcome to %s", Wx::VERSION_STRING)
63
+ Wx::message_box(msg, "About Wizard", Wx::OK|Wx::ICON_INFORMATION, self)
64
+ end
65
+ end
66
+
67
+ class RbApp < Wx::App
68
+ def on_init
69
+ frame = MyFrame.new("Wizard wxRuby App",
70
+ Wx::Point.new(50, 50),
71
+ Wx::Size.new(450, 340))
72
+ frame.show(true)
73
+
74
+ end
75
+ end
76
+
77
+ app = RbApp.new
78
+ app.main_loop()
79
+
data/samples/html/html.rb CHANGED
@@ -18,6 +18,12 @@ require 'uri'
18
18
 
19
19
  class MyHtmlWindow < Wx::HtmlWindow
20
20
  attr_reader :html_src
21
+ def initialize(*args)
22
+ super
23
+ evt_html_link_clicked self, :on_link_clicked
24
+ evt_html_cell_hover self, :on_hover
25
+ end
26
+
21
27
  def load_page_from_uri(uri)
22
28
  case uri
23
29
  when URI::HTTP
@@ -64,21 +70,19 @@ class MyHtmlWindow < Wx::HtmlWindow
64
70
  def set_page(html)
65
71
  super html
66
72
  @html_src = html
67
- get_related_frame.addr_bar.set_value(@loaded_uri.to_s)
73
+ related_frame.addr_bar.value = @loaded_uri.to_s
68
74
  end
69
75
 
70
- def on_link_clicked(link)
71
- href = link.get_href
72
- if href =~ /^#/
73
- super(link)
74
- end
76
+ def on_link_clicked(event)
77
+ href = event.link_info.href
78
+ return if href =~ /^#/
75
79
  link_uri = URI.parse(href)
76
80
  @loaded_uri = load_page_from_uri(link_uri)
77
81
  end
78
82
 
79
- def on_cell_mouse_hover(cell, x, y)
80
- if link = cell.get_link
81
- related_frame.status_text = link.get_href, 1
83
+ def on_hover(event)
84
+ if link = event.cell.link
85
+ related_frame.set_status_text(link.href)
82
86
  else
83
87
  related_frame.status_text = ''
84
88
  end
@@ -114,7 +118,7 @@ class HtmlFrame < Wx::Frame
114
118
 
115
119
  @html_win = MyHtmlWindow.new(panel, -1)
116
120
  @html_win.set_related_frame(self, 'HTML Window: %s')
117
- @html_win.set_related_status_bar(2)
121
+
118
122
  @html_win.set_page(DATA.read)
119
123
  sizer.add(@html_win, 1, Wx::ALL|Wx::GROW, 4)
120
124
  panel.set_sizer(sizer)
@@ -1,181 +1,181 @@
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
- #
17
- # Basic Frame Class. This creates the dialog window
18
- #
19
- class SimpleFrame < Wx::Frame
20
-
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')
31
-
32
- # Create a new menu
33
- bar = Wx::MenuBar.new
34
- menu = Wx::Menu.new
35
- menu.append(FILE_ABOUT,"About...")
36
- menu.append_separator
37
- menu.append(FILE_QUIT,"Quit")
38
- bar.append(menu,"File")
39
-
40
- set_menu_bar(bar)
41
-
42
- # Assign the menu events
43
- evt_menu(FILE_ABOUT) do
44
- Wx::message_box("wxRuby Listbook sample\nby Sean Long", "About Listbook", Wx::OK | Wx::ICON_INFORMATION, self)
45
- 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
52
-
53
- # Variables not in tabs
54
- @listbook = xrcid_to_window('ID_LISTBOOK')
55
- @text_output = xrcid_to_window('ID_ORDER_TEXTCTRL')
56
-
57
- # Variables for widgets in Pizza tab
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')
62
- @pizza_toppings = []
63
- 3.times do |i|
64
- @pizza_toppings << xrcid_to_window("ID_PIZZA_TOPPING_#{i+1}_CHOICE")
65
- end
66
-
67
- # fill in toppings
68
- toppings = ['pepperoni','sausage','italian sausage','olives',
69
- 'mushrooms','artichoke','extra cheese','']
70
- toppings.each do |top_name|
71
- @pizza_toppings.each do |top_obj|
72
- top_obj.append(top_name)
73
- end
74
- end
75
-
76
- index = 0
77
- @pizza_toppings.each do |obj|
78
- obj.set_selection(index)
79
- index += 1
80
- end
81
-
82
- # Events for pizza tab
83
- evt_button( Wx::xrcid('ID_PIZZA_BUTTON') ) do |event|
84
- #get selections and add to order
85
- order_string = @text_output.get_value
86
- if order_string != "" then order_string << "\n" end
87
- order_string << "One #{@pizza_size.get_string_selection} pizza with:\n"
88
- order_string << @pizza_crust.get_string_selection + " crust" + "\n"
89
- order_string << @pizza_sauce.get_string_selection + " sauce" +"\n"
90
- order_string << @pizza_cheese.get_string_selection + " and" + "\n"
91
- @pizza_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
92
-
93
- @text_output.set_value(order_string)
94
- end
95
-
96
-
97
- # Variables for widgets in Drink tab
98
- @drink_size = xrcid_to_window('ID_DRINK_SIZE_CHOICE')
99
- @drink_type = xrcid_to_window('ID_DRINK_TYPE_CHOICE')
100
-
101
- # Events for drink tab
102
- evt_button(Wx::xrcid('ID_DRINK_BUTTON')) do |event|
103
- #get selections and add to order
104
- order_string = @text_output.get_value
105
- if order_string != "" then order_string << "\n" end
106
-
107
- order_string << "One #{@drink_size.get_string_selection} #{@drink_type.get_string_selection }.\n"
108
-
109
- @text_output.set_value(order_string)
110
- end
111
-
112
- # Variables for widgets in Ice Cream tab
113
- @ice_cream_size = xrcid_to_window('ID_ICE_CREAM_SIZE_CHOICE')
114
- @ice_cream_type = xrcid_to_window('ID_ICE_CREAM_TYPE_CHOICE')
115
- @ice_cream_toppings = []
116
- 4.times do |i|
117
- @ice_cream_toppings <<
118
- xrcid_to_window("ID_ICE_CREAM_TOPPING_#{i+1}_CHOICE")
119
- end
120
-
121
- toppings = ['','m&m\'s','chocolate chips','fudge','nuts','cherry','whip cream']
122
- toppings.each do |top_name|
123
- @ice_cream_toppings.each do |top_obj|
124
- top_obj.append(top_name)
125
- end
126
- end
127
- @ice_cream_toppings.each { |obj| obj.set_selection(0) }
128
-
129
- # Events for ice cream tab
130
- evt_button(Wx::xrcid('ID_ICE_CREAM_BUTTON')) do |event|
131
- #get selections and add to order
132
- order_string = @text_output.get_value
133
- if order_string != "" then order_string << "\n" end
134
-
135
- order_string << "One #{@ice_cream_size.get_string_selection} #{@ice_cream_type.get_string_selection} ice cream:\n"
136
- @ice_cream_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
137
-
138
- @text_output.set_value(order_string)
139
- end
140
-
141
- evt_listbook_page_changed(Wx::xrcid('ID_LISTBOOK')) do |event|
142
- tab_number = event.get_selection
143
- order_string = @text_output.get_value
144
- order_string << "moved to tab = #{@listbook.get_page_text(tab_number)} \n"
145
- @text_output.set_value(order_string)
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)
153
- end
154
-
155
- end
156
-
157
- #
158
- # Application class.
159
- #
160
- class XrcApp < Wx::App
161
-
162
- def on_init
163
- # Create a resource handler
164
- $xml = Wx::XmlResource.get();
165
- $xml.init_all_handlers();
166
-
167
- # Load a resource file from the script's directory
168
- xrc_file = File.join( File.dirname( __FILE__ ), 'listbook.xrc' )
169
-
170
- $xml.load(xrc_file)
171
-
172
-
173
- # Show the main frame.
174
- $main = SimpleFrame.new(self)
175
- $main.show(true)
176
-
177
- end
178
- end
179
-
180
-
181
- XrcApp.new().main_loop()
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
+ #
17
+ # Basic Frame Class. This creates the dialog window
18
+ #
19
+ class SimpleFrame < Wx::Frame
20
+
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')
31
+
32
+ # Create a new menu
33
+ bar = Wx::MenuBar.new
34
+ menu = Wx::Menu.new
35
+ menu.append(FILE_ABOUT,"About...")
36
+ menu.append_separator
37
+ menu.append(FILE_QUIT,"Quit")
38
+ bar.append(menu,"File")
39
+
40
+ set_menu_bar(bar)
41
+
42
+ # Assign the menu events
43
+ evt_menu(FILE_ABOUT) do
44
+ Wx::message_box("wxRuby Listbook sample\nby Sean Long", "About Listbook", Wx::OK | Wx::ICON_INFORMATION, self)
45
+ 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
52
+
53
+ # Variables not in tabs
54
+ @listbook = xrcid_to_window('ID_LISTBOOK')
55
+ @text_output = xrcid_to_window('ID_ORDER_TEXTCTRL')
56
+
57
+ # Variables for widgets in Pizza tab
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')
62
+ @pizza_toppings = []
63
+ 3.times do |i|
64
+ @pizza_toppings << xrcid_to_window("ID_PIZZA_TOPPING_#{i+1}_CHOICE")
65
+ end
66
+
67
+ # fill in toppings
68
+ toppings = ['pepperoni','sausage','italian sausage','olives',
69
+ 'mushrooms','artichoke','extra cheese','']
70
+ toppings.each do |top_name|
71
+ @pizza_toppings.each do |top_obj|
72
+ top_obj.append(top_name)
73
+ end
74
+ end
75
+
76
+ index = 0
77
+ @pizza_toppings.each do |obj|
78
+ obj.set_selection(index)
79
+ index += 1
80
+ end
81
+
82
+ # Events for pizza tab
83
+ evt_button( Wx::xrcid('ID_PIZZA_BUTTON') ) do |event|
84
+ #get selections and add to order
85
+ order_string = @text_output.get_value
86
+ if order_string != "" then order_string << "\n" end
87
+ order_string << "One #{@pizza_size.get_string_selection} pizza with:\n"
88
+ order_string << @pizza_crust.get_string_selection + " crust" + "\n"
89
+ order_string << @pizza_sauce.get_string_selection + " sauce" +"\n"
90
+ order_string << @pizza_cheese.get_string_selection + " and" + "\n"
91
+ @pizza_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
92
+
93
+ @text_output.set_value(order_string)
94
+ end
95
+
96
+
97
+ # Variables for widgets in Drink tab
98
+ @drink_size = xrcid_to_window('ID_DRINK_SIZE_CHOICE')
99
+ @drink_type = xrcid_to_window('ID_DRINK_TYPE_CHOICE')
100
+
101
+ # Events for drink tab
102
+ evt_button(Wx::xrcid('ID_DRINK_BUTTON')) do |event|
103
+ #get selections and add to order
104
+ order_string = @text_output.get_value
105
+ if order_string != "" then order_string << "\n" end
106
+
107
+ order_string << "One #{@drink_size.get_string_selection} #{@drink_type.get_string_selection }.\n"
108
+
109
+ @text_output.set_value(order_string)
110
+ end
111
+
112
+ # Variables for widgets in Ice Cream tab
113
+ @ice_cream_size = xrcid_to_window('ID_ICE_CREAM_SIZE_CHOICE')
114
+ @ice_cream_type = xrcid_to_window('ID_ICE_CREAM_TYPE_CHOICE')
115
+ @ice_cream_toppings = []
116
+ 4.times do |i|
117
+ @ice_cream_toppings <<
118
+ xrcid_to_window("ID_ICE_CREAM_TOPPING_#{i+1}_CHOICE")
119
+ end
120
+
121
+ toppings = ['','m&m\'s','chocolate chips','fudge','nuts','cherry','whip cream']
122
+ toppings.each do |top_name|
123
+ @ice_cream_toppings.each do |top_obj|
124
+ top_obj.append(top_name)
125
+ end
126
+ end
127
+ @ice_cream_toppings.each { |obj| obj.set_selection(0) }
128
+
129
+ # Events for ice cream tab
130
+ evt_button(Wx::xrcid('ID_ICE_CREAM_BUTTON')) do |event|
131
+ #get selections and add to order
132
+ order_string = @text_output.get_value
133
+ if order_string != "" then order_string << "\n" end
134
+
135
+ order_string << "One #{@ice_cream_size.get_string_selection} #{@ice_cream_type.get_string_selection} ice cream:\n"
136
+ @ice_cream_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
137
+
138
+ @text_output.set_value(order_string)
139
+ end
140
+
141
+ evt_listbook_page_changed(Wx::xrcid('ID_LISTBOOK')) do |event|
142
+ tab_number = event.get_selection
143
+ order_string = @text_output.get_value
144
+ order_string << "moved to tab = #{@listbook.get_page_text(tab_number)} \n"
145
+ @text_output.set_value(order_string)
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)
153
+ end
154
+
155
+ end
156
+
157
+ #
158
+ # Application class.
159
+ #
160
+ class XrcApp < Wx::App
161
+
162
+ def on_init
163
+ # Create a resource handler
164
+ $xml = Wx::XmlResource.get();
165
+ $xml.init_all_handlers();
166
+
167
+ # Load a resource file from the script's directory
168
+ xrc_file = File.join( File.dirname( __FILE__ ), 'listbook.xrc' )
169
+
170
+ $xml.load(xrc_file)
171
+
172
+
173
+ # Show the main frame.
174
+ $main = SimpleFrame.new(self)
175
+ $main.show(true)
176
+
177
+ end
178
+ end
179
+
180
+
181
+ XrcApp.new().main_loop()