glimmer-dsl-swt 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce119763646f3e3ccc0211534317572ed02c5d21b9820387dec34d83b714e50f
4
- data.tar.gz: 1c4486c574ab3e8d30957133b9aab200dcfbdea10ea1c4aa0279a4991f80a0dd
3
+ metadata.gz: 8dda5c40a0a65d36e4615d40f3456b80d2d990121ed63fa9f447a1d110af3a93
4
+ data.tar.gz: 4bcdc319eda7a7c3542e0d1b8caeda9329726623ae20b87236be0690dbd263c4
5
5
  SHA512:
6
- metadata.gz: cea6c2e7ac8920d4ae87e447f08c7a622fc8851827b76160dc07b36d8c725911bf94a772aa5f47e43465a24961f7dc38b1d974a164ec3704d159dee61deb7712
7
- data.tar.gz: 8efbb95213218c052cbcc8165dc2305c41f26a42f1a374ba05fd9b5912c3a79bfbb99522a524c8cc0fa88b128c471ab22e03fb75a750b7dd31708617b4c6b4cf
6
+ metadata.gz: 12f2085517a77a30197dd499887e0ca55756b2a0d0ec26275be60b38d6b266722c6574256e3f9830e145763eec7cb74543b0df37932d9c751b0497c4ea277a38
7
+ data.tar.gz: bb174b6427e2814b02f4509dc4b31698ca2e28c460f2d18749c2505ec9cb0635641275a5300db0fbb7821d1fdb0cdc8474e9220d2718201073076d567b2865d0
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 /> Glimmer DSL for SWT 0.3.1 (Desktop GUI)
1
+ # <img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 /> Glimmer DSL for SWT 0.4.0 (Desktop GUI)
2
2
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
3
3
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-swt/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-swt?branch=master)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -48,6 +48,17 @@ module Glimmer
48
48
  end
49
49
  @swt_color
50
50
  end
51
+
52
+ def method_missing(method, *args, &block)
53
+ swt_color.send(method, *args, &block)
54
+ rescue => e
55
+ Glimmer::Config.logger&.debug "Neither ColorProxy nor #{swt_color.class.name} can handle the method ##{method}"
56
+ super
57
+ end
58
+
59
+ def respond_to?(method, *args, &block)
60
+ super || swt_color.respond_to?(method, *args, &block)
61
+ end
51
62
  end
52
63
  end
53
64
  end
@@ -33,26 +33,28 @@ module Glimmer
33
33
 
34
34
  def initialize(*args)
35
35
  @swt_display = Display.new(*args)
36
+ @swt_display.set_data('proxy', self)
36
37
  end
37
38
 
38
39
  def dispose
39
40
  @swt_display.dispose
40
41
  end
41
42
 
42
- # Executes code block asynchronously with respect to SWT UI thread
43
- def async_exec(&block)
44
- @swt_display.asyncExec(&block)
43
+ def method_missing(method, *args, &block)
44
+ swt_display.send(method, *args, &block)
45
+ rescue => e
46
+ Glimmer::Config.logger&.debug "Neither DisplayProxy nor #{swt_display.class.name} can handle the method ##{method}"
47
+ super
45
48
  end
46
-
47
- # Executes code block synchronously with respect to SWT UI thread
48
- def sync_exec(&block)
49
- @swt_display.syncExec(&block)
49
+
50
+ def respond_to?(method, *args, &block)
51
+ super || swt_display.respond_to?(method, *args, &block)
50
52
  end
51
53
 
52
54
  def can_handle_observation_request?(observation_request)
53
55
  observation_request = observation_request.to_s
54
- if observation_request.start_with?('on_event_')
55
- constant_name = observation_request.sub(/^on_event_/, '')
56
+ if observation_request.start_with?('on_swt_')
57
+ constant_name = observation_request.sub(/^on_swt_/, '')
56
58
  SWTProxy.has_constant?(constant_name)
57
59
  elsif observation_request.start_with?('on_')
58
60
  event_name = observation_request.sub(/^on_/, '')
@@ -63,8 +65,8 @@ module Glimmer
63
65
  end
64
66
 
65
67
  def handle_observation_request(observation_request, &block)
66
- if observation_request.start_with?('on_event_')
67
- constant_name = observation_request.sub(/^on_event_/, '')
68
+ if observation_request.start_with?('on_swt_')
69
+ constant_name = observation_request.sub(/^on_swt_/, '')
68
70
  add_swt_event_listener(constant_name, &block)
69
71
  elsif observation_request.start_with?('on_')
