wxruby 1.9.0-i686-darwin8.4.1 → 1.9.1-i686-darwin8.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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()
@@ -15,20 +15,14 @@ end
15
15
 
16
16
  # The frame or self-contained window for this application
17
17
  class MinimalFrame < Wx::Frame
18
- def initialize(title, pos, size, style = Wx::DEFAULT_FRAME_STYLE)
18
+ def initialize(title)
19
19
 
20
20
  # A main application frame has no parent (nil)
21
- # -1 means this frame will be supplied a default id
22
- super(nil, -1, title, pos, size, style)
21
+ super(nil, :title => title, :size => [ 400, 300 ])
23
22
 
24
- # Set the frame's icon - use .ico on windows, else .xpm
25
- if Wx::PLATFORM == "WXMSW"
26
- set_icon( Wx::Icon.new(local_icon_file("mondrian.ico"),
27
- Wx::BITMAP_TYPE_ICO) )
28
- else
29
- set_icon( Wx::Icon.new(local_icon_file("mondrian.xpm"),
30
- Wx::BITMAP_TYPE_XPM) )
31
- end
23
+ # PNG is a good choice for cross-platofrm icons
24
+ icon_file = File.join( File.dirname(__FILE__), 'mondrian.png')
25
+ self.icon = Wx::Icon.new(icon_file)
32
26
 
33
27
  menu_file = Wx::Menu.new()
34
28
  menu_help = Wx::Menu.new()
@@ -66,11 +60,6 @@ class MinimalFrame < Wx::Frame
66
60
  Wx::OK|Wx::ICON_INFORMATION )
67
61
  about_dlg.show_modal
68
62
  end
69
-
70
- # utility function to find an icon relative to this ruby script
71
- def local_icon_file(icon_name)
72
- File.join( File.dirname(__FILE__), icon_name)
73
- end
74
63
  end
75
64
 
76
65
  # Wx::App is the container class for any wxruby app - only a single
@@ -79,13 +68,12 @@ class MinimalApp < Wx::App
79
68
  # This method is called when main_loop is entered; it should set up
80
69
  # the application's and display initial GUI windows.
81
70
  def on_init
82
- frame = MinimalFrame.new("Minimal wxRuby App",
83
- Wx::Point.new(50, 50),
84
- Wx::Size.new(450, 340))
85
- set_app_name('Minimal')
86
- # This is required, and on_init must return a true value else the
87
- # app will not start
88
- frame.show()
71
+ self.app_name = 'Minimal'
72
+ frame = MinimalFrame.new("Minimal wxRuby App")
73
+ # This is required,
74
+ frame.show
75
+ # on_init must return a true value else the app will not start
76
+ true
89
77
  end
90
78
  end
91
79
 
Binary file
@@ -24,12 +24,6 @@ class MyFrame < Frame
24
24
  def initialize(title,pos,size,style=DEFAULT_FRAME_STYLE)
25
25
  super(nil,-1,title,pos,size,style)
26
26
 
27
- if Wx::PLATFORM == "WXMSW"
28
- set_icon(Icon.new("mondrian.ico",BITMAP_TYPE_ICO))
29
- else
30
- set_icon(Icon.new("mondrian.xpm",BITMAP_TYPE_XPM))
31
- end
32
-
33
27
  menuFile = Menu.new()
34
28
  menuFile.append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program")
35
29
 
@@ -51,23 +45,23 @@ class MyFrame < Frame
51
45
  create_status_bar(2)
52
46
  set_status_text("Welcome to wxRuby!")
53
47
 
54
- @sci = Wx::Scintilla.new(self)
48
+ @sci = Wx::StyledTextCtrl.new(self)
55
49
 
56
50
  font = Font.new(10, TELETYPE, NORMAL, NORMAL)
57
- @sci.style_set_font(SCI_STYLE_DEFAULT, font);
51
+ @sci.style_set_font(STC_STYLE_DEFAULT, font);
58
52
 
59
53
  @ws_visible = false
60
54
  @eol_visible = false
61
- @sci.set_edge_mode(SCI_EDGE_LINE)
55
+ @sci.set_edge_mode(STC_EDGE_LINE)
62
56
 
63
- line_num_margin = @sci.text_width(SCI_STYLE_LINENUMBER, "_99999")
57
+ line_num_margin = @sci.text_width(STC_STYLE_LINENUMBER, "_99999")
64
58
  @sci.set_margin_width(0, line_num_margin)
65
59
 
