glimmer-dsl-tk 0.0.59 → 0.0.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +16 -14
- data/VERSION +1 -1
- data/glimmer-dsl-tk.gemspec +0 -0
- data/lib/glimmer/dsl/tk/built_in_dialog_expression.rb +1 -0
- data/lib/glimmer/tk/toplevel_proxy.rb +16 -3
- data/lib/glimmer/tk/widget_proxy.rb +37 -1
- data/samples/hello/hello_built_in_dialog.rb +29 -3
- data/samples/hello/hello_label.rb +6 -1
- data/samples/hello/hello_root.rb +1 -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: b6a4152765e0997cd3d29beec05f16be105a09ae868e49335fb09e81d552e576
|
4
|
+
data.tar.gz: 31c3f1d4ee33b5ab9dec7ccd76d11a6c50cde145cf3a5517401859b0ae16a45a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f4820bb0d35553b16fc9b37bfca7d2abdc463cbd2e958f462b5be5c53e79e7ae3abc918fa2bbc6775d642432b127fa3d26ff72d96195287fecd287e13a50a23
|
7
|
+
data.tar.gz: 6f5b093cd7f834e6d8126142d5f63e66dde7c164b463eee577cd8b177d27784335d3f2df88555ce103c68a29eaed72ab1ec1e608018e8b76655c9704e77c0826
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.62
|
4
|
+
|
5
|
+
- `icon_photo` as alias for `iconphoto` attribute on `root` and `toplevel`
|
6
|
+
- `initial_color` as alias for `initialcolor` attribute on `choose_color` built-in dialog
|
7
|
+
|
8
|
+
## 0.0.61
|
9
|
+
|
10
|
+
- Fix issue with Hello, Entry! breaking after the latest release due to mistakenly converting color `'red'` to `'#red'` by thinking it is hex
|
11
|
+
|
12
|
+
## 0.0.60
|
13
|
+
|
14
|
+
- Update Hello, Built-in Dialog! with more options for customizing dialogs
|
15
|
+
- Support setting colors as rgb colors via `r, g, b` (e.g. `foreground 210, 48, 110`)
|
16
|
+
- Accept hex color strings not starting with `#` (e.g. `background 'f828d7'`)
|
17
|
+
|
3
18
|
## 0.0.59
|
4
19
|
|
5
20
|
- Auto-Default to `validate 'key'` on an `entry` when defining `validatecommand {}`, `on('validate') {}`, `invalidcommand {}`, `on('invalid') {}`
|
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.62
|
2
2
|
## Ruby Tk Desktop Development GUI Library
|
3
3
|
[](http://badge.fury.io/rb/glimmer-dsl-tk)
|
4
4
|
[](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.62'
|
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, initial_color: '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
|
@@ -328,11 +328,11 @@ keyword(args) | attributes | event bindings & callbacks
|
|
328
328
|
`menu_item(style = :command, label: , underline: )` (style also can be `:radiobutton`, `:checkbutton`, `:separator`, `:about`, `:preferences`, `:quit`, `:help`) | `state`, `accelerator`, `selection` & `variable` (if `:radiobutton` or `:checkbutton`), `image`, `compound` | `command`
|
329
329
|
`notebook` | None | None
|
330
330
|
`radiobutton` | `text`, `variable` (Boolean), `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `value` (default: `text`) | `command {}`
|
331
|
-
`root` | `title`, `
|
331
|
+
`root` | `title`, `icon_photo`, `background`, `alpha`, `escapable`, `fullscreen?`, `topmost?`, `transparent?`, `stackorder`, `winfo_screendepth`, `winfo_screenvisual`, `winfo_screenwidth`, `winfo_screenheight`, `winfo_pixels('li')`, `winfo_screen`, `wm_maxsize`, `state` (`'normal', 'iconic', 'withdrawn', 'icon', 'zoomed'`) | `'DELETE_WINDOW'`, `'OPEN_WINDOW'`
|
332
332
|
`scrollbar` | `orient` | `command`
|
333
333
|
`scrollbar_frame` | `xscrollbar` (Boolean or scrollbar widget proxy), `yscrollbar` (Boolean or scrollbar widget proxy) | None
|
334
334
|
`separator` | `orient` (`'horizontal' (default) or 'vertical'`) | None
|
335
|
-
`toplevel` | `title`, `
|
335
|
+
`toplevel` | `title`, `icon_photo`, `background`, `alpha`, `escapable`, `fullscreen?`, `topmost?`, `transparent?`, `stackorder`, `winfo_screendepth`, `winfo_screenvisual`, `winfo_screenwidth`, `winfo_screenheight`, `winfo_pixels('li')`, `winfo_screen`, `wm_maxsize`, `state` (`'normal', 'iconic', 'withdrawn', 'icon', 'zoomed'`) | `'DELETE_WINDOW'`
|
336
336
|
`text` | `value`, [many more attributes](https://tcl.tk/man/tcl8.6/TkCmd/text.htm#M116) | `'modified'`, `'selection'`, `'insert_mark_moved'` (alias: `'insert_mark_move', 'InsertMarkMove', 'InsertMarkMoved'`)
|
337
337
|
`x_scrollbar` | `orient` (`'horizontal'`) | `command`
|
338
338
|
`y_scrollbar` | `orient` (`'vertical'`) | `command`
|
@@ -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
|
|
@@ -553,7 +555,7 @@ When nesting `frame` under `notebook`, you can pass a `:text` keyword argument t
|
|
553
555
|
|
554
556
|
#### Icon Photo
|
555
557
|
|
556
|
-
The `
|
558
|
+
The `icon_photo` attribute (alias for `iconphoto`) on `root` is set to the Glimmer icon by default if no icon photo is supplied.
|
557
559
|
|
558
560
|
Otherwise, [Glimmer DSL for Tk](https://rubygems.org/gems/glimmer-dsl-tk) is smart enough to accept an image path directly (no need to wrap with `TkPhotoImage`)
|
559
561
|
|
@@ -562,7 +564,7 @@ Example with direct image path (you may copy/paste in [`girb`](#girb-glimmer-irb
|
|
562
564
|
```ruby
|
563
565
|
root {
|
564
566
|
title 'Title'
|
565
|
-
|
567
|
+
icon_photo 'icons/glimmer.png'
|
566
568
|
}.open
|
567
569
|
```
|
568
570
|
|
@@ -571,7 +573,7 @@ Example with `TkPhotoImage` object (you may copy/paste in [`girb`](#girb-glimmer
|
|
571
573
|
```ruby
|
572
574
|
root {
|
573
575
|
title 'Title'
|
574
|
-
|
576
|
+
icon_photo TkPhotoImage.new(file: 'icons/glimmer.png')
|
575
577
|
}.open
|
576
578
|
```
|
577
579
|
|
@@ -1533,7 +1535,7 @@ include Glimmer
|
|
1533
1535
|
|
1534
1536
|
root { |r|
|
1535
1537
|
title 'Hello, Root!'
|
1536
|
-
|
1538
|
+
icon_photo File.expand_path('../../icons/glimmer.png', __dir__)
|
1537
1539
|
width 400
|
1538
1540
|
height 200
|
1539
1541
|
x -150
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.62
|
data/glimmer-dsl-tk.gemspec
CHANGED
Binary file
|
@@ -38,6 +38,7 @@ module Glimmer
|
|
38
38
|
def interpret(parent, keyword, *args, &block)
|
39
39
|
if args.first.is_a?(Hash)
|
40
40
|
options = args.first.symbolize_keys
|
41
|
+
options[:initialcolor] = options.delete(:initial_color) if options.keys.include?(:initial_color)
|
41
42
|
options[:filetypes] = options.delete(:file_types) if options.keys.include?(:file_types)
|
42
43
|
options[:filetypes] = options[:filetypes].map { |key, value| "{#{key}} {#{value}}" } if options[:filetypes].is_a?(Hash)
|
43
44
|
options[:parent] = options[:parent].tk if options[:parent].is_a?(Glimmer::Tk::RootProxy)
|
@@ -48,14 +48,14 @@ module Glimmer
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def has_attribute?(attribute, *args)
|
51
|
-
%w[width height x y].include?(attribute.to_s) || super
|
51
|
+
%w[width height x y icon_photo].include?(attribute.to_s) || super
|
52
52
|
end
|
53
53
|
|
54
54
|
def set_attribute(attribute, *args)
|
55
55
|
case attribute.to_s
|
56
|
-
when 'iconphoto'
|
56
|
+
when 'iconphoto', 'icon_photo'
|
57
57
|
args[0..-1] = [image_argument(args)]
|
58
|
-
super
|
58
|
+
super('iconphoto', *args)
|
59
59
|
when 'resizable'
|
60
60
|
if args.size == 1 && !args.first.is_a?(Array)
|
61
61
|
self.resizable = [args.first]*2
|
@@ -67,6 +67,19 @@ module Glimmer
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
def get_attribute(attribute)
|
71
|
+
case attribute.to_s
|
72
|
+
when 'icon_photo'
|
73
|
+
super('iconphoto')
|
74
|
+
else
|
75
|
+
super
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def icon_photo
|
80
|
+
iconphoto
|
81
|
+
end
|
82
|
+
|
70
83
|
def width
|
71
84
|
geometry.split(REGEX_GEOMETRY)[0].to_i
|
72
85
|
end
|
@@ -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 ||= {
|
@@ -380,6 +410,10 @@ module Glimmer
|
|
380
410
|
getter: {name: 'text', invoker: lambda { |widget, args| @tk.title }},
|
381
411
|
setter: {name: 'text=', invoker: lambda { |widget, args| @tk.title = args.first }},
|
382
412
|
},
|
413
|
+
'icon_photo' => {
|
414
|
+
getter: {name: 'icon_photo', invoker: lambda { |widget, args| @tk.iconphoto }},
|
415
|
+
setter: {name: 'icon_photo=', invoker: lambda { |widget, args| @tk.iconphoto = image_argument(args) }},
|
416
|
+
},
|
383
417
|
},
|
384
418
|
}
|
385
419
|
end
|
@@ -534,10 +568,12 @@ module Glimmer
|
|
534
568
|
|
535
569
|
def method_missing(method, *args, &block)
|
536
570
|
method = method.to_s
|
571
|
+
attribute_name = method.sub(/=$/, '')
|
572
|
+
args = normalize_attribute_arguments(attribute_name, args)
|
537
573
|
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
574
|
get_attribute(method)
|
539
575
|
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(
|
576
|
+
set_attribute(attribute_name, *args)
|
541
577
|
else
|
542
578
|
tk.send(method, *args, &block)
|
543
579
|
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', initial_color: '#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
|
@@ -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
|
|
data/samples/hello/hello_root.rb
CHANGED
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.62
|
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-30 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
|