70
72
  event_name = observation_request.sub(/^on_/, '')
@@ -40,9 +40,10 @@ module Glimmer
40
40
  end
41
41
  args = args.compact
42
42
  @swt_widget = Shell.new(*args)
43
+ @swt_widget.set_data('proxy', self)
43
44
  @swt_widget.setLayout(FillLayout.new)
44
45
  @swt_widget.setMinimumSize(WIDTH_MIN, HEIGHT_MIN)
45
- on_event_show do
46
+ on_swt_show do
46
47
  Thread.new do
47
48
  sleep(0.25)
48
49
  async_exec do
@@ -144,9 +145,9 @@ module Glimmer
144
145
  visibility_notifier = proc do
145
146
  observer.call(visible?)
146
147
  end
147
- on_event_show(&visibility_notifier)
148
- on_event_hide(&visibility_notifier)
149
- on_event_close(&visibility_notifier)
148
+ on_swt_show(&visibility_notifier)
149
+ on_swt_hide(&visibility_notifier)
150
+ on_swt_close(&visibility_notifier)
150
151
  else
151
152
  super
152
153
  end
@@ -87,7 +87,7 @@ module Glimmer
87
87
  end
88
88
  end
89
89
 
90
- attr_reader :table_editor, :table_editor_text_proxy, :table_editor_widget_proxy, :sort_property, :sort_direction, :sort_block, :sort_type, :sort_by_block, :additional_sort_properties, :editor
90
+ attr_reader :table_editor, :table_editor_widget_proxy, :sort_property, :sort_direction, :sort_block, :sort_type, :sort_by_block, :additional_sort_properties, :editor
91
91
  attr_accessor :column_properties
92
92
 
93
93
  def initialize(underscored_widget_name, parent, args)
@@ -293,7 +293,7 @@ module Glimmer
293
293
  end
294
294
 
295
295
  content {
296
- @table_editor_widget_proxy = @table_editor_text_proxy = TableProxy::editors[editor_widget][:editor_gui].call(editor_widget_args, model, model_editing_property, self)
296
+ @table_editor_widget_proxy = TableProxy::editors[editor_widget][:editor_gui].call(editor_widget_args, model, model_editing_property, self)
297
297
  }
298
298
  @table_editor.setEditor(@table_editor_widget_proxy.swt_widget, table_item, column_index)
299
299
  rescue => e
@@ -60,6 +60,7 @@ module Glimmer
60
60
  styles, extra_options = extract_args(underscored_widget_name, args)
61
61
  swt_widget_class = self.class.swt_widget_class_for(underscored_widget_name)
62
62
  @swt_widget = swt_widget_class.new(parent.swt_widget, style(underscored_widget_name, styles), *extra_options)
63
+ @swt_widget.set_data('proxy', self)
63
64
  DEFAULT_INITIALIZERS[underscored_widget_name]&.call(@swt_widget)
64
65
  parent.post_initialize_child(self)
65
66
  end
@@ -176,44 +177,44 @@ module Glimmer
176
177
  }
177
178
  end,
178
179
  :caret_position => lambda do |observer|
