glimmer-dsl-tk 0.0.43 → 0.0.47
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +92 -83
- data/VERSION +1 -1
- data/glimmer-dsl-tk.gemspec +0 -0
- data/lib/glimmer/dsl/tk/list_selection_data_binding_expression.rb +1 -1
- data/lib/glimmer/tk/{drag_and_drop_extension.rb → draggable_and_droppable.rb} +83 -11
- data/lib/glimmer/tk/lbl_proxy.rb +33 -0
- data/lib/glimmer/tk/menu_proxy.rb +5 -5
- data/lib/glimmer/tk/root_proxy.rb +1 -1
- data/lib/glimmer/tk/scrollbar_frame_proxy.rb +1 -1
- data/lib/glimmer/tk/widget.rb +28 -0
- data/lib/glimmer/tk/widget_proxy.rb +26 -2
- data/lib/glimmer-dsl-tk.rb +0 -1
- data/samples/hello/hello_button.rb +6 -6
- data/samples/hello/hello_drag_and_drop.rb +52 -67
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a534fbbe0b7c850fe702b42bf16eb4bc1854f68baa736b73ebf0bf6d5cc29f28
|
4
|
+
data.tar.gz: b38740259743b4e579ec72251dee2018f826007dc975b3efe8a4b90d9b5031da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03d144a49d2494ce0ff6576aaf510157d15086868f69d14bf70c27b3c7ed08e68125a86892ace5c9c178b52255252ad44a3b90ba49e7ff91e71d5e47af301f7c
|
7
|
+
data.tar.gz: 7543abee9889820cea1911ec3f6c395ea61ad96e761b8f7ad384cc17b50140854fb524852055e34eea7d221a38047bd1d3f053866a6d8b17363066739383529a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.47
|
4
|
+
|
5
|
+
- Upgrade to glimmer 2.5.1 (includes more advanced data-binding/observer features)
|
6
|
+
|
7
|
+
## 0.0.46
|
8
|
+
|
9
|
+
- Support `drag_source true` on `list` widget
|
10
|
+
- 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)
|
11
|
+
- 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')`)
|
12
|
+
|
13
|
+
## 0.0.45
|
14
|
+
|
15
|
+
- Support `lbl` widget as the non-tile-themed version of `label` (i.e. `::TkLabel` not `::Tk::Tile::TLabel`)
|
16
|
+
- Add `#proxy` method to all Tk widgets to return Glimmer widget proxy objects (e.g. `Tk::Tile::TButton#proxy` returns `Glimmer::Tk::WidgetProxy` object)
|
17
|
+
- Provide question mark alias of `event.drop_accepted` (i.e. `drop_accepted?`)
|
18
|
+
- Have `DragAndDropEvent` `source`/`target` be the enhanced Glimmer widget proxy instead of the unenhanced Tk widget
|
19
|
+
- Look into improving code that uses `TkLabel` explicitly in Hello, Drag and Drop! (do `event.tooltip.content {label {...} }` with Glimmer DSL instead)
|
20
|
+
- Add Glimmer Style Guide
|
21
|
+
- Fix issue with dropping button and list unto checkbox in Hello, Drag and Drop!
|
22
|
+
|
23
|
+
## 0.0.44
|
24
|
+
|
25
|
+
- Fix issue with not being able to drop list into checkbox in Hello, Drag and Drop! by disabling functionality for list just like button
|
26
|
+
|
3
27
|
## 0.0.43
|
4
28
|
|
5
29
|
- Modified Hello, Drag and Drop! to include a list
|
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.
|
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.47
|
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)
|
@@ -100,6 +100,7 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
|
|
100
100
|
- [Radiobutton Data-Binding](#radiobutton-data-binding)
|
101
101
|
- [Command Callback](#command-callback)
|
102
102
|
- [Gotchas](#gotchas)
|
103
|
+
- [Glimmer Style Guide](#glimmer-style-guide)
|
103
104
|
- [Samples](#samples)
|
104
105
|
- [Hello, World!](#hello-world)
|
105
106
|
- [Hello, Button!](#hello-button)
|
@@ -181,7 +182,7 @@ gem install glimmer-dsl-tk
|
|
181
182
|
|
182
183
|
Add the following to `Gemfile`:
|
183
184
|
```
|
184
|
-
gem 'glimmer-dsl-tk', '0.0.
|
185
|
+
gem 'glimmer-dsl-tk', '0.0.47'
|
185
186
|
```
|
186
187
|
|
187
188
|
And, then run:
|
@@ -225,6 +226,8 @@ The Glimmer GUI DSL follows these simple concepts in mapping from Tk syntax:
|
|
225
226
|
- **Content/Options Block**: Any keyword may optionally be followed by a Ruby curly-brace block containing nested widgets (content) and attributes (options). Attributes are simply Tk option keywords followed by arguments and no block (e.g. `title 'Hello, World!'` under a `root`)
|
226
227
|
- **Event Binding Block**: `on(event) {}` keyword receiving a Tk binding event name (e.g. `KeyPress` or `ComboboxSelected`). Surrounding event by `<>` is optional as [Glimmer DSL for Tk](https://rubygems.org/gems/glimmer-dsl-tk) can take care of that automatically.
|
227
228
|
|
229
|
+
Note that Glimmer widgets are proxy objects (wrappers) for Tk widgets. To get wrapped Tk widget from a Glimmer widget, you simply invoke `#tk` method. To get the proxy of a wrapped Tk widget, you may invoke `#proxy` method.
|
230
|
+
|
228
231
|
Example of an app written in [Tk](https://www.tcl.tk/) imperative syntax:
|
229
232
|
|
230
233
|
```ruby
|
@@ -303,6 +306,7 @@ keyword(args) | attributes | event bindings & callbacks
|
|
303
306
|
`spinbox` | `text`, `from`, `to`, `increment`, `format`, [more attributes](https://tcl.tk/man/tcl8.6/TkCmd/text.htm#M116) | `command {}`, `'increment'`, `'decrement'`
|
304
307
|
`frame(text: nil)` | `width`, `height`, `borderwidth`, `relief` (`'flat' (default), 'raised', 'sunken', 'solid', 'ridge', 'groove'`) | None
|
305
308
|
`label` | `text`, `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `font` (`'default', 'text', 'fixed', 'menu', 'heading', 'caption', 'small_caption', 'icon', 'tooltip'`), `relief` (`'flat' (default), 'raised', 'sunken', 'solid', 'ridge', 'groove'`), `justify` (`'left', 'center', 'right'`), `foreground`, `background` | None
|
309
|
+
`lbl` (non-tile-themed version of `label`) | `text`, `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `font` (`'default', 'text', 'fixed', 'menu', 'heading', 'caption', 'small_caption', 'icon', 'tooltip'`), `relief` (`'flat' (default), 'raised', 'sunken', 'solid', 'ridge', 'groove'`), `justify` (`'left', 'center', 'right'`), `foreground`, `background`, `bg`, `bitmap`, [more here](https://tcl.tk/man/tcl8.6/TkCmd/label.htm) | None
|
306
310
|
`list` | `selectmode`, `selection` | None
|
307
311
|
`message_box(type: , message: , detail: , title: , icon: , default: , parent: )` | None | None
|
308
312
|
`menu(label: nil) (label is nil if nested under root/toplevel for menu bar)` | None | None
|
@@ -476,14 +480,23 @@ Check out the [Hello, Scrollbar!](#hello-scrollbar) sample for a `text` demo wit
|
|
476
480
|
|
477
481
|
#### Drag and Drop API
|
478
482
|
|
479
|
-
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
|
+
|
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`
|
480
488
|
|
481
|
-
|
482
|
-
- `
|
483
|
-
- `on_drag_motion {|event| ...}`: fires on drag motion receiving an `event` arg to check `event#drop_accepted`, and configure `source` and `tooltip`
|
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.
|
484
491
|
|
485
|
-
|
486
|
-
- `
|
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
|
487
500
|
|
488
501
|
Learn more at the [Hello, Drag and Drop!](#hello-drag-and-drop) sample.
|
489
502
|
|
@@ -824,6 +837,17 @@ More details can be found in the [Hello, Button!](#hello-button) sample below.
|
|
824
837
|
|
825
838
|
- Setting `background` attribute on `frame` or `label` does not work in `'aqua'` theme on the Mac (only in `'classic'` theme)
|
826
839
|
|
840
|
+
## Glimmer Style Guide
|
841
|
+
|
842
|
+
- Widget arguments are always wrapped by parentheses.
|
843
|
+
- Widget blocks are always declared with curly braces `{}` to clearly visualize hierarchical view code and separate from logic code.
|
844
|
+
- Widget attribute declarations always have arguments that are never wrapped inside parentheses and never take a block.
|
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)
|
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.
|
850
|
+
|
827
851
|
## Samples
|
828
852
|
|
829
853
|
The easiest way to run samples is by launching the Glimmer Meta-Sample (the Sample of Samples).
|
@@ -1026,14 +1050,14 @@ class HelloButton
|
|
1026
1050
|
text 'Text Button'
|
1027
1051
|
}
|
1028
1052
|
|
1029
|
-
button {
|
1053
|
+
button { |b|
|
1030
1054
|
text <= [self, :count, on_read: ->(value) { "Click To Increment: #{value} " }]
|
1031
1055
|
default 'active'
|
1032
1056
|
focus true
|
1033
1057
|
|
1034
|
-
command
|
1058
|
+
on('command') do
|
1035
1059
|
self.count += 1
|
1036
|
-
|
1060
|
+
end
|
1037
1061
|
}
|
1038
1062
|
}
|
1039
1063
|
|
@@ -1048,9 +1072,9 @@ class HelloButton
|
|
1048
1072
|
button {
|
1049
1073
|
image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
|
1050
1074
|
|
1051
|
-
command
|
1075
|
+
on('command') do
|
1052
1076
|
message_box(title: 'Image Button', message: 'Image Button Clicked!')
|
1053
|
-
|
1077
|
+
end
|
1054
1078
|
}
|
1055
1079
|
}
|
1056
1080
|
|
@@ -1065,12 +1089,12 @@ class HelloButton
|
|
1065
1089
|
['center', 'top', 'bottom', 'left', 'right'].each do |compound_option|
|
1066
1090
|
button {
|
1067
1091
|
image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
|
1068
|
-
text
|
1092
|
+
text "#{compound_option.capitalize} Image"
|
1069
1093
|
compound compound_option
|
1070
1094
|
|
1071
|
-
command
|
1095
|
+
on('command') do
|
1072
1096
|
message_box(title: 'Text Image Button', message: 'Text Image Button Clicked!', detail: "(#{compound_option})")
|
1073
|
-
|
1097
|
+
end
|
1074
1098
|
}
|
1075
1099
|
end
|
1076
1100
|
}
|
@@ -2699,27 +2723,40 @@ root {
|
|
2699
2723
|
|
2700
2724
|
label {
|
2701
2725
|
grid :row => 0, :column => 0
|
2702
|
-
text "
|
2726
|
+
text "Label"
|
2727
|
+
}
|
2728
|
+
label {
|
2729
|
+
grid :row => 0, :column => 1, :pady => 10, :sticky => "e"
|
2730
|
+
text "Drag label text"
|
2731
|
+
width 30
|
2732
|
+
drag_source true
|
2703
2733
|
}
|
2704
2734
|
|
2735
|
+
label {
|
2736
|
+
grid :row => 1, :column => 0
|
2737
|
+
text "Entry"
|
2738
|
+
}
|
2705
2739
|
entry {
|
2706
|
-
grid :row =>
|
2740
|
+
grid :row => 1, :column => 1, :pady => 5, :sticky => "e"
|
2707
2741
|
text "Drag entry text"
|
2708
2742
|
width 30
|
2709
2743
|
|
2710
|
-
|
2711
|
-
|
2744
|
+
# drag_source true
|
2745
|
+
# This is how to do `drag_source true` the manual way for use in exceptional cases
|
2746
|
+
on('drag_start') do |event|
|
2747
|
+
event.data = event.source.text
|
2712
2748
|
event.source.configure(:cursor => "hand2")
|
2713
|
-
|
2714
|
-
|
2715
|
-
|
2716
|
-
|
2717
|
-
|
2718
|
-
|
2749
|
+
event.tooltip.content { # re-open tooltip content and add a label
|
2750
|
+
lbl { # non-tile-theme version of label
|
2751
|
+
text event.data + " "
|
2752
|
+
bg "yellow"
|
2753
|
+
bitmap "warning"
|
2754
|
+
compound "right"
|
2755
|
+
}
|
2756
|
+
}
|
2719
2757
|
end
|
2720
|
-
|
2721
|
-
|
2722
|
-
if event.drop_accepted
|
2758
|
+
on('drag_motion') do |event|
|
2759
|
+
if event.drop_accepted?
|
2723
2760
|
event.source.configure(:cursor => "hand1")
|
2724
2761
|
else
|
2725
2762
|
event.source.configure(:cursor => "hand2")
|
@@ -2728,48 +2765,34 @@ root {
|
|
2728
2765
|
end
|
2729
2766
|
}
|
2730
2767
|
|
2731
|
-
label {
|
2732
|
-
grid :row => 1, :column => 0
|
2733
|
-
text "Label"
|
2734
|
-
}
|
2735
|
-
|
2736
|
-
label {
|
2737
|
-
grid :row => 1, :column => 1, :pady => 10, :sticky => "e"
|
2738
|
-
text "Drag label text"
|
2739
|
-
width 30
|
2740
|
-
drag_source true
|
2741
|
-
}
|
2742
|
-
|
2743
2768
|
label {
|
2744
2769
|
grid :row => 2, :column => 0
|
2745
2770
|
text "Combobox"
|
2746
2771
|
}
|
2747
|
-
|
2748
2772
|
combobox {
|
2749
2773
|
grid :row => 2, :column => 1, :pady => 5, :sticky => "e"
|
2750
2774
|
text "Spain"
|
2751
2775
|
values %w[USA Canada Mexico Columbia UK Australia Germany Italy Spain]
|
2752
2776
|
width 27
|
2753
2777
|
|
2754
|
-
|
2755
|
-
event.data = event.source.textvariable&.value
|
2756
|
-
end
|
2778
|
+
drag_source true
|
2757
2779
|
}
|
2758
2780
|
|
2759
2781
|
label {
|
2760
2782
|
grid :row => 3, :column => 0
|
2761
2783
|
text 'List'
|
2762
2784
|
}
|
2763
|
-
|
2764
|
-
country_list = list {
|
2785
|
+
list {
|
2765
2786
|
grid :row => 3, :column => 1, :pady => 5, :sticky => "e"
|
2766
2787
|
selectmode 'browse'
|
2767
2788
|
items %w[USA Canada Mexico]
|
2768
2789
|
selection 'Canada'
|
2769
2790
|
height 3
|
2770
2791
|
|
2771
|
-
|
2772
|
-
|
2792
|
+
# drag_source true
|
2793
|
+
# This is another alternative to `drag_source true` with manual specification of transferred data only
|
2794
|
+
on('drag_start') do |event|
|
2795
|
+
event.data = event.source.selection.first
|
2773
2796
|
end
|
2774
2797
|
}
|
2775
2798
|
|
@@ -2777,7 +2800,6 @@ root {
|
|
2777
2800
|
grid :row => 4, :column => 0
|
2778
2801
|
text "Button"
|
2779
2802
|
}
|
2780
|
-
|
2781
2803
|
button {
|
2782
2804
|
grid :row => 4, :column => 1, :pady => 5, :sticky => "w"
|
2783
2805
|
text "Drag it"
|
@@ -2792,89 +2814,76 @@ root {
|
|
2792
2814
|
|
2793
2815
|
label {
|
2794
2816
|
grid :row => 0, :column => 0
|
2795
|
-
text "
|
2817
|
+
text "Label"
|
2796
2818
|
}
|
2797
|
-
|
2798
|
-
|
2799
|
-
grid :row => 0, :column => 1, :pady => 5, :sticky => "e"
|
2819
|
+
label {
|
2820
|
+
grid :row => 0, :column => 1, :pady => 10, :sticky => "e"
|
2800
2821
|
width 30
|
2822
|
+
borderwidth 2
|
2823
|
+
relief "solid"
|
2801
2824
|
|
2802
|
-
|
2803
|
-
event.target.textvariable.value = event.data
|
2804
|
-
}
|
2825
|
+
drop_target true
|
2805
2826
|
}
|
2806
2827
|
|
2807
2828
|
label {
|
2808
2829
|
grid :row => 1, :column => 0
|
2809
|
-
text "
|
2830
|
+
text "Entry"
|
2810
2831
|
}
|
2811
|
-
|
2812
|
-
|
2813
|
-
grid :row => 1, :column => 1, :pady => 10, :sticky => "e"
|
2832
|
+
entry {
|
2833
|
+
grid :row => 1, :column => 1, :pady => 5, :sticky => "e"
|
2814
2834
|
width 30
|
2815
|
-
borderwidth 2
|
2816
|
-
relief "solid"
|
2817
2835
|
|
2818
|
-
|
2819
|
-
event.target.textvariable.value = event.data
|
2820
|
-
end
|
2836
|
+
drop_target true
|
2821
2837
|
}
|
2822
2838
|
|
2823
2839
|
label {
|
2824
2840
|
grid :row => 2, :column => 0
|
2825
2841
|
text "Combobox"
|
2826
2842
|
}
|
2827
|
-
|
2828
2843
|
combobox {
|
2829
2844
|
grid :row => 2, :column => 1, :pady => 5, :sticky => "e"
|
2830
2845
|
width 27
|
2831
2846
|
|
2832
|
-
|
2833
|
-
event.target.textvariable.value = event.data
|
2834
|
-
end
|
2847
|
+
drop_target true
|
2835
2848
|
}
|
2836
2849
|
|
2837
2850
|
label {
|
2838
2851
|
grid :row => 3, :column => 0
|
2839
2852
|
text 'List'
|
2840
2853
|
}
|
2841
|
-
|
2842
2854
|
list {
|
2843
2855
|
grid :row => 3, :column => 1, :pady => 5, :sticky => "e"
|
2844
2856
|
selectmode 'browse'
|
2845
2857
|
height 3
|
2846
2858
|
|
2847
|
-
|
2848
|
-
event.target.insert('', 'end', :text => event.data)
|
2849
|
-
end
|
2859
|
+
drop_target true
|
2850
2860
|
}
|
2851
2861
|
|
2852
2862
|
label {
|
2853
2863
|
grid :row => 4, :column => 0
|
2854
2864
|
text "Button"
|
2855
2865
|
}
|
2856
|
-
|
2857
2866
|
button {
|
2858
2867
|
grid :row => 4, :column => 1, :pady => 5, :sticky => "w"
|
2859
2868
|
text "Drop here"
|
2860
2869
|
|
2861
|
-
|
2862
|
-
event.target.text = event.data
|
2863
|
-
end
|
2870
|
+
drop_target true
|
2864
2871
|
}
|
2865
2872
|
|
2866
2873
|
label {
|
2867
2874
|
grid :row => 5, :column => 0
|
2868
2875
|
text "Checkbutton"
|
2869
2876
|
}
|
2870
|
-
|
2871
2877
|
checkbutton {
|
2872
2878
|
grid :row => 5, :column => 1, :pady => 5, :sticky => "w"
|
2873
|
-
text "Drop here to destroy a widget
|
2874
|
-
|
2875
|
-
|
2879
|
+
text "Drop here to destroy a widget"
|
2880
|
+
|
2881
|
+
# drop_target true
|
2882
|
+
# This is an alternative to `drop_target true` with manual consumption of transferred data
|
2883
|
+
on('drop') do |event|
|
2876
2884
|
event.target.text = event.data
|
2877
|
-
|
2885
|
+
# execute asynchronously after 100ms to ensure all events have been processed before destruction
|
2886
|
+
::Tk.after(100) {event.source.destroy}
|
2878
2887
|
end
|
2879
2888
|
}
|
2880
2889
|
}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.47
|
data/glimmer-dsl-tk.gemspec
CHANGED
Binary file
|
@@ -50,7 +50,7 @@ module Glimmer
|
|
50
50
|
#TODO check if nested data binding works for list widget and other widgets that need custom data binding
|
51
51
|
list_selection_binding.observe(model, model_binding.property_name_expression)
|
52
52
|
|
53
|
-
parent.
|
53
|
+
parent.on('<TreeviewSelect>') do
|
54
54
|
model_binding.call(list_selection_binding.evaluate_property)
|
55
55
|
end
|
56
56
|
end
|
@@ -1,9 +1,43 @@
|
|
1
|
+
# Copyright (c) 2020-2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
1
22
|
require "json"
|
2
23
|
|
3
24
|
module Glimmer
|
4
25
|
module Tk
|
5
|
-
|
26
|
+
module DraggableAndDroppable
|
6
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
|
7
41
|
|
8
42
|
def drag_source=(value)
|
9
43
|
@drag_source = value
|
@@ -14,6 +48,15 @@ module Glimmer
|
|
14
48
|
end
|
15
49
|
end
|
16
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
|
+
|
17
60
|
def on_drag_start_block=(block)
|
18
61
|
@on_drag_start_block = block
|
19
62
|
make_draggable
|
@@ -23,7 +66,7 @@ module Glimmer
|
|
23
66
|
@on_drop_block = value
|
24
67
|
self.tk.bind("<DropEvent>", proc { |tk_event|
|
25
68
|
drop_event = DragAndDropEvent.json_create(JSON.parse("{" + tk_event.detail + "}"))
|
26
|
-
@on_drop_block.call(drop_event) if self
|
69
|
+
@on_drop_block.call(drop_event) if self == drop_event.target
|
27
70
|
})
|
28
71
|
self.tk.bind("<DropCheckEvent>", proc { |tk_event|
|
29
72
|
drop_check_event = DragAndDropEvent.json_create(JSON.parse("{" + tk_event.detail + "}"))
|
@@ -40,23 +83,36 @@ module Glimmer
|
|
40
83
|
bind("<DropAcceptedEvent>", proc { |event| drag_event.drop_accepted = true })
|
41
84
|
bind("B1-Motion", proc { |tk_event|
|
42
85
|
if drag_event.nil?
|
43
|
-
tooltip =
|
86
|
+
tooltip = WidgetProxy.new('toplevel', root_parent_proxy, [])
|
87
|
+
tooltip.overrideredirect(1) #create tooltip window to display dragged data
|
44
88
|
tooltip.geometry("+#{tk_event.x_root + 10}+#{tk_event.y_root - 2}")
|
45
|
-
drag_event = DragAndDropEvent.new(self
|
89
|
+
drag_event = DragAndDropEvent.new(self, nil, tooltip, tk_event.x_root, tk_event.y_root, nil, false)
|
46
90
|
if @drag_source
|
47
91
|
tk_event.widget.configure(:cursor => "hand2")
|
48
92
|
# Default data to drag is text
|
49
|
-
drag_event.data = if textvariable_defined?
|
50
|
-
|
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
|
100
|
+
tooltip_label = WidgetProxy.new('label', tooltip, [])
|
101
|
+
tooltip_label.text = drag_event.data
|
102
|
+
tooltip_label.pack # TODO look into using grid instead to be consistent with the modern Tk way
|
51
103
|
elsif !@on_drag_start_block.nil?
|
52
104
|
@on_drag_start_block.call(drag_event)
|
53
|
-
|
105
|
+
if tooltip.winfo_children().length == 0
|
106
|
+
tooltip_label = WidgetProxy.new('label', tooltip, [])
|
107
|
+
tooltip_label.text = drag_event.data
|
108
|
+
tooltip_label.pack # TODO look into using grid instead to be consistent with the modern Tk way
|
109
|
+
end
|
54
110
|
end
|
55
111
|
else
|
56
112
|
drag_event.x_root, drag_event.y_root = tk_event.x_root, tk_event.y_root
|
57
113
|
drag_event.drop_accepted = false
|
58
114
|
move_over_widget = tk_event.widget.winfo_containing(tk_event.x_root, tk_event.y_root)
|
59
|
-
drag_event.target = move_over_widget
|
115
|
+
drag_event.target = move_over_widget.proxy
|
60
116
|
move_over_widget.event_generate("<DropCheckEvent>", :data => drag_event.to_json)
|
61
117
|
if @on_drag_motion_block.nil?
|
62
118
|
# Default motion behavior:
|
@@ -75,7 +131,7 @@ module Glimmer
|
|
75
131
|
})
|
76
132
|
bind("ButtonRelease-1", proc { |tk_event|
|
77
133
|
if drag_event
|
78
|
-
drag_event.target = tk_event.widget.winfo_containing(tk_event.x_root, tk_event.y_root)
|
134
|
+
drag_event.target = tk_event.widget.winfo_containing(tk_event.x_root, tk_event.y_root).proxy
|
79
135
|
drag_event.source.configure(:cursor => "")
|
80
136
|
drag_event.target.event_generate("<DropEvent>", :data => drag_event.to_json)
|
81
137
|
drag_event.tooltip.destroy
|
@@ -90,7 +146,23 @@ module Glimmer
|
|
90
146
|
@tk.bind_remove("<DropAcceptedEvent>")
|
91
147
|
end
|
92
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
|
+
|
93
163
|
DragAndDropEvent = Struct.new(:source, :target, :tooltip, :x_root, :y_root, :data, :drop_accepted) do
|
164
|
+
alias drop_accepted? drop_accepted
|
165
|
+
|
94
166
|
def as_json(*)
|
95
167
|
klass = self.class.name
|
96
168
|
{
|
@@ -104,9 +176,9 @@ module Glimmer
|
|
104
176
|
end
|
105
177
|
|
106
178
|
def self.json_create(object)
|
107
|
-
new(*[ObjectSpace._id2ref(object["v"][0]), ObjectSpace._id2ref(object["v"][1]), ObjectSpace._id2ref(object["v"][2])].concat(object["v"].drop 3))
|
179
|
+
new(*[ObjectSpace._id2ref(object["v"][0]), ObjectSpace._id2ref(object["v"][1]).proxy, ObjectSpace._id2ref(object["v"][2])].concat(object["v"].drop 3))
|
108
180
|
end
|
109
181
|
end
|
110
182
|
end
|
111
183
|
end
|
112
|
-
end
|
184
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright (c) 2020-2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/tk/widget_proxy'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module Tk
|
26
|
+
# Non-Themable (non-Tile) Tk Label
|
27
|
+
class LblProxy < WidgetProxy
|
28
|
+
def build_widget
|
29
|
+
@tk = ::TkLabel.new(@parent_proxy.tk, *args).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -63,20 +63,20 @@ module Glimmer
|
|
63
63
|
def build_widget
|
64
64
|
if application?
|
65
65
|
if OS.mac?
|
66
|
-
@tk = ::TkSysMenu_Apple.new(@parent_proxy.tk)
|
66
|
+
@tk = ::TkSysMenu_Apple.new(@parent_proxy.tk).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
|
67
67
|
@parent_proxy.tk.add :cascade, :menu => @tk
|
68
68
|
end
|
69
69
|
else
|
70
70
|
if @parent_proxy.parent_proxy.is_a?(ToplevelProxy) && (OS.mac? || OS.linux?) && help?
|
71
|
-
@tk = ::TkSysMenu_Help.new(@parent_proxy.tk)
|
71
|
+
@tk = ::TkSysMenu_Help.new(@parent_proxy.tk).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
|
72
72
|
elsif @parent_proxy.parent_proxy.is_a?(ToplevelProxy) && OS.mac? && window?
|
73
|
-
@tk = ::Tk::TkSysMenu_Window.new(@parent_proxy.tk)
|
73
|
+
@tk = ::Tk::TkSysMenu_Window.new(@parent_proxy.tk).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
|
74
74
|
# Windows system menu does not seem to work
|
75
75
|
# elsif @parent_proxy.parent_proxy.is_a?(ToplevelProxy) && OS.windows? && system?
|
76
|
-
# @tk = ::TkSysMenu_System.new(@parent_proxy.tk)
|
76
|
+
# @tk = ::TkSysMenu_System.new(@parent_proxy.tk).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
|
77
77
|
else
|
78
78
|
tk_widget_class = self.class.tk_widget_class_for(@keyword)
|
79
|
-
@tk = tk_widget_class.new(@parent_proxy.tk)
|
79
|
+
@tk = tk_widget_class.new(@parent_proxy.tk).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
|
80
80
|
end
|
81
81
|
case @parent_proxy
|
82
82
|
when MenuProxy
|
@@ -28,7 +28,7 @@ module Glimmer
|
|
28
28
|
# Follows the Proxy Design Pattern
|
29
29
|
class RootProxy < ToplevelProxy
|
30
30
|
def initialize(*args, &block)
|
31
|
-
@tk = ::TkRoot.new
|
31
|
+
@tk = ::TkRoot.new.tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
|
32
32
|
@tk.minsize = DEFAULT_WIDTH, DEFAULT_HEIGHT
|
33
33
|
initialize_defaults
|
34
34
|
post_add_content if block.nil?
|
@@ -103,7 +103,7 @@ module Glimmer
|
|
103
103
|
build_yscrollbar
|
104
104
|
build_xscrollbar
|
105
105
|
tk_widget_class = self.class.tk_widget_class_for('frame')
|
106
|
-
@tk = tk_widget_class.new(@canvas_proxy.tk, *args)
|
106
|
+
@tk = tk_widget_class.new(@canvas_proxy.tk, *args).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
|
107
107
|
TkcWindow.new(@canvas_proxy.tk, 0, 0, :anchor => "nw", :window => @tk)
|
108
108
|
end
|
109
109
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2020-2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
module Glimmer
|
23
|
+
module Tk
|
24
|
+
module Widget
|
25
|
+
attr_accessor :proxy
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -20,6 +20,8 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/data_binding/tk/one_time_observer'
|
23
|
+
require 'glimmer/tk/widget'
|
24
|
+
require 'glimmer/tk/draggable_and_droppable'
|
23
25
|
|
24
26
|
module Glimmer
|
25
27
|
module Tk
|
@@ -68,9 +70,12 @@ module Glimmer
|
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
73
|
+
prepend DraggableAndDroppable
|
74
|
+
|
71
75
|
FONTS_PREDEFINED = %w[default text fixed menu heading caption small_caption icon tooltip]
|
72
76
|
|
73
|
-
attr_reader :parent_proxy, :tk, :args, :keyword, :children
|
77
|
+
attr_reader :parent_proxy, :tk, :args, :keyword, :children, :bind_ids, :destroyed
|
78
|
+
alias destroyed? destroyed
|
74
79
|
|
75
80
|
# Initializes a new Tk Widget
|
76
81
|
#
|
@@ -153,6 +158,7 @@ module Glimmer
|
|
153
158
|
end
|
154
159
|
|
155
160
|
def has_state?(attribute)
|
161
|
+
attribute = attribute.to_s
|
156
162
|
attribute = attribute.sub(/\?$/, '').sub(/=$/, '')
|
157
163
|
if @tk.respond_to?(:tile_state)
|
158
164
|
begin
|
@@ -168,6 +174,7 @@ module Glimmer
|
|
168
174
|
end
|
169
175
|
|
170
176
|
def has_attributes_attribute?(attribute)
|
177
|
+
attribute = attribute.to_s
|
171
178
|
attribute = attribute.sub(/\?$/, '').sub(/=$/, '')
|
172
179
|
@tk.respond_to?(:attributes) && @tk.attributes.keys.include?(attribute.to_s)
|
173
180
|
end
|
@@ -288,8 +295,10 @@ module Glimmer
|
|
288
295
|
end
|
289
296
|
|
290
297
|
def destroy
|
298
|
+
unbind_all
|
291
299
|
@tk.destroy
|
292
300
|
@on_destroy_procs&.each {|p| p.call(@tk)}
|
301
|
+
@destroyed = true
|
293
302
|
end
|
294
303
|
|
295
304
|
def apply_style(options)
|
@@ -491,6 +500,16 @@ module Glimmer
|
|
491
500
|
handle_listener(listener_name, &listener)
|
492
501
|
end
|
493
502
|
|
503
|
+
def unbind_all
|
504
|
+
@listeners&.keys&.each do |key|
|
505
|
+
if key.to_s.downcase.include?('command')
|
506
|
+
@tk.send(key, '')
|
507
|
+
else
|
508
|
+
@tk.bind(key, '')
|
509
|
+
end
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
494
513
|
def content(&block)
|
495
514
|
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Tk::WidgetExpression.new, keyword, *args, &block)
|
496
515
|
end
|
@@ -514,6 +533,11 @@ module Glimmer
|
|
514
533
|
!super_only && tk.respond_to?(method, *args, &block)
|
515
534
|
end
|
516
535
|
|
536
|
+
# inspect is overridden to prevent printing very long stack traces
|
537
|
+
def inspect
|
538
|
+
"#{super[0, 150]}... >"
|
539
|
+
end
|
540
|
+
|
517
541
|
private
|
518
542
|
|
519
543
|
# The griddable parent widget proxy to apply grid to (is different from @tk in composite widgets like notebook or scrolledframe)
|
@@ -528,7 +552,7 @@ module Glimmer
|
|
528
552
|
|
529
553
|
def build_widget
|
530
554
|
tk_widget_class = self.class.tk_widget_class_for(@keyword)
|
531
|
-
@tk = tk_widget_class.new(@parent_proxy.tk, *args)
|
555
|
+
@tk = tk_widget_class.new(@parent_proxy.tk, *args).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
|
532
556
|
end
|
533
557
|
|
534
558
|
def initialize_defaults
|
data/lib/glimmer-dsl-tk.rb
CHANGED
@@ -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
|
}
|
@@ -35,27 +35,40 @@ root {
|
|
35
35
|
|
36
36
|
label {
|
37
37
|
grid :row => 0, :column => 0
|
38
|
-
text "
|
38
|
+
text "Label"
|
39
|
+
}
|
40
|
+
label {
|
41
|
+
grid :row => 0, :column => 1, :pady => 10, :sticky => "e"
|
42
|
+
text "Drag label text"
|
43
|
+
width 30
|
44
|
+
drag_source true
|
39
45
|
}
|
40
46
|
|
47
|
+
label {
|
48
|
+
grid :row => 1, :column => 0
|
49
|
+
text "Entry"
|
50
|
+
}
|
41
51
|
entry {
|
42
|
-
grid :row =>
|
52
|
+
grid :row => 1, :column => 1, :pady => 5, :sticky => "e"
|
43
53
|
text "Drag entry text"
|
44
54
|
width 30
|
45
55
|
|
46
|
-
|
47
|
-
|
56
|
+
# drag_source true
|
57
|
+
# This is how to do `drag_source true` the manual way for use in exceptional cases
|
58
|
+
on('drag_start') do |event|
|
59
|
+
event.data = event.source.text
|
48
60
|
event.source.configure(:cursor => "hand2")
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
61
|
+
event.tooltip.content { # re-open tooltip content and add a label
|
62
|
+
lbl { # non-tile-theme version of label
|
63
|
+
text event.data + " "
|
64
|
+
bg "yellow"
|
65
|
+
bitmap "warning"
|
66
|
+
compound "right"
|
67
|
+
}
|
68
|
+
}
|
55
69
|
end
|
56
|
-
|
57
|
-
|
58
|
-
if event.drop_accepted
|
70
|
+
on('drag_motion') do |event|
|
71
|
+
if event.drop_accepted?
|
59
72
|
event.source.configure(:cursor => "hand1")
|
60
73
|
else
|
61
74
|
event.source.configure(:cursor => "hand2")
|
@@ -64,48 +77,34 @@ root {
|
|
64
77
|
end
|
65
78
|
}
|
66
79
|
|
67
|
-
label {
|
68
|
-
grid :row => 1, :column => 0
|
69
|
-
text "Label"
|
70
|
-
}
|
71
|
-
|
72
|
-
label {
|
73
|
-
grid :row => 1, :column => 1, :pady => 10, :sticky => "e"
|
74
|
-
text "Drag label text"
|
75
|
-
width 30
|
76
|
-
drag_source true
|
77
|
-
}
|
78
|
-
|
79
80
|
label {
|
80
81
|
grid :row => 2, :column => 0
|
81
82
|
text "Combobox"
|
82
83
|
}
|
83
|
-
|
84
84
|
combobox {
|
85
85
|
grid :row => 2, :column => 1, :pady => 5, :sticky => "e"
|
86
86
|
text "Spain"
|
87
87
|
values %w[USA Canada Mexico Columbia UK Australia Germany Italy Spain]
|
88
88
|
width 27
|
89
89
|
|
90
|
-
|
91
|
-
event.data = event.source.textvariable&.value
|
92
|
-
end
|
90
|
+
drag_source true
|
93
91
|
}
|
94
92
|
|
95
93
|
label {
|
96
94
|
grid :row => 3, :column => 0
|
97
95
|
text 'List'
|
98
96
|
}
|
99
|
-
|
100
|
-
country_list = list {
|
97
|
+
list {
|
101
98
|
grid :row => 3, :column => 1, :pady => 5, :sticky => "e"
|
102
99
|
selectmode 'browse'
|
103
100
|
items %w[USA Canada Mexico]
|
104
101
|
selection 'Canada'
|
105
102
|
height 3
|
106
103
|
|
107
|
-
|
108
|
-
|
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|
|
107
|
+
event.data = event.source.selection.first
|
109
108
|
end
|
110
109
|
}
|
111
110
|
|
@@ -113,7 +112,6 @@ root {
|
|
113
112
|
grid :row => 4, :column => 0
|
114
113
|
text "Button"
|
115
114
|
}
|
116
|
-
|
117
115
|
button {
|
118
116
|
grid :row => 4, :column => 1, :pady => 5, :sticky => "w"
|
119
117
|
text "Drag it"
|
@@ -128,89 +126,76 @@ root {
|
|
128
126
|
|
129
127
|
label {
|
130
128
|
grid :row => 0, :column => 0
|
131
|
-
text "
|
129
|
+
text "Label"
|
132
130
|
}
|
133
|
-
|
134
|
-
|
135
|
-
grid :row => 0, :column => 1, :pady => 5, :sticky => "e"
|
131
|
+
label {
|
132
|
+
grid :row => 0, :column => 1, :pady => 10, :sticky => "e"
|
136
133
|
width 30
|
134
|
+
borderwidth 2
|
135
|
+
relief "solid"
|
137
136
|
|
138
|
-
|
139
|
-
event.target.textvariable.value = event.data
|
140
|
-
}
|
137
|
+
drop_target true
|
141
138
|
}
|
142
139
|
|
143
140
|
label {
|
144
141
|
grid :row => 1, :column => 0
|
145
|
-
text "
|
142
|
+
text "Entry"
|
146
143
|
}
|
147
|
-
|
148
|
-
|
149
|
-
grid :row => 1, :column => 1, :pady => 10, :sticky => "e"
|
144
|
+
entry {
|
145
|
+
grid :row => 1, :column => 1, :pady => 5, :sticky => "e"
|
150
146
|
width 30
|
151
|
-
borderwidth 2
|
152
|
-
relief "solid"
|
153
147
|
|
154
|
-
|
155
|
-
event.target.textvariable.value = event.data
|
156
|
-
end
|
148
|
+
drop_target true
|
157
149
|
}
|
158
150
|
|
159
151
|
label {
|
160
152
|
grid :row => 2, :column => 0
|
161
153
|
text "Combobox"
|
162
154
|
}
|
163
|
-
|
164
155
|
combobox {
|
165
156
|
grid :row => 2, :column => 1, :pady => 5, :sticky => "e"
|
166
157
|
width 27
|
167
158
|
|
168
|
-
|
169
|
-
event.target.textvariable.value = event.data
|
170
|
-
end
|
159
|
+
drop_target true
|
171
160
|
}
|
172
161
|
|
173
162
|
label {
|
174
163
|
grid :row => 3, :column => 0
|
175
164
|
text 'List'
|
176
165
|
}
|
177
|
-
|
178
166
|
list {
|
179
167
|
grid :row => 3, :column => 1, :pady => 5, :sticky => "e"
|
180
168
|
selectmode 'browse'
|
181
169
|
height 3
|
182
170
|
|
183
|
-
|
184
|
-
event.target.insert('', 'end', :text => event.data)
|
185
|
-
end
|
171
|
+
drop_target true
|
186
172
|
}
|
187
173
|
|
188
174
|
label {
|
189
175
|
grid :row => 4, :column => 0
|
190
176
|
text "Button"
|
191
177
|
}
|
192
|
-
|
193
178
|
button {
|
194
179
|
grid :row => 4, :column => 1, :pady => 5, :sticky => "w"
|
195
180
|
text "Drop here"
|
196
181
|
|
197
|
-
|
198
|
-
event.target.text = event.data
|
199
|
-
end
|
182
|
+
drop_target true
|
200
183
|
}
|
201
184
|
|
202
185
|
label {
|
203
186
|
grid :row => 5, :column => 0
|
204
187
|
text "Checkbutton"
|
205
188
|
}
|
206
|
-
|
207
189
|
checkbutton {
|
208
190
|
grid :row => 5, :column => 1, :pady => 5, :sticky => "w"
|
209
|
-
text "Drop here to destroy a widget
|
210
|
-
|
211
|
-
|
191
|
+
text "Drop here to destroy a widget"
|
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|
|
212
196
|
event.target.text = event.data
|
213
|
-
|
197
|
+
# execute asynchronously after 100ms to ensure all events have been processed before destruction
|
198
|
+
::Tk.after(100) {event.source.destroy}
|
214
199
|
end
|
215
200
|
}
|
216
201
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-tk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.47
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.5.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.5.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: puts_debuggerer
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -208,10 +208,11 @@ 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/
|
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
|
215
|
+
- lib/glimmer/tk/lbl_proxy.rb
|
215
216
|
- lib/glimmer/tk/list_proxy.rb
|
216
217
|
- lib/glimmer/tk/menu_item_proxy.rb
|
217
218
|
- lib/glimmer/tk/menu_proxy.rb
|
@@ -225,6 +226,7 @@ files:
|
|
225
226
|
- lib/glimmer/tk/toplevel_proxy.rb
|
226
227
|
- lib/glimmer/tk/treeview_proxy.rb
|
227
228
|
- lib/glimmer/tk/variable_owner.rb
|
229
|
+
- lib/glimmer/tk/widget.rb
|
228
230
|
- lib/glimmer/tk/widget_proxy.rb
|
229
231
|
- lib/os.rb
|
230
232
|
- samples/elaborate/meta_sample.rb
|