66
- @sci.style_set_foreground(SCI_STYLE_DEFAULT, BLACK);
67
- @sci.style_set_background(SCI_STYLE_DEFAULT, WHITE);
68
- @sci.style_set_foreground(SCI_STYLE_LINENUMBER, LIGHT_GREY);
69
- @sci.style_set_background(SCI_STYLE_LINENUMBER, WHITE);
70
- @sci.style_set_foreground(SCI_STYLE_INDENTGUIDE, LIGHT_GREY);
60
+ @sci.style_set_foreground(STC_STYLE_DEFAULT, BLACK);
61
+ @sci.style_set_background(STC_STYLE_DEFAULT, WHITE);
62
+ @sci.style_set_foreground(STC_STYLE_LINENUMBER, LIGHT_GREY);
63
+ @sci.style_set_background(STC_STYLE_LINENUMBER, WHITE);
64
+ @sci.style_set_foreground(STC_STYLE_INDENTGUIDE, LIGHT_GREY);
71
65
 
72
66
  @sci.set_tab_width(4)
73
67
  @sci.set_use_tabs(false)
@@ -76,7 +70,7 @@ class MyFrame < Frame
76
70
  @sci.set_indent(4)
77
71
  @sci.set_edge_column(80)
78
72
 
79
- @sci.set_lexer(SCI_LEX_RUBY)
73
+ @sci.set_lexer(STC_LEX_RUBY)
80
74
  @sci.style_clear_all
81
75
  @sci.style_set_foreground(2, RED)
82
76
  @sci.style_set_foreground(3, GREEN)
@@ -91,17 +85,17 @@ class MyFrame < Frame
91
85
  @sci.set_property("fold.preprocessor", "1")
92
86
 
93
87
  @sci.set_margin_width(1, 0)
94
- @sci.set_margin_type(1, SCI_MARGIN_SYMBOL)
95
- @sci.set_margin_mask(1, SCI_MASK_FOLDERS)
88
+ @sci.set_margin_type(1, STC_MARGIN_SYMBOL)
89
+ @sci.set_margin_mask(1, STC_MASK_FOLDERS)
96
90
  @sci.set_margin_width(1, 20)
97
91
 
98
- @sci.marker_define(SCI_MARKNUM_FOLDER, SCI_MARK_PLUS)
99
- @sci.marker_define(SCI_MARKNUM_FOLDEROPEN, SCI_MARK_MINUS)
100
- @sci.marker_define(SCI_MARKNUM_FOLDEREND, SCI_MARK_EMPTY)
101
- @sci.marker_define(SCI_MARKNUM_FOLDERMIDTAIL, SCI_MARK_EMPTY)
102
- @sci.marker_define(SCI_MARKNUM_FOLDEROPENMID, SCI_MARK_EMPTY)
103
- @sci.marker_define(SCI_MARKNUM_FOLDERSUB, SCI_MARK_EMPTY)
104
- @sci.marker_define(SCI_MARKNUM_FOLDERTAIL, SCI_MARK_EMPTY)
92
+ @sci.marker_define(STC_MARKNUM_FOLDER, STC_MARK_PLUS)
93
+ @sci.marker_define(STC_MARKNUM_FOLDEROPEN, STC_MARK_MINUS)
94
+ @sci.marker_define(STC_MARKNUM_FOLDEREND, STC_MARK_EMPTY)
95
+ @sci.marker_define(STC_MARKNUM_FOLDERMIDTAIL, STC_MARK_EMPTY)
96
+ @sci.marker_define(STC_MARKNUM_FOLDEROPENMID, STC_MARK_EMPTY)
97
+ @sci.marker_define(STC_MARKNUM_FOLDERSUB, STC_MARK_EMPTY)
98
+ @sci.marker_define(STC_MARKNUM_FOLDERTAIL, STC_MARK_EMPTY)
105
99
  @sci.set_fold_flags(16)
106
100
 
107
101
  @sci.set_margin_sensitive(1,1)
@@ -110,8 +104,8 @@ class MyFrame < Frame
110
104
  evt_menu(Minimal_About) {onAbout}
111
105
  evt_menu(Toggle_Whitespace) {onWhitespace}
112
106
  evt_menu(Toggle_EOL) {onEOL}
113
- evt_sci_charadded {|evt| onCharadded(evt)}
114
- evt_sci_marginclick {|evt| onMarginClick(evt)}
107
+ evt_stc_charadded(@sci.get_id) {|evt| onCharadded(evt)}
108
+ evt_stc_marginclick(@sci.get_id) {|evt| onMarginClick(evt)}
115
109
 
116
110
  end
117
111
 
@@ -130,7 +124,7 @@ class MyFrame < Frame
130
124
 
131
125
  def onWhitespace
132
126
  @ws_visible = !@ws_visible
133
- @sci.set_view_white_space(@ws_visible ? SCI_WS_VISIBLEALWAYS : SCI_WS_INVISIBLE)
127
+ @sci.set_view_white_space(@ws_visible ? STC_WS_VISIBLEALWAYS : STC_WS_INVISIBLE)
134
128
  end
135
129
 
136
130
  def onEOL
@@ -102,7 +102,7 @@ class IConvFrame < Wx::Frame
102
102
 