179
- on_event_keydown { |event|
180
+ on_swt_keydown { |event|
180
181
  observer.call(@swt_widget.getCaretPosition)
181
182
  }
182
- on_event_keyup { |event|
183
+ on_swt_keyup { |event|
183
184
  observer.call(@swt_widget.getCaretPosition)
184
185
  }
185
- on_event_mousedown { |event|
186
+ on_swt_mousedown { |event|
186
187
  observer.call(@swt_widget.getCaretPosition)
187
188
  }
188
- on_event_mouseup { |event|
189
+ on_swt_mouseup { |event|
189
190
  observer.call(@swt_widget.getCaretPosition)
190
191
  }
191
192
  end,
192
193
  :selection => lambda do |observer|
193
- on_event_keydown { |event|
194
+ on_swt_keydown { |event|
194
195
  observer.call(@swt_widget.getSelection)
195
196
  }
196
- on_event_keyup { |event|
197
+ on_swt_keyup { |event|
197
198
  observer.call(@swt_widget.getSelection)
198
199
  }
199
- on_event_mousedown { |event|
200
+ on_swt_mousedown { |event|
200
201
  observer.call(@swt_widget.getSelection)
201
202
  }
202
- on_event_mouseup { |event|
203
+ on_swt_mouseup { |event|
203
204
  observer.call(@swt_widget.getSelection)
204
205
  }
205
206
  end,
206
207
  :selection_count => lambda do |observer|
207
- on_event_keydown { |event|
208
+ on_swt_keydown { |event|
208
209
  observer.call(@swt_widget.getSelectionCount)
209
210
  }
210
- on_event_keyup { |event|
211
+ on_swt_keyup { |event|
211
212
  observer.call(@swt_widget.getSelectionCount)
212
213
  }
213
- on_event_mousedown { |event|
214
+ on_swt_mousedown { |event|
214
215
  observer.call(@swt_widget.getSelectionCount)
215
216
  }
216
- on_event_mouseup { |event|
217
+ on_swt_mouseup { |event|
217
218
  observer.call(@swt_widget.getSelectionCount)
218
219
  }
219
220
  end,
@@ -338,8 +339,8 @@ module Glimmer
338
339
 
339
340
  def can_handle_observation_request?(observation_request)
340
341
  observation_request = observation_request.to_s
341
- if observation_request.start_with?('on_event_')
342
- constant_name = observation_request.sub(/^on_event_/, '')
342
+ if observation_request.start_with?('on_swt_')
343
+ constant_name = observation_request.sub(/^on_swt_/, '')
343
344
  SWTProxy.has_constant?(constant_name)
344
345
  elsif observation_request.start_with?('on_')
345
346
  event = observation_request.sub(/^on_/, '')
@@ -357,6 +358,9 @@ module Glimmer
357
358
  @drag_source_proxy = nil
358
359
  end
359
360
  end
361
+ rescue => e
362
+ Glimmer::Config.logger&.debug(e.full_message)
363
+ false
360
364
  end
361
365
 
362
366
  def can_handle_drop_observation_request?(observation_request)
@@ -372,8 +376,8 @@ module Glimmer
372
376
  end
373
377
 
374
378
  def handle_observation_request(observation_request, &block)
375
- if observation_request.start_with?('on_event_')
376
- constant_name = observation_request.sub(/^on_event_/, '')
379
+ if observation_request.start_with?('on_swt_')
380
+ constant_name = observation_request.sub(/^on_swt_/, '')
377
381
  add_swt_event_listener(constant_name, &block)
378
382
  elsif observation_request.start_with?('on_')
379
383
  event = observation_request.sub(/^on_/, '')
@@ -392,6 +396,17 @@ module Glimmer
392
396
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::WidgetExpression.new, &block)
393
397
  end
394
398
 
399
+ def method_missing(method, *args, &block)
400
+ swt_widget.send(method, *args, &block)
401
+ rescue => e
402
+ Glimmer::Config.logger&.debug "Neither WidgetProxy nor #{swt_widget.class.name} can handle the method ##{method}"
403
+ super
404
+ end
405
+
406
+ def respond_to?(method, *args, &block)
407
+ super || swt_widget.respond_to?(method, *args, &block)
408
+ end
409
+
395
410
  private
396
411
 
397
412
  def style(underscored_widget_name, styles)
@@ -437,7 +452,7 @@ module Glimmer
437
452
  def add_listener(underscored_listener_name, &block)
438
453
  widget_add_listener_method, listener_class, listener_method = self.class.find_listener(@swt_widget.getClass, underscored_listener_name)
439
454
  widget_listener_proxy = nil
440
- safe_block = lambda { |event| block.call(event) unless @swt_widget.isDisposed }
455
+ safe_block = lambda { |*args| block.call(*args) unless @swt_widget.isDisposed }
441
456
  listener = listener_class.new(listener_method => safe_block)
442
457
  @swt_widget.send(widget_add_listener_method, listener)
443
458
  widget_listener_proxy = WidgetListenerProxy.new(swt_widget: @swt_widget, swt_listener: listener, widget_add_listener_method: widget_add_listener_method, swt_listener_class: listener_class, swt_listener_method: listener_method)
@@ -479,9 +494,9 @@ module Glimmer
479
494
  listener_class.define_method('initialize') do |event_method_block_mapping|
480
495
  @event_method_block_mapping = event_method_block_mapping
481
496
  end
482
- listener_type.getMethods.each do |event_method|
483
- listener_class.define_method(event_method.getName) do |event|
484
- @event_method_block_mapping[event_method.getName]&.call(event)
497
+ listener_type.getMethods.each do |event_method|
498
+ listener_class.define_method(event_method.getName) do |*args|
499
+ @event_method_block_mapping[event_method.getName]&.call(*args)
485
500
  end
486
501
  end
487
502
  end
@@ -492,7 +507,7 @@ module Glimmer
492
507
  def add_swt_event_listener(swt_constant, &block)
493
508
  event_type = SWTProxy[swt_constant]
494
509
  widget_listener_proxy = nil
495
- safe_block = lambda { |event| block.call(event) unless @swt_widget.isDisposed }
510
+ safe_block = lambda { |*args| block.call(*args) unless @swt_widget.isDisposed }
496
511
  @swt_widget.addListener(event_type, &safe_block)
497
512
  widget_listener_proxy = WidgetListenerProxy.new(swt_widget: @swt_widget, swt_listener: @swt_widget.getListeners(event_type).last, event_type: event_type, swt_constant: swt_constant)
498
513
  end
@@ -579,7 +594,7 @@ module Glimmer
579
594
  end
580
595
  image_data = ImageData.new(value)
581
596
  # TODO in the future, look into unregistering this listener when no longer needed
582
- on_event_Resize do |resize_event|
597
+ on_swt_Resize do |resize_event|
583
598
  new_image_data = image_data.scaledTo(@swt_widget.getSize.x, @swt_widget.getSize.y)
584
599
  @swt_widget.getBackgroundImage&.dispose
585
600
  @swt_widget.setBackgroundImage(Image.new(@swt_widget.getDisplay, new_image_data))
@@ -8,6 +8,7 @@ module Glimmer
8
8
 
9
9
  def initialize(parent, *swt_constants, options, &content)
10
10
  super
11
+ @swt_widget.set_data('custom_shell', self)
11
12
  raise Error, 'Invalid custom shell body root! Must be a shell or another custom shell.' unless body_root.swt_widget.is_a?(org.eclipse.swt.widgets.Shell)
12
13
  end
13
14
 
@@ -134,8 +134,9 @@ module Glimmer
134
134
  body_block = self.class.instance_variable_get("@body_block")
135
135
  raise Glimmer::Error, 'Invalid custom widget for having no body! Please define body block!' if body_block.nil?
136
136
  @body_root = instance_exec(&body_block)
137
- execute_hooks('after_body')
138
137
  @swt_widget = @body_root.swt_widget
138
+ @swt_widget.set_data('custom_widget', self)
139
+ execute_hooks('after_body')
139
140
  end
140
141
 
141
142
  def can_handle_observation_request?(observation_request)
@@ -159,7 +160,7 @@ module Glimmer
159
160
  end
160
161
 
161
162
  def can_add_observer?(attribute_name)
162
- has_instance_method?(attribute_name) || respond_to?("#{attribute_name}?") || @body_root.can_add_observer?(attribute_name)
163
+ has_instance_method?(attribute_name) || has_instance_method?("#{attribute_name}?") || @body_root.can_add_observer?(attribute_name)
163
164
  end
164
165
 
165
166
  def add_observer(observer, attribute_name)
@@ -171,12 +172,12 @@ module Glimmer
171
172
  end
172
173
 
173
174
  def has_attribute?(attribute_name, *args)
174
- respond_to?(attribute_setter(attribute_name), args) ||
175
+ has_instance_method?(attribute_setter(attribute_name)) ||
175
176
  @body_root.has_attribute?(attribute_name, *args)
176
177
  end
177
178
 
178
179
  def set_attribute(attribute_name, *args)
179
- if respond_to?(attribute_setter(attribute_name), args)
180
+ if has_instance_method?(attribute_setter(attribute_name))
180
181
  send(attribute_setter(attribute_name), *args)
181
182
  else
182
183
  @body_root.set_attribute(attribute_name, *args)
@@ -186,6 +187,7 @@ module Glimmer
186
187
  # This method ensures it has an instance method not coming from Glimmer DSL
187
188
  def has_instance_method?(method_name)
188
189
  respond_to?(method_name) &&
190
+ !swt_widget.respond_to?(method_name) &&
189
191
  !method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb') &&
190
192
  !method(method_name)&.source_location&.first&.include?('glimmer/swt/widget_proxy.rb')
191
193
  end
@@ -202,7 +204,6 @@ module Glimmer
202
204
  "#{attribute_name}="
203
205
  end
204
206
 
205
-
206
207
  def has_style?(style)
207
208
  (swt_style & SWT::SWTProxy[style]) == SWT::SWTProxy[style]
208
209
  end
@@ -231,7 +232,8 @@ module Glimmer
231
232
  def method_missing(method, *args, &block)
232
233
  body_root.send(method, *args, &block)
233
234
  end
234
-
235
+
236
+ alias local_respond_to? respond_to?
235
237
  def respond_to?(method, *args, &block)
236
238
  super or
237
239
  body_root.respond_to?(method, *args, &block)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-18 00:00:00.000000000 Z
11
+ date: 2020-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement