wxruby3 1.5.3 → 1.5.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ea544cb7fe32dce3bbef74d16dc56ebe6fe8cb0ff381cbeee3a5ee9a37471d5
4
- data.tar.gz: 2afddf4097dffcf4ee6bb4ed649d86165dd5e1decea9f330c27792e95eb2447d
3
+ metadata.gz: 365785c8c4a67019170ce82f52b08eef0c29c1eeaf83f9868edaf5883e5ca2a2
4
+ data.tar.gz: 48ea3a4a58c2f3f4cb2abab5a935a4b62b933f9413d007dc154aa92e038dc0ac
5
5
  SHA512:
6
- metadata.gz: 03f848a8b259e10f1a7dfe74505361825e2819cbc8fd2f20d5ca1f1990afa9d9fea4abecaa5bbdda4129864c4f24aa22fb7b1508fc2632839f0d7ffa89919cba
7
- data.tar.gz: e187a4d0fd6c3f4985afae321228e6956e56df349001e2f6478ea458bafaf4bd5e8210d94de963270820eaedc7ff8de9f3b60684cc493415ce5ad67d4741a228
6
+ metadata.gz: b5921c7a072a6d44baa1afeea45718abf9e632e7b23ed5a24a431589dcc889bda5bafeb3b78d09cb9aebdfc07e752796849a9dbee95259abc7260a2d09974f85
7
+ data.tar.gz: ab2d3f5579f563a37f7eb61256c4ad95d1498f4b6adf23cb732c6675826c2869d351f049dc91d544427ce0b218e7b1327b8a179ab1dde8c4ed5b1025ce80b206
@@ -55,7 +55,7 @@ class Wx::Dialog
55
55
  functor_nm = scope.pop
56
56
  code = <<~__CODE
57
57
  def #{functor_nm}(*args, **kwargs, &block)
58
- dlg = #{klass.name}.new(*args, **kwargs)
58
+ dlg = kwargs.empty? ? #{klass.name}.new(*args) : #{klass.name}.new(*args, **kwargs)
59
59
  begin
60
60
  if block_given?
61
61
  return block.call(dlg)
data/lib/wx/core/point.rb CHANGED
@@ -41,12 +41,21 @@ class Wx::Point
41
41
  end
42
42
 
43
43
  def <=>(other)
44
+ this_x, this_y = to_ary
44
45
  if Wx::Point === other
45
- (x*y) <=> (other.x*other.y)
46
+ that_x, that_y = other.to_ary
46
47
  elsif Array === other && other.size == 2
47
- (x*y) <=> (other.first.to_i*other.last.to_i)
48
+ that_x, that_y = other
48
49
  else
49
- nil
50
+ return nil
51
+ end
52
+
53
+ if this_y < that_y
54
+ -1
55
+ elsif that_y < this_y
56
+ 1
57
+ else
58
+ this_x <=> that_x
50
59
  end
51
60
  end
52
61
 
data/lib/wx/core/sizer.rb CHANGED
@@ -10,44 +10,71 @@
10
10
 
11
11
  module Wx
12
12
  class Sizer
13
- # Generic method to add items, supporting positional and named
13
+ # Redefine #add and #insert methods to support positional and named
14
14
  # arguments
15
- ADD_ITEM_PARAMS = [Wx::Parameter[:index, -1],
16
- Wx::Parameter[:proportion, 0],
17
- Wx::Parameter[:flag, 0],
18
- Wx::Parameter[:border, 0]]
15
+ SIZER_ADD_PARAMS = [Wx::Parameter[:proportion, 0],
16
+ Wx::Parameter[:flag, 0],
17
+ Wx::Parameter[:border, 0],
18
+ Wx::Parameter[:userData, nil]]
19
19
 
20
- def add_item(item, *mixed_args)
20
+ wx_sizer_add = instance_method :add
21
+ wx_redefine_method :add do |*args, **kwargs|
21
22
 
