glimmer-dsl-tk 0.0.58 → 0.0.61
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +28 -15
- data/VERSION +1 -1
- data/glimmer-dsl-tk.gemspec +0 -0
- data/lib/glimmer/tk/entry_proxy.rb +11 -0
- data/lib/glimmer/tk/widget_proxy.rb +33 -1
- data/samples/hello/hello_built_in_dialog.rb +29 -3
- data/samples/hello/hello_entry.rb +4 -1
- data/samples/hello/hello_label.rb +6 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65202d323a2567e112890475495d310877f839c0a064f8f4e17e2564df47b422
|
4
|
+
data.tar.gz: 93515ff8e8ef6ff1e8b3eae4d3f809522110fb9e0e83e4523eaede034cd605d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5206b004b6b49c5b29444410b86d978cb787314e25c32f069e2e973b456f164a20c04a295a2cac4bd90d0e5627df5477605daf8cc9439bf883caea4e79485b3
|
7
|
+
data.tar.gz: 9addeadf0b91a2c51a0ac137b550d700a2a621d52ca997d8618ff6d83281be2c030eebe34ca0cf4bd0c122b3fa4b26c9ac8ecf4b1e2b3f46ba7bafad562f1052
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.61
|
4
|
+
|
5
|
+
- Fix issue with Hello, Entry! breaking after the latest release due to mistakenly converting color `'red'` to `'#red'` by thinking it is hex
|
6
|
+
|
7
|
+
## 0.0.60
|
8
|
+
|
9
|
+
- Update Hello, Built-in Dialog! with more options for customizing dialogs
|
10
|
+
- Support setting colors as rgb colors via `r, g, b` (e.g. `foreground 210, 48, 110`)
|
11
|
+
- Accept hex color strings not starting with `#` (e.g. `background 'f828d7'`)
|
12
|
+
|
13
|
+
## 0.0.59
|
14
|
+
|
15
|
+
- Auto-Default to `validate 'key'` on an `entry` when defining `validatecommand {}`, `on('validate') {}`, `invalidcommand {}`, `on('invalid') {}`
|
16
|
+
|
3
17
|
## 0.0.58
|
4
18
|
|
5
19
|
- Support `@tk.textvariable.trace('write')` kind of variable tracing via `on_var(trace_operation) {}` listeners (e.g. `on_textvariable('write') {}`)
|
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.61
|
2
2
|
## Ruby Tk 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)
|
@@ -195,7 +195,7 @@ gem install glimmer-dsl-tk
|
|
195
195
|
|
196
196
|
Add the following to `Gemfile`:
|
197
197
|
```
|
198
|
-
gem 'glimmer-dsl-tk', '0.0.
|
198
|
+
gem 'glimmer-dsl-tk', '0.0.61'
|
199
199
|
```
|
200
200
|
|
201
201
|
And, then run:
|
@@ -309,14 +309,14 @@ keyword(args) | attributes | event bindings & callbacks
|
|
309
309
|
------------- | ---------- | ---------
|
310
310
|
`button` | `text`, `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `default` (`'active', 'normal'`) | `command {}`
|
311
311
|
`checkbutton` | `text`, `variable` (Boolean), `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `onvalue` (default: `1`), `offvalue` (default: `0`) | `command {}`
|
312
|
-
`choose_color(
|
313
|
-
`choose_directory(
|
314
|
-
`choose_font(
|
312
|
+
`choose_color(parent: nil, initialcolor: 'white', title: 'Colors')` | None | None
|
313
|
+
`choose_directory(parent: nil)` | None | None
|
314
|
+
`choose_font(family: nil, size: nil, weight: nil) {|font| ... }` | None | None
|
315
315
|
`combobox` | `state`, `text` | `'ComboboxSelected'`
|
316
316
|
`entry` | `width`, `text`, `validate`, `show` (`'none', 'focus', 'focusin', 'focusout', 'key', or 'all'`) | `'validate'`, `'invalid'`, `'change'` (alias: `'changed'`), `validatecommand {}`, `invalidcommand {}`
|
317
|
-
`get_multiple_open_file(
|
318
|
-
`get_open_file(
|
319
|
-
`get_save_file(
|
317
|
+
`get_multiple_open_file(parent: nil, title: '')` | None | None
|
318
|
+
`get_open_file(parent: nil, title: '')` | None | None
|
319
|
+
`get_save_file(parent: nil, title: '')` | None | None
|
320
320
|
`spinbox` | `text`, `from`, `to`, `increment`, `format`, [more attributes](https://tcl.tk/man/tcl8.6/TkCmd/text.htm#M116) | `command {}`, `'increment'`, `'decrement'`
|
321
321
|
`frame(text: nil)` | `width`, `height`, `borderwidth`, `relief` (`'flat' (default), 'raised', 'sunken', 'solid', 'ridge', 'groove'`) | None
|
322
322
|
`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
|
@@ -343,6 +343,8 @@ Options for `get_open_file` and `get_multiple_open_file` include:
|
|
343
343
|
#### Common Attributes
|
344
344
|
|
345
345
|
- `grid`: `Hash` of `:row`, `:column`, `:padx`, `:pady`, `:sticky` (`'e', 'w', 'n', 's'` or any combination of direction letters)
|
346
|
+
- `foreground`: [Built-in Color](https://tcl.tk/man/tcl8.6/TkCmd/colors.htm) (e.g. `'AliceBlue'`), Hex color (e.g. `'#ffd807'`), or RGB color array (e.g. `foreground 255, 128, 75`)
|
347
|
+
- `background`: [Built-in Color](https://tcl.tk/man/tcl8.6/TkCmd/colors.htm) (e.g. `'AliceBlue'`), Hex color (e.g. `'#ffd807'`), or RGB color array (e.g. `foreground 255, 128, 75`)
|
346
348
|
|
347
349
|
#### Common Event Bindings
|
348
350
|
|
@@ -2181,12 +2183,13 @@ class HelloEntry
|
|
2181
2183
|
def launch
|
2182
2184
|
root {
|
2183
2185
|
title 'Hello, Entry!'
|
2184
|
-
|
2186
|
+
minsize 230, 0
|
2187
|
+
|
2185
2188
|
label {
|
2186
2189
|
grid sticky: 'ew'
|
2187
2190
|
text 'default entry'
|
2188
2191
|
}
|
2189
|
-
entry {
|
2192
|
+
entry { |the_entry|
|
2190
2193
|
grid sticky: 'ew'
|
2191
2194
|
text <=> [self, :default]
|
2192
2195
|
}
|
@@ -2205,11 +2208,14 @@ class HelloEntry
|
|
2205
2208
|
grid sticky: 'ew'
|
2206
2209
|
text 'entry with event handlers'
|
2207
2210
|
}
|
2208
|
-
entry {
|
2211
|
+
entry { |the_entry|
|
2209
2212
|
grid sticky: 'ew'
|
2210
2213
|
text <=> [self, :telephone]
|
2211
|
-
validate 'key'
|
2212
2214
|
|
2215
|
+
# validate 'key' # default when on('validate') or on('invalid') is specified
|
2216
|
+
## Validation happens on key change by default when validation listeners are specified
|
2217
|
+
## (other accepted values: 'none', 'focus', 'focusin', 'focusout', 'key', or 'all')
|
2218
|
+
|
2213
2219
|
## this event kicks in just after the user typed and before modifying the text variable
|
2214
2220
|
on('validate') do |new_text_variable|
|
2215
2221
|
telephone?(new_text_variable.value)
|
@@ -2217,7 +2223,7 @@ class HelloEntry
|
|
2217
2223
|
|
2218
2224
|
## this event kicks in just after the text variable is validated and before it is modified
|
2219
2225
|
on('invalid') do |validate_args|
|
2220
|
-
@validated_entry_label.text = "#{validate_args.
|
2226
|
+
@validated_entry_label.text = "#{validate_args.value} is not a valid phone!"
|
2221
2227
|
@validated_entry_label.foreground = 'red'
|
2222
2228
|
end
|
2223
2229
|
|
@@ -2227,6 +2233,13 @@ class HelloEntry
|
|
2227
2233
|
@validated_entry_label.text = 'entry with event handlers'
|
2228
2234
|
@validated_entry_label.foreground = nil
|
2229
2235
|
end
|
2236
|
+
|
2237
|
+
## this is similar to on('change') (which is Glimmer-specific), but more low level at the Tk level
|
2238
|
+
## it is the equivalent of calling: the_entry.tk.textvariable.trace('write') { puts "..." }
|
2239
|
+
## More at: https://tkdocs.com/tutorial/widgets.html#entry and https://tcl.tk/man/tcl8.6/TclCmd/trace.htm#M14
|
2240
|
+
on_textvariable('write') do
|
2241
|
+
puts "\"#{the_entry.text}\" has been written to entry!"
|
2242
|
+
end
|
2230
2243
|
}
|
2231
2244
|
|
2232
2245
|
label {
|
@@ -4274,9 +4287,9 @@ https://github.com/ancorgs/y3network-ruby-ui
|
|
4274
4287
|
|
4275
4288
|
This is a Graphical User Interface for the famous [cryptopunks Ruby gem](https://github.com/cryptopunksnotdead/cryptopunks/tree/master/cryptopunks).
|
4276
4289
|
|
4277
|
-
https://github.com/cryptopunksnotdead/cryptopunks-gui
|
4290
|
+
https://github.com/cryptopunksnotdead/cryptopunks/tree/master/cryptopunks-gui
|
4278
4291
|
|
4279
|
-
![CryptoPunks GUI Screenshot](https://raw.githubusercontent.com/cryptopunksnotdead/cryptopunks-gui/
|
4292
|
+
![CryptoPunks GUI Screenshot](https://raw.githubusercontent.com/cryptopunksnotdead/cryptopunks/master/cryptopunks-gui/screenshots/cryptopunks-gui-screenshot.png)
|
4280
4293
|
|
4281
4294
|
### Circule
|
4282
4295
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.61
|
data/glimmer-dsl-tk.gemspec
CHANGED
Binary file
|
@@ -31,13 +31,24 @@ module Glimmer
|
|
31
31
|
include TextVariableOwner
|
32
32
|
|
33
33
|
def validatecommand_block=(proc)
|
34
|
+
self.validate = 'key' unless validate
|
34
35
|
tk.validatecommand(proc)
|
35
36
|
end
|
36
37
|
|
37
38
|
def invalidcommand_block=(proc)
|
39
|
+
self.validate = 'key' unless validate
|
38
40
|
tk.invalidcommand(proc)
|
39
41
|
end
|
40
42
|
|
43
|
+
def validate
|
44
|
+
@validate
|
45
|
+
end
|
46
|
+
|
47
|
+
def validate=(value)
|
48
|
+
@validate = value
|
49
|
+
@tk.validate(value)
|
50
|
+
end
|
51
|
+
|
41
52
|
def handle_listener(listener_name, &listener)
|
42
53
|
case listener_name.to_s.downcase
|
43
54
|
when 'change', 'changed', 'modified'
|
@@ -73,6 +73,7 @@ module Glimmer
|
|
73
73
|
prepend DraggableAndDroppable
|
74
74
|
|
75
75
|
FONTS_PREDEFINED = %w[default text fixed menu heading caption small_caption icon tooltip]
|
76
|
+
HEXADECIMAL_CHARACTERS = %w[0 1 2 3 4 5 6 7 8 9 a b c d e f]
|
76
77
|
|
77
78
|
attr_reader :parent_proxy, :tk, :args, :keyword, :children, :bind_ids, :destroyed
|
78
79
|
alias destroyed? destroyed
|
@@ -192,6 +193,7 @@ module Glimmer
|
|
192
193
|
|
193
194
|
def set_attribute(attribute, *args)
|
194
195
|
begin
|
196
|
+
args = normalize_attribute_arguments(attribute, args)
|
195
197
|
widget_custom_attribute = widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][attribute.to_s]
|
196
198
|
if respond_to?(attribute_setter(attribute), super_only: true)
|
197
199
|
send(attribute_setter(attribute), *args)
|
@@ -308,6 +310,34 @@ module Glimmer
|
|
308
310
|
@tk.style = style
|
309
311
|
end
|
310
312
|
|
313
|
+
def normalize_attribute_arguments(attribute, args)
|
314
|
+
attribute_argument_normalizers[attribute]&.call(args) || args
|
315
|
+
end
|
316
|
+
|
317
|
+
def attribute_argument_normalizers
|
318
|
+
color_normalizer = lambda do |args|
|
319
|
+
if args.size > 1 || args.first.is_a?(Numeric)
|
320
|
+
rgb = args
|
321
|
+
rgb = rgb.map(&:to_s).map(&:to_i)
|
322
|
+
rgb = 3.times.map { |n| rgb[n] || 0}
|
323
|
+
hex = rgb.map { |color| color.to_s(16).ljust(2, '0') }.join
|
324
|
+
["##{hex}"]
|
325
|
+
elsif args.size == 1 &&
|
326
|
+
args.first.is_a?(String) &&
|
327
|
+
!args.first.start_with?('#') &&
|
328
|
+
(args.first.size == 3 || args.first.size == 6) &&
|
329
|
+
(args.first.chars.all? {|char| HEXADECIMAL_CHARACTERS.include?(char.downcase)})
|
330
|
+
["##{args.first}"]
|
331
|
+
else
|
332
|
+
args
|
333
|
+
end
|
334
|
+
end
|
335
|
+
@attribute_argument_normalizers ||= {
|
336
|
+
'background' => color_normalizer,
|
337
|
+
'foreground' => color_normalizer,
|
338
|
+
}
|
339
|
+
end
|
340
|
+
|
311
341
|
def widget_custom_attribute_mapping
|
312
342
|
# TODO consider extracting to modules/subclasses
|
313
343
|
@widget_custom_attribute_mapping ||= {
|
@@ -534,10 +564,12 @@ module Glimmer
|
|
534
564
|
|
535
565
|
def method_missing(method, *args, &block)
|
536
566
|
method = method.to_s
|
567
|
+
attribute_name = method.sub(/=$/, '')
|
568
|
+
args = normalize_attribute_arguments(attribute_name, args)
|
537
569
|
if args.empty? && block.nil? && ((widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method]) || has_state?(method) || has_attributes_attribute?(method))
|
538
570
|
get_attribute(method)
|
539
571
|
elsif method.end_with?('=') && block.nil? && ((widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method.sub(/=$/, '')]) || has_state?(method) || has_attributes_attribute?(method))
|
540
|
-
set_attribute(
|
572
|
+
set_attribute(attribute_name, *args)
|
541
573
|
else
|
542
574
|
tk.send(method, *args, &block)
|
543
575
|
end
|
@@ -31,21 +31,47 @@ root { |w|
|
|
31
31
|
y 150
|
32
32
|
|
33
33
|
frame {
|
34
|
-
%w[get_open_file get_multiple_open_file get_save_file choose_directory
|
34
|
+
%w[get_open_file get_multiple_open_file get_save_file choose_directory].each do |dialog|
|
35
|
+
dialog_name = dialog.split('_').map(&:capitalize).join(' ')
|
35
36
|
button {
|
36
|
-
text
|
37
|
+
text dialog_name
|
37
38
|
|
38
39
|
on('command') do
|
39
|
-
|
40
|
+
# parent is optional.
|
41
|
+
# It is recommended to set parent to display dialog on top of.
|
42
|
+
#
|
43
|
+
# title is optional (defaults to blank).
|
44
|
+
# It is not supported by choose_directory (its title is always blank).
|
45
|
+
result = send(dialog, parent: w, title: dialog_name)
|
46
|
+
# Uniformly handle both a singular result (e.g. from get_open_file)
|
47
|
+
# and an array of results (e.g. from get_multiple_open_file)
|
40
48
|
@result_label.text = [result].flatten.join("\n")
|
41
49
|
end
|
42
50
|
}
|
43
51
|
end
|
44
52
|
|
53
|
+
button {
|
54
|
+
text 'Choose Color'
|
55
|
+
|
56
|
+
on('command') do
|
57
|
+
# parent is optional.
|
58
|
+
# It is recommended to set parent to display dialog on top of.
|
59
|
+
#
|
60
|
+
# title is optional (defaults to 'Colors').
|
61
|
+
#
|
62
|
+
# initialcolor is optional (defaults to 'white').
|
63
|
+
# It can be a built-in color (e.g. 'AliceBlue') or hex (e.g. '#FFFF00')
|
64
|
+
# Full list of built-in colors is at: https://tcl.tk/man/tcl8.6/TkCmd/colors.htm
|
65
|
+
chosen_color = choose_color(parent: w, title: 'Choose Color', initialcolor: '#FFFF00')
|
66
|
+
@result_label.text = chosen_color
|
67
|
+
end
|
68
|
+
}
|
69
|
+
|
45
70
|
button {
|
46
71
|
text 'Choose Font'
|
47
72
|
|
48
73
|
on('command') do
|
74
|
+
# Initial family, size, and weight are optional.
|
49
75
|
choose_font(family: 'Courier New', size: '30', weight: 'bold') do |chosen_font|
|
50
76
|
@result_label.text = chosen_font
|
51
77
|
end
|
@@ -64,8 +64,11 @@ class HelloEntry
|
|
64
64
|
entry { |the_entry|
|
65
65
|
grid sticky: 'ew'
|
66
66
|
text <=> [self, :telephone]
|
67
|
-
validate 'key'
|
68
67
|
|
68
|
+
# validate 'key' # default when on('validate') or on('invalid') is specified
|
69
|
+
## Validation happens on key change by default when validation listeners are specified
|
70
|
+
## (other accepted values: 'none', 'focus', 'focusin', 'focusout', 'key', or 'all')
|
71
|
+
|
69
72
|
## this event kicks in just after the user typed and before modifying the text variable
|
70
73
|
on('validate') do |new_text_variable|
|
71
74
|
telephone?(new_text_variable.value)
|
@@ -80,8 +80,13 @@ class HelloLabel
|
|
80
80
|
anchor 'center'
|
81
81
|
justify 'center' # other options are: 'left' and 'right'
|
82
82
|
font 'caption' # other options are: 'default', 'text', 'fixed', 'menu', 'heading', 'small_caption', 'icon', 'tooltip'
|
83
|
-
foreground 'blue'
|
84
83
|
relief 'sunken' # other options are: 'flat' (default), 'raised', 'solid', 'ridge', 'groove'
|
84
|
+
foreground 38, 20, 138 # RGB (Red Green Blue) color
|
85
|
+
|
86
|
+
# Other supported color arguments:
|
87
|
+
# foreground 'blue' # built-in color alternative from https://tcl.tk/man/tcl8.6/TkCmd/colors.htm
|
88
|
+
# foreground '#ff0000' # hex color
|
89
|
+
# foreground 'ff0000' # hex color missing the # prefix
|
85
90
|
}
|
86
91
|
}
|
87
92
|
|
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.61
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -170,8 +170,8 @@ dependencies:
|
|
170
170
|
- - "~>"
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: 0.7.0
|
173
|
-
description: Glimmer DSL for Tk (
|
174
|
-
|
173
|
+
description: Glimmer DSL for Tk (Ruby Tk Desktop Development GUI Library) - Ruby DSL
|
174
|
+
for Tcl/Tk with bidirectional/unidirectional data-binding support.
|
175
175
|
email: andy.am@gmail.com
|
176
176
|
executables:
|
177
177
|
- girb
|