wx_sugar 0.1.16 → 0.1.17
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.
- data/lib/wx_sugar/all.rb +2 -2
- data/lib/wx_sugar/version.rb +1 -1
- metadata +2 -6
- data/lib/wx_sugar/accessors.rb +0 -66
- data/lib/wx_sugar/keyword_classes.rb +0 -443
- data/lib/wx_sugar/keyword_constructors.rb +0 -267
- data/lib/wx_sugar/wx_classes/treectrl.rb +0 -40
data/lib/wx_sugar/all.rb
CHANGED
data/lib/wx_sugar/version.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: wx_sugar
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.1.17
|
7
|
+
date: 2007-09-11 00:00:00 +01:00
|
8
8
|
summary: Syntax extensions for WxRuby.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -35,20 +35,16 @@ files:
|
|
35
35
|
- lib/wx_sugar/layout.rb
|
36
36
|
- lib/wx_sugar/delayed_constructors.rb
|
37
37
|
- lib/wx_sugar/class_definitions.rb
|
38
|
-
- lib/wx_sugar/keyword_classes.rb
|
39
38
|
- lib/wx_sugar/enumerable_controls.rb
|
40
39
|
- lib/wx_sugar/menu.rb
|
41
|
-
- lib/wx_sugar/accessors.rb
|
42
40
|
- lib/wx_sugar/all.rb
|
43
41
|
- lib/wx_sugar/itemdata.rb
|
44
42
|
- lib/wx_sugar/event_connector.rb
|
45
43
|
- lib/wx_sugar/wx_classes.rb
|
46
|
-
- lib/wx_sugar/keyword_constructors.rb
|
47
44
|
- lib/wx_sugar/version.rb
|
48
45
|
- lib/wx_sugar/wx_classes/listctrl.rb
|
49
46
|
- lib/wx_sugar/wx_classes/colour.rb
|
50
47
|
- lib/wx_sugar/wx_classes/position.rb
|
51
|
-
- lib/wx_sugar/wx_classes/treectrl.rb
|
52
48
|
- lib/wx_sugar/wx_classes/window.rb
|
53
49
|
- lib/wx_sugar/wx_classes/size.rb
|
54
50
|
- lib/wx_sugar/wx_classes/control_with_items.rb
|
data/lib/wx_sugar/accessors.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# = WxSugar - Accessors
|
2
|
-
#
|
3
|
-
# The default WxRuby interface has lots and lots of methods like
|
4
|
-
#
|
5
|
-
# * get_position()
|
6
|
-
# * set_size(a_size)
|
7
|
-
# * is_checked()
|
8
|
-
#
|
9
|
-
# and so on. Methods that retrieve set, or query attributes of an object
|
10
|
-
# are more normally in Ruby called simply by the attribute name:
|
11
|
-
#
|
12
|
-
# * position()
|
13
|
-
# * size = a_size
|
14
|
-
# * checked?
|
15
|
-
#
|
16
|
-
# This extension creates an alias for every WxRuby instance method that
|
17
|
-
# begins with +get_+, +set_+ or +is_+. Note that if you are calling a
|
18
|
-
# 'setter' method on self, you must explicitly send the message to self:
|
19
|
-
#
|
20
|
-
# # set's self size to be 100px by 100px
|
21
|
-
# self.size = Wx::Size.new(100, 100)
|
22
|
-
# # only sets the value of a local variable 'size'
|
23
|
-
# size = Wx::Size.new
|
24
|
-
|
25
|
-
require 'wx_sugar/class_definitions.rb'
|
26
|
-
|
27
|
-
module NiceRubyMethodNames
|
28
|
-
def self.included(klass)
|
29
|
-
klass.class_eval do
|
30
|
-
instance_methods.grep(/^([gs]et|is)_(\w+)/) do | meth |
|
31
|
-
prefix, basename = $1, $2
|
32
|
-
case prefix
|
33
|
-
when 'get' : alias_method(basename, meth)
|
34
|
-
when 'set' : alias_method("#{basename}=", meth)
|
35
|
-
when 'is' : alias_method("#{basename}?", meth)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module MethMissingNiceRubyNames
|
43
|
-
def method_missing(sym, *args)
|
44
|
-
case sym.to_s
|
45
|
-
when /^(.*)\=$/
|
46
|
-
meth = "set_#{$1}"
|
47
|
-
when /^(.*)\?$/
|
48
|
-
meth = "is_#{$1}"
|
49
|
-
else
|
50
|
-
meth = "get_#{sym}"
|
51
|
-
end
|
52
|
-
if respond_to?(meth)
|
53
|
-
send(meth, *args)
|
54
|
-
else
|
55
|
-
e = NoMethodError.new("undefined method '#{sym}' for #{self.inspect}")
|
56
|
-
e.set_backtrace(caller)
|
57
|
-
Kernel.raise e
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
WxSugar::ALL_CLASSES.each do | klass |
|
64
|
-
# klass.class_eval { include NiceRubyMethodNames }
|
65
|
-
klass.class_eval { include MethMissingNiceRubyNames }
|
66
|
-
end
|
@@ -1,443 +0,0 @@
|
|
1
|
-
# = WxSugar - Keyword Constructors Classes
|
2
|
-
#
|
3
|
-
# This extension defines the keyword parameters for +new+ methods for
|
4
|
-
# widgets, windows and frames. It's for use with *Keyword Constructors*
|
5
|
-
# and is no use on its own - except if you are looking for a bug or want
|
6
|
-
# to add a missing class.
|
7
|
-
|
8
|
-
module WxSugar
|
9
|
-
@defined_classes = {}
|
10
|
-
|
11
|
-
# accepts a string unadorned name of a WxWidgets class, and block, which
|
12
|
-
# defines the constructor parameters and style flags for that class.
|
13
|
-
# If the named class exists in the available WxRuby, the block is run and
|
14
|
-
# the class may use keyword constructors. If the class is not available, the
|
15
|
-
# block is ignored.
|
16
|
-
def self.define_keyword_ctors(klass_name, &block)
|
17
|
-
# check this class hasn't already been defined
|
18
|
-
if @defined_classes[klass_name]
|
19
|
-
raise ArgumentError, "Keyword ctor for #{klass_name} already defined"
|
20
|
-
else
|
21
|
-
@defined_classes[klass_name] = true
|
22
|
-
end
|
23
|
-
|
24
|
-
begin
|
25
|
-
klass = Wx::const_get(klass_name)
|
26
|
-
rescue NameError
|
27
|
-
return nil
|
28
|
-
end
|
29
|
-
klass.module_eval { include WxSugar::KeywordConstructor }
|
30
|
-
# automatically add :id as the first argument, unless this is a
|
31
|
-
# Dialog subclass - which don't require this argument
|
32
|
-
unless klass < Wx::Dialog
|
33
|
-
klass.wx_ctor_params :id
|
34
|
-
end
|
35
|
-
klass.instance_eval(&block)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Window : base class for all widgets and frames
|
40
|
-
WxSugar.define_keyword_ctors('Window') do
|
41
|
-
wx_ctor_params :pos, :size, :style
|
42
|
-
wx_ctor_params :name => 'window'
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
### FRAMES
|
47
|
-
|
48
|
-
# wxTopLevelWindow ABSTRACT: Any top level window, dialog or frame
|
49
|
-
|
50
|
-
# Normal frame
|
51
|
-
WxSugar.define_keyword_ctors('Frame') do
|
52
|
-
wx_ctor_params :title => ''
|
53
|
-
wx_ctor_params :pos, :size, :style => Wx::DEFAULT_FRAME_STYLE
|
54
|
-
wx_ctor_params :name => 'frame'
|
55
|
-
end
|
56
|
-
|
57
|
-
# MDI child frame
|
58
|
-
WxSugar.define_keyword_ctors('MDIChildFrame') do
|
59
|
-
wx_ctor_params :title => ''
|
60
|
-
wx_ctor_params :pos, :size, :style => Wx::DEFAULT_FRAME_STYLE
|
61
|
-
wx_ctor_params :name => 'frame'
|
62
|
-
end
|
63
|
-
|
64
|
-
# MDI parent frame
|
65
|
-
WxSugar.define_keyword_ctors('MDIParentFrame') do
|
66
|
-
wx_ctor_params :title => ''
|
67
|
-
wx_ctor_params :pos, :size
|
68
|
-
wx_ctor_params :style => Wx::DEFAULT_FRAME_STYLE|Wx::VSCROLL|Wx::HSCROLL
|
69
|
-
wx_ctor_params :name => 'frame'
|
70
|
-
end
|
71
|
-
|
72
|
-
# wxMiniFrame A frame with a small title bar
|
73
|
-
WxSugar.define_keyword_ctors('MiniFrame') do
|
74
|
-
wx_ctor_params :title => ''
|
75
|
-
wx_ctor_params :pos, :size
|
76
|
-
wx_ctor_params :style => Wx::DEFAULT_FRAME_STYLE
|
77
|
-
wx_ctor_params :name => 'frame'
|
78
|
-
end
|
79
|
-
|
80
|
-
# wxSplashScreen Splash screen class
|
81
|
-
# FIXME - this probably won't work at present because the 'parent' arg
|
82
|
-
# comes in a funny place in this class's ctor
|
83
|
-
#
|
84
|
-
# WxSugar.define_keyword_ctors('SplashScreen') do
|
85
|
-
# wx_ctor_params :bitmap => Wx::NULL_BITMAP
|
86
|
-
# wx_ctor_params :splashstyle, :milliseconds, :id => 1
|
87
|
-
# wx_ctor_params :parent => nil
|
88
|
-
# wx_ctor_params :title => ''
|
89
|
-
# wx_ctor_params :pos, :size
|
90
|
-
# wx_ctor_params :style => Wx::SIMPLE_BORDER|Wx::FRAME_NO_TASKBAR|Wx::STAY_ON_TOP
|
91
|
-
# end
|
92
|
-
|
93
|
-
# wxPropertySheetDialog Property sheet dialog
|
94
|
-
# wxTipWindow Shows text in a small window
|
95
|
-
|
96
|
-
# wxWizard A wizard dialog
|
97
|
-
WxSugar.define_keyword_ctors('Wizard') do
|
98
|
-
wx_ctor_params :title => ''
|
99
|
-
wx_ctor_params :bitmap => Wx::NULL_BITMAP
|
100
|
-
wx_ctor_params :pos, :size
|
101
|
-
wx_ctor_params :style => Wx::DEFAULT_DIALOG_STYLE
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
# MISCELLANEOUS WINDOWS
|
106
|
-
|
107
|
-
# A window whose colour changes according to current user settings
|
108
|
-
WxSugar.define_keyword_ctors('Panel') do
|
109
|
-
wx_ctor_params :pos, :size, :style => Wx::TAB_TRAVERSAL
|
110
|
-
wx_ctor_params :name => 'panel'
|
111
|
-
end
|
112
|
-
|
113
|
-
# wxScrolledWindow Window with automatically managed scrollbars
|
114
|
-
WxSugar.define_keyword_ctors('ScrolledWindow') do
|
115
|
-
wx_ctor_params :pos, :size, :style => Wx::VSCROLL|Wx::HSCROLL
|
116
|
-
wx_ctor_params :name => 'scrolledWindow'
|
117
|
-
wx_ctor_flags :h_scroll => Wx::HSCROLL,
|
118
|
-
:v_scroll => Wx::VSCROLL
|
119
|
-
end
|
120
|
-
|
121
|
-
# wxGrid A grid (table) window
|
122
|
-
WxSugar.define_keyword_ctors('Grid') do
|
123
|
-
wx_ctor_params :pos, :size, :style => Wx::WANTS_CHARS
|
124
|
-
wx_ctor_params :name => 'grid'
|
125
|
-
end
|
126
|
-
|
127
|
-
# Window which can be split vertically or horizontally
|
128
|
-
WxSugar.define_keyword_ctors('SplitterWindow') do
|
129
|
-
wx_ctor_params :pos, :size, :style => Wx::SP_3D
|
130
|
-
wx_ctor_params :name => 'splitterWindow'
|
131
|
-
end
|
132
|
-
|
133
|
-
# Implements the status bar on a frame
|
134
|
-
WxSugar.define_keyword_ctors('StatusBar') do
|
135
|
-
wx_ctor_params :style => Wx::ST_SIZEGRIP
|
136
|
-
wx_ctor_params :name => 'statusBar'
|
137
|
-
end
|
138
|
-
|
139
|
-
# Toolbar class
|
140
|
-
WxSugar.define_keyword_ctors('ToolBar') do
|
141
|
-
wx_ctor_params :pos, :size, :style => Wx::TB_HORIZONTAL|Wx::NO_BORDER
|
142
|
-
wx_ctor_params :name => 'toolBar' # not as documented in Wx 2.6.3
|
143
|
-
end
|
144
|
-
|
145
|
-
# Notebook class
|
146
|
-
WxSugar.define_keyword_ctors('Notebook') do
|
147
|
-
wx_ctor_params :pos, :size, :style, :name => 'noteBook'
|
148
|
-
end
|
149
|
-
|
150
|
-
# Similar to notebook but using list control - undocumented
|
151
|
-
WxSugar.define_keyword_ctors('Listbook') do
|
152
|
-
wx_ctor_params :pos, :size, :style, :name => 'listBook'
|
153
|
-
end
|
154
|
-
|
155
|
-
# Similar to notebook but using choice control
|
156
|
-
WxSugar.define_keyword_ctors('Choicebook') do
|
157
|
-
wx_ctor_params :pos, :size, :style, :name => 'choiceBook'
|
158
|
-
end
|
159
|
-
|
160
|
-
# wxSashWindow: Window with four optional sashes that can be dragged
|
161
|
-
WxSugar.define_keyword_ctors('SashWindow') do
|
162
|
-
wx_ctor_params :pos, :size
|
163
|
-
wx_ctor_params :style => Wx::CLIP_CHILDREN|Wx::SW_3D
|
164
|
-
wx_ctor_params :name => 'sashWindow'
|
165
|
-
end
|
166
|
-
|
167
|
-
# wxSashLayoutWindow: Window that can be involved in an IDE-like layout
|
168
|
-
# arrangement
|
169
|
-
WxSugar.define_keyword_ctors('SashLayoutWindow') do
|
170
|
-
wx_ctor_params :pos, :size
|
171
|
-
wx_ctor_params :style => Wx::CLIP_CHILDREN|Wx::SW_3D
|
172
|
-
wx_ctor_params :name => 'layoutWindow'
|
173
|
-
end
|
174
|
-
|
175
|
-
# wxVScrolledWindow: As wxScrolledWindow but supports lines of variable height
|
176
|
-
|
177
|
-
# wxWizardPage: A base class for the page in wizard dialog.
|
178
|
-
WxSugar.define_keyword_ctors('WizardPage') do
|
179
|
-
wx_ctor_params :bitmap => Wx::NULL_BITMAP
|
180
|
-
end
|
181
|
-
|
182
|
-
# wxWizardPageSimple: A page in wizard dialog.
|
183
|
-
WxSugar.define_keyword_ctors('WizardPageSimple') do
|
184
|
-
wx_ctor_params :prev, :next, :bitmap => Wx::NULL_BITMAP
|
185
|
-
end
|
186
|
-
|
187
|
-
### DIALOGS
|
188
|
-
# wxDialog Base class for common dialogs
|
189
|
-
WxSugar.define_keyword_ctors('Dialog') do
|
190
|
-
wx_ctor_params :title => ''
|
191
|
-
wx_ctor_params :pos, :size, :style => Wx::DEFAULT_DIALOG_STYLE
|
192
|
-
wx_ctor_params :name => 'dialogBox'
|
193
|
-
end
|
194
|
-
|
195
|
-
# wxColourDialog Colour chooser dialog
|
196
|
-
WxSugar.define_keyword_ctors('ColourDialog') do
|
197
|
-
wx_ctor_params :colour_data => nil
|
198
|
-
end
|
199
|
-
|
200
|
-
# wxDirDialog Directory selector dialog
|
201
|
-
WxSugar.define_keyword_ctors('DirDialog') do
|
202
|
-
wx_ctor_params :message => 'Choose a directory'
|
203
|
-
wx_ctor_params :default_path => ''
|
204
|
-
wx_ctor_params :style, :pos, :size, :name => 'wxDirCtrl'
|
205
|
-
end
|
206
|
-
|
207
|
-
# wxFileDialog File selector dialog
|
208
|
-
WxSugar.define_keyword_ctors('FileDialog') do
|
209
|
-
wx_ctor_params :message => 'Choose a file'
|
210
|
-
wx_ctor_params :default_dir => ''
|
211
|
-
wx_ctor_params :default_file => ''
|
212
|
-
wx_ctor_params :wildcard => '*.*'
|
213
|
-
wx_ctor_params :style, :pos
|
214
|
-
end
|
215
|
-
|
216
|
-
# wxFindReplaceDialog Text search/replace dialog
|
217
|
-
WxSugar.define_keyword_ctors('FindReplaceDialog') do
|
218
|
-
wx_ctor_params :find_replace_data => Wx::FindReplaceData.new()
|
219
|
-
wx_ctor_params :title => 'findReplaceDialog'
|
220
|
-
wx_ctor_params :style
|
221
|
-
end
|
222
|
-
|
223
|
-
# wxMultiChoiceDialog Dialog to get one or more selections from a list
|
224
|
-
# wxSingleChoiceDialog Dialog to get a single selection from a list and return the string
|
225
|
-
|
226
|
-
# Dialog to get a single line of text from the user
|
227
|
-
WxSugar.define_keyword_ctors('TextEntryDialog') do
|
228
|
-
wx_ctor_params :message => ''
|
229
|
-
wx_ctor_params :caption => 'Please enter text'
|
230
|
-
wx_ctor_params :default_value => ''
|
231
|
-
wx_ctor_params :style => Wx::OK|Wx::CANCEL|Wx::CENTRE
|
232
|
-
wx_ctor_params :pos
|
233
|
-
end
|
234
|
-
|
235
|
-
# wxPasswordEntryDialog Dialog to get a password from the user
|
236
|
-
# WxSugar.define_keyword_ctors('PasswordEntryDialog') do
|
237
|
-
# wx_ctor_params :message => ''
|
238
|
-
# wx_ctor_params :caption => 'Enter password'
|
239
|
-
# wx_ctor_params :default_value => ''
|
240
|
-
# wx_ctor_params :style => Wx::OK|Wx::CANCEL|Wx::CENTRE
|
241
|
-
# wx_ctor_params :pos
|
242
|
-
# end
|
243
|
-
|
244
|
-
# wxFontDialog Font chooser dialog
|
245
|
-
# wxPageSetupDialog Standard page setup dialog
|
246
|
-
WxSugar.define_keyword_ctors('PageSetupDialog') do
|
247
|
-
wx_ctor_params :data
|
248
|
-
end
|
249
|
-
|
250
|
-
# wxPrintDialog Standard print dialog
|
251
|
-
WxSugar.define_keyword_ctors('PrintDialog') do
|
252
|
-
wx_ctor_params :data
|
253
|
-
end
|
254
|
-
|
255
|
-
|
256
|
-
# Simple message box dialog
|
257
|
-
WxSugar.define_keyword_ctors('MessageDialog') do
|
258
|
-
wx_ctor_params :message => ''
|
259
|
-
wx_ctor_params :caption => 'Message box'
|
260
|
-
wx_ctor_params :style => Wx::OK|Wx::CANCEL
|
261
|
-
wx_ctor_params :pos
|
262
|
-
end
|
263
|
-
|
264
|
-
### CONTROLS
|
265
|
-
|
266
|
-
# Push button control, displaying text
|
267
|
-
WxSugar.define_keyword_ctors('Button') do
|
268
|
-
wx_ctor_params :label => ''
|
269
|
-
wx_ctor_params :pos, :size, :style
|
270
|
-
wx_ctor_params :validator, :name => 'button'
|
271
|
-
end
|
272
|
-
|
273
|
-
# Push button control, displaying a bitmap
|
274
|
-
WxSugar.define_keyword_ctors('BitmapButton') do
|
275
|
-
wx_ctor_params :bitmap, :pos, :size, :style => Wx::BU_AUTODRAW
|
276
|
-
wx_ctor_params :validator, :name => 'button'
|
277
|
-
end
|
278
|
-
|
279
|
-
# A button which stays pressed when clicked by user.
|
280
|
-
WxSugar.define_keyword_ctors('ToggleButton') do
|
281
|
-
wx_ctor_params :label, :pos, :size, :style
|
282
|
-
wx_ctor_params :validator, :name => 'checkBox'
|
283
|
-
end
|
284
|
-
|
285
|
-
# Control showing an entire calendar month
|
286
|
-
WxSugar.define_keyword_ctors('CalendarCtrl') do
|
287
|
-
wx_ctor_params :date => Time.now()
|
288
|
-
wx_ctor_params :pos, :size, :style => Wx::CAL_SHOW_HOLIDAYS
|
289
|
-
wx_ctor_params :name => 'calendar'
|
290
|
-
end
|
291
|
-
|
292
|
-
# Checkbox control
|
293
|
-
WxSugar.define_keyword_ctors('CheckBox') do
|
294
|
-
wx_ctor_params :label => ''
|
295
|
-
wx_ctor_params :pos, :size, :style
|
296
|
-
wx_ctor_params :validator, :name => 'checkBox'
|
297
|
-
end
|
298
|
-
|
299
|
-
# A listbox with a checkbox to the left of each item
|
300
|
-
WxSugar.define_keyword_ctors('CheckListBox') do
|
301
|
-
wx_ctor_params :pos, :size, :choices, :style
|
302
|
-
wx_ctor_params :validator, :name => 'listBox'
|
303
|
-
end
|
304
|
-
|
305
|
-
# wxChoice Choice control (a combobox without the editable area)
|
306
|
-
WxSugar.define_keyword_ctors('Choice') do
|
307
|
-
wx_ctor_params :pos, :size, :choices, :style
|
308
|
-
wx_ctor_params :validator, :name => 'choice'
|
309
|
-
end
|
310
|
-
|
311
|
-
# wxComboBox A choice with an editable area
|
312
|
-
WxSugar.define_keyword_ctors('ComboBox') do
|
313
|
-
wx_ctor_params :value => ''
|
314
|
-
wx_ctor_params :pos, :size, :choices => []
|
315
|
-
wx_ctor_params :style
|
316
|
-
wx_ctor_params :validator, :name => 'comboBox'
|
317
|
-
end
|
318
|
-
|
319
|
-
# wxDatePickerCtrl Small date picker control
|
320
|
-
|
321
|
-
# wxGauge A control to represent a varying quantity, such as time
|
322
|
-
# remaining
|
323
|
-
WxSugar.define_keyword_ctors('Gauge') do
|
324
|
-
wx_ctor_params :range, :pos, :size, :style => Wx::GA_HORIZONTAL
|
325
|
-
wx_ctor_params :validator, :name => 'gauge'
|
326
|
-
end
|
327
|
-
|
328
|
-
# wxGenericDirCtrl A control for displaying a directory tree
|
329
|
-
WxSugar.define_keyword_ctors('GenericDirCtrl') do
|
330
|
-
# TODO :dir => Wx::DIR_DIALOG_DEFAULT_FOLDER_STR
|
331
|
-
wx_ctor_params :dir => ''
|
332
|
-
wx_ctor_params :pos, :size,
|
333
|
-
:style => Wx::DIRCTRL_3D_INTERNAL|Wx::SUNKEN_BORDER
|
334
|
-
wx_ctor_params :filter => ''
|
335
|
-
wx_ctor_params :default_filter => 0
|
336
|
-
wx_ctor_params :name => 'genericDirCtrl'
|
337
|
-
end
|
338
|
-
|
339
|
-
|
340
|
-
# wxHtmlListBox A listbox showing HTML content
|
341
|
-
# wxListBox A list of strings for single or multiple selection
|
342
|
-
WxSugar.define_keyword_ctors('ListBox') do
|
343
|
-
wx_ctor_params :pos, :size, :choices => []
|
344
|
-
wx_ctor_params :style
|
345
|
-
wx_ctor_params :validator, :name => 'listBox'
|
346
|
-
end
|
347
|
-
|
348
|
-
# wxListCtrl A control for displaying lists of strings and/or icons, plus a multicolumn report view
|
349
|
-
WxSugar.define_keyword_ctors('ListCtrl') do
|
350
|
-
wx_ctor_params :pos, :size, :style => Wx::LC_ICON
|
351
|
-
wx_ctor_params :validator, :name => 'listCtrl'
|
352
|
-
end
|
353
|
-
|
354
|
-
# wxListView A simpler interface (facade for wxListCtrl in report mode
|
355
|
-
|
356
|
-
# wxTreeCtrl Tree (hierarchy) control
|
357
|
-
WxSugar.define_keyword_ctors('TreeCtrl') do
|
358
|
-
wx_ctor_params :pos, :size, :style => Wx::TR_HAS_BUTTONS
|
359
|
-
wx_ctor_params :validator, :name => 'treeCtrl'
|
360
|
-
end
|
361
|
-
|
362
|
-
# wxSpinCtrl A spin control - i.e. spin button and text control
|
363
|
-
WxSugar.define_keyword_ctors('SpinCtrl') do
|
364
|
-
wx_ctor_params :value => ''
|
365
|
-
wx_ctor_params :pos, :size, :style => Wx::SP_ARROW_KEYS
|
366
|
-
wx_ctor_params :min => 0
|
367
|
-
wx_ctor_params :max => 100
|
368
|
-
wx_ctor_params :initial => 0
|
369
|
-
wx_ctor_params :name => 'spinCtrl'
|
370
|
-
end
|
371
|
-
|
372
|
-
# One or more lines of non-editable text
|
373
|
-
WxSugar.define_keyword_ctors('StaticText') do
|
374
|
-
wx_ctor_params :label, :pos, :size, :style, :name => 'staticText'
|
375
|
-
end
|
376
|
-
|
377
|
-
WxSugar.define_keyword_ctors('StaticBox') do
|
378
|
-
wx_ctor_params :label, :pos, :size, :style, :name => 'staticBox'
|
379
|
-
end
|
380
|
-
|
381
|
-
WxSugar.define_keyword_ctors('StaticLine') do
|
382
|
-
wx_ctor_params :pos, :size, :style => Wx::LI_HORIZONTAL
|
383
|
-
wx_ctor_params :name => 'staticBox'
|
384
|
-
end
|
385
|
-
|
386
|
-
# wxStaticBitmap A control to display a bitmap
|
387
|
-
WxSugar.define_keyword_ctors('StaticBitmap') do
|
388
|
-
wx_ctor_params :label, :pos, :size, :style
|
389
|
-
end
|
390
|
-
|
391
|
-
|
392
|
-
# wxRadioBox A group of radio buttons
|
393
|
-
WxSugar.define_keyword_ctors('RadioBox') do
|
394
|
-
wx_ctor_params :label => ''
|
395
|
-
wx_ctor_params :pos, :size, :choices => []
|
396
|
-
wx_ctor_params :major_dimension => 0
|
397
|
-
wx_ctor_params :style => Wx::RA_SPECIFY_COLS
|
398
|
-
wx_ctor_params :validator, :name => 'radioBox'
|
399
|
-
end
|
400
|
-
|
401
|
-
# wxRadioButton: A round button used with others in a mutually exclusive way
|
402
|
-
WxSugar.define_keyword_ctors('RadioButton') do
|
403
|
-
wx_ctor_params :label => ''
|
404
|
-
wx_ctor_params :pos, :size, :style => 0
|
405
|
-
wx_ctor_params :validator, :name => 'radioButton'
|
406
|
-
end
|
407
|
-
|
408
|
-
# wxSlider A slider that can be dragged by the user
|
409
|
-
WxSugar.define_keyword_ctors('Slider') do
|
410
|
-
wx_ctor_params :value => 0
|
411
|
-
wx_ctor_params :min_value, :max_value
|
412
|
-
wx_ctor_params :pos, :size, :style => Wx::SL_HORIZONTAL
|
413
|
-
wx_ctor_params :validator, :name => 'slider'
|
414
|
-
end
|
415
|
-
|
416
|
-
# wxSpinButton - Has two small up and down (or left and right) arrow buttons
|
417
|
-
WxSugar.define_keyword_ctors('SpinButton') do
|
418
|
-
wx_ctor_params :pos, :size, :style => Wx::SP_HORIZONTAL
|
419
|
-
wx_ctor_params :name => 'spinButton'
|
420
|
-
end
|
421
|
-
|
422
|
-
# wxVListBox A listbox supporting variable height rows
|
423
|
-
|
424
|
-
# wxTextCtrl Single or multiline text editing control
|
425
|
-
WxSugar.define_keyword_ctors('TextCtrl') do
|
426
|
-
wx_ctor_params :value => ''
|
427
|
-
wx_ctor_params :pos, :size, :style
|
428
|
-
wx_ctor_params :validator, :name => 'textCtrl'
|
429
|
-
end
|
430
|
-
|
431
|
-
# wxHtmlWindow - Control for displaying HTML
|
432
|
-
WxSugar.define_keyword_ctors('HtmlWindow') do
|
433
|
-
wx_ctor_params :pos, :size, :style => Wx::HW_DEFAULT_STYLE
|
434
|
-
wx_ctor_params :name => 'htmlWindow'
|
435
|
-
end
|
436
|
-
|
437
|
-
# wxHyperTextCtrl - display a clickable URL
|
438
|
-
WxSugar.define_keyword_ctors('HyperlinkCtrl') do
|
439
|
-
wx_ctor_params :label => ''
|
440
|
-
wx_ctor_params :url => ''
|
441
|
-
wx_ctor_params :pos, :size, :style => 0
|
442
|
-
wx_ctor_params :name => 'hyperlink'
|
443
|
-
end
|
@@ -1,267 +0,0 @@
|
|
1
|
-
# = WxRuby Extensions - Keyword Constructors
|
2
|
-
#
|
3
|
-
# The *Keyword Constructors* extension allows the use of Ruby hash-style
|
4
|
-
# keyword arguments in constructors of common WxWidgets Windows, Frame,
|
5
|
-
# Dialog and Control classes.
|
6
|
-
#
|
7
|
-
# == Introduction
|
8
|
-
#
|
9
|
-
# Building a GUI in WxWidgets involves lots of calls to +new+, but
|
10
|
-
# these methods often have long parameter lists. Often the default
|
11
|
-
# values for many of these parameters are correct. For example, if
|
12
|
-
# you're using a sizer-based layout, you usually don't want to specify a
|
13
|
-
# size for widgets, but you still have to type
|
14
|
-
#
|
15
|
-
# Wx::TreeCtrl.new( parent, -1, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE,
|
16
|
-
# Wx::NO_BUTTONS )
|
17
|
-
#
|
18
|
-
# just to create a standard TreeCtrl with the 'no buttons' style. If you
|
19
|
-
# want to specify the 'NO BUTTONS' style, you can't avoid all the typing
|
20
|
-
# of DEFAULT_POSITION etc.
|
21
|
-
#
|
22
|
-
# == Basic Keyword Constructors
|
23
|
-
#
|
24
|
-
# With keyword_constructors, you could write the above as
|
25
|
-
#
|
26
|
-
# TreeCtrl.new(parent, :style => Wx::NO_BUTTONS)
|
27
|
-
#
|
28
|
-
# And it will assume you want the default id (-1), and the default size
|
29
|
-
# and position. If you want to specify an explicit size, you can do so:
|
30
|
-
#
|
31
|
-
# TreeCtrl.new(parent, :size => Wx::Size.new(100, 300))
|
32
|
-
#
|
33
|
-
# For brevity, this module also allows you to specify positions and
|
34
|
-
# sizes using a a two-element array:
|
35
|
-
#
|
36
|
-
# TreeCtrl.new(parent, :size => [100, 300])
|
37
|
-
#
|
38
|
-
# Similarly with position:
|
39
|
-
#
|
40
|
-
# TreeCtrl.new(parent, :pos => Wx::Point.new(5, 25))
|
41
|
-
#
|
42
|
-
# TreeCtrl.new(parent, :pos => [5, 25])
|
43
|
-
#
|
44
|
-
# You can have multiple keyword arguments:
|
45
|
-
#
|
46
|
-
# TreeCtrl.new(parent, :pos => [5, 25], :size => [100, 300] )
|
47
|
-
#
|
48
|
-
# == No ID required
|
49
|
-
#
|
50
|
-
# As with position and size, you usually don't want to deal with
|
51
|
-
# assigning unique ids to every widget and frame you create - it's a C++
|
52
|
-
# hangover that often seems clunky in Ruby. The *Event Connectors*
|
53
|
-
# extension allows you to set up event handling without having to use
|
54
|
-
# ids, and if no :id argument is supplied to a constructor, the default
|
55
|
-
# (-1) will be passed.
|
56
|
-
#
|
57
|
-
# There are occasions when a specific ID does need to be used - for
|
58
|
-
# example, to tell WxWidgets that a button is a 'stock' item, so that it
|
59
|
-
# can be displayed using platform-standard text and icon. To do this,
|
60
|
-
# simply pass an :id argument to the constructor - here, the system's
|
61
|
-
# standard 'preview' button
|
62
|
-
#
|
63
|
-
# Wx::Button.new(parent, :id => Wx::ID_PREVIEW)
|
64
|
-
#
|
65
|
-
# == Class-specific arguments
|
66
|
-
#
|
67
|
-
# The arguments :size, :pos and :style are common to many WxWidgets
|
68
|
-
# window classes. The +new+ methods of these classes also have
|
69
|
-
# parameters that are specific to those classes; for example, the text
|
70
|
-
# label on a button, or the initial value of a text control.
|
71
|
-
#
|
72
|
-
# Wx::Button.new(parent, :label => 'press me')
|
73
|
-
# Wx::TextCtrl.new(parent, :value => 'type some text here')
|
74
|
-
#
|
75
|
-
# The keyword names of these arguments can be found by looking at the
|
76
|
-
# WxRuby documentation, in the relevant class's +new+ method. You can
|
77
|
-
# also get a string description of the class's +new+ method parameters
|
78
|
-
# within Ruby by doing:
|
79
|
-
#
|
80
|
-
# puts Wx::TextCtrl.describe_constructor()
|
81
|
-
#
|
82
|
-
# This will print a list of the argument names expected by the class's
|
83
|
-
# +new+ method, and the correct type for them.
|
84
|
-
#
|
85
|
-
# == Mixing positional and keyword arguments
|
86
|
-
#
|
87
|
-
# To support existing code, and to avoid forcing the use of more verbose
|
88
|
-
# keyword-style arguments where they're not desired, you can mix
|
89
|
-
# positional and keyword arguments, omitting or including +id+s as
|
90
|
-
# desired.
|
91
|
-
#
|
92
|
-
# Wx::Button.new(parent, 'press me', :style => Wx::BU_RIGHT)
|
93
|
-
#
|
94
|
-
module WxSugar
|
95
|
-
module KeywordConstructor
|
96
|
-
module ClassMethods
|
97
|
-
# Shorthand constructors
|
98
|
-
TYPEMAP = {
|
99
|
-
Wx::Size => lambda { | x | Wx::Size === x ? x : Wx::Size.new(*x) },
|
100
|
-
Wx::Point => lambda { | x | Wx::Point === x ? x : Wx::Point.new(*x) }
|
101
|
-
}
|
102
|
-
|
103
|
-
# Common Wx constructor argument keywords, with their default values.
|
104
|
-
STANDARD_DEFAULTS = {
|
105
|
-
:id => -1,
|
106
|
-
:size => Wx::DEFAULT_SIZE,
|
107
|
-
:pos => Wx::DEFAULT_POSITION,
|
108
|
-
:style => 0,
|
109
|
-
:validator => Wx::DEFAULT_VALIDATOR,
|
110
|
-
:choices => [] # for Choice, ComboBox etc
|
111
|
-
}
|
112
|
-
|
113
|
-
# Provide convenient convertors for Wx::Size and Wx::Point to be
|
114
|
-
# specified as simple ruby array.
|
115
|
-
#
|
116
|
-
# instead of
|
117
|
-
# :size => Wx::Size.new(150, 225)
|
118
|
-
# just
|
119
|
-
# :size => [ 150, 225 ]
|
120
|
-
def map_type(in_obj, default)
|
121
|
-
if TYPEMAP.include?(default.class)
|
122
|
-
in_obj = TYPEMAP[default.class].call(in_obj)
|
123
|
-
end
|
124
|
-
in_obj
|
125
|
-
end
|
126
|
-
|
127
|
-
# A named parameter in a Wx constructor parameter list
|
128
|
-
Parameter = Struct.new( :name, :default )
|
129
|
-
|
130
|
-
attr_writer :param_spec
|
131
|
-
def param_spec
|
132
|
-
@param_spec ||= [ ]
|
133
|
-
end
|
134
|
-
|
135
|
-
attr_writer :param_flags
|
136
|
-
def param_flags
|
137
|
-
@param_flags ||= {}
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
# Adds a list of named parameters *params* to the parameter
|
142
|
-
# specification for this Wx class's constructor. Each parameter
|
143
|
-
# should be specified as a either a common known symbol, such as
|
144
|
-
# +:size+ or +:pos:+ or +:style:+ (corresponding to the common
|
145
|
-
# constructor arguments in WxWidgets API), or a single-key with the
|
146
|
-
# key the name of the argument, and the value a default value.
|
147
|
-
#
|
148
|
-
# Parameters should be specified in the order they occur in the Wx
|
149
|
-
# API constructor
|
150
|
-
def wx_ctor_params(*params)
|
151
|
-
self.param_spec += params.map do | param |
|
152
|
-
param.kind_of?(Hash) ? Parameter[*param.to_a.flatten] :
|
153
|
-
Parameter[param, STANDARD_DEFAULTS[param] ]
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
# Add a named style constructor flag.
|
158
|
-
def wx_ctor_flags(flags)
|
159
|
-
param_flags.update(flags)
|
160
|
-
end
|
161
|
-
|
162
|
-
def args_as_list(*mixed_args)
|
163
|
-
# get keyword arguments from mixed args if supplied, else empty
|
164
|
-
kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
|
165
|
-
out_args = []
|
166
|
-
param_spec.zip(mixed_args) do | param, arg |
|
167
|
-
if arg # use the supplied list arg
|
168
|
-
out_args << map_type(arg, param.default)
|
169
|
-
elsif kwa.key?(param.name) # use the keyword arg
|
170
|
-
out_args << map_type(kwa[param.name], param.default)
|
171
|
-
else # use the default argument
|
172
|
-
out_args << param.default
|
173
|
-
end
|
174
|
-
end
|
175
|
-
out_args
|
176
|
-
rescue
|
177
|
-
Kernel.raise ArgumentError,
|
178
|
-
"Bad arg composition of #{mixed_args.inspect}"
|
179
|
-
end
|
180
|
-
|
181
|
-
def args_as_hash(*mixed_args)
|
182
|
-
kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
|
183
|
-
param_spec.zip(mixed_args) do | param, arg |
|
184
|
-
kwa[param.name] = arg if arg
|
185
|
-
end
|
186
|
-
kwa
|
187
|
-
end
|
188
|
-
|
189
|
-
# Look through a set of keyword arguments +in_flags+ and return a
|
190
|
-
# style parameter based on the known style flags applicable to this
|
191
|
-
# widget type.
|
192
|
-
# TODO - not currently used
|
193
|
-
def style_constant(kw_args)
|
194
|
-
# get the default flag for this style parameter
|
195
|
-
base_style = kw_args[:style] ||
|
196
|
-
param_spec.find { | x | x.name == :style }.default
|
197
|
-
|
198
|
-
# go through each of the known style flags for this widget
|
199
|
-
param_flags.each do | sym, const |
|
200
|
-
next unless kw_args.key?(sym)
|
201
|
-
# add or delete flag, depending on whether true or false
|
202
|
-
kw_args[sym] ? base_style |= const : base_style &= ~const
|
203
|
-
end
|
204
|
-
base_style
|
205
|
-
end
|
206
|
-
|
207
|
-
def describe_constructor()
|
208
|
-
param_spec.inject("") do | desc, param |
|
209
|
-
desc << "#{param.name} (#{param.default.class.name})\n"
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def self.included(klass)
|
215
|
-
klass.extend ClassMethods
|
216
|
-
|
217
|
-
klass.module_eval do
|
218
|
-
alias :pre_wx_kwctor_init :initialize
|
219
|
-
|
220
|
-
def initialize(parent, *mixed_args)
|
221
|
-
if parent and not parent.is_a?(Wx::Window)
|
222
|
-
Kernel.raise ArgumentError,
|
223
|
-
"Parent must be a Wx::Window, not #{parent.inspect}"
|
224
|
-
end
|
225
|
-
|
226
|
-
# Allow classes to ignore :id argument in positional args
|
227
|
-
unless self.class < Wx::Dialog
|
228
|
-
if not mixed_args[0].kind_of?(Fixnum)
|
229
|
-
mixed_args.unshift(-1)
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
real_args = [ parent ] + self.class.args_as_list(*mixed_args)
|
234
|
-
|
235
|
-
|
236
|
-
# deal with style flags
|
237
|
-
# if mixed_args.last.kind_of?(Hash)
|
238
|
-
# flags = self.class.style_constant(mixed_args.last)
|
239
|
-
# style_param = self.class.param_spec.find { | param | param.name == :style }
|
240
|
-
# real_args[ self.class.param_spec.index(style_param) + 1 ] = flags
|
241
|
-
# end
|
242
|
-
|
243
|
-
begin
|
244
|
-
pre_wx_kwctor_init(*real_args)
|
245
|
-
rescue
|
246
|
-
Kernel.raise ArgumentError, "Error initializing #{self.inspect} \n" +
|
247
|
-
"Sent parameters: #{real_args.inspect}\n" +
|
248
|
-
"correct parameters are:\n" +
|
249
|
-
self.class.describe_constructor()
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
|
255
|
-
# Any class inheriting from a class including this module must have
|
256
|
-
# its own copy of the param_spec
|
257
|
-
def klass.inherited(sub_klass)
|
258
|
-
sub_klass.instance_variable_set(:@param_spec,
|
259
|
-
self.instance_variable_get(:@param_spec) )
|
260
|
-
sub_klass.instance_variable_set(:@param_flags,
|
261
|
-
self.instance_variable_get(:@param_flags) )
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
require 'wx_sugar/keyword_classes'
|
@@ -1,40 +0,0 @@
|
|
1
|
-
class Wx::TreeCtrl
|
2
|
-
# Recurses over the tree item +start_item+ and its descendants,
|
3
|
-
# yielding each item in the tree in turn into the block. If
|
4
|
-
# +start_item+ is not specified, this method will recurse over every
|
5
|
-
# item within the tree, starting with the root item.
|
6
|
-
#
|
7
|
-
# In its simplest form, the method accepts a block with one parameter,
|
8
|
-
# which will be the TreeItemId of the item. This is an opaque integer
|
9
|
-
# value which uniquely identifies the tree item. It can be used as an
|
10
|
-
# argument to many other methods within TreeCtrl (for example,
|
11
|
-
# get_item_text).
|
12
|
-
#
|
13
|
-
# The block passed to +traverse+ may optionally receive two additional
|
14
|
-
# parameters, +text+ and +data+. If these are specified, they will be
|
15
|
-
# filled with the text label for the item and any ruby item data
|
16
|
-
# associated with the item, respectively.
|
17
|
-
def traverse(start_item = self.get_root_item, &block)
|
18
|
-
case block.arity
|
19
|
-
when 1
|
20
|
-
block.call(start_item)
|
21
|
-
when 2
|
22
|
-
block.call(start_item,
|
23
|
-
get_item_text(start_item))
|
24
|
-
when 3
|
25
|
-
block.call(start_item,
|
26
|
-
get_item_text(start_item),
|
27
|
-
get_item_data(start_item))
|
28
|
-
else
|
29
|
-
raise ArgumentError, "Invalid number of block parameters"
|
30
|
-
end
|
31
|
-
|
32
|
-
if item_has_children(start_item)
|
33
|
-
child, cookie = get_first_child(start_item)
|
34
|
-
while child.nonzero?
|
35
|
-
traverse(child, &block)
|
36
|
-
child = get_next_sibling(child)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|