22
- begin
23
- args = Wx::args_as_list(ADD_ITEM_PARAMS, *mixed_args)
24
- rescue => err
25
- err.set_backtrace(caller)
26
- Kernel.raise err
27
- end
23
+ if args.last.is_a?(Wx::SizerFlags) # using 'flags' variant?
24
+ wx_sizer_add.bind(self).call(*args) # no need for keyword scanning
25
+ else
26
+ full_args = []
28
27
 
29
- full_args = []
28
+ full_args << args.shift # get first argument
30
29
 
31
- # extract the width and the height in the case of a spacer
32
- # defined as an array
33
- if item.kind_of?(Array)
34
- Kernel.raise ArgumentError,
35
- "Invalid Sizer specification : [width, height] expected" if item.size != 2
36
- full_args << item[0] << item[1]
37
- else
38
- full_args << item
30
+ unless full_args.first.is_a?(Wx::Window) || full_args.first.is_a?(Wx::Sizer)
31
+ full_args << args.shift # must be spacer variant, get height argument as well
32
+ end
33
+
34
+ begin
35
+ args = Wx::args_as_list(SIZER_ADD_PARAMS, *args, **kwargs)
36
+ rescue => err
37
+ err.set_backtrace(caller)
38
+ Kernel.raise err
39
+ end
40
+
41
+ # update the full arguments list with the optional arguments
42
+ full_args.concat(args)
43
+
44
+ # Call original add with full args
45
+ wx_sizer_add.bind(self).call(*full_args)
39
46
  end
40
47
 
41
- # update the full arguments list with the optional arguments (except index)
42
- idx = args.shift
43
- full_args.concat(args)
48
+ end
44
49
 
45
- # Call add to append if default position
46
- if idx == -1
47
- add(*full_args)
50
+ wx_sizer_insert = instance_method :insert
51
+ wx_redefine_method :insert do |index, *args, **kwargs|
52
+
53
+ if args.last.is_a?(Wx::SizerFlags) # using 'flags' variant?
54
+ wx_sizer_insert.bind(self).call(index, *args) # no need for keyword scanning
48
55
  else
49
- insert(idx, *full_args)
56
+ full_args = []
57
+
58
+ full_args << args.shift # get first argument after index
59
+
60
+ unless full_args.first.is_a?(Wx::Window) || full_args.first.is_a?(Wx::Sizer)
61
+ full_args << args.shift # must be spacer variant, get height argument as well
62
+ end
63
+
64
+ begin
65
+ args = Wx::args_as_list(SIZER_ADD_PARAMS, *args, **kwargs)
66
+ rescue => err
67
+ err.set_backtrace(caller)
68
+ Kernel.raise err
69
+ end
70
+
71
+ # update the full arguments list with the optional arguments
72
+ full_args.concat(args)
73
+
74
+ # Call original insert with full args
75
+ wx_sizer_insert.bind(self).call(index, *full_args)
50
76
  end
77
+
51
78
  end
52
79
 
53
80
  # Overload to provide Enumerator without block
@@ -169,6 +196,42 @@ module Wx
169
196
 
170
197
  class GridBagSizer < FlexGridSizer
171
198
 
