glimmer-dsl-tk 0.0.45 → 0.0.46

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: 0a9655c46ab2b4638e96077e0795a6b7201456baf020ade27838d139797d3a44
4
- data.tar.gz: dc2b2924a180df216a16161aa938b4429f814a59f18e0fba945b73eb40513bd6
3
+ metadata.gz: 5313d90447c3c864cdbc16c6704c6bcb07fc2b8adcd51f136d92762be919327e
4
+ data.tar.gz: e4e48e9330f79b4a5c677651336560805485d6d0b036fc7c248f3b0a338e0f82
5
5
  SHA512:
6
- metadata.gz: cab872767a730b059ebdaee18a124f0ded5e9fa0d5f980592b2c9fc9a20d756894846a4662b1f20043108987424daf6b79f895df639d1e273b66cad90f8437ae
7
- data.tar.gz: 5a92bbe321b0ca538fbebc84d5e076047b2a761294f47be236f041853873c60787ce593dd142e7a5ba9671b9cdc7faaf1ca6d9f41c9a45fed1dde8cc55b5f184
6
+ metadata.gz: 41b3096f2f320ae2bd277b71f4f98ca8ba0f43e05d50eba9adc1a200106d698c17a67bee78082e2f62cb1179d2185df0765e1e9b4a83fc4de15d367a4701e83d
7
+ data.tar.gz: 74761ae2d6f037d7c237d47da581ff2be8bf5f2c2c6e96a9656b900b5bc19ea39442afc14b16b9d2f5ac5ff370887973262b0d2cc8223a2fa7080972a63c564d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.46
4
+
5
+ - Support `drag_source true` on `list` widget
6
+ - Support `drop_target true` keyword alternative to `on_drop` for cases where it is implied what to drop (text in the case of label, entry, combo, list, and button)
7
+ - Support `on('drag_start')` (instead of `on_drag_start`), `on('drag_motion')`, and `on('drop')` for consistency with Glimmer DSL for general Tk listener style (`on('event')`)
8
+
3
9
  ## 0.0.45
4
10
 
