glimmer-dsl-tk 0.0.12 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +264 -32
- data/VERSION +1 -1
- data/glimmer-dsl-tk.gemspec +0 -0
- data/lib/glimmer/dsl/tk/message_box_expression.rb +36 -0
- data/lib/glimmer/tk/root_proxy.rb +1 -3
- data/lib/glimmer/tk/widget_proxy.rb +48 -2
- data/samples/hello/hello_button.rb +97 -0
- data/samples/hello/{hello_combo.rb → hello_combobox.rb} +3 -3
- data/samples/hello/hello_message_box.rb +94 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86a726f184dac65952c4a78352e88df639707b156a3a95bf9a9e99728b78b3a1
|
4
|
+
data.tar.gz: f6caaace87672c8f636d3f97f5b223b167e48f1f23620b82c0b19286cdfd6f35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e64dc523caf04755e3380846ef1ac9b9abec8bfdb3cd8b1e251dd98ef4a70470e73e744310cf2e9ce943a0085ac9c730b655dc5945c29409d6e09cc6f1095dd4
|
7
|
+
data.tar.gz: 23f99d7734e49d93f702c8987840e6ac043c247c83457be9f6cd1b028624aedb733e68b98c7922a2ec5a17afe05134da90664ab5dcf464350f31dc1afb45dd18
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.16
|
4
|
+
|
5
|
+
- Support common themed widget state attributes: `active`, `disabled`, `focus`, `pressed`, `selected`, `background`, `readonly`, `alternate`, `invalid`, and `hover`
|
6
|
+
- Update Hello, Button! to utilize `focus true` in first button.
|
7
|
+
|
8
|
+
## 0.0.15
|
9
|
+
|
10
|
+
- Update Hello, Button! to demo all button attributes
|
11
|
+
- Support `button` `image` attribute (accepting image arguments: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule` to automatically process image)
|
12
|
+
- Update `root` `iconphoto` support to accept image arguments: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule` to automatically process image
|
13
|
+
- Support `button` `compound` attribute (`'center', 'top', 'bottom', 'left', 'right'`)
|
14
|
+
- Support `button` `default` attribute (`'active'` or `'normal'`)
|
15
|
+
|
16
|
+
## 0.0.14
|
17
|
+
|
18
|
+
- Hello, Button!
|
19
|
+
|
20
|
+
## 0.0.13
|
21
|
+
|
22
|
+
- Hello, Message Box!
|
23
|
+
- Support `message_box`
|
24
|
+
|
3
25
|
## 0.0.12
|
4
26
|
|
5
27
|
- Upgrade to glimmer 2.3.0
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Tk 0.0.
|
1
|
+
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Tk 0.0.16
|
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
|
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
|
|
@@ -29,7 +29,13 @@ The trade-off is that while [SWT](https://www.eclipse.org/swt/) provides a pleth
|
|
29
29
|
Glimmer code (from [samples/hello/hello_world.rb](samples/hello/hello_world.rb)):
|
30
30
|
|
31
31
|
```ruby
|
32
|
+
require 'glimmer-dsl-tk'
|
33
|
+
|
34
|
+
include Glimmer
|
35
|
+
|
32
36
|
root {
|
37
|
+
title 'Hello, World!'
|
38
|
+
|
33
39
|
label {
|
34
40
|
text 'Hello, World!'
|
35
41
|
}
|
@@ -81,7 +87,7 @@ gem install glimmer-dsl-tk
|
|
81
87
|
|
82
88
|
Add the following to `Gemfile`:
|
83
89
|
```
|
84
|
-
gem 'glimmer-dsl-tk', '~> 0.0.
|
90
|
+
gem 'glimmer-dsl-tk', '~> 0.0.16'
|
85
91
|
```
|
86
92
|
|
87
93
|
And, then run:
|
@@ -167,6 +173,36 @@ root {
|
|
167
173
|
}.open
|
168
174
|
```
|
169
175
|
|
176
|
+
### Supported Widgets
|
177
|
+
|
178
|
+
keyword(args) | attributes | event bindings & callbacks
|
179
|
+
------------- | ---------- | ---------
|
180
|
+
`button` | `text`, `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `default` (`'active', 'normal'`) | `command`
|
181
|
+
`entry` | `width`, `text` | None
|
182
|
+
`frame(text: )` | None | None
|
183
|
+
`label` | `text` | None
|
184
|
+
`list` | `selectmode`, `selection` | None
|
185
|
+
`message_box(type: , message: , detail: , title: , icon: , default: , parent: )` | None | None
|
186
|
+
`notebook` | None | None
|
187
|
+
`root` | `title`, `iconphoto` | None
|
188
|
+
|
189
|
+
#### Common Attributes
|
190
|
+
|
191
|
+
- `grid`: `Hash` of `:row`, `:column`, `:padx`, `:pady`, `:sticky` (`'e', 'w', 'n', 's'` or any combination of direction letters)
|
192
|
+
|
193
|
+
#### Common Themed Widget States
|
194
|
+
|
195
|
+
- `active?`
|
196
|
+
- `disabled?`
|
197
|
+
- `focus?`
|
198
|
+
- `pressed?`
|
199
|
+
- `selected?`
|
200
|
+
- `background?`
|
201
|
+
- `readonly?`
|
202
|
+
- `alternate?`
|
203
|
+
- `invalid?`
|
204
|
+
- `hover?`
|
205
|
+
|
170
206
|
### Smart Defaults and Convensions
|
171
207
|
|
172
208
|
#### Grid Layout
|
@@ -221,7 +257,25 @@ More details can be found in the [Hello, Computed!](#hello-computed) sample belo
|
|
221
257
|
|
222
258
|
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).
|
223
259
|
|
224
|
-
###
|
260
|
+
### General Property Data-Binding
|
261
|
+
|
262
|
+
Example:
|
263
|
+
|
264
|
+
This assumes a `Person` model with a `country` attribute.
|
265
|
+
|
266
|
+
```ruby
|
267
|
+
label {
|
268
|
+
text <=> [person, :country]
|
269
|
+
}
|
270
|
+
```
|
271
|
+
|
272
|
+
That code binds the `textvariable` value of the `label` to the `country` property on the `person` model.
|
273
|
+
|
274
|
+
It automatically handles all the Tk plumbing behind the scenes.
|
275
|
+
|
276
|
+
More details can be found in the [Hello, Computed!](#hello-computed) sample below.
|
277
|
+
|
278
|
+
### Combobox Data-Binding
|
225
279
|
|
226
280
|
Example:
|
227
281
|
|
@@ -239,7 +293,7 @@ It also binds the `text` selection of the `combobox` to the `country` property o
|
|
239
293
|
|
240
294
|
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").
|
241
295
|
|
242
|
-
More details can be found in the [Hello,
|
296
|
+
More details can be found in the [Hello, Combobox!](#hello-combobox) sample below.
|
243
297
|
|
244
298
|
### List Single Selection Data-Binding
|
245
299
|
|
@@ -284,24 +338,6 @@ It automatically handles all the Tk plumbing behind the scenes.
|
|
284
338
|
|
285
339
|
More details can be found in the [Hello, List Multi Selection!](#hello-list-multi-selection) sample below.
|
286
340
|
|
287
|
-
### Label Data-Binding
|
288
|
-
|
289
|
-
Example:
|
290
|
-
|
291
|
-
This assumes a `Person` model with a `country` attribute.
|
292
|
-
|
293
|
-
```ruby
|
294
|
-
label {
|
295
|
-
text <=> [person, :country]
|
296
|
-
}
|
297
|
-
```
|
298
|
-
|
299
|
-
That code binds the `textvariable` value of the `label` to the `country` property on the `person` model.
|
300
|
-
|
301
|
-
It automatically handles all the Tk plumbing behind the scenes.
|
302
|
-
|
303
|
-
More details can be found in the [Hello, Computed!](#hello-computed) sample below.
|
304
|
-
|
305
341
|
### Entry Data-Binding
|
306
342
|
|
307
343
|
Example:
|
@@ -337,7 +373,7 @@ Example:
|
|
337
373
|
|
338
374
|
This resets the person country.
|
339
375
|
|
340
|
-
More details can be found in the [Hello,
|
376
|
+
More details can be found in the [Hello, Combobox!](#hello-combobox) sample below.
|
341
377
|
|
342
378
|
## Samples
|
343
379
|
|
@@ -346,9 +382,13 @@ More details can be found in the [Hello, Combo!](#hello-combo) sample below.
|
|
346
382
|
Glimmer code (from [samples/hello/hello_world.rb](samples/hello/hello_world.rb)):
|
347
383
|
|
348
384
|
```ruby
|
385
|
+
require 'glimmer-dsl-tk'
|
386
|
+
|
349
387
|
include Glimmer
|
350
388
|
|
351
389
|
root {
|
390
|
+
title 'Hello, World!'
|
391
|
+
|
352
392
|
label {
|
353
393
|
text 'Hello, World!'
|
354
394
|
}
|
@@ -364,13 +404,112 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_world'"
|
|
364
404
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
365
405
|
|
366
406
|
```
|
367
|
-
ruby -
|
407
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_world.rb
|
368
408
|
```
|
369
409
|
|
370
410
|
Glimmer app:
|
371
411
|
|
372
412
|
![glimmer dsl tk screenshot sample hello world](images/glimmer-dsl-tk-screenshot-sample-hello-world.png)
|
373
413
|
|
414
|
+
### Hello, Button!
|
415
|
+
|
416
|
+
Glimmer code (from [samples/hello/hello_button.rb](samples/hello/hello_button.rb)):
|
417
|
+
|
418
|
+
```ruby
|
419
|
+
require 'glimmer-dsl-tk'
|
420
|
+
|
421
|
+
class HelloButton
|
422
|
+
include Glimmer
|
423
|
+
|
424
|
+
attr_accessor :count
|
425
|
+
|
426
|
+
def initialize
|
427
|
+
@count = 0
|
428
|
+
end
|
429
|
+
|
430
|
+
def launch
|
431
|
+
root {
|
432
|
+
title 'Hello, Button!'
|
433
|
+
|
434
|
+
frame {
|
435
|
+
grid row: 0, column: 0
|
436
|
+
|
437
|
+
label {
|
438
|
+
grid pady: 15
|
439
|
+
text 'Text Button'
|
440
|
+
}
|
441
|
+
|
442
|
+
button {
|
443
|
+
text <= [self, :count, on_read: ->(value) { "Click To Increment: #{value} " }]
|
444
|
+
default 'active'
|
445
|
+
focus true
|
446
|
+
|
447
|
+
command {
|
448
|
+
self.count += 1
|
449
|
+
}
|
450
|
+
}
|
451
|
+
}
|
452
|
+
|
453
|
+
frame {
|
454
|
+
grid row: 0, column: 1
|
455
|
+
|
456
|
+
label {
|
457
|
+
grid pady: 15
|
458
|
+
text 'Image Button'
|
459
|
+
}
|
460
|
+
|
461
|
+
button {
|
462
|
+
image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
|
463
|
+
|
464
|
+
command {
|
465
|
+
message_box(title: 'Image Button', message: 'Image Button Clicked!')
|
466
|
+
}
|
467
|
+
}
|
468
|
+
}
|
469
|
+
|
470
|
+
frame {
|
471
|
+
grid row: 0, column: 2
|
472
|
+
|
473
|
+
label {
|
474
|
+
grid pady: 15
|
475
|
+
text 'Text Image Buttons'
|
476
|
+
}
|
477
|
+
|
478
|
+
['center', 'top', 'bottom', 'left', 'right'].each do |compound_option|
|
479
|
+
button {
|
480
|
+
image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
|
481
|
+
text 'Text Image Button'
|
482
|
+
compound compound_option
|
483
|
+
|
484
|
+
command {
|
485
|
+
message_box(title: 'Text Image Button', message: 'Text Image Button Clicked!', detail: "(#{compound_option})")
|
486
|
+
}
|
487
|
+
}
|
488
|
+
end
|
489
|
+
}
|
490
|
+
}.open
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
HelloButton.new.launch
|
495
|
+
```
|
496
|
+
|
497
|
+
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
498
|
+
|
499
|
+
```
|
500
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_button'"
|
501
|
+
```
|
502
|
+
|
503
|
+
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
504
|
+
|
505
|
+
```
|
506
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_button.rb
|
507
|
+
```
|
508
|
+
|
509
|
+
Glimmer app:
|
510
|
+
|
511
|
+
![glimmer dsl tk screenshot sample hello button](images/glimmer-dsl-tk-screenshot-sample-hello-button.png)
|
512
|
+
|
374
513
|
### Hello, Tab!
|
375
514
|
|
376
515
|
Glimmer code (from [samples/hello/hello_tab.rb](samples/hello/hello_tab.rb)):
|
@@ -414,14 +553,107 @@ Glimmer app:
|
|
414
553
|
![glimmer dsl tk screenshot sample hello tab English](images/glimmer-dsl-tk-screenshot-sample-hello-tab-english.png)
|
415
554
|
![glimmer dsl tk screenshot sample hello tab French](images/glimmer-dsl-tk-screenshot-sample-hello-tab-french.png)
|
416
555
|
|
417
|
-
### Hello,
|
556
|
+
### Hello, Message Box!
|
557
|
+
|
558
|
+
Glimmer code (from [samples/hello/hello_message_box.rb](samples/hello/hello_message_box.rb)):
|
559
|
+
|
560
|
+
```ruby
|
561
|
+
root { |r|
|
562
|
+
title 'Hello, Message Box!'
|
563
|
+
|
564
|
+
frame {
|
565
|
+
grid sticky: 'nsew', padx: 15, pady: 15
|
566
|
+
|
567
|
+
button {
|
568
|
+
text 'Please Click To Win a Surprise'
|
569
|
+
|
570
|
+
command {
|
571
|
+
# specifying parent ensures dialog shows up centered on top of window (instead of centered in display monitor)
|
572
|
+
@result_label.text = message_box(parent: r, title: 'Surprise', message: "Congratulations!\n\nYou won $1,000,000!") # type: 'ok' by default
|
573
|
+
}
|
574
|
+
}
|
575
|
+
|
576
|
+
button {
|
577
|
+
text 'Download Software Update'
|
578
|
+
|
579
|
+
command {
|
580
|
+
@result_label.text = message_box(type: 'okcancel', title: 'Software Update', message: "We will begin to download software update.")
|
581
|
+
}
|
582
|
+
}
|
583
|
+
|
584
|
+
button {
|
585
|
+
text 'Format Hard Drive'
|
586
|
+
|
587
|
+
command {
|
588
|
+
@result_label.text = message_box(type: 'yesno', icon: 'question', title: 'Format', message: "Would you like to format your hard drive?")
|
589
|
+
}
|
590
|
+
}
|
591
|
+
|
592
|
+
button {
|
593
|
+
text 'Submit Application'
|
594
|
+
|
595
|
+
command {
|
596
|
+
@result_label.text = message_box(type: 'yesnocancel', icon: 'question', title: 'Application', message: "Would you like to review application before submitting?")
|
597
|
+
}
|
598
|
+
}
|
599
|
+
|
600
|
+
button {
|
601
|
+
text 'Play Video'
|
602
|
+
|
603
|
+
command {
|
604
|
+
@result_label.text = message_box(type: 'retrycancel', icon: 'error', title: 'Video Replay', message: "Video has failed to play. Would you like to retry?")
|
605
|
+
}
|
606
|
+
}
|
607
|
+
|
608
|
+
button {
|
609
|
+
text 'Installation Completed'
|
610
|
+
|
611
|
+
command {
|
612
|
+
@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')
|
613
|
+
}
|
614
|
+
}
|
615
|
+
}
|
616
|
+
|
617
|
+
frame {
|
618
|
+
grid sticky: 'nsew', padx: 15, pady: 15
|
619
|
+
|
620
|
+
label {
|
621
|
+
grid row: 0, column: 0
|
622
|
+
text 'Result:'
|
623
|
+
}
|
624
|
+
|
625
|
+
@result_label = label {
|
626
|
+
grid row: 0, column: 1
|
627
|
+
}
|
628
|
+
}
|
629
|
+
}.open
|
630
|
+
```
|
631
|
+
|
632
|
+
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
633
|
+
|
634
|
+
```
|
635
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_tab'"
|
636
|
+
```
|
637
|
+
|
638
|
+
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
639
|
+
|
640
|
+
```
|
641
|
+
ruby -e "require './lib/glimmer-dsl-tk'; require './samples/hello/hello_tab'"
|
642
|
+
```
|
643
|
+
|
644
|
+
Glimmer app:
|
645
|
+
|
646
|
+
![glimmer dsl tk screenshot sample hello message box](images/glimmer-dsl-tk-screenshot-sample-hello-message-box.png)
|
647
|
+
![glimmer dsl tk screenshot sample hello message box open](images/glimmer-dsl-tk-screenshot-sample-hello-message-box-open.png)
|
648
|
+
|
649
|
+
### Hello, Combobox!
|
418
650
|
|
419
|
-
Glimmer code (from [samples/hello/
|
651
|
+
Glimmer code (from [samples/hello/hello_combobox.rb](samples/hello/hello_combobox.rb)):
|
420
652
|
|
421
653
|
```ruby
|
422
654
|
# ... more code precedes
|
423
655
|
root {
|
424
|
-
title 'Hello,
|
656
|
+
title 'Hello, Combobox!'
|
425
657
|
|
426
658
|
combobox { |proxy|
|
427
659
|
state 'readonly'
|
@@ -441,19 +673,19 @@ root {
|
|
441
673
|
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
442
674
|
|
443
675
|
```
|
444
|
-
ruby -r glimmer-dsl-tk -e "require 'samples/hello/
|
676
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_combobox'"
|
445
677
|
```
|
446
678
|
|
447
679
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
448
680
|
|
449
681
|
```
|
450
|
-
ruby -e "require './lib/glimmer-dsl-tk'; require './samples/hello/
|
682
|
+
ruby -e "require './lib/glimmer-dsl-tk'; require './samples/hello/hello_combobox'"
|
451
683
|
```
|
452
684
|
|
453
685
|
Glimmer app:
|
454
686
|
|
455
|
-
![glimmer dsl tk screenshot sample hello
|
456
|
-
![glimmer dsl tk screenshot sample hello
|
687
|
+
![glimmer dsl tk screenshot sample hello combobox](images/glimmer-dsl-tk-screenshot-sample-hello-combobox.png)
|
688
|
+
![glimmer dsl tk screenshot sample hello combobox dropdown](images/glimmer-dsl-tk-screenshot-sample-hello-combobox-dropdown.png)
|
457
689
|
|
458
690
|
### Hello, List Single Selection!
|
459
691
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.16
|
data/glimmer-dsl-tk.gemspec
CHANGED
Binary file
|
@@ -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
|
@@ -45,9 +45,7 @@ module Glimmer
|
|
45
45
|
|
46
46
|
def set_attribute(attribute, *args)
|
47
47
|
if attribute.to_s == 'iconphoto'
|
48
|
-
|
49
|
-
args[0] = ::TkPhotoImage.new(file: args.first)
|
50
|
-
end
|
48
|
+
args[0..-1] = [image_argument(args)]
|
51
49
|
super
|
52
50
|
else
|
53
51
|
super
|
@@ -120,10 +120,25 @@ module Glimmer
|
|
120
120
|
@tk.respond_to?(attribute)
|
121
121
|
end
|
122
122
|
|
123
|
+
def has_state?(attribute)
|
124
|
+
attribute = attribute.sub(/\?$/, '').sub(/=$/, '')
|
125
|
+
if @tk.respond_to?(:tile_state)
|
126
|
+
begin
|
127
|
+
@tk.tile_instate(attribute)
|
128
|
+
true
|
129
|
+
rescue
|
130
|
+
false
|
131
|
+
end
|
132
|
+
else
|
133
|
+
false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
123
137
|
def has_attribute?(attribute, *args)
|
124
138
|
(widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][attribute.to_s]) ||
|
125
139
|
tk_widget_has_attribute_setter?(attribute) ||
|
126
140
|
tk_widget_has_attribute_getter_setter?(attribute) ||
|
141
|
+
has_state?(attribute) ||
|
127
142
|
respond_to?(attribute_setter(attribute), args)
|
128
143
|
end
|
129
144
|
|
@@ -135,6 +150,13 @@ module Glimmer
|
|
135
150
|
@tk.send(attribute_setter(attribute), *args) unless @tk.send(attribute) == args.first
|
136
151
|
elsif tk_widget_has_attribute_getter_setter?(attribute)
|
137
152
|
@tk.send(attribute, *args)
|
153
|
+
elsif has_state?(attribute)
|
154
|
+
attribute = attribute.sub(/=$/, '')
|
155
|
+
if !!args.first
|
156
|
+
@tk.tile_state(attribute)
|
157
|
+
else
|
158
|
+
@tk.tile_state("!#{attribute}")
|
159
|
+
end
|
138
160
|
else
|
139
161
|
send(attribute_setter(attribute), args)
|
140
162
|
end
|
@@ -146,6 +168,8 @@ module Glimmer
|
|
146
168
|
widget_custom_attribute[:getter][:invoker].call(@tk, args)
|
147
169
|
elsif tk_widget_has_attribute_getter_setter?(attribute)
|
148
170
|
@tk.send(attribute)
|
171
|
+
elsif has_state?(attribute)
|
172
|
+
@tk.tile_instate(attribute.sub(/\?$/, ''))
|
149
173
|
else
|
150
174
|
send(attribute)
|
151
175
|
end
|
@@ -157,6 +181,12 @@ module Glimmer
|
|
157
181
|
|
158
182
|
def widget_custom_attribute_mapping
|
159
183
|
@widget_custom_attribute_mapping ||= {
|
184
|
+
::Tk::Tile::TButton => {
|
185
|
+
'image' => {
|
186
|
+
getter: {name: 'image', invoker: lambda { |widget, args| @tk.textvariable&.value }},
|
187
|
+
setter: {name: 'image=', invoker: lambda { |widget, args| @tk['image'] = image_argument(args) }},
|
188
|
+
},
|
189
|
+
},
|
160
190
|
::Tk::Tile::TCombobox => {
|
161
191
|
'text' => {
|
162
192
|
getter: {name: 'text', invoker: lambda { |widget, args| @tk.textvariable&.value }},
|
@@ -210,6 +240,22 @@ module Glimmer
|
|
210
240
|
}
|
211
241
|
end
|
212
242
|
|
243
|
+
def image_argument(args)
|
244
|
+
if args.first.is_a?(::TkPhotoImage)
|
245
|
+
args.first
|
246
|
+
else
|
247
|
+
image_args = {}
|
248
|
+
image_args.merge!(file: args.first.to_s) if args.first.is_a?(String)
|
249
|
+
the_image = ::TkPhotoImage.new(image_args)
|
250
|
+
if args.last.is_a?(Hash)
|
251
|
+
processed_image = ::TkPhotoImage.new
|
252
|
+
processed_image.copy(the_image, args.last)
|
253
|
+
the_image = processed_image
|
254
|
+
end
|
255
|
+
the_image
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
213
259
|
def add_observer(observer, attribute)
|
214
260
|
attribute_listener_installers = @tk.class.ancestors.map {|ancestor| widget_attribute_listener_installers[ancestor]}.compact
|
215
261
|
widget_listener_installers = attribute_listener_installers.map{|installer| installer[attribute.to_s]}.compact if !attribute_listener_installers.empty?
|
@@ -222,9 +268,9 @@ module Glimmer
|
|
222
268
|
|
223
269
|
def method_missing(method, *args, &block)
|
224
270
|
method = method.to_s
|
225
|
-
if args.empty? && block.nil? && widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method]
|
271
|
+
if args.empty? && block.nil? && ((widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method]) || has_state?(method))
|
226
272
|
get_attribute(method)
|
227
|
-
elsif widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method.sub(/=$/, '')]
|
273
|
+
elsif method.end_with?('=') && block.nil? && ((widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method.sub(/=$/, '')]) || has_state?(method))
|
228
274
|
set_attribute(method.sub(/=$/, ''), *args)
|
229
275
|
else
|
230
276
|
tk.send(method, *args, &block)
|
@@ -0,0 +1,97 @@
|
|
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
|
+
frame {
|
38
|
+
grid row: 0, column: 0
|
39
|
+
|
40
|
+
label {
|
41
|
+
grid pady: 15
|
42
|
+
text 'Text Button'
|
43
|
+
}
|
44
|
+
|
45
|
+
button { |b|
|
46
|
+
text <= [self, :count, on_read: ->(value) { "Click To Increment: #{value} " }]
|
47
|
+
default 'active'
|
48
|
+
focus true
|
49
|
+
|
50
|
+
command {
|
51
|
+
self.count += 1
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
frame {
|
57
|
+
grid row: 0, column: 1
|
58
|
+
|
59
|
+
label {
|
60
|
+
grid pady: 15
|
61
|
+
text 'Image Button'
|
62
|
+
}
|
63
|
+
|
64
|
+
button {
|
65
|
+
image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
|
66
|
+
|
67
|
+
command {
|
68
|
+
message_box(title: 'Image Button', message: 'Image Button Clicked!')
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
frame {
|
74
|
+
grid row: 0, column: 2
|
75
|
+
|
76
|
+
label {
|
77
|
+
grid pady: 15
|
78
|
+
text 'Text Image Buttons'
|
79
|
+
}
|
80
|
+
|
81
|
+
['center', 'top', 'bottom', 'left', 'right'].each do |compound_option|
|
82
|
+
button {
|
83
|
+
image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
|
84
|
+
text 'Text Image Button'
|
85
|
+
compound compound_option
|
86
|
+
|
87
|
+
command {
|
88
|
+
message_box(title: 'Text Image Button', message: 'Text Image Button Clicked!', detail: "(#{compound_option})")
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
}
|
93
|
+
}.open
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
HelloButton.new.launch
|
@@ -34,14 +34,14 @@ class Person
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
class
|
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,
|
44
|
+
title 'Hello, Combobox!'
|
45
45
|
|
46
46
|
combobox {
|
47
47
|
state 'readonly'
|
@@ -58,4 +58,4 @@ class HelloCombo
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
HelloCombobox.new.launch
|
@@ -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.
|
4
|
+
version: 0.0.16
|
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-
|
11
|
+
date: 2021-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -197,6 +197,7 @@ 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
|
201
202
|
- lib/glimmer/dsl/tk/shine_data_binding_expression.rb
|
202
203
|
- lib/glimmer/dsl/tk/widget_expression.rb
|
@@ -209,11 +210,13 @@ files:
|
|
209
210
|
- lib/glimmer/tk/root_proxy.rb
|
210
211
|
- lib/glimmer/tk/treeview_proxy.rb
|
211
212
|
- lib/glimmer/tk/widget_proxy.rb
|
212
|
-
- samples/hello/
|
213
|
+
- samples/hello/hello_button.rb
|
214
|
+
- samples/hello/hello_combobox.rb
|
213
215
|
- samples/hello/hello_computed.rb
|
214
216
|
- samples/hello/hello_computed/contact.rb
|
215
217
|
- samples/hello/hello_list_multi_selection.rb
|
216
218
|
- samples/hello/hello_list_single_selection.rb
|
219
|
+
- samples/hello/hello_message_box.rb
|
217
220
|
- samples/hello/hello_tab.rb
|
218
221
|
- samples/hello/hello_world.rb
|
219
222
|
homepage: http://github.com/AndyObtiva/glimmer-dsl-tk
|