199
+ # Redefine #add method to support positional and named
200
+ # arguments
201
+ GBSIZER_ADD_PARAMS = [Wx::Parameter[:span, Wx::DEFAULT_SPAN],
202
+ Wx::Parameter[:flag, 0],
203
+ Wx::Parameter[:border, 0],
204
+ Wx::Parameter[:userData, nil]]
205
+
206
+ wx_gbsizer_add = instance_method :add
207
+ wx_redefine_method :add do |*args, **kwargs|
208
+
209
+ full_args = []
210
+
211
+ full_args << args.shift # get first argument
212
+
213
+ unless full_args.first.is_a?(Wx::Window) || full_args.first.is_a?(Wx::Sizer)
214
+ full_args << args.shift # must be spacer variant, get height argument as well
215
+ end
216
+
217
+ # get mandatory pos arg
218
+ full_args << args.shift
219
+
220
+ begin
221
+ args = Wx::args_as_list(GBSIZER_ADD_PARAMS, *args, **kwargs)
222
+ rescue => err
223
+ err.set_backtrace(caller)
224
+ Kernel.raise err
225
+ end
226
+
227
+ # update the full arguments list with the optional arguments
228
+ full_args.concat(args)
229
+
230
+ # Call original add with full args
231
+ wx_gbsizer_add.bind(self).call(*full_args)
232
+
233
+ end
234
+
172
235
  wx_initialize = instance_method :initialize
173
236
  wx_redefine_method :initialize do |*args, &block|
174
237
  wx_initialize.bind(self).call(*args)
@@ -186,4 +249,76 @@ module Wx
186
249
 
187
250
  end
188
251
 
252
+ class GBPosition
253
+
254
+ include Comparable
255
+
256
+ # make GBPosition usable for parallel assignments like `r, c = pos`
257
+ def to_ary
258
+ [row, col]
259
+ end
260
+
261
+ # Compare with another position value
262
+ def <=>(other)
263
+ this_row, this_col = to_ary
264
+ if Wx::GBPosition === other
265
+ that_row, that_col = other.to_ary
266
+ elsif Array === other and other.size == 2
267
+ that_row, that_col = other
268
+ else
269
+ return nil
270
+ end
271
+
272
+ if this_row < that_row
273
+ -1
274
+ elsif that_row < this_row
275
+ 1
276
+ else
277
+ this_col <=> that_col
278
+ end
279
+ end
280
+
281
+ def eql?(other)
282
+ if other.instance_of?(self.class)
283
+ self == other
284
+ else
285
+ false
286
+ end
287
+ end
288
+
289
+ def hash
290
+ to_ary.hash
291
+ end
292
+
293
+ def dup
294
+ Wx::GBPosition.new(*self.to_ary)
295
+ end
296
+
297
+ end
298
+
299
+ class GBSpan
300
+
301
+ # make GBSpan usable for parallel assignments like `r, c = span`
302
+ def to_ary
303
+ [rowspan, colspan]
304
+ end
305
+
306
+ def eql?(other)
307
+ if other.instance_of?(self.class)
308
+ self == other
309
+ else
310
+ false
311
+ end
312
+ end
313
+
314
+ def hash
315
+ to_ary.hash
316
+ end
317
+
318
+ def dup
319
+ Wx::GBSpan.new(*self.to_ary)
320
+ end
321
+
322
+ end
323
+
189
324
  end
@@ -15,15 +15,15 @@ class Wx::SplashScreen
15
15
  end
16
16
 
17
17
  # now redefine the overridden ctor to account for deviating arglist
18
- wx_redefine_method :initialize do |bitmap, splashstyle, milliseconds, parent = nil, *mixed_args, &block|
18
+ wx_redefine_method :initialize do |bitmap, splashstyle, milliseconds, parent = nil, *args, **kwargs, &block|
19
19
  # no zero-args ctor for use with XRC!
20
20
 
21
21
  real_args = begin
22
- [ bitmap, splashstyle, milliseconds, parent ] + self.class.args_as_list(*mixed_args)
22
+ [ bitmap, splashstyle, milliseconds, parent ] + self.class.args_as_list(*args, **kwargs)
23
23
  rescue => err
24
24
  msg = "Error initializing #{self.inspect}\n"+
25
25
  " : #{err.message} \n" +
26
- "Provided are #{[ bitmap, splashstyle, milliseconds, parent ] + mixed_args} \n" +
26
+ "Provided are #{[ bitmap, splashstyle, milliseconds, parent ] + args + [kwargs]} \n" +
27
27
  "Correct parameters for #{self.class.name}.new are:\n" +
