glimmer-dsl-tk 0.0.21 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49a3f4e1f560a01173a20fa1a13fc62f107445c63cad77f353b3b7a9765433c3
4
- data.tar.gz: 70decda6f2e3a73a24916b2e9d0685ff386fc4fe29b89fff3b4188fab830f21b
3
+ metadata.gz: f1af2971637c33b4dcebacf0de9239fa24402b92325157df38453a1ba535d99c
4
+ data.tar.gz: f327b2f968225d46be3768dc109aba6799ad4b00cd4c77b2584ed3729de57a7d
5
5
  SHA512:
6
- metadata.gz: 7f9b8ee1544898bcb7031eacaf4ebb532ab113ac5852b6606bf247a05e27937b5d22c87833b5947527e6b525d83e2eb5714a42f1cf8f754bf7513d59eaf19ff4
7
- data.tar.gz: 479e321c66646a97bd5fee7e6844e4b7a862ec88b2ba25697a9f8e1ac231717297258576b4b88facab135094bff30b2a507bd6b1a624fb0288f163ca5dff54c9
6
+ metadata.gz: a94b3eff61254b4b134cd19011c51ea1ec1ca952f6f2a753897840a0586cd39ca41483f4701a6746d8768b186a28790f6a010dfa6ba8f27d38d1698058ee11b4
7
+ data.tar.gz: d0fba3f64cb7b54f94ae6c00d7d6dbe4c1fe400cbc66c15c55b3648cfa3d05b0cb2eba123e6a4a9b1e79c78e9f0c9376282a2f9829d8f95013aa9804bcc05609
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.22
4
+
5
+ - Hello, Checkbutton!
6
+ - Support checkbutton data-binding
7
+
3
8
  ## 0.0.21
4
9
 
5
10
  - Support event bindings via `on(event) {}` syntax nestable under any widget
