glimmer-dsl-tk 0.0.10 → 0.0.14

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: 795ec888a423df168b27805ca72bb845e59784134838cb01f65c63ce683d8c5f
4
- data.tar.gz: d54e9355ae521246e6b2394e3350f1786cf185a01115504847247f116d715cbf
3
+ metadata.gz: 497468a4ac3cef00c77957d6cb216ba1aed9916214e54561e8bff752c5117261
4
+ data.tar.gz: 3da1ce8af59ea3e03f45b1ab7c218c375fd86a145959657e8251d431bc6d0d90
5
5
  SHA512:
6
- metadata.gz: d9aa0e7c01d07179a4ee40b9dd796f3dd9ace09448f3b4b03df253a731fd73aa39b3bbb7936e32e40d9a1950442d1f7e54fd8804bd257eb69f7e0506114be131
7
- data.tar.gz: 7e57301dfd0a4ff29cb5e8a3d10d96d8ba5bb7d12c4af85baa70313639e5b1f6696936e7d0b0dde8319289b6b9fdb19c704813806669cc8ff263b537c72df46f
6
+ metadata.gz: f8def1bfc6f2263a3557a0fd6ccdf48b53180a259a63972463341e9afa235610634b4070b3b5b425c7a0205b73d2b22f3f9562cdebb53b3792232723f7a3a0bb
7
+ data.tar.gz: 7bd54e692f828e9134876bf9b00f3f3d2413235c919673ffe44be294c6890fcf1c2655ab5928a92a3e814049a37bd458e82f5870c0d051c91f0f60f14eebcd6b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.12
4
+
5
+ - Upgrade to glimmer 2.3.0
6
+ - Support Shine syntax for data-binding
7
+ - Update all data-binding samples to use Shine syntax for data-binding
8
+
9
+ ## 0.0.11
10
+
11
+ - Add preliminary support for `treeview` (no data-binding) with `columns`, `show`, and `heading_configure` attributes/methods
12
+
3
13
  ## 0.0.10
4
14
 