28
28
  self.class.describe_constructor(
29
29
  ":bitmap => (Wx::Bitmap)\n:splashstyle => (Integer)\n:milliseconds => (Integer)\n:parent => (Wx::Window)\n")
@@ -21,10 +21,10 @@ class Wx::ToolBar
21
21
  Wx::Parameter[ :long_help, "" ],
22
22
  Wx::Parameter[ :client_data, nil ] ]
23
23
 
24
- def add_item(bitmap1, *mixed_args)
24
+ def add_item(bitmap1, *args, **kwargs)
25
25
 
26
26
  begin
27
- args = Wx::args_as_list(ADD_ITEM_PARAMS, *mixed_args)
27
+ args = Wx::args_as_list(ADD_ITEM_PARAMS, *args, **kwargs)
28
28
  rescue => err
29
29
  err.set_backtrace(caller)
30
30
  Kernel.raise err
data/lib/wx/helpers.rb CHANGED
@@ -19,16 +19,14 @@ module Wx
19
19
  # structs containing the keyword name and default value for each
20
20
  # possible argument. +mixed_args+ is an array which may optionally end
21
21
  # with a set of named arguments
22
- def self.args_as_list(param_spec, *mixed_args)
22
+ def self.args_as_list(param_spec, *args, **kwargs)
23
23
 
24
24
  begin
25
- # get keyword arguments from mixed args if supplied, else empty
26
- kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
27
25
  out_args = []
28
26
  param_spec.each_with_index do | param, i |
29
27
  # has supplied list arg or the keyword arg?
30
- arg = mixed_args[i]
31
- arg = kwa.delete(param.name) if arg.nil? && kwa.key?(param.name)
28
+ arg = args[i]
29
+ arg = kwargs.delete(param.name) if arg.nil? && kwargs.key?(param.name)
32
30
  if Proc === param.default_or_proc
33
31
  arg = param.default_or_proc.call(arg) # provides default or converts arg
34
32
  elsif arg.nil?
@@ -37,13 +35,13 @@ module Wx
37
35
  out_args << arg
38
36
  end
39
37
  rescue
40
- Kernel.raise ArgumentError,
41
- "Bad arg composition of #{mixed_args.inspect}"
38
+ Kernel.raise ArgumentError,
39
+ "Bad arg composition of #{args.inspect}"
42
40
  end
43
41
 
44
- unless kwa.empty?
45
- Kernel.raise ArgumentError,
46
- "Unknown keyword argument(s) : #{kwa.keys.inspect}"
42
+ unless kwargs.empty?
43
+ Kernel.raise ArgumentError,
44
+ "Unknown keyword argument(s) : #{kwargs.keys.inspect}"
47
45
  end
48
46
 
49
47
  out_args
@@ -164,18 +164,16 @@ module Wx
164
164
  end
165
165
  end
166
166
 
167
- def args_as_list(*mixed_args)
168
- Wx::args_as_list(param_spec, *mixed_args)
169
- end
170
-
171
- def args_as_hash(*mixed_args)
172
- kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
173
- param_spec.zip(mixed_args) do | param, arg |
174
- kwa[param.name] = arg if arg
167
+ if RUBY_VERSION < '3.0.0'
168
+ def args_as_list(*mixed_args)
169
+ Wx::args_as_list(param_spec, *mixed_args)
170
+ end
171
+ else
172
+ def args_as_list(*args, **kwargs)
173
+ Wx::args_as_list(param_spec, *args, **kwargs)
175
174
  end
176
- kwa
177
175
  end
178
-
176
+
179
177
  def describe_constructor(txt = '')
180
178
  param_spec.inject(txt) do | desc, param |
181
179
  if Proc === param.default_or_proc
@@ -198,7 +196,7 @@ module Wx
198
196
  # The new definition of initialize; accepts a parent arg
199
197
  # mixed_args, which may zero or more position args, optionally