103
103
  sizer.add(ctrl_sizer, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
104
104
  construct_menus()
105
- panel.set_sizer( sizer )
105
+ panel.set_sizer_and_fit( sizer )
106
106
  end
107
107
 
108
108
  # Prompt the user to specify a file whose contents should be loaded
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: wxruby
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.9.0
7
- date: 2007-07-28 00:00:00 -07:00
6
+ version: 1.9.1
7
+ date: 2007-09-09 00:00:00 -07:00
8
8
  summary: Ruby interface to the wxWidgets GUI library
9
9
  require_paths:
10
10
  - lib
@@ -32,7 +32,10 @@ files:
32
32
  - lib/wx
33
33
  - lib/wx.rb
34
34
  - lib/wxruby2.bundle
35
+ - lib/wx/accessors.rb
35
36
  - lib/wx/classes
37
+ - lib/wx/keyword_ctors.rb
38
+ - lib/wx/keyword_defs.rb
36
39
  - lib/wx/version.rb
37
40
  - lib/wx/classes/app.rb
38
41
  - lib/wx/classes/artprovider.rb
@@ -57,6 +60,8 @@ files:
57
60
  - lib/wx/classes/previewframe.rb
58
61
  - lib/wx/classes/rect.rb
59
62
  - lib/wx/classes/size.rb
63
+ - lib/wx/classes/styledtextctrl.rb
64
+ - lib/wx/classes/textctrl.rb
60
65
  - lib/wx/classes/texturlevent.rb
61
66
  - lib/wx/classes/timer.rb
62
67
  - lib/wx/classes/window.rb
@@ -68,6 +73,7 @@ files:
68
73
  - samples/controls
69
74
  - samples/dialogs
70
75
  - samples/etc
76
+ - samples/event
71
77
  - samples/grid
72
78
  - samples/html
73
79
  - samples/images
@@ -218,6 +224,7 @@ files:
218
224
  - samples/etc/scrollwin.rb
219
225
  - samples/etc/system_settings.rb
220
226
  - samples/etc/wizard.rb
227
+ - samples/event/event.rb
221
228
  - samples/grid/grid.rb
222
229
  - samples/html/html.rb
223
230
  - samples/images/images.rb
@@ -227,8 +234,7 @@ files:
227
234
  - samples/listbook/listbook.xrc
228
235
  - samples/mdi/mdi.rb
229
236
  - samples/minimal/minimal.rb
230
- - samples/minimal/mondrian.ico
231
- - samples/minimal/mondrian.xpm
237
+ - samples/minimal/mondrian.png
232
238
  - samples/minimal/nothing.rb
233
239
  - samples/minimal/text.rb
234
240
  - samples/printing/mondrian.ico
Binary file
@@ -1,44 +0,0 @@
1
- /* XPM */
2
- static char *mondrian_xpm[] = {
3
- /* columns rows colors chars-per-pixel */
4
- "32 32 6 1",
5
- " c Black",
6
- ". c Blue",
7
- "X c #00bf00",
8
- "o c Red",
9
- "O c Yellow",
10
- "+ c Gray100",
11
- /* pixels */
12
- " ",
13
- " oooooo +++++++++++++++++++++++ ",
14
- " oooooo +++++++++++++++++++++++ ",
15
- " oooooo +++++++++++++++++++++++ ",
16
- " oooooo +++++++++++++++++++++++ ",
17
- " oooooo +++++++++++++++++++++++ ",
18
- " oooooo +++++++++++++++++++++++ ",
19
- " oooooo +++++++++++++++++++++++ ",
20
- " ",
21
- " ++++++ ++++++++++++++++++ .... ",
22
- " ++++++ ++++++++++++++++++ .... ",
23
- " ++++++ ++++++++++++++++++ .... ",
24
- " ++++++ ++++++++++++++++++ .... ",
25
- " ++++++ ++++++++++++++++++ .... ",
26
- " ++++++ ++++++++++++++++++ ",
27
- " ++++++ ++++++++++++++++++ ++++ ",
28
- " ++++++ ++++++++++++++++++ ++++ ",
29
- " ++++++ ++++++++++++++++++ ++++ ",
30
- " ++++++ ++++++++++++++++++ ++++ ",
31
- " ++++++ ++++++++++++++++++ ++++ ",
32
- " ++++++ ++++++++++++++++++ ++++ ",
33
- " ++++++ ++++++++++++++++++ ++++ ",
34
- " ++++++ ++++++++++++++++++ ++++ ",
35
- " ++++++ ++++++++++++++++++ ++++ ",
36
- " ++++++ ++++ ",
37
- " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
38
- " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
39
- " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
40
- " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
41
- " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
42
- " ++++++ OOOOOOOOOOOO XXXXX ++++ ",
43
- " "
44
- };