glimmer-dsl-tk 0.0.23 → 0.0.24

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: 9d722c9396a9adb7252e4fc65c283fbf923dbe0cb93e17a9d34649ea887f5e56
4
- data.tar.gz: 20682a6aa497800f683b87fc180754a58a96362a5a286fab3754bc38edd5d084
3
+ metadata.gz: 406613fff26324b7f91ddbaea11f01f90241b883f99a7732beb27a097eaae24d
4
+ data.tar.gz: d2e0828831b9cb7a6b017be648253972ad1cb8e8c48fa20046e6a3bd4b0b59f5
5
5
  SHA512:
6
- metadata.gz: 77c488d614a997861369fd032fc1ebc578bee01aa8367c0fd267b99442ec462769f0218c11e236533b3443558294c2ca0940c773777698f4216df85cd1179243
7
- data.tar.gz: 521a5c5e3db695b7938fc225619779114e32c06fa2bce870de16f233597d212b3662218a101e95921733c58f4ea02764598167eaa507835bbb25855187566b6a
6
+ metadata.gz: 9ba903e6e9d4e611e7c7f17c94f902a6a33945e07ab46136c30003ad5189b707a6485ab4f7c472503699ead75119b20d237e9bda1484f32373354dc74ba8e90a
7
+ data.tar.gz: c4d5f2c7f8338e3fdfc0452e97d7f0498b7b2ded75a586272f11cfadc61b71ee6db197d2b76441d2c2f925914ff61e6577d8fef36c106426267bd7a23c3d3d5f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.24
4
+
5
+ - Hello, Entry!
6
+ - Update `entry` data-binding logic to trace 'write' changes to `entry` `textvariable` as that is more correct than monitoring `validatecommand`
7
+ - Support `entry` `validate` (alias for `validatecommand`), `invalid` (alias for `invalidcommand`), and `change` event bindings
8
+ - Support `entry` `show` and `validate` attributes
9
+ - Support `grid` options `row_weight` (for row expansion), `column_weight` (for column expansion), `row_minsize` (alias: `min_height`), and `column_minsize` (alias: `min_width`)
10
+
3
11
  ## 0.0.23
4
12
 