200
198
  # terminated with hash keyword args, and an optional block
201
- wx_redefine_method :initialize do |parent = :default_ctor, *mixed_args, &block|
199
+ wx_redefine_method :initialize do |parent = :default_ctor, *args, **kwargs, &block|
202
200
  # allow zero-args ctor for use with XRC
203
201
  if parent == :default_ctor
204
202
  pre_wx_kwctor_init
@@ -206,11 +204,11 @@ module Wx
206
204
  end
207
205
 
208
206
  real_args = begin
209
- [ parent ] + self.class.args_as_list(*mixed_args)
207
+ [ parent ] + self.class.args_as_list(*args, **kwargs)
210
208
  rescue => err
211
209
  msg = "Error initializing #{self.inspect}\n"+
212
210
  " : #{err.message} \n" +
213
- "Provided are #{[parent] + mixed_args} \n" +
211
+ "Provided are #{[parent] + args + [kwargs]} \n" +
214
212
  "Correct parameters for #{self.class.name}.new are:\n" +
215
213
  self.class.describe_constructor(":parent => (Wx::Window)\n")
216
214
 
@@ -23,7 +23,7 @@ module Wx::RTC
23
23
  end
24
24
 
25
25
  # now redefine the overridden ctor to account for deviating arglist
26
- wx_redefine_method :initialize do |flags = nil, parent = nil, *mixed_args, &block|
26
+ wx_redefine_method :initialize do |flags = nil, parent = nil, *args, **kwargs, &block|
27
27
  # allow zero-args ctor for use with XRC
28
28
  if flags.nil?
29
29
  pre_wx_kwctor_init
@@ -31,11 +31,11 @@ module Wx::RTC
31
31
  end
32
32
 
33
33
  real_args = begin
34
- [ flags, parent ] + self.class.args_as_list(*mixed_args)
34
+ [ flags, parent ] + self.class.args_as_list(*args, **kwargs)
35
35
  rescue => err
36
36
  msg = "Error initializing #{self.inspect}\n"+
37
37
  " : #{err.message} \n" +
38
- "Provided are #{[ flags, parent ] + mixed_args} \n" +
38
+ "Provided are #{[ flags, parent ] + args + [kwargs]} \n" +
39
39
  "Correct parameters for #{self.class.name}.new are:\n" +
40
40
  self.class.describe_constructor(
41
41
  ":flags => (Integer)\n:parent => (Wx::Window)\n")
@@ -12,13 +12,13 @@ class Wx::RTC::RichTextStyleOrganiserDialog
12
12
  end
13
13
 
14
14
  # now redefine the overridden ctor to account for deviating arglist
15
- wx_redefine_method :initialize do |flags, sheet, ctrl, parent = nil, *mixed_args, &block|
15
+ wx_redefine_method :initialize do |flags, sheet, ctrl, parent = nil, *args, **kwargs, &block|
16
16
  real_args = begin
17
- [ flags, sheet, ctrl, parent ] + self.class.args_as_list(*mixed_args)
17
+ [ flags, sheet, ctrl, parent ] + self.class.args_as_list(*args, **kwargs)
18
18
  rescue => err
19
19
  msg = "Error initializing #{self.inspect}\n"+
20
20
  " : #{err.message} \n" +
21
- "Provided are #{[ flags, sheet, ctrl, parent ] + mixed_args} \n" +
21
+ "Provided are #{[ flags, sheet, ctrl, parent ] + args + [kwargs]} \n" +
22
22
  "Correct parameters for #{self.class.name}.new are:\n" +
23
23
  self.class.describe_constructor(
24
24
  ":flags => (Integer)\n:sheet => (Wx::RTC::RichTextStyleSheet)\n:ctrl => (Wx::RTC::RichTextCtrl)\n:parent => (Wx::Window)\n")
@@ -13,13 +13,13 @@ class Wx::RTC::SymbolPickerDialog
13
13
  end
