wxruby 1.9.0-i386-mswin32 → 1.9.1-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/lib/wx.rb +42 -35
  2. data/lib/wx/accessors.rb +52 -0
  3. data/lib/wx/classes/evthandler.rb +36 -32
  4. data/lib/wx/classes/grid.rb +13 -13
  5. data/lib/wx/classes/point.rb +43 -0
  6. data/lib/wx/classes/size.rb +44 -0
  7. data/lib/wx/classes/styledtextctrl.rb +92 -0
  8. data/lib/wx/classes/textctrl.rb +14 -0
  9. data/lib/wx/classes/window.rb +4 -0
  10. data/lib/wx/keyword_ctors.rb +219 -0
  11. data/lib/wx/keyword_defs.rb +455 -0
  12. data/lib/wx/version.rb +1 -1
  13. data/lib/wxruby2.exp +0 -0
  14. data/lib/wxruby2.lib +0 -0
  15. data/lib/wxruby2.so +0 -0
  16. data/samples/SAMPLES-LICENSE.TXT +17 -17
  17. data/samples/aui/aui.rb +6 -5
  18. data/samples/bigdemo/About.rbw +39 -39
  19. data/samples/bigdemo/ColorPanel.rbw +25 -25
  20. data/samples/bigdemo/GridSimple.rbw +80 -80
  21. data/samples/bigdemo/MDIDemo.rbw +59 -59
  22. data/samples/bigdemo/PopupMenu.rbw +151 -151
  23. data/samples/bigdemo/Sizers.rbw +545 -545
  24. data/samples/bigdemo/bigdemo.rb +826 -826
  25. data/samples/bigdemo/demoTemplate.rbw +37 -37
  26. data/samples/bigdemo/icons/choice.xpm +27 -27
  27. data/samples/bigdemo/icons/combo.xpm +27 -27
  28. data/samples/bigdemo/icons/copy.xpm +25 -25
  29. data/samples/bigdemo/icons/cut.xpm +24 -24
  30. data/samples/bigdemo/icons/gauge.xpm +27 -27
  31. data/samples/bigdemo/icons/help.xpm +25 -25
  32. data/samples/bigdemo/icons/list.xpm +27 -27
  33. data/samples/bigdemo/icons/mondrian.xpm +44 -44
  34. data/samples/bigdemo/icons/new.xpm +24 -24
  35. data/samples/bigdemo/icons/ogl.ico +0 -0
  36. data/samples/bigdemo/icons/ogl.xpm +45 -45
  37. data/samples/bigdemo/icons/open.xpm +26 -26
  38. data/samples/bigdemo/icons/paste.xpm +38 -38
  39. data/samples/bigdemo/icons/preview.xpm +26 -26
  40. data/samples/bigdemo/icons/print.xpm +26 -26
  41. data/samples/bigdemo/icons/radio.xpm +27 -27
  42. data/samples/bigdemo/icons/robert.xpm +415 -415
  43. data/samples/bigdemo/icons/save.xpm +25 -25
  44. data/samples/bigdemo/icons/smiles.xpm +39 -39
  45. data/samples/bigdemo/icons/smiley.xpm +42 -42
  46. data/samples/bigdemo/icons/stattext.xpm +24 -24
  47. data/samples/bigdemo/icons/test2.bmp +0 -0
  48. data/samples/bigdemo/icons/test2.xpm +79 -79
  49. data/samples/bigdemo/icons/text.xpm +27 -27
  50. data/samples/bigdemo/icons/tog1.xpm +38 -38
  51. data/samples/bigdemo/icons/tog2.xpm +38 -38
  52. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -25
  53. data/samples/bigdemo/tips.txt +7 -7
  54. data/samples/bigdemo/utils.rb +11 -11
  55. data/samples/bigdemo/wxButton.rbw +66 -66
  56. data/samples/bigdemo/wxCalendarCtrl.rbw +72 -72
  57. data/samples/bigdemo/wxCheckBox.rbw +52 -52
  58. data/samples/bigdemo/wxCheckListBox.rbw +77 -77
  59. data/samples/bigdemo/wxChoice.rbw +49 -49
  60. data/samples/bigdemo/wxColourDialog.rbw +34 -34
  61. data/samples/bigdemo/wxComboBox.rbw +79 -79
  62. data/samples/bigdemo/wxDialog.rbw +92 -92
  63. data/samples/bigdemo/wxDirDialog.rbw +32 -32
  64. data/samples/bigdemo/wxFileDialog.rbw +39 -39
  65. data/samples/bigdemo/wxFileDialog_Save.rbw +38 -38
  66. data/samples/bigdemo/wxFindReplaceDialog.rbw +85 -85
  67. data/samples/bigdemo/wxFontDialog.rbw +176 -176
  68. data/samples/bigdemo/wxFrame.rbw +55 -55
  69. data/samples/bigdemo/wxGauge.rbw +73 -73
  70. data/samples/bigdemo/wxGrid.rbw +68 -68
  71. data/samples/bigdemo/wxListBox.rbw +142 -142
  72. data/samples/bigdemo/wxListCtrl_virtual.rbw +109 -109
  73. data/samples/bigdemo/wxMDIWindows.rbw +52 -52
  74. data/samples/bigdemo/wxMenu.rbw +238 -238
  75. data/samples/bigdemo/wxMessageDialog.rbw +30 -30
  76. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +34 -34
  77. data/samples/bigdemo/wxNotebook.rbw +138 -138
  78. data/samples/bigdemo/wxProgressDialog.rbw +45 -45
  79. data/samples/bigdemo/wxRadioBox.rbw +74 -74
  80. data/samples/bigdemo/wxRadioButton.rbw +127 -127
  81. data/samples/bigdemo/wxScrolledMessageDialog.rbw +59 -59
  82. data/samples/bigdemo/wxScrolledWindow.rbw +196 -196
  83. data/samples/bigdemo/wxSingleChoiceDialog.rbw +35 -35
  84. data/samples/bigdemo/wxSlider.rbw +44 -44
  85. data/samples/bigdemo/wxSpinButton.rbw +52 -52
  86. data/samples/bigdemo/wxSpinCtrl.rbw +53 -53
  87. data/samples/bigdemo/wxSplitterWindow.rbw +65 -65
  88. data/samples/bigdemo/wxStaticBitmap.rbw +53 -53
  89. data/samples/bigdemo/wxStaticText.rbw +57 -57
  90. data/samples/bigdemo/wxStatusBar.rbw +128 -128
  91. data/samples/bigdemo/wxTextCtrl.rbw +151 -151
  92. data/samples/bigdemo/wxTextEntryDialog.rbw +34 -34
  93. data/samples/bigdemo/wxToggleButton.rbw +51 -51
  94. data/samples/bigdemo/wxToolBar.rbw +133 -133
  95. data/samples/bigdemo/wxTreeCtrl.rbw +192 -192
  96. data/samples/calendar/calendar.rb +275 -275
  97. data/samples/caret/caret.rb +296 -296
  98. data/samples/caret/mondrian.xpm +44 -44
  99. data/samples/controls/controls.rb +1140 -1140
  100. data/samples/controls/get_item_sample.rb +87 -87
  101. data/samples/controls/icons/choice.xpm +27 -27
  102. data/samples/controls/icons/combo.xpm +27 -27
  103. data/samples/controls/icons/gauge.xpm +27 -27
  104. data/samples/controls/icons/list.xpm +27 -27
  105. data/samples/controls/icons/radio.xpm +27 -27
  106. data/samples/controls/icons/stattext.xpm +24 -24
  107. data/samples/controls/icons/text.xpm +27 -27
  108. data/samples/controls/mondrian.xpm +44 -44
  109. data/samples/dialogs/dialogs.rb +724 -724
  110. data/samples/dialogs/tips.txt +18 -18
  111. data/samples/etc/activation.rb +108 -108
  112. data/samples/etc/choice.rb +72 -72
  113. data/samples/etc/miniframe.rb +84 -84
  114. data/samples/etc/sash.rb +135 -135
  115. data/samples/etc/scrollwin.rb +116 -116
  116. data/samples/etc/system_settings.rb +258 -258
  117. data/samples/etc/wizard.rb +81 -81
  118. data/samples/event/event.rb +184 -0
  119. data/samples/images/images.rb +48 -48
  120. data/samples/listbook/listbook.rb +183 -183
  121. data/samples/listbook/listbook.xrc +370 -370
  122. data/samples/mdi/mdi.rb +87 -87
  123. data/samples/minimal/minimal.rb +83 -95
  124. data/samples/minimal/mondrian.png +0 -0
  125. data/samples/minimal/nothing.rb +46 -46
  126. data/samples/minimal/text.rb +35 -35
  127. data/samples/text/scintilla.rb +22 -28
  128. data/samples/text/textctrl.rb +124 -124
  129. data/samples/text/unicode.rb +238 -238
  130. data/samples/text/utf8.txt +14 -14
  131. data/samples/treectrl/treectrl.rb +1210 -1210
  132. data/samples/xrc/samples.xrc +46 -46
  133. data/samples/xrc/xrc_sample.rb +107 -107
  134. metadata +13 -5
  135. data/samples/minimal/mondrian.ico +0 -0
  136. data/samples/minimal/mondrian.xpm +0 -44
