glimmer-dsl-tk 0.0.59 → 0.0.60

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26c20e8d681d57d11f540136ad94fd26a4f7ab51a5663eba95599dd5fa1589fe
4
- data.tar.gz: 6f70dd20a48487e0c73135790b24e38f8080fa376cda20f1da2c8db83cb78d4c
3
+ metadata.gz: 9c0553115fdb0b7a912c59f6feda8b475e76c546fc2db32984037e7bbc8db204
4
+ data.tar.gz: 450c7795ef8adafe88db9fbfdf78691933f79b06f1f4b1e899f5ddacac3da567
5
5
  SHA512:
6
- metadata.gz: 97fc2a77f286aec0cef3f0733aa1642415a0cf5ae420ea7713344b4b9f0de676d96fbb40b6cdba8d5a3338f8340a6b94ef3e6497043b86cd154258d66e320616
7
- data.tar.gz: d48746949f04d68643d6493cab85c04bc7951da0fcbced1c7f13ab9a968d3bab6e452b8c804b2b012ab6b662c8092e87c0bea4386a214b2ccd494a94e46b6299
6
+ metadata.gz: 256d0e2d25fd50791b979cf92ba9dad8dedf77941e6e6394f1474f41f20a035bb601f6cc2af3b2bab8ed0b3acf11825d041a3d65d5d8941da85e6fc563c7c23b
7
+ data.tar.gz: b122dd08e9a6b2ec400ecf49c15d0be69fcc3c4e4fbe4de9c427dc0b1a085cae6ab8c95deca79272f28ecb21479477a6792ae434544c64013ebfe8cc4b8b49de
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.60
4
+
5
+ - Update Hello, Built-in Dialog! with more options for customizing dialogs
6
+ - Support setting colors as rgb colors via `r, g, b` (e.g. `foreground 210, 48, 110`)
7
+ - Accept hex color strings not starting with `#` (e.g. `background 'f828d7'`)
8
+
3
9
  ## 0.0.59
4
10
 
5
11
  - 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.59
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.60
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.59'
198
+ gem 'glimmer-dsl-tk', '0.0.60'
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(options = nil)` | None | None
313
- `choose_directory(options = nil)` | None | None
314
- `choose_font(options = nil) {|font| ... }` | None | None
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(options = nil)` | None | None
318
- `get_open_file(options = nil)` | None | None
319
- `get_save_file(options = nil)` | None | None
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'`) or Hex color (e.g. `'#ffd807'`)
347
+ - `background`: [Built-in Color](https://tcl.tk/man/tcl8.6/TkCmd/colors.htm) (e.g. `'AliceBlue'`) or Hex color (e.g. `'#ffd807'`)
346
348
 
347
349
  #### Common Event Bindings
348
350
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.59
1
+ 0.0.60
Binary file
@@ -192,6 +192,7 @@ module Glimmer
192
192
 
193
193
  def set_attribute(attribute, *args)
194
194
  begin
195
+ args = normalize_attribute_arguments(attribute, args)
195
196
  widget_custom_attribute = widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][attribute.to_s]
196
197
  if respond_to?(attribute_setter(attribute), super_only: true)
197
198
  send(attribute_setter(attribute), *args)
@@ -308,6 +309,30 @@ module Glimmer
308
309
  @tk.style = style
309
310
  end
310
311
 
312
+ def normalize_attribute_arguments(attribute, args)
313
+ attribute_argument_normalizers[attribute]&.call(args) || args
314
+ end
315
+
316
+ def attribute_argument_normalizers
317
+ color_normalizer = lambda do |args|
318
+ if args.size > 1 || args.first.is_a?(Numeric)
319
+ rgb = args
320
+ rgb = rgb.map(&:to_s).map(&:to_i)
321
+ rgb = 3.times.map { |n| rgb[n] || 0}
322
+ hex = rgb.map { |color| color.to_s(16).ljust(2, '0') }.join
323
+ ["##{hex}"]
324
+ elsif args.size == 1 && args.first.is_a?(String) && !args.first.start_with?('#')
325
+ ["##{args.first}"]
326
+ else
327
+ args
328
+ end
329
+ end
330
+ @attribute_argument_normalizers ||= {
331
+ 'background' => color_normalizer,
332
+ 'foreground' => color_normalizer,
333
+ }
334
+ end
335
+
311
336
  def widget_custom_attribute_mapping
312
337
  # TODO consider extracting to modules/subclasses
313
338
  @widget_custom_attribute_mapping ||= {
@@ -534,10 +559,12 @@ module Glimmer
534
559
 
535
560
  def method_missing(method, *args, &block)
536
561
  method = method.to_s
562
+ attribute_name = method.sub(/=$/, '')
563
+ args = normalize_attribute_arguments(attribute_name, args)
537
564
  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
565
  get_attribute(method)
539
566
  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(method.sub(/=$/, ''), *args)
567
+ set_attribute(attribute_name, *args)
541
568
  else
542
569
  tk.send(method, *args, &block)
543
570
  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 choose_color].each do |dialog|
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 dialog.split('_').map(&:capitalize).join(' ')
37
+ text dialog_name
37
38
 
38
39
  on('command') do
39
- result = send(dialog, parent: w)
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
@@ -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.59
4
+ version: 0.0.60
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-21 00:00:00.000000000 Z
11
+ date: 2022-06-24 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 (MRI Ruby Desktop Development GUI Library) - Ruby
174
- DSL for Tcl/Tk with bidirectional/unidirectional data-binding support.
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