wx_sugar 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wx_sugar/all.rb +0 -68
- data/lib/wx_sugar/keyword_classes.rb +29 -23
- data/lib/wx_sugar/keyword_constructors.rb +1 -1
- data/lib/wx_sugar/layout.rb +20 -9
- data/lib/wx_sugar/version.rb +1 -1
- data/lib/wx_sugar/wx_classes/position.rb +7 -0
- data/lib/wx_sugar/wx_classes/size.rb +7 -0
- data/lib/wx_sugar/wx_classes/treectrl.rb +19 -0
- data/lib/wx_sugar/wx_classes/window.rb +21 -0
- data/lib/wx_sugar.rb +65 -0
- metadata +9 -3
data/lib/wx_sugar/all.rb
CHANGED
@@ -1,71 +1,3 @@
|
|
1
|
-
# = WxSugar
|
2
|
-
#
|
3
|
-
# WxSugar is a set of additions to the WxRuby API, written in pure
|
4
|
-
# ruby. They're intended to:
|
5
|
-
#
|
6
|
-
# * Make some tricky WxWidgets things easier and more consistent
|
7
|
-
# * Reduce repetitiveness and redundancy for common tasks
|
8
|
-
# * Make code more expressive
|
9
|
-
# * Make code more idiomatically Rubyish
|
10
|
-
#
|
11
|
-
# Not everyone will like all the extensions to WxRuby here. So the
|
12
|
-
# Sugar modules:
|
13
|
-
#
|
14
|
-
# * Can generally be used separately, without depending on each other
|
15
|
-
# * Supplement rather than replace the underlying 'raw' API
|
16
|
-
#
|
17
|
-
# == Using WxSugar
|
18
|
-
#
|
19
|
-
# The extensions can currently be used with WxRuby2 or the old WxRuby
|
20
|
-
# (0.6.0). WxRuby2 is strongly recommended, and support for the old
|
21
|
-
# series may be dropped in the future.
|
22
|
-
#
|
23
|
-
# The simplest way to use WxSugar is to load all the behaviours. You
|
24
|
-
# should load the wx library first:
|
25
|
-
#
|
26
|
-
# require 'wx'
|
27
|
-
# # OR ... old non-SWIG beta veresion
|
28
|
-
# require 'wxruby'
|
29
|
-
#
|
30
|
-
# require 'wx_sugar/all'
|
31
|
-
# ...
|
32
|
-
#
|
33
|
-
# If you only want to load specific WxSugar behaviours, just +require+
|
34
|
-
# the desired extensions only
|
35
|
-
#
|
36
|
-
# require 'wx_sugar/keyword_constructors'
|
37
|
-
# require 'wx_sugar/acccessors'
|
38
|
-
#
|
39
|
-
# == Overview of extensions
|
40
|
-
#
|
41
|
-
# The following are the WxSugar behaviours that are available. In
|
42
|
-
# general you require one of these extensions, it modifies the behaviour
|
43
|
-
# of all relevant Wx classes, and affects all new instances.
|
44
|
-
#
|
45
|
-
# [accessors]
|
46
|
-
# Provide ruby-style getters, setters and question-mark methods
|
47
|
-
# [delayed_constructors]
|
48
|
-
# Required by +layout+, of limited independent interest
|
49
|
-
# [event_connector]
|
50
|
-
# Neater syntax for connecting event listeners
|
51
|
-
# [keyword_constructors]
|
52
|
-
# Use keyword-style hash arguments to construct widgets
|
53
|
-
# [layout]
|
54
|
-
# Easy interface to using WxWidgets Sizers to arrange controls
|
55
|
-
# [menu]
|
56
|
-
# Create and update menus without a mess of system ids
|
57
|
-
# [wx_classes]
|
58
|
-
# Useful ruby methods added to individual Wx classes.
|
59
|
-
#
|
60
|
-
# === Deprecated extensions
|
61
|
-
#
|
62
|
-
# This module is deprecated and will soon be removed.
|
63
|
-
#
|
64
|
-
# [itemdata.rb]
|
65
|
-
# Linking ruby objects with wx controls; use the
|
66
|
-
# get/set_item_data methods in core wxruby2 instead.
|
67
|
-
|
68
|
-
|
69
1
|
%w[ accessors delayed_constructors event_connector
|
70
2
|
keyword_constructors layout menu wx_classes ].each do | ext_feature |
|
71
3
|
require 'wx_sugar/' + ext_feature
|
@@ -5,13 +5,6 @@
|
|
5
5
|
# and is no use on its own - except if you are looking for a bug or want
|
6
6
|
# to add a missing class.
|
7
7
|
|
8
|
-
# This is a dummy, this variable is not loaded until Wx init
|
9
|
-
# hush warnings if it has already been loaded when we get here
|
10
|
-
v = $VERBOSE
|
11
|
-
$VERBOSE = nil
|
12
|
-
Wx::NULL_BITMAP = nil
|
13
|
-
$VERBOSE = v
|
14
|
-
|
15
8
|
module WxSugar
|
16
9
|
@defined_classes = {}
|
17
10
|
|
@@ -85,6 +78,18 @@ WxSugar.define_keyword_ctors('MiniFrame') do
|
|
85
78
|
end
|
86
79
|
|
87
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
|
+
|
88
93
|
# wxPropertySheetDialog Property sheet dialog
|
89
94
|
# wxTipWindow Shows text in a small window
|
90
95
|
|
@@ -262,18 +267,19 @@ end
|
|
262
267
|
WxSugar.define_keyword_ctors('Button') do
|
263
268
|
wx_ctor_params :label => ''
|
264
269
|
wx_ctor_params :pos, :size, :style
|
265
|
-
|
270
|
+
wx_ctor_params :validator, :name => 'button'
|
266
271
|
end
|
267
272
|
|
268
273
|
# Push button control, displaying a bitmap
|
269
274
|
WxSugar.define_keyword_ctors('BitmapButton') do
|
270
275
|
wx_ctor_params :bitmap, :pos, :size, :style => Wx::BU_AUTODRAW
|
276
|
+
wx_ctor_params :validator, :name => 'button'
|
271
277
|
end
|
272
278
|
|
273
279
|
# A button which stays pressed when clicked by user.
|
274
280
|
WxSugar.define_keyword_ctors('ToggleButton') do
|
275
281
|
wx_ctor_params :label, :pos, :size, :style
|
276
|
-
|
282
|
+
wx_ctor_params :validator, :name => 'checkBox'
|
277
283
|
end
|
278
284
|
|
279
285
|
# Control showing an entire calendar month
|
@@ -287,27 +293,27 @@ end
|
|
287
293
|
WxSugar.define_keyword_ctors('CheckBox') do
|
288
294
|
wx_ctor_params :label => ''
|
289
295
|
wx_ctor_params :pos, :size, :style
|
290
|
-
|
296
|
+
wx_ctor_params :validator, :name => 'checkBox'
|
291
297
|
end
|
292
298
|
|
293
299
|
# A listbox with a checkbox to the left of each item
|
294
300
|
WxSugar.define_keyword_ctors('CheckListBox') do
|
295
301
|
wx_ctor_params :pos, :size, :choices, :style
|
296
|
-
|
302
|
+
wx_ctor_params :validator, :name => 'listBox'
|
297
303
|
end
|
298
304
|
|
299
305
|
# wxChoice Choice control (a combobox without the editable area)
|
300
306
|
WxSugar.define_keyword_ctors('Choice') do
|
301
307
|
wx_ctor_params :pos, :size, :choices, :style
|
302
|
-
|
308
|
+
wx_ctor_params :validator, :name => 'choice'
|
303
309
|
end
|
304
310
|
|
305
311
|
# wxComboBox A choice with an editable area
|
306
312
|
WxSugar.define_keyword_ctors('ComboBox') do
|
307
313
|
wx_ctor_params :value => ''
|
308
314
|
wx_ctor_params :pos, :size, :choices => []
|
309
|
-
wx_ctor_params :style
|
310
|
-
|
315
|
+
wx_ctor_params :style
|
316
|
+
wx_ctor_params :validator, :name => 'comboBox'
|
311
317
|
end
|
312
318
|
|
313
319
|
# wxDatePickerCtrl Small date picker control
|
@@ -316,7 +322,7 @@ end
|
|
316
322
|
# remaining
|
317
323
|
WxSugar.define_keyword_ctors('Gauge') do
|
318
324
|
wx_ctor_params :range, :pos, :size, :style => Wx::GA_HORIZONTAL
|
319
|
-
|
325
|
+
wx_ctor_params :validator, :name
|
320
326
|
end
|
321
327
|
|
322
328
|
# wxGenericDirCtrl A control for displaying a directory tree
|
@@ -336,12 +342,13 @@ end
|
|
336
342
|
WxSugar.define_keyword_ctors('ListBox') do
|
337
343
|
wx_ctor_params :pos, :size, :choices => []
|
338
344
|
wx_ctor_params :style
|
345
|
+
wx_ctor_params :validator, :name => 'listBox'
|
339
346
|
end
|
340
347
|
|
341
348
|
# wxListCtrl A control for displaying lists of strings and/or icons, plus a multicolumn report view
|
342
349
|
WxSugar.define_keyword_ctors('ListCtrl') do
|
343
350
|
wx_ctor_params :pos, :size, :style => Wx::LC_ICON
|
344
|
-
|
351
|
+
wx_ctor_params :validator, :name => 'listCtrl'
|
345
352
|
end
|
346
353
|
|
347
354
|
# wxListView A simpler interface (facade for wxListCtrl in report mode
|
@@ -349,7 +356,7 @@ end
|
|
349
356
|
# wxTreeCtrl Tree (hierarchy) control
|
350
357
|
WxSugar.define_keyword_ctors('TreeCtrl') do
|
351
358
|
wx_ctor_params :pos, :size, :style => Wx::TR_HAS_BUTTONS
|
352
|
-
|
359
|
+
wx_ctor_params :validator, :name => 'treeCtrl'
|
353
360
|
end
|
354
361
|
|
355
362
|
# wxSpinCtrl A spin control - i.e. spin button and text control
|
@@ -388,14 +395,14 @@ WxSugar.define_keyword_ctors('RadioBox') do
|
|
388
395
|
wx_ctor_params :pos, :size, :choices => []
|
389
396
|
wx_ctor_params :major_dimension => 0
|
390
397
|
wx_ctor_params :style => Wx::RA_SPECIFY_COLS
|
391
|
-
|
398
|
+
wx_ctor_params :validator, :name => 'radioBox'
|
392
399
|
end
|
393
400
|
|
394
|
-
# wxRadioButton
|
401
|
+
# wxRadioButton: A round button used with others in a mutually exclusive way
|
395
402
|
WxSugar.define_keyword_ctors('RadioButton') do
|
396
403
|
wx_ctor_params :label => ''
|
397
404
|
wx_ctor_params :pos, :size, :style => 0
|
398
|
-
|
405
|
+
wx_ctor_params :validator, :name => 'radioButton'
|
399
406
|
end
|
400
407
|
|
401
408
|
# wxSlider A slider that can be dragged by the user
|
@@ -403,10 +410,9 @@ WxSugar.define_keyword_ctors('Slider') do
|
|
403
410
|
wx_ctor_params :value => 0
|
404
411
|
wx_ctor_params :min_value, :max_value
|
405
412
|
wx_ctor_params :pos, :size, :style => Wx::SL_HORIZONTAL
|
406
|
-
|
413
|
+
wx_ctor_params :validator, :name => 'slider'
|
407
414
|
end
|
408
415
|
|
409
|
-
|
410
416
|
# wxSpinButton - Has two small up and down (or left and right) arrow buttons
|
411
417
|
WxSugar.define_keyword_ctors('SpinButton') do
|
412
418
|
wx_ctor_params :pos, :size, :style => Wx::SP_HORIZONTAL
|
@@ -419,7 +425,7 @@ end
|
|
419
425
|
WxSugar.define_keyword_ctors('TextCtrl') do
|
420
426
|
wx_ctor_params :value => ''
|
421
427
|
wx_ctor_params :pos, :size, :style
|
422
|
-
|
428
|
+
wx_ctor_params :validator, :name => 'textCtrl'
|
423
429
|
end
|
424
430
|
|
425
431
|
# wxHtmlWindow - Control for displaying HTML
|
@@ -106,7 +106,7 @@ module KeywordConstructor
|
|
106
106
|
:size => Wx::DEFAULT_SIZE,
|
107
107
|
:pos => Wx::DEFAULT_POSITION,
|
108
108
|
:style => 0,
|
109
|
-
:validator =>
|
109
|
+
:validator => Wx::DEFAULT_VALIDATOR,
|
110
110
|
:choices => [] # for Choice, ComboBox etc
|
111
111
|
}
|
112
112
|
|
data/lib/wx_sugar/layout.rb
CHANGED
@@ -67,7 +67,9 @@ module Arranger
|
|
67
67
|
elsif sizer = self.get_sizer
|
68
68
|
return sizer
|
69
69
|
else
|
70
|
-
|
70
|
+
@current_sizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
71
|
+
self.set_sizer(@current_sizer)
|
72
|
+
@current_sizer
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
@@ -93,7 +95,7 @@ module Arranger
|
|
93
95
|
end
|
94
96
|
|
95
97
|
superior_sizer, @current_sizer = @current_sizer, a_sizer
|
96
|
-
yield(
|
98
|
+
yield(a_sizer)
|
97
99
|
@current_sizer = superior_sizer
|
98
100
|
proportion = layout[:proportion] || 0
|
99
101
|
this_padding = padding || 0
|
@@ -106,9 +108,12 @@ module Arranger
|
|
106
108
|
end
|
107
109
|
# set as main sizer
|
108
110
|
else
|
111
|
+
if @current_sizer
|
112
|
+
warn "Sizer already specified, redefining layout for #{self}"
|
113
|
+
end
|
109
114
|
@padding = layout[:padding] if layout[:padding]
|
110
115
|
@current_sizer = a_sizer
|
111
|
-
yield(
|
116
|
+
yield(a_sizer) if block_given?
|
112
117
|
self.set_sizer(a_sizer)
|
113
118
|
end
|
114
119
|
end
|
@@ -123,7 +128,7 @@ module Arranger
|
|
123
128
|
child = build_child(child)
|
124
129
|
layout = hints_to_constants(layout_hints)
|
125
130
|
proportion = layout_hints[:proportion] || 0
|
126
|
-
siz = self.current_sizer
|
131
|
+
siz = self.current_sizer
|
127
132
|
padding = layout_hints[:padding] || @padding
|
128
133
|
siz.add(child, proportion, layout, padding || 0)
|
129
134
|
siz.layout()
|
@@ -205,11 +210,17 @@ module Arranger
|
|
205
210
|
end
|
206
211
|
end
|
207
212
|
|
208
|
-
|
209
213
|
# Convert a hash of layout hints to WxWidgets Sizer constants
|
214
|
+
|
210
215
|
def hints_to_constants(layout_hints)
|
211
|
-
|
212
|
-
|
216
|
+
if layout_hints[:pad]
|
217
|
+
layout = layout_hints[:pad].split(',').inject(0) do | l, edge |
|
218
|
+
l | Wx::const_get(edge.upcase)
|
219
|
+
end
|
220
|
+
else
|
221
|
+
layout = Wx::ALL
|
222
|
+
end
|
223
|
+
|
213
224
|
if layout_hints[:minsize]
|
214
225
|
layout = layout | Wx::ADJUST_MINSIZE|Wx::EXPAND
|
215
226
|
end
|
@@ -218,9 +229,9 @@ module Arranger
|
|
218
229
|
end
|
219
230
|
|
220
231
|
|
221
|
-
if layout_hints[:align]
|
232
|
+
if align = layout_hints[:align]
|
222
233
|
begin
|
223
|
-
align_const = Wx::const_get('ALIGN_' <<
|
234
|
+
align_const = Wx::const_get('ALIGN_' << align.to_s.upcase)
|
224
235
|
layout = layout | align_const
|
225
236
|
rescue NameError
|
226
237
|
Kernel.raise ArgumentError,
|
data/lib/wx_sugar/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
class Wx::TreeCtrl
|
2
|
+
# Recurses over the tree item +start_item+ and its descendants,
|
3
|
+
# yielding each Wx::TreeItemId in turn into the passed block. This
|
4
|
+
# TreeItemId can be used as an argument to many other methods within
|
5
|
+
# TreeCtrl (for example, get_item_text).
|
6
|
+
#
|
7
|
+
# If +start_item+ is not specified, this method will recurse over
|
8
|
+
# every item within the tree, starting with the root item.
|
9
|
+
def traverse(start_item = self.get_root_item, &block)
|
10
|
+
block.call(start_item)
|
11
|
+
if has_children(start_item)
|
12
|
+
child, cookie = get_first_child(start_item)
|
13
|
+
while child.nonzero?
|
14
|
+
traverse(child, &block)
|
15
|
+
child = get_next_sibling(child)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,5 +1,26 @@
|
|
1
1
|
# extensions to Wx::Window
|
2
2
|
class Wx::Window
|
3
|
+
# Returns an array containing this window and all windows descended
|
4
|
+
# from it.
|
5
|
+
def get_descendants
|
6
|
+
get_children.inject([ self ]) do | desc, child |
|
7
|
+
desc + child.get_descendants
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Passed a block, returns the first window within self's window
|
12
|
+
# hierarchy for which the block evaluates to true. A class name may
|
13
|
+
# optionally be passed to restrict the search to windows of that class
|
14
|
+
# (or its subclasses) only - this can be useful if the search
|
15
|
+
# specification calls methods that are only defined for certain
|
16
|
+
# classes.
|
17
|
+
#
|
18
|
+
# # Example - find a StaticText with a label matching /foo/
|
19
|
+
# a_frame.find_window(Wx::StaticText) { | tx | tx.label =~ /foo/ }
|
20
|
+
def find_window(a_class = Wx::Window, &block)
|
21
|
+
descendants.grep(a_class).detect(&block)
|
22
|
+
end
|
23
|
+
|
3
24
|
# Returns the window's current size as a two element array
|
4
25
|
def get_size_xy
|
5
26
|
size = get_size
|
data/lib/wx_sugar.rb
CHANGED
@@ -1 +1,66 @@
|
|
1
|
+
# = WxSugar
|
2
|
+
#
|
3
|
+
# WxSugar is a set of additions to the WxRuby API, written in pure
|
4
|
+
# ruby. They're intended to:
|
5
|
+
#
|
6
|
+
# * Make some tricky WxWidgets things easier and more consistent
|
7
|
+
# * Reduce repetitiveness and redundancy for common tasks
|
8
|
+
# * Make code more expressive
|
9
|
+
# * Make code more idiomatically Rubyish
|
10
|
+
#
|
11
|
+
# Not everyone will like all the extensions to WxRuby here. So the
|
12
|
+
# Sugar modules:
|
13
|
+
#
|
14
|
+
# * Can generally be used separately, without depending on each other
|
15
|
+
# * Supplement rather than replace the underlying 'raw' API
|
16
|
+
#
|
17
|
+
# == Using WxSugar
|
18
|
+
#
|
19
|
+
# As of version 0.1.14, the WxSugar extensions require the latest
|
20
|
+
# version of WxRuby2, preview 0.0.39. Support for the old series of
|
21
|
+
# WxRuby (version 0.6.0) has now been dropped.
|
22
|
+
#
|
23
|
+
# The simplest way to use WxSugar is to load all the behaviours. You
|
24
|
+
# should load the wx library first:
|
25
|
+
#
|
26
|
+
# require 'wx'
|
27
|
+
# require 'wx_sugar'
|
28
|
+
# ...
|
29
|
+
#
|
30
|
+
# If you only want to load specific WxSugar behaviours, just +require+
|
31
|
+
# the desired extensions only
|
32
|
+
#
|
33
|
+
# require 'wx_sugar/keyword_constructors'
|
34
|
+
# require 'wx_sugar/acccessors'
|
35
|
+
#
|
36
|
+
# == Overview of extensions
|
37
|
+
#
|
38
|
+
# The following are the WxSugar behaviours that are available. In
|
39
|
+
# general you require one of these extensions, it modifies the behaviour
|
40
|
+
# of all relevant Wx classes, and affects all new instances.
|
41
|
+
#
|
42
|
+
# [accessors]
|
43
|
+
# Provide ruby-style getters, setters and question-mark methods
|
44
|
+
# [delayed_constructors]
|
45
|
+
# Required by +layout+, of limited independent interest
|
46
|
+
# [event_connector]
|
47
|
+
# Neater syntax for connecting event listeners
|
48
|
+
# [keyword_constructors]
|
49
|
+
# Use keyword-style hash arguments to construct widgets
|
50
|
+
# [layout]
|
51
|
+
# Easy interface to using WxWidgets Sizers to arrange controls
|
52
|
+
# [menu]
|
53
|
+
# Create and update menus without a mess of system ids
|
54
|
+
# [wx_classes]
|
55
|
+
# Useful ruby methods added to individual Wx classes.
|
56
|
+
#
|
57
|
+
# === Deprecated extensions
|
58
|
+
#
|
59
|
+
# This module is deprecated and will soon be removed.
|
60
|
+
#
|
61
|
+
# [itemdata.rb]
|
62
|
+
# Linking ruby objects with wx controls; use the
|
63
|
+
# get/set_item_data methods in core wxruby2 instead.
|
64
|
+
|
65
|
+
|
1
66
|
require 'wx_sugar/all'
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
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:
|
6
|
+
version: 0.1.14
|
7
|
+
date: 2007-03-22 00:00:00 +00:00
|
8
8
|
summary: Syntax extensions for WxRuby.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -24,6 +24,9 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
24
24
|
version: 1.8.1
|
25
25
|
version:
|
26
26
|
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
post_install_message:
|
27
30
|
authors:
|
28
31
|
- Alex Fenton
|
29
32
|
files:
|
@@ -43,6 +46,9 @@ files:
|
|
43
46
|
- lib/wx_sugar/wx_classes
|
44
47
|
- lib/wx_sugar/wx_classes.rb
|
45
48
|
- lib/wx_sugar/wx_classes/colour.rb
|
49
|
+
- lib/wx_sugar/wx_classes/position.rb
|
50
|
+
- lib/wx_sugar/wx_classes/size.rb
|
51
|
+
- lib/wx_sugar/wx_classes/treectrl.rb
|
46
52
|
- lib/wx_sugar/wx_classes/window.rb
|
47
53
|
- samples/sugar-sample.rb
|
48
54
|
- LICENCE
|