5
15
  - puts_debuggerer gem to help consumers with debugging in and out of girb
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.10
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.14
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
  [![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-tk/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-tk?branch=master)
@@ -9,7 +9,7 @@
9
9
 
10
10
  [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [Tk](https://www.tcl.tk/) enables desktop development with [Glimmer](https://github.com/AndyObtiva/glimmer) in [Ruby](https://github.com/ruby/ruby).
11
11
 
12
- [Tcl/Tk](https://www.tcl.tk/) has evolved into a practical desktop GUI toolkit due to gaining truly native looking themed widgets on Mac, Windows, and Linux in [Tk version 8.5](https://www.tcl.tk/software/tcltk/8.5.html#:~:text=Highlights%20of%20Tk%208.5&text=Font%20rendering%3A%20Now%20uses%20anti,and%20window%20layout%2C%20and%20more.).
12
+ [Tcl/Tk](https://www.tcl.tk/) has evolved into a practical desktop GUI toolkit due to gaining native looking themed widgets on Mac, Windows, and Linux in [Tk version 8.5](https://www.tcl.tk/software/tcltk/8.5.html#:~:text=Highlights%20of%20Tk%208.5&text=Font%20rendering%3A%20Now%20uses%20anti,and%20window%20layout%2C%20and%20more.).
13
13
 
14
14
  Additionally, [Ruby](https://www.ruby-lang.org/en/) 3.0 Ractor (formerly known as [Guilds](https://olivierlacan.com/posts/concurrency-in-ruby-3-with-guilds/)) supports truly parallel multi-threading, making both [MRI](https://github.com/ruby/ruby) and [Tk](https://www.tcl.tk/) finally viable for support in [Glimmer](https://github.com/AndyObtiva/glimmer) (Ruby Desktop Development GUI Library) as an alternative to [JRuby on SWT](https://github.com/AndyObtiva/glimmer-dsl-swt).
15
15
 
@@ -46,10 +46,11 @@ Glimmer app:
46
46
 
47
47
  ![glimmer dsl tk screenshot sample hello world](images/glimmer-dsl-tk-screenshot-sample-hello-world.png)
48
48
 
49
- NOTE: Glimmer DSL for Tk is in alpha mode. Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
49
+ NOTE: Glimmer DSL for Tk is currently in early alpha mode (incomplete). Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
50
50
 
51
51
  Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
52
52
  - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
53
+ - [glimmer-dsl-libui](https://github.com/AndyObtiva/glimmer-dsl-libui): Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library)
53
54
  - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps)
54
55
  - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
55
56
  - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
@@ -80,7 +81,7 @@ gem install glimmer-dsl-tk
80
81
 
81
82
  Add the following to `Gemfile`:
82
83
  ```
83
- gem 'glimmer-dsl-tk', '~> 0.0.10'
84
+ gem 'glimmer-dsl-tk', '~> 0.0.14'
84
85
  ```
85
86
 
86
87
  And, then run:
@@ -166,6 +167,23 @@ root {
166
167
  }.open
167
168
  ```
168
169
 
170
+ ### Supported Widgets
171
+
172
+ keyword(args) | attributes | listeners/events
173
+ ------------- | ---------- | ---------
174
+ `button` | `text` | `command`
175
+ `entry` | `width`, `text` | None
176
+ `frame(text: )` | None | None
177
+ `label` | `text` | None
178
+ `list` | `selectmode`, `selection` | None
179
+ `message_box(type: , message: , detail: , title: , icon: , default: , parent: )` | None | None
180
+ `notebook` | None | None
181
+ `root` | `title`, `iconphoto` | None
182
+
183
+ #### Common Attributes
184
+
185
+ - `grid`
186
+
169
187
  ### Smart Defaults and Convensions
170
188
 
171
189
  #### Grid Layout
@@ -210,7 +228,7 @@ Example:
210
228
  entry {
211
229
  grid column: 1, row: 2
212
230
  width 15
213
- text bind(@contact, :year_of_birth)
231
+ text <=> [@contact, :year_of_birth]
214
232
  }
215
233
  ```
216
234
 
@@ -218,9 +236,27 @@ More details can be found in the [Hello, Computed!](#hello-computed) sample belo
218
236
 
219
237
  ## Bidirectional Data-Binding
220
238
 
221
- Glimmer supports bidirectional data-binding via the `bind` keyword, which takes a model and an attribute.
239
+ 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).
240
+
241
+ ### General Property Data-Binding
242
+
243
+ Example:
244
+
245
+ This assumes a `Person` model with a `country` attribute.
246
+
247
+ ```ruby
248
+ label {
249
+ text <=> [person, :country]
250
+ }
251
+ ```
252
+
253
+ That code binds the `textvariable` value of the `label` to the `country` property on the `person` model.
254
+
255
+ It automatically handles all the Tk plumbing behind the scenes.
256
+
257
+ More details can be found in the [Hello, Computed!](#hello-computed) sample below.
222
258
 
223
- ### Combo Data-Binding
259
+ ### Combobox Data-Binding
224
260
 
225
261
  Example:
226
262
 
@@ -229,7 +265,7 @@ This assumes a `Person` model with a `country` attribute representing their curr
229
265
  ```ruby
230
266
  combobox {
231
267
  state 'readonly'
232
- text bind(person, :country)
268
+ text <=> [person, :country]
233
269
  }
234
270
  ```
235
271
 
@@ -238,7 +274,7 @@ It also binds the `text` selection of the `combobox` to the `country` property o
238
274
 
239
275
  It automatically handles all the Tk plumbing behind the scenes, such as using `TkVariable` and setting `combobox` `values` from `person.country_options` by convention (attribute_name + "_options").
240
276
 
241
- More details can be found in the [Hello, Combo!](#hello-combo) sample below.
277
+ More details can be found in the [Hello, Combobox!](#hello-combobox) sample below.
242
278
 
243
279
  ### List Single Selection Data-Binding
244
280
 
@@ -251,7 +287,7 @@ This assumes a `Person` model with a `country` attribute representing their curr
251
287
  ```ruby
252
288
  list {
253
289
  selectmode 'browse'
254
- text bind(person, :country)
290
+ text <=> [person, :country]
255
291
  }
256
292
  ```
257
293
 
@@ -272,7 +308,7 @@ This assumes a `Person` model with a `provinces` attribute representing their cu
272
308
 
273
309
  ```ruby
274
310
  list {
275
- text bind(person, :provinces)
311
+ text <=> [person, :provinces]
276
312
  }
277
313
  ```
278
314
 
@@ -283,24 +319,6 @@ It automatically handles all the Tk plumbing behind the scenes.
283
319
 
284
320
  More details can be found in the [Hello, List Multi Selection!](#hello-list-multi-selection) sample below.
285
321
 
286
- ### Label Data-Binding
287
-
288
- Example:
289
-
290
- This assumes a `Person` model with a `country` attribute.
291
-
292
- ```ruby
293
- label {
294
- text bind(person, :country)
295
- }
296
- ```
297
-
298
- That code binds the `textvariable` value of the `label` to the `country` property on the `person` model.
299
-
300
- It automatically handles all the Tk plumbing behind the scenes.
301
-
302
- More details can be found in the [Hello, Computed!](#hello-computed) sample below.
303
-
304
322
  ### Entry Data-Binding
305
323
 
306
324
  Example:
@@ -309,7 +327,7 @@ This assumes a `Person` model with a `country` attribute.
309
327
 
310
328
  ```ruby
311
329
  entry {
312
- text bind(person, :country)
330
+ text <=> [person, :country]
313
331
  }
314
332
  ```
315
333
 
@@ -336,7 +354,7 @@ Example:
336
354
 
337
355
  This resets the person country.
338
356
 
339
- More details can be found in the [Hello, Combo!](#hello-combo) sample below.
357
+ More details can be found in the [Hello, Combobox!](#hello-combobox) sample below.
340
358
 
341
359
  ## Samples
342
360
 
@@ -370,6 +388,56 @@ Glimmer app:
370
388
 
371
389
  ![glimmer dsl tk screenshot sample hello world](images/glimmer-dsl-tk-screenshot-sample-hello-world.png)
372
390
 
391
+ ### Hello, Button!
392
+
393
+ Glimmer code (from [samples/hello/hello_button.rb](samples/hello/hello_button.rb)):
394
+
395
+ ```ruby
396
+ require 'glimmer-dsl-tk'
397
+
398
+ class HelloButton
399
+ include Glimmer
400
+
401
+ attr_accessor :count
402
+
403
+ def initialize
404
+ @count = 0
405
+ end
406
+
407
+ def launch
408
+ root {
409
+ title 'Hello, Button!'
410
+
411
+ button {
412
+ text <= [self, :count, on_read: ->(value) { "Click To Increment: #{value} " }]
413
+
414
+ command {
415
+ self.count += 1
416
+ }
417
+ }
418
+ }.open
419
+ end
420
+ end
421
+
422
+ HelloButton.new.launch
423
+ ```
424
+
425
+ Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
426
+
427
+ ```
428
+ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_button'"
429
+ ```
430
+
431
+ Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
432
+
433
+ ```
434
+ ruby -e "require './lib/glimmer-dsl-tk'; require './samples/hello/hello_button'"
435
+ ```
436
+
437
+ Glimmer app:
438
+
439
+ ![glimmer dsl tk screenshot sample hello button](images/glimmer-dsl-tk-screenshot-sample-hello-button.png)
440
+
373
441
  ### Hello, Tab!
374
442
 
375
443
  Glimmer code (from [samples/hello/hello_tab.rb](samples/hello/hello_tab.rb)):
@@ -413,18 +481,111 @@ Glimmer app:
413
481
  ![glimmer dsl tk screenshot sample hello tab English](images/glimmer-dsl-tk-screenshot-sample-hello-tab-english.png)
414
482
  ![glimmer dsl tk screenshot sample hello tab French](images/glimmer-dsl-tk-screenshot-sample-hello-tab-french.png)
415
483
 
416
- ### Hello, Combo!
484
+ ### Hello, Message Box!
485
+
486
+ Glimmer code (from [samples/hello/hello_message_box.rb](samples/hello/hello_message_box.rb)):
487
+
488
+ ```ruby
489
+ root { |r|
490
+ title 'Hello, Message Box!'
491
+
492
+ frame {
493
+ grid sticky: 'nsew', padx: 15, pady: 15
494
+
495
+ button {
496
+ text 'Please Click To Win a Surprise'
497
+
498
+ command {
499
+ # specifying parent ensures dialog shows up centered on top of window (instead of centered in display monitor)
500
+ @result_label.text = message_box(parent: r, title: 'Surprise', message: "Congratulations!\n\nYou won $1,000,000!") # type: 'ok' by default
501
+ }
502
+ }
503
+
504
+ button {
505
+ text 'Download Software Update'
506
+
507
+ command {
508
+ @result_label.text = message_box(type: 'okcancel', title: 'Software Update', message: "We will begin to download software update.")
509
+ }
510
+ }
511
+
512
+ button {
513
+ text 'Format Hard Drive'
514
+
515
+ command {
516
+ @result_label.text = message_box(type: 'yesno', icon: 'question', title: 'Format', message: "Would you like to format your hard drive?")
517
+ }
518
+ }
519
+
520
+ button {
521
+ text 'Submit Application'
522
+
523
+ command {
524
+ @result_label.text = message_box(type: 'yesnocancel', icon: 'question', title: 'Application', message: "Would you like to review application before submitting?")
525
+ }
526
+ }
527
+
528
+ button {
529
+ text 'Play Video'
530
+
531
+ command {
532
+ @result_label.text = message_box(type: 'retrycancel', icon: 'error', title: 'Video Replay', message: "Video has failed to play. Would you like to retry?")
533
+ }
534
+ }
535
+
536
+ button {
537
+ text 'Installation Completed'
538
+
539
+ command {
540
+ @result_label.text = message_box(type: 'abortretryignore', icon: 'warning', default: 'ignore', title: 'Failed To Install Extra Utilities', message: "Installation is complete, but extra utilities have failed to install. Would you like to retry installing extra utilities?", detail: 'Encountered network error in downloading extra utilities, resulting in failure to install them')
541
+ }
542
+ }
543
+ }
544
+
545
+ frame {
546
+ grid sticky: 'nsew', padx: 15, pady: 15
547
+
548
+ label {
549
+ grid row: 0, column: 0
550
+ text 'Result:'
551
+ }
552
+
553
+ @result_label = label {
554
+ grid row: 0, column: 1
555
+ }
556
+ }
557
+ }.open
558
+ ```
559
+
560
+ Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
561
+
562
+ ```
563
+ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_tab'"
564
+ ```
565
+
566
+ Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
567
+
568
+ ```
569
+ ruby -e "require './lib/glimmer-dsl-tk'; require './samples/hello/hello_tab'"
570
+ ```
571
+
572
+ Glimmer app:
573
+
574
+ ![glimmer dsl tk screenshot sample hello message box](images/glimmer-dsl-tk-screenshot-sample-hello-message-box.png)
575
+ ![glimmer dsl tk screenshot sample hello message box open](images/glimmer-dsl-tk-screenshot-sample-hello-message-box-open.png)
576
+
577
+ ### Hello, Combobox!
417
578
 
418
- Glimmer code (from [samples/hello/hello_combo.rb](samples/hello/hello_combo.rb)):
579
+ Glimmer code (from [samples/hello/hello_combobox.rb](samples/hello/hello_combobox.rb)):
419
580
 
420
581
  ```ruby
421
582
  # ... more code precedes
422
583
  root {
423
- title 'Hello, Combo!'
584
+ title 'Hello, Combobox!'
424
585
 
425
586
  combobox { |proxy|
426
587
  state 'readonly'
427
- text bind(person, :country)
588
+ text <=> [person, :country]
428
589
  }
429
590
 
430
591
  button { |proxy|
@@ -440,19 +601,19 @@ root {
440
601
  Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
441
602
 
442
603
  ```
443
- ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_combo'"
604
+ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_combobox'"
444
605
  ```
445
606
 
446
607
  Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
447
608
 
448
609
  ```
449
- ruby -e "require './lib/glimmer-dsl-tk'; require './samples/hello/hello_combo'"
610
+ ruby -e "require './lib/glimmer-dsl-tk'; require './samples/hello/hello_combobox'"
450
611
  ```
451
612
 
452
613
  Glimmer app:
453
614
 
454
- ![glimmer dsl tk screenshot sample hello combo](images/glimmer-dsl-tk-screenshot-sample-hello-combo.png)
455
- ![glimmer dsl tk screenshot sample hello combo dropdown](images/glimmer-dsl-tk-screenshot-sample-hello-combo-dropdown.png)
615
+ ![glimmer dsl tk screenshot sample hello combobox](images/glimmer-dsl-tk-screenshot-sample-hello-combobox.png)
616
+ ![glimmer dsl tk screenshot sample hello combobox dropdown](images/glimmer-dsl-tk-screenshot-sample-hello-combobox-dropdown.png)
456
617
 
457
618
  ### Hello, List Single Selection!
458
619
 
@@ -465,7 +626,7 @@ root {
465
626
 
466
627
  list {
467
628
  selectmode 'browse'
468
- selection bind(person, :country)
629
+ selection <=> [person, :country]
469
630
  }
470
631
 
471
632
  button {
@@ -503,7 +664,7 @@ root {
503
664
  title 'Hello, List Multi Selection!'
504
665
 
505
666
  list {
506
- selection bind(person, :provinces)
667
+ selection <=> [person, :provinces]
507
668
  }
508
669
 
509
670
  button {
@@ -550,7 +711,7 @@ Glimmer code (from [samples/hello/hello_computed.rb](samples/hello/hello_compute
550
711
  entry {
551
712
  grid column: 1, row: 0
552
713
  width 15
553
- text bind(@contact, :first_name)
714
+ text <=> [@contact, :first_name]
554
715
  }
555
716
 
556
717
  label {
@@ -560,7 +721,7 @@ Glimmer code (from [samples/hello/hello_computed.rb](samples/hello/hello_compute
560
721
  entry {
561
722
  grid column: 1, row: 1
562
723
  width 15
563
- text bind(@contact, :last_name)
724
+ text <=> [@contact, :last_name]
564
725
  }
565
726
 
566
727
  label {
@@ -570,7 +731,7 @@ Glimmer code (from [samples/hello/hello_computed.rb](samples/hello/hello_compute
570
731
  entry {
571
732
  grid column: 1, row: 2
572
733
  width 15
573
- text bind(@contact, :year_of_birth)
734
+ text <=> [@contact, :year_of_birth]
574
735
  }
575
736
 
576
737
  label {
@@ -579,7 +740,7 @@ Glimmer code (from [samples/hello/hello_computed.rb](samples/hello/hello_compute
579
740
  }
580
741
  label {
581
742
  grid column: 1, row: 3, sticky: 'w'
582
- text bind(@contact, :name, computed_by: [:first_name, :last_name])
743
+ text <=> [@contact, :name, computed_by: [:first_name, :last_name]]
583
744
  }
584
745
 
585
746
  label {
@@ -588,7 +749,7 @@ Glimmer code (from [samples/hello/hello_computed.rb](samples/hello/hello_compute
588
749
  }
589
750
  label {
590
751
  grid column: 1, row: 4, sticky: 'w'
591
- text bind(@contact, :age, on_write: :to_i, computed_by: [:year_of_birth])
752
+ text <=> [@contact, :age, on_write: :to_i, computed_by: [:year_of_birth]]
592
753
  }
593
754
  }
594
755
  }.open
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.14
Binary file
@@ -40,6 +40,7 @@ module Glimmer
40
40
  data_binding
41
41
  block_attribute
42
42
  attribute
43
+ shine_data_binding
43
44
  widget
44
45
  ]
45
46
  )
@@ -0,0 +1,36 @@
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/static_expression'
23
+ require 'glimmer/tk/root_proxy'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Tk
28
+ class MessageBoxExpression < StaticExpression
29
+ def interpret(parent, keyword, *args, &block)
30
+ args.first[:parent] = args.first[:parent].tk if args.first.is_a?(Hash) && args.first[:parent].is_a?(Glimmer::Tk::RootProxy)
31
+ ::Tk::messageBox(*args)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2007-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/expression'
23
+ require 'glimmer/data_binding/model_binding'
24
+ require 'glimmer/data_binding/tk/widget_binding'
25
+ require 'glimmer/data_binding/shine'
26
+
27
+ module Glimmer
28
+ module DSL
29
+ module Tk
30
+ class ShineDataBindingExpression < Expression
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ args.size == 0 and
33
+ block.nil? and
34
+ (parent.respond_to?(:has_attribute?) and parent.has_attribute?(keyword))
35
+ end
36
+
37
+ def interpret(parent, keyword, *args, &block)
38
+ Glimmer::DataBinding::Shine.new(parent, keyword)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -58,3 +58,4 @@ require 'glimmer/tk/button_proxy'
58
58
  require 'glimmer/tk/label_proxy'
59
59
  require 'glimmer/tk/list_proxy'
60
60
  require 'glimmer/tk/entry_proxy'
61
+ require 'glimmer/tk/treeview_proxy'
@@ -40,7 +40,7 @@ module Glimmer
40
40
  end
41
41
 
42
42
  def content(&block)
43
- Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Tk::RootExpression.new, &block)
43
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Tk::RootExpression.new, keyword, *args, &block)
44
44
  end
45
45
 
46
46
  def set_attribute(attribute, *args)
@@ -0,0 +1,50 @@
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
+ # Custom treeview widget implementation
27
+ class TreeviewProxy < WidgetProxy
28
+ def has_attribute?(attribute, *args)
29
+ attribute == 'columns' || super
30
+ end
31
+
32
+ def set_attribute(attribute, *args)
33
+ if attribute == 'columns'
34
+ self[attribute] = args.first
35
+ else
36
+ super
37
+ end
38
+ end
39
+
40
+ def get_attribute(attribute)
41
+ if attribute == 'columns'
42
+ self[attribute]
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -25,20 +25,6 @@ module Glimmer
25
25
  #
26
26
  # Follows the Proxy Design Pattern
27
27
  class WidgetProxy
28
- attr_reader :parent_proxy, :tk, :args
29
-
30
- DEFAULT_INITIALIZERS = {
31
- 'combobox' => lambda do |tk|
32
- tk.textvariable = ::TkVariable.new
33
- end,
34
- 'label' => lambda do |tk|
35
- tk.textvariable = ::TkVariable.new
36
- end,
37
- 'entry' => lambda do |tk|
38
- tk.textvariable = ::TkVariable.new
39
- end,
40
- }
41
-
42
28
  class << self
43
29
  def create(keyword, parent, args)
44
30
  widget_proxy_class(keyword).new(keyword, parent, args)
@@ -75,12 +61,27 @@ module Glimmer
75
61
  end
76
62
  end
77
63
 
64
+ attr_reader :parent_proxy, :tk, :args, :keyword
65
+
66
+ DEFAULT_INITIALIZERS = {
67
+ 'combobox' => lambda do |tk|
68
+ tk.textvariable = ::TkVariable.new
69
+ end,
70
+ 'label' => lambda do |tk|
71
+ tk.textvariable = ::TkVariable.new
72
+ end,
73
+ 'entry' => lambda do |tk|
74
+ tk.textvariable = ::TkVariable.new
75
+ end,
76
+ }
77
+
78
78
  # Initializes a new Tk Widget
79
79
  #
80
80
  # Styles is a comma separate list of symbols representing Tk styles in lower case
81
81
  def initialize(underscored_widget_name, parent_proxy, args)
82
82
  @parent_proxy = parent_proxy
83
83
  @args = args
84
+ @keyword = underscored_widget_name
84
85
  tk_widget_class = self.class.tk_widget_class_for(underscored_widget_name)
85
86
  @tk = tk_widget_class.new(@parent_proxy.tk, *args)
86
87
  # a common widget initializer
@@ -133,7 +134,7 @@ module Glimmer
133
134
  elsif tk_widget_has_attribute_setter?(attribute)
134
135
  @tk.send(attribute_setter(attribute), *args) unless @tk.send(attribute) == args.first
135
136
  elsif tk_widget_has_attribute_getter_setter?(attribute)
136
- @tk.send(attribute, *args) unless @tk.send(attribute) == args.first
137
+ @tk.send(attribute, *args)
137
138
  else
138
139
  send(attribute_setter(attribute), args)
139
140
  end
@@ -216,7 +217,7 @@ module Glimmer
216
217
  end
217
218
 
218
219
  def content(&block)
219
- Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Tk::WidgetExpression.new, &block)
220
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Tk::WidgetExpression.new, keyword, *args, &block)
220
221
  end
221
222
 
222
223
  def method_missing(method, *args, &block)
@@ -0,0 +1,48 @@
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 HelloButton
25
+ include Glimmer
26
+
27
+ attr_accessor :count
28
+
29
+ def initialize
30
+ @count = 0
31
+ end
32
+
33
+ def launch
34
+ root {
35
+ title 'Hello, Button!'
36
+
37
+ button {
38
+ text <= [self, :count, on_read: ->(value) { "Click To Increment: #{value} " }]
39
+
40
+ command {
41
+ self.count += 1
42
+ }
43
+ }
44
+ }.open
45
+ end
46
+ end
47
+
48
+ HelloButton.new.launch
@@ -34,18 +34,18 @@ class Person
34
34
  end
35
35
  end
36
36
 
37
- class HelloCombo
37
+ class HelloCombobox
38
38
  include Glimmer
39
39
 
40
40
  def launch
41
41
  person = Person.new
42
42
 
43
43
  root {
44
- title 'Hello, Combo!'
44
+ title 'Hello, Combobox!'
45
45
 
46
46
  combobox {
47
47
  state 'readonly'
48
- text bind(person, :country)
48
+ text <=> [person, :country]
49
49
  }
50
50
 
51
51
  button {
@@ -58,4 +58,4 @@ class HelloCombo
58
58
  end
59
59
  end
60
60
 
61
- HelloCombo.new.launch
61
+ HelloCombobox.new.launch
@@ -48,7 +48,7 @@ class HelloComputed
48
48
  entry {
49
49
  grid column: 1, row: 0
50
50
  width 15
51
- text bind(@contact, :first_name)
51
+ text <=> [@contact, :first_name]
52
52
  }
53
53
 
54
54
  label {
@@ -58,7 +58,7 @@ class HelloComputed
58
58
  entry {
59
59
  grid column: 1, row: 1
60
60
  width 15
61
- text bind(@contact, :last_name)
61
+ text <=> [@contact, :last_name]
62
62
  }
63
63
 
64
64
  label {
@@ -68,7 +68,7 @@ class HelloComputed
68
68
  entry {
69
69
  grid column: 1, row: 2
70
70
  width 15
71
- text bind(@contact, :year_of_birth)
71
+ text <=> [@contact, :year_of_birth]
72
72
  }
73
73
 
74
74
  label {
@@ -77,7 +77,7 @@ class HelloComputed
77
77
  }
78
78
  label {
79
79
  grid column: 1, row: 3, sticky: 'w'
80
- text bind(@contact, :name, computed_by: [:first_name, :last_name])
80
+ text <=> [@contact, :name, computed_by: [:first_name, :last_name]]
81
81
  }
82
82
 
83
83
  label {
@@ -86,7 +86,7 @@ class HelloComputed
86
86
  }
87
87
  label {
88
88
  grid column: 1, row: 4, sticky: 'w'
89
- text bind(@contact, :age, on_write: :to_i, computed_by: [:year_of_birth])
89
+ text <=> [@contact, :age, on_write: :to_i, computed_by: :year_of_birth]
90
90
  }
91
91
  }
92
92
  }.open
@@ -54,7 +54,7 @@ class HelloListMultiSelection
54
54
  title 'Hello, List Multi Selection!'
55
55
 
56
56
  list {
57
- selection bind(person, :provinces)
57
+ selection <=> [person, :provinces]
58
58
  }
59
59
 
60
60
  button {
@@ -45,7 +45,7 @@ class HelloListSingleSelection
45
45
 
46
46
  list {
47
47
  selectmode 'browse'
48
- selection bind(person, :country)
48
+ selection <=> [person, :country]
49
49
  }
50
50
 
51
51
  button {
@@ -0,0 +1,94 @@
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
+ include Glimmer
25
+
26
+ root { |r|
27
+ title 'Hello, Message Box!'
28
+
29
+ frame {
30
+ grid sticky: 'nsew', padx: 15, pady: 15
31
+
32
+ button {
33
+ text 'Please Click To Win a Surprise'
34
+
35
+ command {
36
+ # specifying parent ensures dialog shows up centered on top of window (instead of centered in display monitor)
37
+ @result_label.text = message_box(parent: r, title: 'Surprise', message: "Congratulations!\n\nYou won $1,000,000!") # type: 'ok' by default
38
+ }
39
+ }
40
+
41
+ button {
42
+ text 'Download Software Update'
43
+
44
+ command {
45
+ @result_label.text = message_box(type: 'okcancel', title: 'Software Update', message: "We will begin to download software update.")
46
+ }
47
+ }
48
+
49
+ button {
50
+ text 'Format Hard Drive'
51
+
52
+ command {
53
+ @result_label.text = message_box(type: 'yesno', icon: 'question', title: 'Format', message: "Would you like to format your hard drive?")
54
+ }
55
+ }
56
+
57
+ button {
58
+ text 'Submit Application'
59
+
60
+ command {
61
+ @result_label.text = message_box(type: 'yesnocancel', icon: 'question', title: 'Application', message: "Would you like to review application before submitting?")
62
+ }
63
+ }
64
+
65
+ button {
66
+ text 'Play Video'
67
+
68
+ command {
69
+ @result_label.text = message_box(type: 'retrycancel', icon: 'error', title: 'Video Replay', message: "Video has failed to play. Would you like to retry?")
70
+ }
71
+ }
72
+
73
+ button {
74
+ text 'Installation Completed'
75
+
76
+ command {
77
+ @result_label.text = message_box(type: 'abortretryignore', icon: 'warning', default: 'ignore', title: 'Failed To Install Extra Utilities', message: "Installation is complete, but extra utilities have failed to install. Would you like to retry installing extra utilities?", detail: 'Encountered network error in downloading extra utilities, resulting in failure to install them')
78
+ }
79
+ }
80
+ }
81
+
82
+ frame {
83
+ grid sticky: 'nsew', padx: 15, pady: 15
84
+
85
+ label {
86
+ grid row: 0, column: 0
87
+ text 'Result:'
88
+ }
89
+
90
+ @result_label = label {
91
+ grid row: 0, column: 1
92
+ }
93
+ }
94
+ }.open
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.10
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-15 00:00:00.000000000 Z
11
+ date: 2021-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -197,7 +197,9 @@ files:
197
197
  - lib/glimmer/dsl/tk/data_binding_expression.rb
198
198
  - lib/glimmer/dsl/tk/dsl.rb
199
199
  - lib/glimmer/dsl/tk/list_selection_data_binding_expression.rb
200
+ - lib/glimmer/dsl/tk/message_box_expression.rb
200
201
  - lib/glimmer/dsl/tk/root_expression.rb
202
+ - lib/glimmer/dsl/tk/shine_data_binding_expression.rb
201
203
  - lib/glimmer/dsl/tk/widget_expression.rb
202
204
  - lib/glimmer/tk/button_proxy.rb
203
205
  - lib/glimmer/tk/entry_proxy.rb
@@ -206,12 +208,15 @@ files:
206
208
  - lib/glimmer/tk/list_proxy.rb
207
209
  - lib/glimmer/tk/notebook_proxy.rb
208
210
  - lib/glimmer/tk/root_proxy.rb
211
+ - lib/glimmer/tk/treeview_proxy.rb
209
212
  - lib/glimmer/tk/widget_proxy.rb
210
- - samples/hello/hello_combo.rb
213
+ - samples/hello/hello_button.rb
214
+ - samples/hello/hello_combobox.rb
211
215
  - samples/hello/hello_computed.rb
212
216
  - samples/hello/hello_computed/contact.rb
213
217
  - samples/hello/hello_list_multi_selection.rb
214
218
  - samples/hello/hello_list_single_selection.rb
219
+ - samples/hello/hello_message_box.rb
215
220
  - samples/hello/hello_tab.rb
216
221
  - samples/hello/hello_world.rb
217
222
  homepage: http://github.com/AndyObtiva/glimmer-dsl-tk
@@ -234,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
239
  - !ruby/object:Gem::Version
235
240
  version: '0'
236
241
  requirements: []
237
- rubygems_version: 3.2.22
242
+ rubygems_version: 3.2.28
238
243
  signing_key:
239
244
  specification_version: 4
240
245
  summary: Glimmer DSL for Tk