5
11
  - Support `lbl` widget as the non-tile-themed version of `label` (i.e. `::TkLabel` not `::Tk::Tile::TLabel`)
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 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Tk 0.0.45
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Tk 0.0.46
2
2
  ## MRI Ruby Desktop Development GUI Library
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-tk.svg)](http://badge.fury.io/rb/glimmer-dsl-tk)
4
4
  [![Ruby](https://github.com/AndyObtiva/glimmer-dsl-tk/actions/workflows/ruby.yml/badge.svg)](https://github.com/AndyObtiva/glimmer-dsl-tk/actions/workflows/ruby.yml)
@@ -182,7 +182,7 @@ gem install glimmer-dsl-tk
182
182
 
183
183
  Add the following to `Gemfile`:
184
184
  ```
185
- gem 'glimmer-dsl-tk', '0.0.45'
185
+ gem 'glimmer-dsl-tk', '0.0.46'
186
186
  ```
187
187
 
188
188
  And, then run:
@@ -480,14 +480,23 @@ Check out the [Hello, Scrollbar!](#hello-scrollbar) sample for a `text` demo wit
480
480
 
481
481
  #### Drag and Drop API
482
482
 
483
- Drag and drop works by simply designating a widget as a drag source with attribute `drag_source true`
483
+ Drag and drop works by simply designating a widget as a drag source with attribute `drag_source true` and another widget as a drop target with attribute `drop_target true`.
484
484
 
485
- Alternatively, add listeners:
486
- - `on_drag_start {|event| ...}`: fires on drag start receiving an `event` arg to set `data` and configure `source`
487
- - `on_drag_motion {|event| ...}`: fires on drag motion receiving an `event` arg to check `event#drop_accepted`, and configure `source` and `tooltip`
485
+ Alternatively, add listeners on the drag source:
486
+ - `on('drag_start') {|event| ...}`: fires on drag start receiving an `event` arg to set `data` and configure `source`
487
+ - `on('drag_motion') {|event| ...}`: fires on drag motion receiving an `event` arg to check `event#drop_accepted`, and configure `source` and `tooltip`
488
488
 
489
- On the drop target, you simply define:
490
- - `on_drop { |event| ...}`: fires on drop, receiving an `event` arg with `event#target` and `event#data` (set during drag). You can even destroy the `event#source` if you want to get rid of the dragged widget.
489
+ And on the drop target, add listener:
490
+ - `on('drop') { |event| ...}`: fires on drop, receiving an `event` arg with `event#target` and `event#data` (set during drag). You can even destroy the `event#source` if you want to get rid of the dragged widget.
491
+
492
+ These are all the available attributes on event, which is of type `DragAndDropEvent`:
493
+ - `source`: drag source widget proxy
494
+ - `target`: drop target widget proxy
495
+ - `tooltip`: tooltip widget proxy
496
+ - `x_root`: x coordinate from top-left root corner
497
+ - `y_root`: y coordinate from top-left root corner
498
+ - `data`: data being transferred through drag and drop
499
+ - `drop_accepted`: boolean indicating if drop was accepted
491
500
 
492
501
  Learn more at the [Hello, Drag and Drop!](#hello-drag-and-drop) sample.
493
502
 
@@ -834,6 +843,9 @@ More details can be found in the [Hello, Button!](#hello-button) sample below.
834
843
  - Widget blocks are always declared with curly braces `{}` to clearly visualize hierarchical view code and separate from logic code.
835
844
  - Widget attribute declarations always have arguments that are never wrapped inside parentheses and never take a block.
836
845
  - Widget listeners are always declared with `on` keyword receiving listener event name as an argument. Their multi-line blocks have a `do; end` style to distinguish as logic from widget keywords and attributes.
846
+ - In a widget's content block, group attributes on top first, with the `grid` geometry management attribute being first, and separate by an empty line from nested widgets and listeners following afterwards.
847
+ - In a widget's content block, after attributes, you may either include nested widgets second and listeners third or vice versa.
848
+ - Unlike attributes, nested widgets and listeners are all separated by an empty line to make readability easier except where it helps to group two widgets together (e.g. label and described entry)
837
849
  - Pure logic multi-line blocks that do not constitute GUI DSL view elements in general always have `do; end` style to clearly separate logic code from view code.
838
850
 
839
851
  ## Samples
@@ -1038,14 +1050,14 @@ class HelloButton
1038
1050
  text 'Text Button'
1039
1051
  }
1040
1052
 
1041
- button {
1053
+ button { |b|
1042
1054
  text <= [self, :count, on_read: ->(value) { "Click To Increment: #{value} " }]
1043
1055
  default 'active'
1044
1056
  focus true
1045
1057
 
1046
- command {
1058
+ on('command') do
1047
1059
  self.count += 1
1048
- }
1060
+ end
1049
1061
  }
1050
1062
  }
1051
1063
 
@@ -1060,9 +1072,9 @@ class HelloButton
1060
1072
  button {
1061
1073
  image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
1062
1074
 
1063
- command {
1075
+ on('command') do
1064
1076
  message_box(title: 'Image Button', message: 'Image Button Clicked!')
1065
- }
1077
+ end
1066
1078
  }
1067
1079
  }
1068
1080
 
@@ -1077,12 +1089,12 @@ class HelloButton
1077
1089
  ['center', 'top', 'bottom', 'left', 'right'].each do |compound_option|
1078
1090
  button {
1079
1091
  image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
1080
- text 'Text Image Button'
1092
+ text "#{compound_option.capitalize} Image"
1081
1093
  compound compound_option
1082
1094
 
1083
- command {
1095
+ on('command') do
1084
1096
  message_box(title: 'Text Image Button', message: 'Text Image Button Clicked!', detail: "(#{compound_option})")
1085
- }
1097
+ end
1086
1098
  }
1087
1099
  end
1088
1100
  }
@@ -2729,11 +2741,12 @@ root {
2729
2741
  text "Drag entry text"
2730
2742
  width 30
2731
2743
 
2744
+ # drag_source true
2732
2745
  # This is how to do `drag_source true` the manual way for use in exceptional cases
2733
2746
  on_drag_start do |event|
2734
2747
  event.data = event.source.text
2735
2748
  event.source.configure(:cursor => "hand2")
2736
- event.tooltip.content {
2749
+ event.tooltip.content { # re-open tooltip content and add a label
2737
2750
  lbl { # non-tile-theme version of label
2738
2751
  text event.data + " "
2739
2752
  bg "yellow"
@@ -2762,9 +2775,7 @@ root {
2762
2775
  values %w[USA Canada Mexico Columbia UK Australia Germany Italy Spain]
2763
2776
  width 27
2764
2777
 
2765
- on_drag_start do |event|
2766
- event.data = event.source.text
2767
- end
2778
+ drag_source true
2768
2779
  }
2769
2780
 
2770
2781
  label {
@@ -2778,6 +2789,8 @@ root {
2778
2789
  selection 'Canada'
2779
2790
  height 3
2780
2791
 
2792
+ # drag_source true
2793
+ # This is another alternative to `drag_source true` with manual specification of transferred data only
2781
2794
  on_drag_start do |event|
2782
2795
  event.data = event.source.selection.first
2783
2796
  end
@@ -2809,9 +2822,7 @@ root {
2809
2822
  borderwidth 2
2810
2823
  relief "solid"
2811
2824
 
2812
- on_drop do |event|
2813
- event.target.text = event.data
2814
- end
2825
+ drop_target true
2815
2826
  }
2816
2827
 
2817
2828
  label {
@@ -2822,9 +2833,7 @@ root {
2822
2833
  grid :row => 1, :column => 1, :pady => 5, :sticky => "e"
2823
2834
  width 30
2824
2835
 
2825
- on_drop { |event|
2826
- event.target.text = event.data
2827
- }
2836
+ drop_target true
2828
2837
  }
2829
2838
 
2830
2839
  label {
@@ -2835,9 +2844,7 @@ root {
2835
2844
  grid :row => 2, :column => 1, :pady => 5, :sticky => "e"
2836
2845
  width 27
2837
2846
 
2838
- on_drop do |event|
2839
- event.target.text = event.data
2840
- end
2847
+ drop_target true
2841
2848
  }
2842
2849
 
2843
2850
  label {
@@ -2849,9 +2856,7 @@ root {
2849
2856
  selectmode 'browse'
2850
2857
  height 3
2851
2858
 
2852
- on_drop do |event|
2853
- event.target.items += [event.data]
2854
- end
2859
+ drop_target true
2855
2860
  }
2856
2861
 
2857
2862
  label {
@@ -2862,9 +2867,7 @@ root {
2862
2867
  grid :row => 4, :column => 1, :pady => 5, :sticky => "w"
2863
2868
  text "Drop here"
2864
2869
 
2865
- on_drop do |event|
2866
- event.target.text = event.data
2867
- end
2870
+ drop_target true
2868
2871
  }
2869
2872
 
2870
2873
  label {
@@ -2874,7 +2877,9 @@ root {
2874
2877
  checkbutton {
2875
2878
  grid :row => 5, :column => 1, :pady => 5, :sticky => "w"
2876
2879
  text "Drop here to destroy a widget"
2877
-
2880
+
2881
+ # drop_target true
2882
+ # This is an alternative to `drop_target true` with manual consumption of transferred data
2878
2883
  on_drop do |event|
2879
2884
  event.target.text = event.data
2880
2885
  # execute asynchronously after 100ms to ensure all events have been processed before destruction
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.45
1
+ 0.0.46
Binary file
@@ -23,8 +23,21 @@ require "json"
23
23
 
24
24
  module Glimmer
25
25
  module Tk
26
- class WidgetProxy
26
+ module DraggableAndDroppable
27
27
  attr_accessor :on_drag_motion_block
28
+
29
+ def handle_listener(listener_name, &listener)
30
+ case listener_name.to_s.downcase
31
+ when 'drag_start'
32
+ self.on_drag_start_block = listener
33
+ when 'drag_motion'
34
+ self.on_drag_motion_block = listener
35
+ when 'drop'
36
+ self.on_drop_block = listener
37
+ else
38
+ super
39
+ end
40
+ end
28
41
 
29
42
  def drag_source=(value)
30
43
  @drag_source = value
@@ -35,6 +48,15 @@ module Glimmer
35
48
  end
36
49
  end
37
50
 
51
+ def drop_target=(value)
52
+ @drop_target = value
53
+ if @drop_target
54
+ make_droppable
55
+ else
56
+ make_non_droppable
57
+ end
58
+ end
59
+
38
60
  def on_drag_start_block=(block)
39
61
  @on_drag_start_block = block
40
62
  make_draggable
@@ -68,7 +90,13 @@ module Glimmer
68
90
  if @drag_source
69
91
  tk_event.widget.configure(:cursor => "hand2")
70
92
  # Default data to drag is text
71
- drag_event.data = if textvariable_defined? then tk.textvariable.value elsif has_attribute?(:text) then tk.text end
93
+ drag_event.data = if textvariable_defined?
94
+ tk.textvariable.value
95
+ elsif has_attribute?('text')
96
+ tk.text
97
+ elsif has_attribute?('selection')
98
+ selection.first
99
+ end
72
100
  tooltip_label = WidgetProxy.new('label', tooltip, [])
73
101
  tooltip_label.text = drag_event.data
74
102
  tooltip_label.pack # TODO look into using grid instead to be consistent with the modern Tk way
@@ -118,6 +146,20 @@ module Glimmer
118
146
  @tk.bind_remove("<DropAcceptedEvent>")
119
147
  end
120
148
 
149
+ def make_droppable
150
+ self.on_drop_block = Proc.new do |event|
151
+ event.target.text = event.data if event.target.has_attribute?('text')
152
+ event.target.items += [event.data] if event.target.has_attribute?('items')
153
+ event.target.selection += [event.data] if event.target.has_attribute?('selection')
154
+ end
155
+ end
156
+
157
+ def make_non_droppable
158
+ @tk.bind_remove('<DropEvent>')
159
+ @tk.bind_remove('<DropCheckEvent>')
160
+ @on_drop_block = nil
161
+ end
162
+
121
163
  DragAndDropEvent = Struct.new(:source, :target, :tooltip, :x_root, :y_root, :data, :drop_accepted) do
122
164
  alias drop_accepted? drop_accepted
123
165
 
@@ -21,6 +21,7 @@
21
21
 
22
22
  require 'glimmer/data_binding/tk/one_time_observer'
23
23
  require 'glimmer/tk/widget'
24
+ require 'glimmer/tk/draggable_and_droppable'
24
25
 
25
26
  module Glimmer
26
27
  module Tk
@@ -69,6 +70,8 @@ module Glimmer
69
70
  end
70
71
  end
71
72
 
73
+ prepend DraggableAndDroppable
74
+
72
75
  FONTS_PREDEFINED = %w[default text fixed menu heading caption small_caption icon tooltip]
73
76
 
74
77
  attr_reader :parent_proxy, :tk, :args, :keyword, :children, :bind_ids, :destroyed
@@ -155,6 +158,7 @@ module Glimmer
155
158
  end
156
159
 
157
160
  def has_state?(attribute)
161
+ attribute = attribute.to_s
158
162
  attribute = attribute.sub(/\?$/, '').sub(/=$/, '')
159
163
  if @tk.respond_to?(:tile_state)
160
164
  begin
@@ -170,6 +174,7 @@ module Glimmer
170
174
  end
171
175
 
172
176
  def has_attributes_attribute?(attribute)
177
+ attribute = attribute.to_s
173
178
  attribute = attribute.sub(/\?$/, '').sub(/=$/, '')
174
179
  @tk.respond_to?(:attributes) && @tk.attributes.keys.include?(attribute.to_s)
175
180
  end
@@ -39,7 +39,6 @@ require 'delegate'
39
39
  # require 'ext/glimmer/config'
40
40
  # require 'ext/glimmer'
41
41
  require 'glimmer/dsl/tk/dsl'
42
- require 'glimmer/tk/drag_and_drop_extension'
43
42
 
44
43
  Glimmer::Config.loop_max_count = -1
45
44
 
@@ -47,9 +47,9 @@ class HelloButton
47
47
  default 'active'
48
48
  focus true
49
49
 
50
- on('command') {
50
+ on('command') do
51
51
  self.count += 1
52
- }
52
+ end
53
53
  }
54
54
  }
55
55
 
@@ -64,9 +64,9 @@ class HelloButton
64
64
  button {
65
65
  image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
66
66
 
67
- on('command') {
67
+ on('command') do
68
68
  message_box(title: 'Image Button', message: 'Image Button Clicked!')
69
- }
69
+ end
70
70
  }
71
71
  }
72
72
 
@@ -84,9 +84,9 @@ class HelloButton
84
84
  text "#{compound_option.capitalize} Image"
85
85
  compound compound_option
86
86
 
87
- on('command') {
87
+ on('command') do
88
88
  message_box(title: 'Text Image Button', message: 'Text Image Button Clicked!', detail: "(#{compound_option})")
89
- }
89
+ end
90
90
  }
91
91
  end
92
92
  }
@@ -53,11 +53,12 @@ root {
53
53
  text "Drag entry text"
54
54
  width 30
55
55
 
56
+ # drag_source true
56
57
  # This is how to do `drag_source true` the manual way for use in exceptional cases
57
- on_drag_start do |event|
58
+ on('drag_start') do |event|
58
59
  event.data = event.source.text
59
60
  event.source.configure(:cursor => "hand2")
60
- event.tooltip.content {
61
+ event.tooltip.content { # re-open tooltip content and add a label
61
62
  lbl { # non-tile-theme version of label
62
63
  text event.data + " "
63
64
  bg "yellow"
@@ -66,7 +67,7 @@ root {
66
67
  }
67
68
  }
68
69
  end
69
- on_drag_motion do |event|
70
+ on('drag_motion') do |event|
70
71
  if event.drop_accepted?
71
72
  event.source.configure(:cursor => "hand1")
72
73
  else
@@ -86,9 +87,7 @@ root {
86
87
  values %w[USA Canada Mexico Columbia UK Australia Germany Italy Spain]
87
88
  width 27
88
89
 
89
- on_drag_start do |event|
90
- event.data = event.source.text
91
- end
90
+ drag_source true
92
91
  }
93
92
 
94
93
  label {
@@ -102,7 +101,9 @@ root {
102
101
  selection 'Canada'
103
102
  height 3
104
103
 
105
- on_drag_start do |event|
104
+ # drag_source true
105
+ # This is another alternative to `drag_source true` with manual specification of transferred data only
106
+ on('drag_start') do |event|
106
107
  event.data = event.source.selection.first
107
108
  end
108
109
  }
@@ -133,9 +134,7 @@ root {
133
134
  borderwidth 2
134
135
  relief "solid"
135
136
 
136
- on_drop do |event|
137
- event.target.text = event.data
138
- end
137
+ drop_target true
139
138
  }
140
139
 
141
140
  label {
@@ -146,9 +145,7 @@ root {
146
145
  grid :row => 1, :column => 1, :pady => 5, :sticky => "e"
147
146
  width 30
148
147
 
149
- on_drop { |event|
150
- event.target.text = event.data
151
- }
148
+ drop_target true
152
149
  }
153
150
 
154
151
  label {
@@ -159,9 +156,7 @@ root {
159
156
  grid :row => 2, :column => 1, :pady => 5, :sticky => "e"
160
157
  width 27
161
158
 
162
- on_drop do |event|
163
- event.target.text = event.data
164
- end
159
+ drop_target true
165
160
  }
166
161
 
167
162
  label {
@@ -173,9 +168,7 @@ root {
173
168
  selectmode 'browse'
174
169
  height 3
175
170
 
176
- on_drop do |event|
177
- event.target.items += [event.data]
178
- end
171
+ drop_target true
179
172
  }
180
173
 
181
174
  label {
@@ -186,9 +179,7 @@ root {
186
179
  grid :row => 4, :column => 1, :pady => 5, :sticky => "w"
187
180
  text "Drop here"
188
181
 
189
- on_drop do |event|
190
- event.target.text = event.data
191
- end
182
+ drop_target true
192
183
  }
193
184
 
194
185
  label {
@@ -198,8 +189,10 @@ root {
198
189
  checkbutton {
199
190
  grid :row => 5, :column => 1, :pady => 5, :sticky => "w"
200
191
  text "Drop here to destroy a widget"
201
-
202
- on_drop do |event|
192
+
193
+ # drop_target true
194
+ # This is an alternative to `drop_target true` with manual consumption of transferred data
195
+ on('drop') do |event|
203
196
  event.target.text = event.data
204
197
  # execute asynchronously after 100ms to ensure all events have been processed before destruction
205
198
  ::Tk.after(100) {event.source.destroy}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-tk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.45
4
+ version: 0.0.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
@@ -208,7 +208,7 @@ files:
208
208
  - lib/glimmer/dsl/tk/widget_expression.rb
209
209
  - lib/glimmer/tk/checkbutton_proxy.rb
210
210
  - lib/glimmer/tk/combobox_proxy.rb
211
- - lib/glimmer/tk/drag_and_drop_extension.rb
211
+ - lib/glimmer/tk/draggable_and_droppable.rb
212
212
  - lib/glimmer/tk/entry_proxy.rb
213
213
  - lib/glimmer/tk/frame_proxy.rb
214
214
  - lib/glimmer/tk/label_proxy.rb