wxruby 1.9.0-powerpc-darwin8.10.0 → 1.9.2-powerpc-darwin8.10.0

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 (46) hide show
  1. data/LICENSE +53 -0
  2. data/README +299 -0
  3. data/lib/wx.rb +7 -0
  4. data/lib/wx/accessors.rb +52 -0
  5. data/lib/wx/classes/app.rb +15 -1
  6. data/lib/wx/classes/bitmap.rb +2 -2
  7. data/lib/wx/classes/checklistbox.rb +30 -0
  8. data/lib/wx/classes/clientdc.rb +1 -1
  9. data/lib/wx/classes/commandevent.rb +7 -0
  10. data/lib/wx/classes/controlwithitems.rb +10 -0
  11. data/lib/wx/classes/evthandler.rb +99 -39
  12. data/lib/wx/classes/grid.rb +13 -13
  13. data/lib/wx/classes/listctrl.rb +9 -0
  14. data/lib/wx/classes/menu.rb +62 -0
  15. data/lib/wx/classes/menuitem.rb +7 -0
  16. data/lib/wx/classes/paintdc.rb +1 -1
  17. data/lib/wx/classes/point.rb +43 -0
  18. data/lib/wx/classes/size.rb +44 -0
  19. data/lib/wx/classes/styledtextctrl.rb +92 -0
  20. data/lib/wx/classes/textctrl.rb +14 -0
  21. data/lib/wx/classes/timer.rb +2 -2
  22. data/lib/wx/classes/treectrl.rb +18 -0
  23. data/lib/wx/classes/window.rb +13 -2
  24. data/lib/wx/keyword_ctors.rb +205 -0
  25. data/lib/wx/keyword_defs.rb +465 -0
  26. data/lib/wx/version.rb +1 -1
  27. data/lib/wxruby2.bundle +0 -0
  28. data/samples/aui/aui.rb +6 -5
  29. data/samples/bigdemo/wxListCtrl_virtual.rbw +21 -21
  30. data/samples/bigdemo/wxScrolledWindow.rbw +8 -3
  31. data/samples/calendar/calendar.rb +1 -1
  32. data/samples/caret/caret.rb +29 -39
  33. data/samples/etc/threaded.rb +81 -0
  34. data/samples/etc/wizard.rb +22 -24
  35. data/samples/event/event.rb +184 -0
  36. data/samples/html/html.rb +25 -12
  37. data/samples/listbook/listbook.rb +65 -67
  38. data/samples/minimal/minimal.rb +40 -50
  39. data/samples/minimal/mondrian.png +0 -0
  40. data/samples/minimal/nothing.rb +5 -30
  41. data/samples/text/scintilla.rb +22 -28
  42. data/samples/text/unicode.rb +1 -1
  43. data/samples/treectrl/treectrl.rb +197 -226
  44. metadata +20 -4
  45. data/samples/minimal/mondrian.xpm +0 -44
  46. data/samples/minimal/text.rb +0 -35
@@ -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()
@@ -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()