@@ -1,81 +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
- class MyFrame < Wx::Frame
17
- def initialize(title, pos, size, style = Wx::DEFAULT_FRAME_STYLE)
18
- super(nil, -1, title, pos, size, style)
19
-
20
-
21
- menuFile = Wx::Menu.new()
22
- helpMenu = Wx::Menu.new()
23
- helpMenu.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
24
- menuFile.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
25
- menuBar = Wx::MenuBar.new()
26
- menuBar.append(menuFile, "&File")
27
- 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')
33
-
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')
38
- p1 = Wx::WizardPageSimple.new(w)
39
- s = Wx::StaticText.new(p1, -1, 'This is the first page')
40
- p2 = Wx::WizardPageSimple.new(w, p1)
41
- p1.set_next(p2)
42
- s = Wx::StaticText.new(p2, -1, 'This is the second page')
43
- p3 = Wx::WizardPageSimple.new(w, p2)
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" }
52
-
53
-
54
- w.run_wizard(p1)
55
- end
56
-
57
- def on_quit
58
- close(true)
59
- end
60
-
61
- def on_about
62
- msg = sprintf("This is the About dialog of the wizard sample.\n" \
63
- "Welcome to %s", Wx::VERSION_STRING)
64
- Wx::message_box(msg, "About Wizard", Wx::OK|Wx::ICON_INFORMATION, self)
65
- end
66
- end
67
-
68
- class RbApp < Wx::App
69
- def on_init
70
- frame = MyFrame.new("Wizard wxRuby App",
71
- Wx::Point.new(50, 50),
72
- Wx::Size.new(450, 340))
73
-
74
- frame.show(true)
75
-
76
- end
77
- end
78
-
79
- app = RbApp.new
80
- app.main_loop()
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
+ class MyFrame < Wx::Frame
17
+ def initialize(title, pos, size, style = Wx::DEFAULT_FRAME_STYLE)
18
+ super(nil, -1, title, pos, size, style)
19
+
20
+
21
+ menuFile = Wx::Menu.new()
22
+ helpMenu = Wx::Menu.new()
23
+ helpMenu.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
24
+ menuFile.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
25
+ menuBar = Wx::MenuBar.new()
26
+ menuBar.append(menuFile, "&File")
27
+ 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')
33
+
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')
38
+ p1 = Wx::WizardPageSimple.new(w)
39
+ s = Wx::StaticText.new(p1, -1, 'This is the first page')
40
+ p2 = Wx::WizardPageSimple.new(w, p1)
41
+ p1.set_next(p2)
42
+ s = Wx::StaticText.new(p2, -1, 'This is the second page')
43
+ p3 = Wx::WizardPageSimple.new(w, p2)
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" }
52
+
53
+
54
+ w.run_wizard(p1)
55
+ end
56
+
57
+ def on_quit
58
+ close(true)
59
+ end
60
+
61
+ def on_about
62
+ msg = sprintf("This is the About dialog of the wizard sample.\n" \
63
+ "Welcome to %s", Wx::VERSION_STRING)
64
+ Wx::message_box(msg, "About Wizard", Wx::OK|Wx::ICON_INFORMATION, self)
65
+ end
66
+ end
67
+
68
+ class RbApp < Wx::App
69
+ def on_init
70
+ frame = MyFrame.new("Wizard wxRuby App",
71
+ Wx::Point.new(50, 50),
72
+ Wx::Size.new(450, 340))
73
+
74
+ frame.show(true)
75
+
76
+ end
77
+ end
78
+
79
+ app = RbApp.new
80
+ app.main_loop()
81
+
@@ -0,0 +1,184 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2007 wxRuby development team
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+
5
+ begin
6
+ require 'rubygems'
7
+ require 'wx'
8
+ rescue LoadError
9
+ require 'wx'
10
+ end
11
+
12
+ # This sample demonstrates how to dynamically connect and disconnect
13
+ # event handlers, and how to create custom event types and listeners
14
+ # associated with user-defined control classes.
15
+
16
+ # A custom type of event associated with a target control. Note that for
17
+ # user-defined controls, the associated event should inherit from
18
+ # Wx::CommandEvent rather than Wx::Event.
19
+ class TargetHitEvent < Wx::CommandEvent
20
+ # Create a new unique constant identifier, associate this class
21
+ # with events of that identifier, and create a shortcut 'evt_target'
22
+ # method for setting up this handler.
23
+ EVT_HIT_TARGET = Wx::EvtHandler.register_class(self, nil, 'evt_target', 1)
24
+
25
+ def initialize(target, score, distance)
26
+ # The constant id is the arg to super
27
+ super(EVT_HIT_TARGET)
28
+ # client_data should be used to store any information associated
29
+ # with the event.
30
+ self.client_data = { :score => score, :distance => distance }
31
+ self.id = target.get_id
32
+ end
33
+
34
+ # Returns the points score associated with this event
35
+ def score
36
+ client_data[:score]
37
+ end
38
+
39
+ # Returns the distance (in pixels) from the centre of the target
40
+ def distance
41
+ client_data[:distance]
42
+ end
43
+ end
44
+
45
+ # An example of a simple user-written control, which displays a
46
+ # "bulls-eye" like target, and sends events with a score and distance
47
+ class TargetControl < Wx::Window
48
+ TargetCircle = Struct.new(:radius, :score, :brush)
49
+
50
+ def initialize(parent, *args)
51
+ super(parent, *args)
52
+
53
+ # Set up the scores and sizes of the rings
54
+ @radii = [
55
+ TargetCircle[ 0.1, 20, Wx::RED_BRUSH ],
56
+ TargetCircle[ 0.25, 10, Wx::BLUE_BRUSH ],
57
+ TargetCircle[ 0.4, 5, Wx::GREEN_BRUSH ] ]
58
+ evt_paint { | e | on_paint(e) }
59
+ evt_left_down { | e | on_left_down(e) }
60
+ end
61
+
62
+ # What point is at the centre (assuming this control is always square)
63
+ def centre_point
64
+ size.width / 2
65
+ end
66
+
67
+ # Called whenever the target is repainted, draws a series of
68
+ # concentric circles
69
+ def on_paint(evt)
70
+ paint do | dc |
71
+ dc.clear
72
+ @radii.reverse_each do | circ |
73
+ dc.brush = circ.brush
74
+ dc.draw_circle(centre_point, centre_point,
75
+ ( size.width * circ.radius).to_i )
76
+ end
77
+ end
78
+ end
79
+
80
+ # Test if the target was hit, and generate a TargetHitEvent if so
81
+ def on_left_down(evt)
82
+ # quick bit of pythagoras...
83
+ distance = Math.sqrt( ( evt.x - centre_point ) ** 2 +
84
+ ( evt.y - centre_point ) ** 2 )
85
+ # See which target ring, if any, was hit by the event
86
+ @radii.each do | circ |
87
+ if distance < ( size.width * circ.radius)
88
+ # Create an instance of the event
89
+ evt = TargetHitEvent.new(self, circ.score, distance)
90
+ # This sends the event for processing by listeners
91
+ event_handler.process_event(evt)
92
+ break
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ # Container frame for the target control
99
+ class TargetFrame < Wx::Frame
100
+ def initialize(title)
101
+ super(nil, :title => title, :size => [300, 300])
102
+ @tgt = TargetControl.new(self)
103
+ # This user-defined event handling method was set up by
104
+ # EvtHandler.register_class, above
105
+ evt_target(@tgt.get_id) { | e | on_target(e) }
106
+ @listening = true
107
+ evt_size { | e | on_size(e) }
108
+ setup_menus
109
+ create_status_bar
110
+ end
111
+
112
+ # What's done when the target is hit
113
+ def on_target(evt)
114
+ msg = "Target hit for score %i, %.2f pixels from centre" %
115
+ [ evt.score, evt.distance ]
116
+ self.status_text = msg
117
+ end
118
+
119
+ # Keep the target centred and square
120
+ def on_size(evt)
121
+ smaller = [ evt.size.width, evt.size.height ].min
122
+ @tgt.centre
123
+ @tgt.size = Wx::Size.new(smaller, smaller)
124
+ @tgt.refresh
125
+ end
126
+
127
+ # Toggle whether or not we are listening for events from the bulls-eye
128
+ # target
129
+ def on_toggle_connect
130
+ if @listening
131
+ # Remove :evt_target event handler for the @tgt
132
+ disconnect(@tgt.get_id, Wx::ID_ANY, :evt_target)
133
+ menu_bar.check(TOGGLE_LISTEN, false)
134
+ self.status_text = "Ignoring target events"
135
+ @listening = false
136
+ else
137
+ # Restore evt_target event handler for the @tgt
138
+ evt_target(@tgt.get_id) { | e | on_target(e) }
139
+ menu_bar.check(TOGGLE_LISTEN, true)
140
+ self.status_text = ''
141
+ @listening = true
142
+ end
143
+ end
144
+
145
+ def on_about
146
+ msg = sprintf("This is the About dialog of the event handling sample.\n" \
147
+ "Welcome to wxRuby, version %s", Wx::WXRUBY_VERSION)
148
+
149
+ about_dlg = Wx::MessageDialog.new( self, msg, 'About Event Handling',
150
+ Wx::OK|Wx::ICON_INFORMATION )
151
+ about_dlg.show_modal
152
+
153
+ end
154
+
155
+ TOGGLE_LISTEN = 1001
156
+ def setup_menus
157
+ menu_file = Wx::Menu.new
158
+ menu_help = Wx::Menu.new
159
+ menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
160
+ evt_menu(Wx::ID_ABOUT) { on_about }
161
+ menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
162
+ evt_menu(Wx::ID_EXIT) { self.close }
163
+ menu_file.append_check_item(TOGGLE_LISTEN, "L&isten for events",
164
+ "Toggle listening for target events")
165
+ evt_menu(TOGGLE_LISTEN) { on_toggle_connect }
166
+
167
+ menu_bar = Wx::MenuBar.new
168
+ menu_bar.append(menu_file, "&File")
169
+ menu_bar.append(menu_help, "&Help")
170
+
171
+ self.menu_bar = menu_bar
172
+ menu_bar.check(TOGGLE_LISTEN, true)
173
+ end
174
+ end
175
+
176
+ class TargetApp < Wx::App
177
+ def on_init
178
+ TargetFrame.new("Event Handling Sample").show
179
+ return true
180
+ end
181
+ end
182
+
183
+ a = TargetApp.new
184
+ a.main_loop()
@@ -1,48 +1,48 @@
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 sample demonstrates how to draw an image from a file onto a
17
- # window. This one uses a small PNG file, but other formats such as JPEG
18
- # are supported - see documentation for more details.
19
-
20
- class MyFrame < Wx::Frame
21
- def initialize(title)
22
- super(nil, -1, title)
23
- evt_paint { on_paint }
24
-
25
- img_file = File.join( File.dirname(__FILE__), 'paperclip.png')
26
- # first load the image into an Image object
27
- image = Wx::Image.new(img_file)
28
- # then create a Bitmap suitable for drawing
29
- @bitmap = Wx::Bitmap.new(image)
30
- end
31
-
32
- def on_paint
33
- paint do | dc |
34
- dc.clear
35
- dc.draw_bitmap(@bitmap, 0, 0, false)
36
- end
37
- end
38
- end
39
-
40
- class ImagesApp < Wx::App
41
- def on_init
42
- frame = MyFrame.new("Simple Image Demo")
43
- frame.show
44
- end
45
- end
46
-
47
- a = ImagesApp.new
48
- a.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
+ # This sample demonstrates how to draw an image from a file onto a
17
+ # window. This one uses a small PNG file, but other formats such as JPEG
18
+ # are supported - see documentation for more details.
19
+
20
+ class MyFrame < Wx::Frame
21
+ def initialize(title)
22
+ super(nil, -1, title)
23
+ evt_paint { on_paint }
24
+
25
+ img_file = File.join( File.dirname(__FILE__), 'paperclip.png')
26
+ # first load the image into an Image object
27
+ image = Wx::Image.new(img_file)
28
+ # then create a Bitmap suitable for drawing
29
+ @bitmap = Wx::Bitmap.new(image)
30
+ end
31
+
32
+ def on_paint
33
+ paint do | dc |
34
+ dc.clear
35
+ dc.draw_bitmap(@bitmap, 0, 0, false)
36
+ end
37
+ end
38
+ end
39
+
40
+ class ImagesApp < Wx::App
41
+ def on_init
42
+ frame = MyFrame.new("Simple Image Demo")
43
+ frame.show
44
+ end
45
+ end
46
+
47
+ a = ImagesApp.new
48
+ a.main_loop()
@@ -1,183 +1,183 @@
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 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
- #
22
- # Basic Frame Class. This creates the dialog window
23
- #
24
- class SimpleFrame < Wx::Frame
25
-
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')
36
-
37
- # Create a new menu
38
- bar = Wx::MenuBar.new
39
- menu = Wx::Menu.new
40
- menu.append(FILE_ABOUT,"About...")
41
- 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
48
- evt_menu(FILE_ABOUT) do
49
- Wx::message_box("wxRuby Listbook sample\nby Sean Long", "About Listbook", Wx::OK | Wx::ICON_INFORMATION, self)
50
- 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
57
-
58
- # 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)
61
-
62
- # 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)
67
- @pizza_toppings = []
68
- 3.times do |i|
69
- @pizza_toppings << Wx::Window.find_window_by_id(Wx::xrcid("ID_PIZZA_TOPPING_#{i+1}_CHOICE"),self)
70
- end
71
-
72
- # fill in toppings
73
- toppings = ['pepperoni','sausage','itallian sausage','olives','mushrooms','artichoke','extra cheese','']
74
- toppings.each do |top_name|
75
- @pizza_toppings.each do |top_obj|
76
- top_obj.append(top_name)
77
- end
78
- end
79
- index = 0
80
- @pizza_toppings.each do |obj|
81
- obj.set_selection(index)
82
- index += 1
83
- end
84
-
85
- # Events for pizza tab
86
- evt_button(Wx::xrcid('ID_PIZZA_BUTTON')) do |event|
87
- #get selections and add to order
88
- order_string = @text_output.get_value
89
- if order_string != "" then order_string << "\n" end
90
-
91
- order_string << "One #{@pizza_size.get_string_selection} pizza with:\n"
92
- order_string << @pizza_crust.get_string_selection + " crust" + "\n"
93
- order_string << @pizza_sauce.get_string_selection + " sauce" +"\n"
94
- order_string << @pizza_cheese.get_string_selection + " and" + "\n"
95
- @pizza_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
96
-
97
- @text_output.set_value(order_string)
98
- end
99
-
100
-
101
- # 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)
104
-
105
- # Events for drink tab
106
- evt_button(Wx::xrcid('ID_DRINK_BUTTON')) do |event|
107
- #get selections and add to order
108
- order_string = @text_output.get_value
109
- if order_string != "" then order_string << "\n" end
110
-
111
- order_string << "One #{@drink_size.get_string_selection} #{@drink_type.get_string_selection }.\n"
112
-
113
- @text_output.set_value(order_string)
114
- end
115
-
116
- # 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)
119
- @ice_cream_toppings = []
120
- 4.times do |i|
121
- @ice_cream_toppings << Wx::Window.find_window_by_id(Wx::xrcid("ID_ICE_CREAM_TOPPING_#{i+1}_CHOICE"),self)
122
- end
123
-
124
- toppings = ['','m&m\'s','chocolate chips','fudge','nuts','cherry','whip cream']
125
- toppings.each do |top_name|
126
- @ice_cream_toppings.each do |top_obj|
127
- top_obj.append(top_name)
128
- end
129
- end
130
- @ice_cream_toppings.each { |obj| obj.set_selection(0) }
131
-
132
- # Events for ice cream tab
133
- evt_button(Wx::xrcid('ID_ICE_CREAM_BUTTON')) do |event|
134
- #get selections and add to order
135
- order_string = @text_output.get_value
136
- if order_string != "" then order_string << "\n" end
137
-
138
- order_string << "One #{@ice_cream_size.get_string_selection} #{@ice_cream_type.get_string_selection} ice cream:\n"
139
- @ice_cream_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
140
-
141
- @text_output.set_value(order_string)
142
- end
143
-
144
- evt_listbook_page_changed(Wx::xrcid('ID_LISTBOOK')) do |event|
145
- tab_number = event.get_selection
146
- order_string = @text_output.get_value
147
- order_string << "moved to tab = #{@listbook.get_page_text(tab_number)} \n"
148
- @text_output.set_value(order_string)
149
- end
150
-
151
- end
152
-
153
- end
154
-
155
- #
156
- # Application class.
157
- #
158
- class XrcApp < Wx::App
159
-
160
- def on_init
161
- #
162
- # Create a resource handler
163
- #
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
- #
175
- $main = SimpleFrame.new(self)
176
- $main.show(true)
177
-
178
- end
179
-
180
- end
181
-
182
-
183
- 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
+ # 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
+ #
22
+ # Basic Frame Class. This creates the dialog window
23
+ #
24
+ class SimpleFrame < Wx::Frame
25
+
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')
36
+
37
+ # Create a new menu
38
+ bar = Wx::MenuBar.new
39
+ menu = Wx::Menu.new
40
+ menu.append(FILE_ABOUT,"About...")
41
+ 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
48
+ evt_menu(FILE_ABOUT) do
49
+ Wx::message_box("wxRuby Listbook sample\nby Sean Long", "About Listbook", Wx::OK | Wx::ICON_INFORMATION, self)
50
+ 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
57
+
58
+ # 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)
61
+
62
+ # 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)
67
+ @pizza_toppings = []
68
+ 3.times do |i|
69
+ @pizza_toppings << Wx::Window.find_window_by_id(Wx::xrcid("ID_PIZZA_TOPPING_#{i+1}_CHOICE"),self)
70
+ end
71
+
72
+ # fill in toppings
73
+ toppings = ['pepperoni','sausage','itallian sausage','olives','mushrooms','artichoke','extra cheese','']
74
+ toppings.each do |top_name|
75
+ @pizza_toppings.each do |top_obj|
76
+ top_obj.append(top_name)
77
+ end
78
+ end
79
+ index = 0
80
+ @pizza_toppings.each do |obj|
81
+ obj.set_selection(index)
82
+ index += 1
83
+ end
84
+
85
+ # Events for pizza tab
86
+ evt_button(Wx::xrcid('ID_PIZZA_BUTTON')) do |event|
87
+ #get selections and add to order
88
+ order_string = @text_output.get_value
89
+ if order_string != "" then order_string << "\n" end
90
+
91
+ order_string << "One #{@pizza_size.get_string_selection} pizza with:\n"
92
+ order_string << @pizza_crust.get_string_selection + " crust" + "\n"
93
+ order_string << @pizza_sauce.get_string_selection + " sauce" +"\n"
94
+ order_string << @pizza_cheese.get_string_selection + " and" + "\n"
95
+ @pizza_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
96
+
97
+ @text_output.set_value(order_string)
98
+ end
99
+
100
+
101
+ # 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)
104
+
105
+ # Events for drink tab
106
+ evt_button(Wx::xrcid('ID_DRINK_BUTTON')) do |event|
107
+ #get selections and add to order
108
+ order_string = @text_output.get_value
109
+ if order_string != "" then order_string << "\n" end
110
+
111
+ order_string << "One #{@drink_size.get_string_selection} #{@drink_type.get_string_selection }.\n"
112
+
113
+ @text_output.set_value(order_string)
114
+ end
115
+
116
+ # 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)
119
+ @ice_cream_toppings = []
120
+ 4.times do |i|
121
+ @ice_cream_toppings << Wx::Window.find_window_by_id(Wx::xrcid("ID_ICE_CREAM_TOPPING_#{i+1}_CHOICE"),self)
122
+ end
123
+
124
+ toppings = ['','m&m\'s','chocolate chips','fudge','nuts','cherry','whip cream']
125
+ toppings.each do |top_name|
126
+ @ice_cream_toppings.each do |top_obj|
127
+ top_obj.append(top_name)
128
+ end
129
+ end
130
+ @ice_cream_toppings.each { |obj| obj.set_selection(0) }
131
+
132
+ # Events for ice cream tab
133
+ evt_button(Wx::xrcid('ID_ICE_CREAM_BUTTON')) do |event|
134
+ #get selections and add to order
135
+ order_string = @text_output.get_value
136
+ if order_string != "" then order_string << "\n" end
137
+
138
+ order_string << "One #{@ice_cream_size.get_string_selection} #{@ice_cream_type.get_string_selection} ice cream:\n"
139
+ @ice_cream_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
140
+
141
+ @text_output.set_value(order_string)
142
+ end
143
+
144
+ evt_listbook_page_changed(Wx::xrcid('ID_LISTBOOK')) do |event|
145
+ tab_number = event.get_selection
146
+ order_string = @text_output.get_value
147
+ order_string << "moved to tab = #{@listbook.get_page_text(tab_number)} \n"
148
+ @text_output.set_value(order_string)
149
+ end
150
+
151
+ end
152
+
153
+ end
154
+
155
+ #
156
+ # Application class.
157
+ #
158
+ class XrcApp < Wx::App
159
+
160
+ def on_init
161
+ #
162
+ # Create a resource handler
163
+ #
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
+ #
175
+ $main = SimpleFrame.new(self)
176
+ $main.show(true)
177
+
178
+ end
179
+
180
+ end
181
+
182
+
183
+ XrcApp.new().main_loop()