data/README.md CHANGED
@@ -83,16 +83,18 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
83
83
  - [Icon Photo](#icon-photo)
84
84
  - [The Grid Geometry Manager](#the-grid-geometry-manager)
85
85
  - [Bidirectional Data-Binding](#bidirectional-data-binding)
86
- - [General Property Data-Binding](#general-property-data-binding)
86
+ - [Label Data-Binding](#label-data-binding)
87
87
  - [Combobox Data-Binding](#combobox-data-binding)
88
88
  - [List Single Selection Data-Binding](#list-single-selection-data-binding)
89
89
  - [List Multi Selection Data-Binding](#list-multi-selection-data-binding)
90
90
  - [Entry Data-Binding](#entry-data-binding)
91
- - [Command Observer](#command-observer)
91
+ - [Checkbox Data-Binding](#checkbox-data-binding)
92
+ - [Command Callback](#command-callback)
92
93
  - [Gotchas](#gotchas)
93
94
  - [Samples](#samples)
94
95
  - [Hello, World!](#hello-world)
95
96
  - [Hello, Button!](#hello-button)
97
+ - [Hello, Checkbutton!](#hello-checkbutton)
96
98
  - [Hello, Frame!](#hello-frame)
97
99
  - [Hello, Root!](#hello-root)
98
100
  - [Hello, Notebook!](#hello-notebook)
@@ -248,6 +250,7 @@ root {
248
250
  keyword(args) | attributes | event bindings & callbacks
249
251
  ------------- | ---------- | ---------
250
252
  `button` | `text`, `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `default` (`'active', 'normal'`) | `command {}`
253
+ `checkbutton` | `text`, `variable` (Boolean), `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `default` (`'active', 'normal'`) | `command {}`
251
254
  `combobox` | `state`, `text` | `'ComboboxSelected'`
252
255
  `entry` | `width`, `text` | None
253
256
  `frame(text: nil)` | `width`, `height`, `borderwidth`, `relief` (`'flat' (default), 'raised', 'sunken', 'solid', 'ridge', 'groove'`) | None
@@ -371,7 +374,7 @@ More details can be found in the [Hello, Computed!](#hello-computed) sample belo
371
374
 
372
375
  Glimmer supports Shine syntax bidirectional data-binding via the `<=>` operator (read-write) and unidirectional data-binding via the `<=` operator (read-only), which takes a model and an attribute (the `bind` keyword may also be used as the old-style of data-binding).
373
376
 
374
- ### General Property Data-Binding
377
+ ### Label Data-Binding
375
378
 
376
379
  Example:
377
380
 
@@ -379,11 +382,11 @@ This assumes a `Person` model with a `country` attribute.
379
382
 
380
383
  ```ruby
381
384
  label {
382
- text <=> [person, :country]
385
+ text <= [person, :country]
383
386
  }
384
387
  ```
385
388
 
386
- That code binds the `textvariable` value of the `label` to the `country` property on the `person` model.
389
+ That code binds the `textvariable` value of the `label` unidirectionally (read-only) to the `country` property on the `person` model.
387
390
 
388
391
  It automatically handles all the Tk plumbing behind the scenes.
389
392
 
@@ -424,8 +427,8 @@ This assumes a `Person` model with a `country` attribute representing their curr
424
427
  }
425
428
  ```
426
429
 
427
- That code binds the `items` text of the `list` to the `country_options` property on the `person` model (data-binding attribute + "_options" by convention).
428
- It also binds the `selection` text of the `list` to the `country` property on the `person` model.
430
+ That code binds the `items` text of the `list` to the `country_options` attribute on the `person` model (data-binding attribute + "_options" by convention).
431
+ It also binds the `selection` text of the `list` to the `country` attribute on the `person` model.
429
432
 
430
433
  It automatically handles all the Tk plumbing behind the scenes.
431
434
 
@@ -445,8 +448,8 @@ This assumes a `Person` model with a `provinces` attribute representing their cu
445
448
  }
446
449
  ```
447
450
 
448
- That code binds the `items` text of the `list` to the `provinces_options` property on the `person` model (data-binding attribute + "_options" by convention).
449
- It also binds the `selection` text of the `list` to the `provinces` property on the `person` model.
451
+ That code binds the `items` text of the `list` to the `provinces_options` attribute on the `person` model (data-binding attribute + "_options" by convention).
452
+ It also binds the `selection` text of the `list` to the `provinces` attribute on the `person` model.
450
453
 
451
454
  It automatically handles all the Tk plumbing behind the scenes.
452
455
 
@@ -464,30 +467,47 @@ This assumes a `Person` model with a `country` attribute.
464
467
  }
465
468
  ```
466
469
 
467
- That code binds the `textvariable` value of the `entry` to the `country` property on the `person` model.
470
+ That code binds the `textvariable` value of the `entry` to the `country` attribute on the `person` model.
468
471
 
469
472
  It automatically handles all the Tk plumbing behind the scenes.
470
473
 
471
474
  More details can be found in the [Hello, Computed!](#hello-computed) sample below.
472
475
 
473
- ## Command Observer
476
+ ### Checkbox Data-Binding
477
+
478
+ Example:
479
+
480
+ This assumes a `Person` model with a boolean `adult` attribute.
481
+
482
+ ```ruby
483
+ checkbutton {
484
+ variable <=> [person, :adult]
485
+ }
486
+ ```
487
+
488
+ That code binds the `variable` value of the `checkbutton` to the boolean `adult` attribute on the `person` model.
474
489
 
475
- Buttons can set a `command` option to trigger when the user clicks the button. This may be done with the `command` keyword, passing in a block directly (no need for `proc` as per Tk)
490
+ It automatically handles all the Tk plumbing behind the scenes.
491
+
492
+ More details can be found in the [Hello, Checkbutton!](#hello-checkbutton) sample below.
493
+
494
+ ## Command Callback
495
+
496
+ `button` and `checkbutton` can set a `command` block to trigger when the user clicks the button/checkbutton. This may be done with the `command` keyword, passing in a block directly.
476
497
 
477
498
  Example:
478
499
 
479
500
  ```ruby
480
501
  button {
481
502
  text "Reset Selection"
503
+
482
504
  command {
483
505
  person.reset_country
484
506
  }
485
507
  }
486
508
  ```
487
509
 
488
- This resets the person country.
489
-
490
- More details can be found in the [Hello, Combobox!](#hello-combobox) sample below.
510
+ More details can be found in the [Hello, Button!](#hello-button) sample below.
491
511
 
492
512
  ## Gotchas
493
513
 
@@ -628,6 +648,97 @@ Glimmer app:
628
648
 
629
649
  ![glimmer dsl tk screenshot sample hello button](images/glimmer-dsl-tk-screenshot-sample-hello-button.png)
630
650
 
651
+ ### Hello, Checkbutton!
652
+
653
+ Glimmer code (from [samples/hello/hello_checkbutton.rb](samples/hello/hello_checkbutton.rb)):
654
+
655
+ ```ruby
656
+ require 'glimmer-dsl-tk'
657
+
658
+ class HelloCheckbutton
659
+ class Person
660
+ attr_accessor :skiing, :snowboarding, :snowmobiling, :snowshoeing
661
+
662
+ def initialize
663
+ reset_activities!
664
+ end
665
+
666
+ def reset_activities!
667
+ self.skiing = false
668
+ self.snowboarding = true
669
+ self.snowmobiling = false
670
+ self.snowshoeing = false
671
+ end
672
+ end
673
+
674
+ include Glimmer
675
+
676
+ def initialize
677
+ @person = Person.new
678
+ end
679
+
680
+ def launch
681
+ root {
682
+ title 'Hello, Checkbutton!'
683
+ background '#ececec' if OS.mac?
684
+
685
+ label {
686
+ text 'Check all snow activities you are interested in:'
687
+ font 'caption'
688
+ }
689
+
690
+ frame {
691
+ checkbutton {
692
+ text 'Skiing'
693
+ variable <=> [@person, :skiing]
694
+ }
695
+
696
+ checkbutton {
697
+ text 'Snowboarding'
698
+ variable <=> [@person, :snowboarding]
699
+ }
700
+
701
+ checkbutton {
702
+ text 'Snowmobiling'
703
+ variable <=> [@person, :snowmobiling]
704
+ }
705
+
706
+ checkbutton {
707
+ text 'Snowshoeing'
708
+ variable <=> [@person, :snowshoeing]
709
+ }
710
+ }
711
+
712
+ button {
713
+ text 'Reset Activities'
714
+
715
+ command do
716
+ @person.reset_activities!
717
+ end
718
+ }
719
+ }.open
720
+ end
721
+ end
722
+
723
+ HelloCheckbutton.new.launch
724
+ ```
725
+
726
+ Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
727
+
728
+ ```
729
+ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_checkbutton'"
730
+ ```
731
+
732
+ Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
733
+
734
+ ```
735
+ ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_checkbutton.rb
736
+ ```
737
+
738
+ Glimmer app:
739
+
740
+ ![glimmer dsl tk screenshot sample hello checkbutton](images/glimmer-dsl-tk-screenshot-sample-hello-checkbutton.png)
741
+
631
742
  ### Hello, Frame!
632
743
 
633
744
  Glimmer code (from [samples/hello/hello_frame.rb](samples/hello/hello_frame.rb)):
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.21
1
+ 0.0.22
Binary file
@@ -27,9 +27,20 @@ module Glimmer
27
27
  #
28
28
  # Follows the Proxy Design Pattern
29
29
  class ButtonProxy < WidgetProxy
30
+ # TODO extract to a module
31
+
30
32
  def command_block=(proc)
31
33
  tk.command(proc)
32
34
  end
35
+
36
+ def handle_listener(listener_name, &listener)
37
+ case listener_name.to_s.downcase
38
+ when 'command'
39
+ command(listener)
40
+ else
41
+ super
42
+ end
43
+ end
33
44
  end
34
45
  end
35
46
  end
@@ -0,0 +1,44 @@
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
+ # Proxy for Tk::Tile::Checkbutton
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class ChecktbuttonProxy < WidgetProxy
30
+ def command_block=(proc)
31
+ tk.command(proc)
32
+ end
33
+
34
+ def handle_listener(listener_name, &listener)
35
+ case listener_name.to_s.downcase
36
+ when 'command'
37
+ command(listener)
38
+ else
39
+ super
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -127,7 +127,7 @@ module Glimmer
127
127
  end
128
128
 
129
129
  def handle_listener(listener_name, &listener)
130
- case listener_name.to_s
130
+ case listener_name.to_s.upcase
131
131
  when 'WM_DELETE_WINDOW', 'DELETE_WINDOW'
132
132
  listener_name = 'WM_DELETE_WINDOW'
133
133
  @tk.protocol(listener_name, &listener)
@@ -64,6 +64,9 @@ module Glimmer
64
64
  attr_reader :parent_proxy, :tk, :args, :keyword
65
65
 
66
66
  DEFAULT_INITIALIZERS = {
67
+ 'checkbutton' => lambda do |tk|
68
+ tk.variable = ::TkVariable.new
69
+ end,
67
70
  'combobox' => lambda do |tk|
68
71
  tk.textvariable = ::TkVariable.new
69
72
  end,
@@ -212,6 +215,16 @@ module Glimmer
212
215
  setter: {name: 'image=', invoker: lambda { |widget, args| @tk.image = image_argument(args) }},
213
216
  },
214
217
  },
218
+ ::Tk::Tile::TCheckbutton => {
219
+ 'image' => {
220
+ getter: {name: 'image', invoker: lambda { |widget, args| @tk.image }},
221
+ setter: {name: 'image=', invoker: lambda { |widget, args| @tk.image = image_argument(args) }},
222
+ },
223
+ 'variable' => {
224
+ getter: {name: 'variable', invoker: lambda { |widget, args| @tk.variable&.value.to_i == 1 }},
225
+ setter: {name: 'variable=', invoker: lambda { |widget, args| @tk.variable&.value = args.first.is_a?(Integer) ? args.first : (args.first ? 1 : 0) }},
226
+ },
227
+ },
215
228
  ::Tk::Tile::TCombobox => {
216
229
  'text' => {
217
230
  getter: {name: 'text', invoker: lambda { |widget, args| @tk.textvariable&.value }},
@@ -239,6 +252,13 @@ module Glimmer
239
252
 
240
253
  def widget_attribute_listener_installers
241
254
  @tk_widget_attribute_listener_installers ||= {
255
+ ::Tk::Tile::TCheckbutton => {
256
+ 'variable' => lambda do |observer|
257
+ @tk.command {
258
+ observer.call(@tk.variable.value.to_i == 1)
259
+ }
260
+ end,
261
+ },
242
262
  ::Tk::Tile::TCombobox => {
243
263
  'text' => lambda do |observer|
244
264
  if observer.is_a?(Glimmer::DataBinding::ModelBinding)
@@ -27,6 +27,7 @@ require 'glimmer'
27
27
  require 'puts_debuggerer' if ENV['pd'].to_s.downcase == 'true'
28
28
  # require 'super_module'
29
29
  require 'tk'
30
+ require 'os'
30
31
 
31
32
  # Internal requires
32
33
  # require 'ext/glimmer/config'
@@ -0,0 +1,89 @@
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 HelloCheckbutton
25
+ class Person
26
+ attr_accessor :skiing, :snowboarding, :snowmobiling, :snowshoeing
27
+
28
+ def initialize
29
+ reset_activities!
30
+ end
31
+
32
+ def reset_activities!
33
+ self.skiing = false
34
+ self.snowboarding = true
35
+ self.snowmobiling = false
36
+ self.snowshoeing = false
37
+ end
38
+ end
39
+
40
+ include Glimmer
41
+
42
+ def initialize
43
+ @person = Person.new
44
+ end
45
+
46
+ def launch
47
+ root {
48
+ title 'Hello, Checkbutton!'
49
+ background '#ececec' if OS.mac?
50
+
51
+ label {
52
+ text 'Check all snow activities you are interested in:'
53
+ font 'caption'
54
+ }
55
+
56
+ frame {
57
+ checkbutton {
58
+ text 'Skiing'
59
+ variable <=> [@person, :skiing]
60
+ }
61
+
62
+ checkbutton {
63
+ text 'Snowboarding'
64
+ variable <=> [@person, :snowboarding]
65
+ }
66
+
67
+ checkbutton {
68
+ text 'Snowmobiling'
69
+ variable <=> [@person, :snowmobiling]
70
+ }
71
+
72
+ checkbutton {
73
+ text 'Snowshoeing'
74
+ variable <=> [@person, :snowshoeing]
75
+ }
76
+ }
77
+
78
+ button {
79
+ text 'Reset Activities'
80
+
81
+ command do
82
+ @person.reset_activities!
83
+ end
84
+ }
85
+ }.open
86
+ end
87
+ end
88
+
89
+ HelloCheckbutton.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.21
4
+ version: 0.0.22
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-12 00:00:00.000000000 Z
11
+ date: 2021-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -38,6 +38,26 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.13.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: os
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 2.0.0
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 1.0.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 2.0.0
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: tk
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -203,6 +223,7 @@ files:
203
223
  - lib/glimmer/dsl/tk/shine_data_binding_expression.rb
204
224
  - lib/glimmer/dsl/tk/widget_expression.rb
205
225
  - lib/glimmer/tk/button_proxy.rb
226
+ - lib/glimmer/tk/checkbutton_proxy.rb
206
227
  - lib/glimmer/tk/entry_proxy.rb
207
228
  - lib/glimmer/tk/frame_proxy.rb
208
229
  - lib/glimmer/tk/label_proxy.rb
@@ -212,6 +233,7 @@ files:
212
233
  - lib/glimmer/tk/treeview_proxy.rb
213
234
  - lib/glimmer/tk/widget_proxy.rb
214
235
  - samples/hello/hello_button.rb
236
+ - samples/hello/hello_checkbutton.rb
215
237
  - samples/hello/hello_combobox.rb
216
238
  - samples/hello/hello_computed.rb
217
239
  - samples/hello/hello_computed/contact.rb
@@ -252,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
274
  - !ruby/object:Gem::Version
253
275
  version: '0'
254
276
  requirements: []
255
- rubygems_version: 3.2.28
277
+ rubygems_version: 3.2.22
256
278
  signing_key:
257
279
  specification_version: 4
258
280
  summary: Glimmer DSL for Tk