14
14
 
15
15
  # now redefine the overridden ctor to account for deviating arglist
16
- wx_redefine_method :initialize do |symbol, initialFont, normalTextFont, parent = nil, *mixed_args, &block|
16
+ wx_redefine_method :initialize do |symbol, initialFont, normalTextFont, parent = nil, *args, **kwargs, &block|
17
17
  real_args = begin
18
- [ symbol, initialFont, normalTextFont, parent ] + self.class.args_as_list(*mixed_args)
18
+ [ symbol, initialFont, normalTextFont, parent ] + self.class.args_as_list(*args, **kwargs)
19
19
  rescue => err
20
20
  msg = "Error initializing #{self.inspect}\n"+
21
21
  " : #{err.message} \n" +
22
- "Provided are #{[ symbol, initialFont, normalTextFont, parent ] + mixed_args} \n" +
22
+ "Provided are #{[ symbol, initialFont, normalTextFont, parent ] + args + [kwargs]} \n" +
23
23
  "Correct parameters for #{self.class.name}.new are:\n" +
24
24
  self.class.describe_constructor(
25
25
  ":symbol => (String)\n:initialFont => (String)\n:normalTextFont => (String)\n:parent => (Wx::Window)\n")
data/lib/wx/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # This software is released under the MIT license.
4
4
 
5
5
  module Wx
6
- WXRUBY_VERSION = '1.5.3'
6
+ WXRUBY_VERSION = '1.5.4'
7
7
  end
@@ -139,6 +139,36 @@ module WXRuby3
139
139
  'wxSizerItem * Add(wxWindow *window, const wxGBPosition &pos, const wxGBSpan &span=wxDefaultSpan, int flag=0, int border=0, wxObject *userData=NULL)',
140
140
  'wxSizerItem * Add(int width, int height, const wxGBPosition &pos, const wxGBSpan &span=wxDefaultSpan, int flag=0, int border=0, wxObject *userData=NULL)'
141
141
  spec.disown 'wxSizer* sizer_disown'
142
+ spec.map 'const wxGBPosition&' => 'Array(Integer, Integer), Wx::GBPosition',
143
+ 'const wxGBSpan&' => 'Array(Integer, Integer), Wx::GBSpan' do
144
+ add_header_code '#include <memory>'
145
+ map_in temp: 'std::unique_ptr<$1_basetype> tmp', code: <<~__CODE
146
+ if ( TYPE($input) == T_DATA )
147
+ {
148
+ void* argp$argnum;
149
+ SWIG_ConvertPtr($input, &argp$argnum, $1_descriptor, 0);
150
+ $1 = reinterpret_cast< $1_basetype * >(argp$argnum);
151
+ }
152
+ else if ( TYPE($input) == T_ARRAY )
153
+ {
154
+ $1 = new $1_basetype( NUM2INT( rb_ary_entry($input, 0) ),
155
+ NUM2INT( rb_ary_entry($input, 1) ) );
156
+ tmp.reset($1); // auto destruct when method scope ends
157
+ }
158
+ else
159
+ {
160
+ rb_raise(rb_eTypeError, "Wrong type for $1_basetype parameter");
161
+ }
162
+ __CODE
163
+ map_typecheck precedence: 'POINTER', code: <<~__CODE
164
+ void *vptr = 0;
165
+ $1 = 0;
166
+ if (TYPE($input) == T_ARRAY && RARRAY_LEN($input) == 2)
167
+ $1 = 1;
168
+ else if (TYPE($input) == T_DATA && SWIG_CheckState (SWIG_ConvertPtr ($input, &vptr, $1_descriptor, 0)))
169
+ $1 = 1;
170
+ __CODE
171
+ end
142
172
  end
143
173
  # no real use for allowing these to be overloaded but a whole lot of grieve
144
174
  # if we do allow it
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wxruby3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Corino