5
13
  - Hello, Radiobutton!
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.23
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.24
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)
@@ -105,6 +105,7 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
105
105
  - [Hello, Combobox!](#hello-combobox)
106
106
  - [Hello, List Single Selection!](#hello-list-single-selection)
107
107
  - [Hello, List Multi Selection!](#hello-list-multi-selection)
108
+ - [Hello, Entry!](#hello-entry)
108
109
  - [Hello, Computed!](#hello-computed)
109
110
  - [Help](#help)
110
111
  - [Issues](#issues)
@@ -142,7 +143,7 @@ gem install glimmer-dsl-tk
142
143
 
143
144
  Add the following to `Gemfile`:
144
145
  ```
145
- gem 'glimmer-dsl-tk', '~> 0.0.23'
146
+ gem 'glimmer-dsl-tk', '~> 0.0.24'
146
147
  ```
147
148
 
148
149
  And, then run:
@@ -254,7 +255,7 @@ keyword(args) | attributes | event bindings & callbacks
254
255
  `button` | `text`, `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `default` (`'active', 'normal'`) | `command {}`
255
256
  `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 {}`
256
257
  `combobox` | `state`, `text` | `'ComboboxSelected'`
257
- `entry` | `width`, `text` | None
258
+ `entry` | `width`, `text`, `validate`, `show` (`'none', 'focus', 'focusin', 'focusout', 'key', or 'all'`) | `'validate'`, `'invalid'`, `'change'`, `validatecommand {}`, `invalidcommand {}`
258
259
  `frame(text: nil)` | `width`, `height`, `borderwidth`, `relief` (`'flat' (default), 'raised', 'sunken', 'solid', 'ridge', 'groove'`) | None
259
260
  `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
260
261
  `list` | `selectmode`, `selection` | None
@@ -315,7 +316,7 @@ keyword(args) | attributes | event bindings & callbacks
315
316
 
316
317
  #### Event Bindings
317
318
 
318
- Any events that normally can be accepted by the Tk `bind` or `protocol` methods can be accepted by the `on(event) {}` listener syntax. There is no need to surround event name by `<>` as [Glimmer DSL for Tk](https://rubygems.org/gems/glimmer-dsl-tk) automatically takes care of that when needed and leaves out when not needed.
319
+ Any events that normally can be accepted by the Tk `bind` or `protocol` methods can be accepted by the `on(event) {}` listener syntax. For actual (non-virtual) events, there is no need to surround event name by `<>` as [Glimmer DSL for Tk](https://rubygems.org/gems/glimmer-dsl-tk) automatically takes care of that when needed and leaves out when not needed.
319
320
 
320
321
  #### Grid Layout
321
322
 
@@ -474,7 +475,7 @@ That code binds the `textvariable` value of the `entry` to the `country` attribu
474
475
 
475
476
  It automatically handles all the Tk plumbing behind the scenes.
476
477
 
477
- More details can be found in the [Hello, Computed!](#hello-computed) sample below.
478
+ More details can be found in [Hello, Entry!](#hello-entry) and [Hello, Computed!](#hello-computed) samples below.
478
479
 
479
480
  ### Checkbutton Data-Binding
480
481
 
@@ -573,7 +574,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_world'"
573
574
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
574
575
 
575
576
  ```
576
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_world.rb
577
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_world.rb
577
578
  ```
578
579
 
579
580
  Glimmer app:
@@ -672,7 +673,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_button'"
672
673
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
673
674
 
674
675
  ```
675
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_button.rb
676
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_button.rb
676
677
  ```
677
678
 
678
679
  Glimmer app:
@@ -805,7 +806,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_checkbutton'"
805
806
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
806
807
 
807
808
  ```
808
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_checkbutton.rb
809
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_checkbutton.rb
809
810
  ```
810
811
 
811
812
  Glimmer app:
@@ -919,7 +920,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_radiobutton'"
919
920
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
920
921
 
921
922
  ```
922
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_radiobutton.rb
923
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_radiobutton.rb
923
924
  ```
924
925
 
925
926
  Glimmer app:
@@ -992,7 +993,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_frame'"
992
993
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
993
994
 
994
995
  ```
995
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_frame.rb
996
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_frame.rb
996
997
  ```
997
998
 
998
999
  Glimmer app:
@@ -1042,7 +1043,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_root'"
1042
1043
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1043
1044
 
1044
1045
  ```
1045
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_root.rb
1046
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_root.rb
1046
1047
  ```
1047
1048
 
1048
1049
  Glimmer app:
@@ -1096,7 +1097,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_notebook'"
1096
1097
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1097
1098
 
1098
1099
  ```
1099
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_notebook.rb
1100
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_notebook.rb
1100
1101
  ```
1101
1102
 
1102
1103
  Glimmer app:
@@ -1209,7 +1210,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_label'"
1209
1210
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1210
1211
 
1211
1212
  ```
1212
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_label.rb
1213
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_label.rb
1213
1214
  ```
1214
1215
 
1215
1216
  Glimmer app:
@@ -1311,7 +1312,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_message_box'"
1311
1312
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1312
1313
 
1313
1314
  ```
1314
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_message_box.rb
1315
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_message_box.rb
1315
1316
  ```
1316
1317
 
1317
1318
  Glimmer app:
@@ -1352,7 +1353,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_combobox'"
1352
1353
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1353
1354
 
1354
1355
  ```
1355
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_combobox.rb
1356
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_combobox.rb
1356
1357
  ```
1357
1358
 
1358
1359
  Glimmer app:
@@ -1392,7 +1393,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_list_single_selection'"
1392
1393
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1393
1394
 
1394
1395
  ```
1395
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_list_single_selection.rb
1396
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_list_single_selection.rb
1396
1397
  ```
1397
1398
 
1398
1399
  Glimmer app:
@@ -1430,7 +1431,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_list_multi_selection'"
1430
1431
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1431
1432
 
1432
1433
  ```
1433
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_list_multi_selection.rb
1434
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_list_multi_selection.rb
1434
1435
  ```
1435
1436
 
1436
1437
  Glimmer app:
@@ -1510,7 +1511,194 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_computed'"
1510
1511
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1511
1512
 
1512
1513
  ```
1513
- ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_computed.rb
1514
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_computed.rb
1515
+ ```
1516
+
1517
+ Glimmer app:
1518
+
1519
+ ![glimmer dsl tk screenshot sample hello computed](images/glimmer-dsl-tk-screenshot-sample-hello-computed.png)
1520
+
1521
+ ### Hello, Entry!
1522
+
1523
+ Glimmer code (from [samples/hello/hello_entry.rb](samples/hello/hello_entry.rb)):
1524
+
1525
+ ```ruby
1526
+ require 'glimmer-dsl-tk'
1527
+
1528
+ class HelloEntry
1529
+ include Glimmer
1530
+
1531
+ attr_accessor :default, :password, :telephone, :read_only
1532
+
1533
+ def initialize
1534
+ self.default = 'default'
1535
+ self.password = 'password'
1536
+ self.telephone = '555-555-5555'
1537
+ self.read_only = 'Telephone area code is 555'
1538
+ end
1539
+
1540
+ def launch
1541
+ root {
1542
+ title 'Hello, Entry!'
1543
+
1544
+ label {
1545
+ grid sticky: 'ew', column_weight: 1
1546
+ text 'default entry'
1547
+ }
1548
+ entry {
1549
+ grid sticky: 'ew'
1550
+ text <=> [self, :default]
1551
+ }
1552
+
1553
+ label {
1554
+ grid sticky: 'ew'
1555
+ text 'password entry'
1556
+ }
1557
+ entry {
1558
+ grid sticky: 'ew'
1559
+ show '*'
1560
+ text <=> [self, :password]
1561
+ }
1562
+
1563
+ @validated_entry_label = label {
1564
+ grid sticky: 'ew'
1565
+ text 'entry with event handlers'
1566
+ }
1567
+ entry {
1568
+ grid sticky: 'ew'
1569
+ text <=> [self, :telephone]
1570
+ validate 'key'
1571
+
1572
+ ## this event kicks in just after the user typed and before modifying the text variable
1573
+ on('validate') do |new_text_variable|
1574
+ telephone?(new_text_variable.value)
1575
+ end
1576
+
1577
+ ## this event kicks in just after the text variable is validated and before it is modified
1578
+ on('invalid') do |validate_args|
1579
+ @validated_entry_label.text = "#{validate_args.string} is not valid!"
1580
+ @validated_entry_label.foreground = 'red'
1581
+ end
1582
+
1583
+ ## this event kicks in just after the text variable is validated and modified
1584
+ on('change') do |new_text_variable|
1585
+ self.read_only = "Telephone area code is #{new_text_variable.value.gsub(/[^0-9]/, '')[0...3]}"
1586
+ @validated_entry_label.text = 'entry with event handlers'
1587
+ @validated_entry_label.foreground = nil
1588
+ end
1589
+ }
1590
+
1591
+ label {
1592
+ grid sticky: 'ew'
1593
+ text 'read-only entry'
1594
+ }
1595
+ entry {
1596
+ grid sticky: 'ew'
1597
+ text <=> [self, :read_only]
1598
+ readonly true
1599
+ }
1600
+ }.open
1601
+ end
1602
+
1603
+ def telephone?(text)
1604
+ !!text.match(/^\d{0,3}[-.\/]?\d{0,3}[-.\/]?\d{0,4}$/)
1605
+ end
1606
+ end
1607
+
1608
+ HelloEntry.new.launch
1609
+ ```
1610
+
1611
+ Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1612
+
1613
+ ```
1614
+ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_entry'"
1615
+ ```
1616
+
1617
+ Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1618
+
1619
+ ```
1620
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_entry.rb
1621
+ ```
1622
+
1623
+ Glimmer app:
1624
+
1625
+ ![glimmer dsl tk screenshot sample hello entry](images/glimmer-dsl-tk-screenshot-sample-hello-entry.png)
1626
+ ![glimmer dsl tk screenshot sample hello entry validated](images/glimmer-dsl-tk-screenshot-sample-hello-entry-validated.png)
1627
+
1628
+ ### Hello, Computed!
1629
+
1630
+ Glimmer code (from [samples/hello/hello_computed.rb](samples/hello/hello_computed.rb)):
1631
+
1632
+ ```ruby
1633
+ # ... more code precedes
1634
+ root {
1635
+ title 'Hello, Computed!'
1636
+
1637
+ frame {
1638
+ grid column: 0, row: 0, padx: 5, pady: 5
1639
+
1640
+ label {
1641
+ grid column: 0, row: 0, sticky: 'w'
1642
+ text 'First Name: '
1643
+ }
1644
+ entry {
1645
+ grid column: 1, row: 0
1646
+ width 15
1647
+ text <=> [@contact, :first_name]
1648
+ }
1649
+
1650
+ label {
1651
+ grid column: 0, row: 1, sticky: 'w'
1652
+ text 'Last Name: '
1653
+ }
1654
+ entry {
1655
+ grid column: 1, row: 1
1656
+ width 15
1657
+ text <=> [@contact, :last_name]
1658
+ }
1659
+
1660
+ label {
1661
+ grid column: 0, row: 2, sticky: 'w'
1662
+ text 'Year of Birth: '
1663
+ }
1664
+ entry {
1665
+ grid column: 1, row: 2
1666
+ width 15
1667
+ text <=> [@contact, :year_of_birth]
1668
+ }
1669
+
1670
+ label {
1671
+ grid column: 0, row: 3, sticky: 'w'
1672
+ text 'Name: '
1673
+ }
1674
+ label {
1675
+ grid column: 1, row: 3, sticky: 'w'
1676
+ text <=> [@contact, :name, computed_by: [:first_name, :last_name]]
1677
+ }
1678
+
1679
+ label {
1680
+ grid column: 0, row: 4, sticky: 'w'
1681
+ text 'Age: '
1682
+ }
1683
+ label {
1684
+ grid column: 1, row: 4, sticky: 'w'
1685
+ text <=> [@contact, :age, on_write: :to_i, computed_by: [:year_of_birth]]
1686
+ }
1687
+ }
1688
+ }.open
1689
+ # ... more code follows
1690
+ ```
1691
+
1692
+ Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1693
+
1694
+ ```
1695
+ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_computed'"
1696
+ ```
1697
+
1698
+ Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1699
+
1700
+ ```
1701
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_computed.rb
1514
1702
  ```
1515
1703
 
1516
1704
  Glimmer app:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.23
1
+ 0.0.24
Binary file
@@ -33,9 +33,26 @@ module Glimmer
33
33
  def validatecommand_block=(proc)
34
34
  tk.validatecommand(proc)
35
35
  end
36
+
36
37
  def invalidcommand_block=(proc)
37
38
  tk.invalidcommand(proc)
38
39
  end
40
+
41
+ def handle_listener(listener_name, &listener)
42
+ case listener_name.to_s.downcase
43
+ when 'change'
44
+ tk.textvariable.trace('write') {
45
+ listener.call(@tk.textvariable)
46
+ }
47
+ when 'validatecommand', 'validate'
48
+ self.validatecommand_block = listener
49
+ when 'invalidcommand', 'invalid'
50
+ self.invalidcommand_block = listener
51
+ else
52
+ super
53
+ end
54
+ end
55
+
39
56
  end
40
57
  end
41
58
  end
@@ -149,7 +149,11 @@ module Glimmer
149
149
 
150
150
  def set_attribute(attribute, *args)
151
151
  widget_custom_attribute = widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][attribute.to_s]
152
- if widget_custom_attribute
152
+ if respond_to?(attribute, super_only: true)
153
+ send(attribute, *args)
154
+ elsif respond_to?(attribute_setter(attribute), super_only: true)
155
+ send(attribute_setter(attribute), *args)
156
+ elsif widget_custom_attribute
153
157
  widget_custom_attribute[:setter][:invoker].call(@tk, args)
154
158
  elsif tk_widget_has_attribute_setter?(attribute)
155
159
  unless args.size == 1 && @tk.send(attribute) == args.first
@@ -197,6 +201,26 @@ module Glimmer
197
201
  "#{attribute}="
198
202
  end
199
203
 
204
+ def grid(options = {})
205
+ options = options.stringify_keys
206
+ index_in_parent = @parent_proxy.children.index(self)
207
+ options['rowweight'] = options.delete('row_weight') if options.keys.include?('row_weight')
208
+ options['columnweight'] = options.delete('column_weight') if options.keys.include?('column_weight')
209
+ options['columnweight'] = options['rowweight'] = options.delete('weight') if options.keys.include?('weight')
210
+ options['rowminsize'] = options.delete('row_minsize') if options.keys.include?('row_minsize')
211
+ options['rowminsize'] = options.delete('minheight') if options.keys.include?('minheight')
212
+ options['rowminsize'] = options.delete('min_height') if options.keys.include?('min_height')
213
+ options['columnminsize'] = options.delete('column_minsize') if options.keys.include?('column_minsize')
214
+ options['columnminsize'] = options.delete('minwidth') if options.keys.include?('minwidth')
215
+ options['columnminsize'] = options.delete('min_width') if options.keys.include?('min_width')
216
+ options['columnminsize'] = options['rowminsize'] = options.delete('minsize') if options.keys.include?('minsize')
217
+ TkGrid.rowconfigure(@parent_proxy.tk, index_in_parent, 'weight'=> options.delete('rowweight')) if options.keys.include?('rowweight')
218
+ TkGrid.rowconfigure(@parent_proxy.tk, index_in_parent, 'minsize'=> options.delete('rowminsize')) if options.keys.include?('rowminsize')
219
+ TkGrid.columnconfigure(@parent_proxy.tk, index_in_parent, 'weight'=> options.delete('columnweight')) if options.keys.include?('columnweight')
220
+ TkGrid.columnconfigure(@parent_proxy.tk, index_in_parent, 'minsize'=> options.delete('columnminsize')) if options.keys.include?('columnminsize')
221
+ @tk.grid(options)
222
+ end
223
+
200
224
  def widget_custom_attribute_mapping
201
225
  # TODO consider extracting to modules/subclasses
202
226
  @widget_custom_attribute_mapping ||= {
@@ -249,7 +273,7 @@ module Glimmer
249
273
  ::Tk::Tile::TEntry => {
250
274
  'text' => {
251
275
  getter: {name: 'text', invoker: lambda { |widget, args| @tk.textvariable&.value }},
252
- setter: {name: 'text=', invoker: lambda { |widget, args| @tk.textvariable&.value = args.first unless @text_variable_edit }},
276
+ setter: {name: 'text=', invoker: lambda { |widget, args| @tk.textvariable&.value = args.first }},
253
277
  },
254
278
  },
255
279
  ::Tk::Root => {
@@ -285,23 +309,14 @@ module Glimmer
285
309
  },
286
310
  ::Tk::Tile::TEntry => {
287
311
  'text' => lambda do |observer|
288
- tk.validate = 'key'
289
- tk.validatecommand { |new_tk_variable|
290
- @text_variable_edit = new_tk_variable.value != @tk.textvariable.value
291
- if @text_variable_edit
292
- observer.call(new_tk_variable.value)
293
- @text_variable_edit = nil
294
- true
295
- else
296
- false
297
- end
312
+ tk.textvariable.trace('write') {
313
+ observer.call(@tk.textvariable.value)
298
314
  }
299
315
  end,
300
316
  },
301
317
  ::Tk::Tile::TRadiobutton => {
302
318
  'variable' => lambda do |observer|
303
319
  @tk.command {
304
- pd @tk.variable.value, @tk.value
305
320
  observer.call(@tk.variable.value == @tk.value)
306
321
  }
307
322
  end,
@@ -361,15 +376,15 @@ module Glimmer
361
376
  super(method.to_sym, *args, &block)
362
377
  end
363
378
 
364
- def respond_to?(method, *args, &block)
365
- super ||
366
- tk.respond_to?(method, *args, &block)
379
+ def respond_to?(method, *args, super_only: false, &block)
380
+ super(method, true) ||
381
+ !super_only && tk.respond_to?(method, *args, &block)
367
382
  end
368
383
 
369
384
  private
370
385
 
371
386
  def initialize_defaults
372
- @tk.grid unless @tk.is_a?(::Tk::Toplevel)
387
+ grid unless @tk.is_a?(::Tk::Toplevel)
373
388
  end
374
389
  end
375
390
  end
@@ -28,6 +28,7 @@ require 'puts_debuggerer' if ENV['pd'].to_s.downcase == 'true'
28
28
  # require 'super_module'
29
29
  require 'tk'
30
30
  require 'os'
31
+ require 'facets/hash/symbolize_keys'
31
32
 
32
33
  # Internal requires
33
34
  # require 'ext/glimmer/config'
@@ -0,0 +1,104 @@
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-dsl-tk'
23
+
24
+ class HelloEntry
25
+ include Glimmer
26
+
27
+ attr_accessor :default, :password, :telephone, :read_only
28
+
29
+ def initialize
30
+ self.default = 'default'
31
+ self.password = 'password'
32
+ self.telephone = '555-555-5555'
33
+ self.read_only = 'Telephone area code is 555'
34
+ end
35
+
36
+ def launch
37
+ root {
38
+ title 'Hello, Entry!'
39
+
40
+ label {
41
+ grid sticky: 'ew', column_weight: 1
42
+ text 'default entry'
43
+ }
44
+ entry {
45
+ grid sticky: 'ew'
46
+ text <=> [self, :default]
47
+ }
48
+
49
+ label {
50
+ grid sticky: 'ew'
51
+ text 'password entry'
52
+ }
53
+ entry {
54
+ grid sticky: 'ew'
55
+ show '*'
56
+ text <=> [self, :password]
57
+ }
58
+
59
+ @validated_entry_label = label {
60
+ grid sticky: 'ew'
61
+ text 'entry with event handlers'
62
+ }
63
+ entry {
64
+ grid sticky: 'ew'
65
+ text <=> [self, :telephone]
66
+ validate 'key'
67
+
68
+ ## this event kicks in just after the user typed and before modifying the text variable
69
+ on('validate') do |new_text_variable|
70
+ telephone?(new_text_variable.value)
71
+ end
72
+
73
+ ## this event kicks in just after the text variable is validated and before it is modified
74
+ on('invalid') do |validate_args|
75
+ @validated_entry_label.text = "#{validate_args.string} is not valid!"
76
+ @validated_entry_label.foreground = 'red'
77
+ end
78
+
79
+ ## this event kicks in just after the text variable is validated and modified
80
+ on('change') do |new_text_variable|
81
+ self.read_only = "Telephone area code is #{new_text_variable.value.gsub(/[^0-9]/, '')[0...3]}"
82
+ @validated_entry_label.text = 'entry with event handlers'
83
+ @validated_entry_label.foreground = nil
84
+ end
85
+ }
86
+
87
+ label {
88
+ grid sticky: 'ew'
89
+ text 'read-only entry'
90
+ }
91
+ entry {
92
+ grid sticky: 'ew'
93
+ text <=> [self, :read_only]
94
+ readonly true
95
+ }
96
+ }.open
97
+ end
98
+
99
+ def telephone?(text)
100
+ !!text.match(/^\d{0,3}[-.\/]?\d{0,3}[-.\/]?\d{0,4}$/)
101
+ end
102
+ end
103
+
104
+ HelloEntry.new.launch
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.23
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-13 00:00:00.000000000 Z
11
+ date: 2021-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -190,7 +190,8 @@ dependencies:
190
190
  - - "~>"
191
191
  - !ruby/object:Gem::Version
192
192
  version: 0.7.0
193
- description: Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)
193
+ description: Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library) - Ruby
194
+ DSL for Tcl/Tk with bidirectional/unidirectional data-binding support
194
195
  email: andy.am@gmail.com
195
196
  executables:
196
197
  - girb
@@ -242,6 +243,7 @@ files:
242
243
  - samples/hello/hello_combobox.rb
243
244
  - samples/hello/hello_computed.rb
244
245
  - samples/hello/hello_computed/contact.rb
246
+ - samples/hello/hello_entry.rb
245
247
  - samples/hello/hello_frame.rb
246
248
  - samples/hello/hello_label.rb
247
249
  - samples/hello/hello_list_multi_selection.rb