glimmer-dsl-tk 0.0.14 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -0
- data/README.md +381 -44
- data/VERSION +1 -1
- data/glimmer-dsl-tk.gemspec +0 -0
- data/lib/glimmer/tk/label_proxy.rb +8 -8
- data/lib/glimmer/tk/root_proxy.rb +1 -3
- data/lib/glimmer/tk/widget_proxy.rb +63 -7
- data/samples/hello/hello_button.rb +53 -4
- data/samples/hello/hello_frame.rb +71 -0
- data/samples/hello/hello_label.rb +110 -0
- data/samples/hello/{hello_tab.rb → hello_notebook.rb} +3 -3
- data/samples/hello/images/denmark.png +0 -0
- data/samples/hello/images/finland.png +0 -0
- data/samples/hello/images/france.png +0 -0
- data/samples/hello/images/germany.png +0 -0
- data/samples/hello/images/italy.png +0 -0
- data/samples/hello/images/mexico.png +0 -0
- data/samples/hello/images/netherlands.png +0 -0
- data/samples/hello/images/norway.png +0 -0
- data/samples/hello/images/usa.png +0 -0
- metadata +15 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa03163d6b0577d65e67d245b810079da4ddd6aca50cde649963e9448defe1ee
|
4
|
+
data.tar.gz: 3d2cadbe0dff5e003ada1938a461785b11d5899d671d12f998b0c783983fa4dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6160cea03e0e6ed6e1511271cd780db176ba569b2774e9a304749e612ec242ad65d611dce0c475f29dfe3f9dce869bee8c660825a90fff0b3a0f5315cf7fbb47
|
7
|
+
data.tar.gz: abc75b8c436416257770b9af8e38470bbf4ab53f448a281c6626fa56ef7617ffee4d551038fa9618b00d33cd63f9c8cf19f51b311406497e1ce99a54ba22d2f0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,50 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.18
|
4
|
+
|
5
|
+
- Hello, Frame! sample
|
6
|
+
- Avoid setting grid geometry manager on `toplevel` widget
|
7
|
+
- Support `frame` `width` and `height` attributes
|
8
|
+
- Support `frame` `borderwidth` attribute
|
9
|
+
- Support `frame` `relief` attribute
|
10
|
+
- Support `frame` `padding` attribute
|
11
|
+
- Rename Hello, Tab! to Hello, Notebook!
|
12
|
+
|
13
|
+
## 0.0.17
|
14
|
+
|
15
|
+
- Hello, Label! sample
|
16
|
+
- Support `label` `anchor` attribute (`'e'`, `'se'`, `'s'`, `'sw'`, `'w'`, `'nw'` or `'center'`)
|
17
|
+
- Support `label` `width` attributes
|
18
|
+
- Support `label` `image` attribute
|
19
|
+
- Support `label` `justify` attribute (`'left', 'center', 'right'`)
|
20
|
+
- Support `label` `font` attribute (`'default', 'text', 'fixed', 'menu', 'heading', 'caption', 'small_caption', 'icon', 'tooltip'`)
|
21
|
+
- Support `label` `foreground` attribute
|
22
|
+
- Support `label` `background` attribute (note that it does not work in Mac 'aqua' theme)
|
23
|
+
- Support `label` `compound` attribute
|
24
|
+
- Support `label` `relief` attributes (`'flat' (default), 'raised', 'sunken', 'solid', 'ridge', 'groove'`)
|
25
|
+
|
26
|
+
## 0.0.16
|
27
|
+
|
28
|
+
- Support common themed widget state attributes: `active`, `disabled`, `focus`, `pressed`, `selected`, `background`, `readonly`, `alternate`, `invalid`, and `hover`
|
29
|
+
- Update Hello, Button! to utilize `focus true` in first button.
|
30
|
+
|
31
|
+
## 0.0.15
|
32
|
+
|
33
|
+
- Update Hello, Button! to demo all button attributes
|
34
|
+
- Support `button` `image` attribute (accepting image arguments: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule` to automatically process image)
|
35
|
+
- Update `root` `iconphoto` support to accept image arguments: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule` to automatically process image
|
36
|
+
- Support `button` `compound` attribute (`'center', 'top', 'bottom', 'left', 'right'`)
|
37
|
+
- Support `button` `default` attribute (`'active'` or `'normal'`)
|
38
|
+
|
39
|
+
## 0.0.14
|
40
|
+
|
41
|
+
- Hello, Button!
|
42
|
+
|
43
|
+
## 0.0.13
|
44
|
+
|
45
|
+
- Hello, Message Box!
|
46
|
+
- Support `message_box`
|
47
|
+
|
3
48
|
## 0.0.12
|
4
49
|
|
5
50
|
- Upgrade to glimmer 2.3.0
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
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.18
|
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
|
+
[![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)
|
4
5
|
[![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)
|
5
6
|
[![Maintainability](https://api.codeclimate.com/v1/badges/ce2853efdbecf6ebdc73/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-tk/maintainability)
|
6
7
|
[![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
@@ -9,7 +10,7 @@
|
|
9
10
|
|
10
11
|
[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
12
|
|
12
|
-
[Tcl/Tk](https://www.tcl.tk/) has
|
13
|
+
[Tcl/Tk](https://www.tcl.tk/) has recently improved by 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
14
|
|
14
15
|
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
16
|
|
@@ -29,7 +30,13 @@ The trade-off is that while [SWT](https://www.eclipse.org/swt/) provides a pleth
|
|
29
30
|
Glimmer code (from [samples/hello/hello_world.rb](samples/hello/hello_world.rb)):
|
30
31
|
|
31
32
|
```ruby
|
33
|
+
require 'glimmer-dsl-tk'
|
34
|
+
|
35
|
+
include Glimmer
|
36
|
+
|
32
37
|
root {
|
38
|
+
title 'Hello, World!'
|
39
|
+
|
33
40
|
label {
|
34
41
|
text 'Hello, World!'
|
35
42
|
}
|
@@ -55,6 +62,55 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
|
|
55
62
|
- [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
|
56
63
|
- [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
|
57
64
|
|
65
|
+
## Table of Contents
|
66
|
+
|
67
|
+
- [Glimmer DSL for Tk](#)
|
68
|
+
- [MRI Ruby Desktop Development GUI Library](#mri-ruby-desktop-development-gui-library)
|
69
|
+
- [Pre-requisites](#pre-requisites)
|
70
|
+
- [Setup](#setup)
|
71
|
+
- [Option 1: Install](#option-1-install)
|
72
|
+
- [Option 2: Bundler](#option-2-bundler)
|
73
|
+
- [Girb (Glimmer IRB)](#girb-glimmer-irb)
|
74
|
+
- [Tk Concepts](#tk-concepts)
|
75
|
+
- [Glimmer GUI DSL Concepts](#glimmer-gui-dsl-concepts)
|
76
|
+
- [Supported Widgets](#supported-widgets)
|
77
|
+
- [Common Attributes](#common-attributes)
|
78
|
+
- [Common Themed Widget States](#common-themed-widget-states)
|
79
|
+
- [Smart Defaults and Convensions](#smart-defaults-and-convensions)
|
80
|
+
- [Grid Layout](#grid-layout)
|
81
|
+
- [Label/Button Image](#labelbutton-image)
|
82
|
+
- [Notebook Frame](#notebook-frame)
|
83
|
+
- [Icon Photo](#icon-photo)
|
84
|
+
- [The Grid Geometry Manager](#the-grid-geometry-manager)
|
85
|
+
- [Bidirectional Data-Binding](#bidirectional-data-binding)
|
86
|
+
- [General Property Data-Binding](#general-property-data-binding)
|
87
|
+
- [Combobox Data-Binding](#combobox-data-binding)
|
88
|
+
- [List Single Selection Data-Binding](#list-single-selection-data-binding)
|
89
|
+
- [List Multi Selection Data-Binding](#list-multi-selection-data-binding)
|
90
|
+
- [Entry Data-Binding](#entry-data-binding)
|
91
|
+
- [Command Observer](#command-observer)
|
92
|
+
- [Gotchas](#gotchas)
|
93
|
+
- [Samples](#samples)
|
94
|
+
- [Hello, World!](#hello-world)
|
95
|
+
- [Hello, Button!](#hello-button)
|
96
|
+
- [Hello, Frame!](#hello-frame)
|
97
|
+
- [Hello, Notebook!](#hello-notebook)
|
98
|
+
- [Hello, Label!](#hello-label)
|
99
|
+
- [Hello, Message Box!](#hello-message-box)
|
100
|
+
- [Hello, Combobox!](#hello-combobox)
|
101
|
+
- [Hello, List Single Selection!](#hello-list-single-selection)
|
102
|
+
- [Hello, List Multi Selection!](#hello-list-multi-selection)
|
103
|
+
- [Hello, Computed!](#hello-computed)
|
104
|
+
- [Help](#help)
|
105
|
+
- [Issues](#issues)
|
106
|
+
- [Chat](#chat)
|
107
|
+
- [Process](#process)
|
108
|
+
- [Planned Features and Feature Suggestions](#planned-features-and-feature-suggestions)
|
109
|
+
- [Change Log](#change-log)
|
110
|
+
- [Contributing](#contributing)
|
111
|
+
- [Contributors](#contributors)
|
112
|
+
- [License](#license)
|
113
|
+
|
58
114
|
## Pre-requisites
|
59
115
|
|
60
116
|
- [Tcl/Tk](https://www.tcl.tk/): Follow the [install instructions](https://tkdocs.com/tutorial/install.html)
|
@@ -81,7 +137,7 @@ gem install glimmer-dsl-tk
|
|
81
137
|
|
82
138
|
Add the following to `Gemfile`:
|
83
139
|
```
|
84
|
-
gem 'glimmer-dsl-tk', '~> 0.0.
|
140
|
+
gem 'glimmer-dsl-tk', '~> 0.0.18'
|
85
141
|
```
|
86
142
|
|
87
143
|
And, then run:
|
@@ -128,7 +184,7 @@ Example of an app written in [Tk](https://www.tcl.tk/) imperative syntax:
|
|
128
184
|
|
129
185
|
```ruby
|
130
186
|
root = TkRoot.new
|
131
|
-
root.title = 'Hello,
|
187
|
+
root.title = 'Hello, Notebook!'
|
132
188
|
|
133
189
|
notebook = ::Tk::Tile::Notebook.new(root).grid
|
134
190
|
|
@@ -149,7 +205,7 @@ Example of the same app written in [Glimmer](https://github.com/AndyObtiva/glimm
|
|
149
205
|
|
150
206
|
```ruby
|
151
207
|
root {
|
152
|
-
title 'Hello,
|
208
|
+
title 'Hello, Notebook!'
|
153
209
|
|
154
210
|
notebook {
|
155
211
|
frame(text: 'English') {
|
@@ -169,12 +225,12 @@ root {
|
|
169
225
|
|
170
226
|
### Supported Widgets
|
171
227
|
|
172
|
-
keyword(args) | attributes |
|
228
|
+
keyword(args) | attributes | event bindings & callbacks
|
173
229
|
------------- | ---------- | ---------
|
174
|
-
`button` | `text` | `command`
|
230
|
+
`button` | `text`, `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `default` (`'active', 'normal'`) | `command`
|
175
231
|
`entry` | `width`, `text` | None
|
176
|
-
`frame(text: )` |
|
177
|
-
`label` | `text` | None
|
232
|
+
`frame(text: nil)` | `width`, `height`, `borderwidth`, `relief` (`'flat' (default), 'raised', 'sunken', 'solid', 'ridge', 'groove'`) | None
|
233
|
+
`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
|
178
234
|
`list` | `selectmode`, `selection` | None
|
179
235
|
`message_box(type: , message: , detail: , title: , icon: , default: , parent: )` | None | None
|
180
236
|
`notebook` | None | None
|
@@ -182,7 +238,20 @@ keyword(args) | attributes | listeners/events
|
|
182
238
|
|
183
239
|
#### Common Attributes
|
184
240
|
|
185
|
-
- `grid`
|
241
|
+
- `grid`: `Hash` of `:row`, `:column`, `:padx`, `:pady`, `:sticky` (`'e', 'w', 'n', 's'` or any combination of direction letters)
|
242
|
+
|
243
|
+
#### Common Themed Widget States
|
244
|
+
|
245
|
+
- `active?`
|
246
|
+
- `disabled?`
|
247
|
+
- `focus?`
|
248
|
+
- `pressed?`
|
249
|
+
- `selected?`
|
250
|
+
- `background?`
|
251
|
+
- `readonly?`
|
252
|
+
- `alternate?`
|
253
|
+
- `invalid?`
|
254
|
+
- `hover?`
|
186
255
|
|
187
256
|
### Smart Defaults and Convensions
|
188
257
|
|
@@ -190,6 +259,14 @@ keyword(args) | attributes | listeners/events
|
|
190
259
|
|
191
260
|
`grid` layout is the default on most widgets (which support it).
|
192
261
|
|
262
|
+
#### Label/Button Image
|
263
|
+
|
264
|
+
Label and Button `image` attribute can accept image path directly as an alternative to `TkPhotoImage` object in addition to key values for automatic processing of image (`subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`)
|
265
|
+
|
266
|
+
#### Notebook Frame
|
267
|
+
|
268
|
+
When nesting `frame` under `notebook`, you can pass a `:text` keyword argument to indicate the tab title.
|
269
|
+
|
193
270
|
#### Icon Photo
|
194
271
|
|
195
272
|
The `iconphoto` attribute on `root` is set to the Glimmer icon by default if no icon photo is supplied.
|
@@ -356,6 +433,10 @@ This resets the person country.
|
|
356
433
|
|
357
434
|
More details can be found in the [Hello, Combobox!](#hello-combobox) sample below.
|
358
435
|
|
436
|
+
## Gotchas
|
437
|
+
|
438
|
+
- Setting `background` attribute on `frame` or `label` does not work in `'aqua'` theme on the Mac (only in `'classic'` theme)
|
439
|
+
|
359
440
|
## Samples
|
360
441
|
|
361
442
|
### Hello, World!
|
@@ -363,9 +444,13 @@ More details can be found in the [Hello, Combobox!](#hello-combobox) sample belo
|
|
363
444
|
Glimmer code (from [samples/hello/hello_world.rb](samples/hello/hello_world.rb)):
|
364
445
|
|
365
446
|
```ruby
|
447
|
+
require 'glimmer-dsl-tk'
|
448
|
+
|
366
449
|
include Glimmer
|
367
450
|
|
368
451
|
root {
|
452
|
+
title 'Hello, World!'
|
453
|
+
|
369
454
|
label {
|
370
455
|
text 'Hello, World!'
|
371
456
|
}
|
@@ -381,7 +466,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_world'"
|
|
381
466
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
382
467
|
|
383
468
|
```
|
384
|
-
ruby -
|
469
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_world.rb
|
385
470
|
```
|
386
471
|
|
387
472
|
Glimmer app:
|
@@ -408,13 +493,62 @@ class HelloButton
|
|
408
493
|
root {
|
409
494
|
title 'Hello, Button!'
|
410
495
|
|
411
|
-
|
412
|
-
|
496
|
+
frame {
|
497
|
+
grid row: 0, column: 0
|
413
498
|
|
414
|
-
|
415
|
-
|
499
|
+
label {
|
500
|
+
grid pady: 15
|
501
|
+
text 'Text Button'
|
502
|
+
}
|
503
|
+
|
504
|
+
button {
|
505
|
+
text <= [self, :count, on_read: ->(value) { "Click To Increment: #{value} " }]
|
506
|
+
default 'active'
|
507
|
+
focus true
|
508
|
+
|
509
|
+
command {
|
510
|
+
self.count += 1
|
511
|
+
}
|
512
|
+
}
|
513
|
+
}
|
514
|
+
|
515
|
+
frame {
|
516
|
+
grid row: 0, column: 1
|
517
|
+
|
518
|
+
label {
|
519
|
+
grid pady: 15
|
520
|
+
text 'Image Button'
|
521
|
+
}
|
522
|
+
|
523
|
+
button {
|
524
|
+
image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
|
525
|
+
|
526
|
+
command {
|
527
|
+
message_box(title: 'Image Button', message: 'Image Button Clicked!')
|
528
|
+
}
|
416
529
|
}
|
417
530
|
}
|
531
|
+
|
532
|
+
frame {
|
533
|
+
grid row: 0, column: 2
|
534
|
+
|
535
|
+
label {
|
536
|
+
grid pady: 15
|
537
|
+
text 'Text Image Buttons'
|
538
|
+
}
|
539
|
+
|
540
|
+
['center', 'top', 'bottom', 'left', 'right'].each do |compound_option|
|
541
|
+
button {
|
542
|
+
image File.expand_path('../../icons/glimmer.png', __dir__), subsample: 5
|
543
|
+
text 'Text Image Button'
|
544
|
+
compound compound_option
|
545
|
+
|
546
|
+
command {
|
547
|
+
message_box(title: 'Text Image Button', message: 'Text Image Button Clicked!', detail: "(#{compound_option})")
|
548
|
+
}
|
549
|
+
}
|
550
|
+
end
|
551
|
+
}
|
418
552
|
}.open
|
419
553
|
end
|
420
554
|
end
|
@@ -431,55 +565,258 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_button'"
|
|
431
565
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
432
566
|
|
433
567
|
```
|
434
|
-
ruby -
|
568
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_button.rb
|
435
569
|
```
|
436
570
|
|
437
571
|
Glimmer app:
|
438
572
|
|
439
573
|
![glimmer dsl tk screenshot sample hello button](images/glimmer-dsl-tk-screenshot-sample-hello-button.png)
|
440
574
|
|
441
|
-
### Hello,
|
575
|
+
### Hello, Frame!
|
442
576
|
|
443
|
-
Glimmer code (from [samples/hello/
|
577
|
+
Glimmer code (from [samples/hello/hello_frame.rb](samples/hello/hello_frame.rb)):
|
444
578
|
|
445
579
|
```ruby
|
446
|
-
|
580
|
+
require 'glimmer-dsl-tk'
|
447
581
|
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
582
|
+
class HelloFrame
|
583
|
+
include Glimmer
|
584
|
+
|
585
|
+
def launch
|
586
|
+
root {
|
587
|
+
title 'Hello, Frame!'
|
588
|
+
|
589
|
+
frame { # frame simply contains widgets for visual organization via a layout
|
590
|
+
relief 'sunken'
|
591
|
+
|
592
|
+
label {
|
593
|
+
grid row: 0, column: 0, columnspan: 4, padx: 5, pady: 5
|
594
|
+
text 'Enter Your Full Name'
|
595
|
+
font 'caption'
|
596
|
+
anchor 'center'
|
597
|
+
}
|
598
|
+
|
599
|
+
label {
|
600
|
+
grid row: 1, column: 0, padx: 5
|
601
|
+
text "First Name:"
|
602
|
+
}
|
603
|
+
|
604
|
+
entry {
|
605
|
+
grid row: 1, column: 1, padx: 5
|
606
|
+
}
|
607
|
+
|
608
|
+
label {
|
609
|
+
grid row: 2, column: 0, padx: 5
|
610
|
+
text "Last Name:"
|
611
|
+
}
|
612
|
+
|
613
|
+
entry {
|
614
|
+
grid row: 2, column: 1, padx: 5
|
615
|
+
}
|
455
616
|
}
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
617
|
+
|
618
|
+
frame { # an empty frame can specify width and height
|
619
|
+
grid padx: 7, pady: 7
|
620
|
+
width 200
|
621
|
+
height 100
|
622
|
+
borderwidth 3
|
623
|
+
relief 'sunken'
|
461
624
|
}
|
462
|
-
}
|
463
|
-
|
464
|
-
|
625
|
+
}.open
|
626
|
+
end
|
627
|
+
end
|
628
|
+
|
629
|
+
HelloFrame.new.launch
|
465
630
|
```
|
466
631
|
|
467
632
|
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
468
633
|
|
469
634
|
```
|
470
|
-
ruby -r glimmer-dsl-tk -e "require 'samples/hello/
|
635
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_frame'"
|
471
636
|
```
|
472
637
|
|
473
638
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
474
639
|
|
475
640
|
```
|
476
|
-
ruby -
|
641
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_frame.rb
|
477
642
|
```
|
478
643
|
|
479
644
|
Glimmer app:
|
480
645
|
|
481
|
-
![glimmer dsl tk screenshot sample hello
|
482
|
-
|
646
|
+
![glimmer dsl tk screenshot sample hello frame](images/glimmer-dsl-tk-screenshot-sample-hello-frame.png)
|
647
|
+
|
648
|
+
### Hello, Notebook!
|
649
|
+
|
650
|
+
Glimmer code (from [samples/hello/hello_notebook.rb](samples/hello/hello_notebook.rb)):
|
651
|
+
|
652
|
+
```ruby
|
653
|
+
require 'glimmer-dsl-tk'
|
654
|
+
|
655
|
+
class HelloNotebook
|
656
|
+
include Glimmer
|
657
|
+
|
658
|
+
def launch
|
659
|
+
root {
|
660
|
+
title 'Hello, Notebook!'
|
661
|
+
|
662
|
+
notebook {
|
663
|
+
frame(text: 'English') {
|
664
|
+
label {
|
665
|
+
text 'Hello, World!'
|
666
|
+
}
|
667
|
+
}
|
668
|
+
|
669
|
+
frame(text: 'French') {
|
670
|
+
label {
|
671
|
+
text 'Bonjour, Univers!'
|
672
|
+
}
|
673
|
+
}
|
674
|
+
}
|
675
|
+
}.open
|
676
|
+
end
|
677
|
+
end
|
678
|
+
|
679
|
+
HelloNotebook.new.launch
|
680
|
+
```
|
681
|
+
|
682
|
+
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
683
|
+
|
684
|
+
```
|
685
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_notebook'"
|
686
|
+
```
|
687
|
+
|
688
|
+
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
689
|
+
|
690
|
+
```
|
691
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_notebook.rb
|
692
|
+
```
|
693
|
+
|
694
|
+
Glimmer app:
|
695
|
+
|
696
|
+
![glimmer dsl tk screenshot sample hello notebook English](images/glimmer-dsl-tk-screenshot-sample-hello-notebook-english.png)
|
697
|
+
![glimmer dsl tk screenshot sample hello notebook French](images/glimmer-dsl-tk-screenshot-sample-hello-notebook-french.png)
|
698
|
+
|
699
|
+
### Hello, Label!
|
700
|
+
|
701
|
+
Glimmer code (from [samples/hello/hello_label.rb](samples/hello/hello_label.rb)):
|
702
|
+
|
703
|
+
```ruby
|
704
|
+
require 'glimmer-dsl-tk'
|
705
|
+
|
706
|
+
class HelloLabel
|
707
|
+
include Glimmer
|
708
|
+
|
709
|
+
LABEL_FONTS = ['default', 'text', 'fixed', 'menu', 'heading', 'caption', 'small_caption', 'icon', 'tooltip']
|
710
|
+
LABEL_RELIEFS = ['flat', 'raised', 'sunken', 'solid', 'ridge', 'groove']
|
711
|
+
|
712
|
+
def launch
|
713
|
+
root {
|
714
|
+
title 'Hello, Label!'
|
715
|
+
|
716
|
+
notebook {
|
717
|
+
frame(text: 'left-aligned') {
|
718
|
+
3.times do |n|
|
719
|
+
label {
|
720
|
+
text "Field #{n + 1} / default font / flat relief"
|
721
|
+
width 60
|
722
|
+
anchor 'w'
|
723
|
+
}
|
724
|
+
end
|
725
|
+
}
|
726
|
+
|
727
|
+
frame(text: 'centered') {
|
728
|
+
9.times do |n|
|
729
|
+
label {
|
730
|
+
text "Field #{n + 1} / fixed font / raised relief"
|
731
|
+
width 80
|
732
|
+
anchor 'center'
|
733
|
+
font 'fixed'
|
734
|
+
relief 'raised'
|
735
|
+
}
|
736
|
+
end
|
737
|
+
}
|
738
|
+
|
739
|
+
frame(text: 'right-aligned') {
|
740
|
+
9.times do |n|
|
741
|
+
label {
|
742
|
+
text "Field #{n + 1} / small_caption font / ridge relief"
|
743
|
+
width 80
|
744
|
+
anchor 'e'
|
745
|
+
font 'small_caption'
|
746
|
+
relief 'ridge'
|
747
|
+
}
|
748
|
+
end
|
749
|
+
}
|
750
|
+
|
751
|
+
frame(text: 'justified') {
|
752
|
+
label {
|
753
|
+
text <<~MULTI_LINE_STRING
|
754
|
+
This is a very long paragraph that spans multiple lines. It looks better and
|
755
|
+
is easier to read when justified. In fact, this is how to make it look like a
|
756
|
+
new paper column. That results in professional looking text. Magazines use the
|
757
|
+
same sort of justified text. Word processors also support justified text. In
|
758
|
+
fact, this is how text is made for news papers and magainzes, and then published
|
759
|
+
in paper form and digitally.
|
760
|
+
MULTI_LINE_STRING
|
761
|
+
width 60
|
762
|
+
anchor 'center'
|
763
|
+
justify 'center' # other options are: 'left' and 'right'
|
764
|
+
font 'caption' # other options are: 'default', 'text', 'fixed', 'menu', 'heading', 'small_caption', 'icon', 'tooltip'
|
765
|
+
foreground 'blue'
|
766
|
+
relief 'sunken' # other options are: 'flat' (default), 'raised', 'solid', 'ridge', 'groove'
|
767
|
+
}
|
768
|
+
}
|
769
|
+
|
770
|
+
frame(text: 'images') {
|
771
|
+
['denmark', 'finland', 'norway'].each do |image_name|
|
772
|
+
label {
|
773
|
+
image File.expand_path("images/#{image_name}.png", __dir__)
|
774
|
+
}
|
775
|
+
end
|
776
|
+
}
|
777
|
+
|
778
|
+
frame(text: 'background images') {
|
779
|
+
['italy', 'france', 'mexico'].each do |image_name|
|
780
|
+
label {
|
781
|
+
text image_name.capitalize
|
782
|
+
image File.expand_path("images/#{image_name}.png", __dir__)
|
783
|
+
compound 'center'
|
784
|
+
}
|
785
|
+
end
|
786
|
+
}
|
787
|
+
}
|
788
|
+
}.open
|
789
|
+
end
|
790
|
+
end
|
791
|
+
|
792
|
+
HelloLabel.new.launch
|
793
|
+
```
|
794
|
+
|
795
|
+
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
796
|
+
|
797
|
+
```
|
798
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_label'"
|
799
|
+
```
|
800
|
+
|
801
|
+
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
802
|
+
|
803
|
+
```
|
804
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_label.rb
|
805
|
+
```
|
806
|
+
|
807
|
+
Glimmer app:
|
808
|
+
|
809
|
+
![glimmer dsl tk screenshot sample hello label left aligned](images/glimmer-dsl-tk-screenshot-sample-hello-label-left-aligned.png)
|
810
|
+
|
811
|
+
![glimmer dsl tk screenshot sample hello label centered](images/glimmer-dsl-tk-screenshot-sample-hello-label-centered.png)
|
812
|
+
|
813
|
+
![glimmer dsl tk screenshot sample hello label right aligned](images/glimmer-dsl-tk-screenshot-sample-hello-label-right-aligned.png)
|
814
|
+
|
815
|
+
![glimmer dsl tk screenshot sample hello label justified](images/glimmer-dsl-tk-screenshot-sample-hello-label-justified.png)
|
816
|
+
|
817
|
+
![glimmer dsl tk screenshot sample hello label images](images/glimmer-dsl-tk-screenshot-sample-hello-label-images.png)
|
818
|
+
|
819
|
+
![glimmer dsl tk screenshot sample hello label background images](images/glimmer-dsl-tk-screenshot-sample-hello-label-background-images.png)
|
483
820
|
|
484
821
|
### Hello, Message Box!
|
485
822
|
|
@@ -560,13 +897,13 @@ root { |r|
|
|
560
897
|
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
561
898
|
|
562
899
|
```
|
563
|
-
ruby -r glimmer-dsl-tk -e "require 'samples/hello/
|
900
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_message_box'"
|
564
901
|
```
|
565
902
|
|
566
903
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
567
904
|
|
568
905
|
```
|
569
|
-
ruby -
|
906
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_message_box.rb
|
570
907
|
```
|
571
908
|
|
572
909
|
Glimmer app:
|
@@ -607,7 +944,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_combobox'"
|
|
607
944
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
608
945
|
|
609
946
|
```
|
610
|
-
ruby -
|
947
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_combobox.rb
|
611
948
|
```
|
612
949
|
|
613
950
|
Glimmer app:
|
@@ -647,7 +984,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_list_single_selection'"
|
|
647
984
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
648
985
|
|
649
986
|
```
|
650
|
-
ruby -
|
987
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_list_single_selection.rb
|
651
988
|
```
|
652
989
|
|
653
990
|
Glimmer app:
|
@@ -685,7 +1022,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_list_multi_selection'"
|
|
685
1022
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
686
1023
|
|
687
1024
|
```
|
688
|
-
ruby -
|
1025
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_list_multi_selection.rb
|
689
1026
|
```
|
690
1027
|
|
691
1028
|
Glimmer app:
|
@@ -765,7 +1102,7 @@ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_computed'"
|
|
765
1102
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
766
1103
|
|
767
1104
|
```
|
768
|
-
ruby -
|
1105
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_computed.rb
|
769
1106
|
```
|
770
1107
|
|
771
1108
|
Glimmer app:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.18
|
data/glimmer-dsl-tk.gemspec
CHANGED
Binary file
|
@@ -27,14 +27,14 @@ module Glimmer
|
|
27
27
|
#
|
28
28
|
# Follows the Proxy Design Pattern
|
29
29
|
class LabelProxy < WidgetProxy
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
def set_attribute(attribute, *args)
|
31
|
+
if attribute.to_s == 'font'
|
32
|
+
args[0] = "tk_#{args[0]}_font".camelcase(:upper) if (args[0].is_a?(Symbol) || args[0].is_a?(String)) && args[0].to_s == args[0].to_s.downcase
|
33
|
+
super
|
34
|
+
else
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
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
|
@@ -85,7 +85,7 @@ module Glimmer
|
|
85
85
|
tk_widget_class = self.class.tk_widget_class_for(underscored_widget_name)
|
86
86
|
@tk = tk_widget_class.new(@parent_proxy.tk, *args)
|
87
87
|
# a common widget initializer
|
88
|
-
@tk.grid
|
88
|
+
@tk.grid unless @tk.is_a?(::Tk::Toplevel)
|
89
89
|
DEFAULT_INITIALIZERS[underscored_widget_name]&.call(@tk)
|
90
90
|
@parent_proxy.post_initialize_child(self)
|
91
91
|
end
|
@@ -117,13 +117,34 @@ module Glimmer
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def tk_widget_has_attribute_getter_setter?(attribute)
|
120
|
-
|
120
|
+
begin
|
121
|
+
# TK Widget currently doesn't support respond_to? properly, so I have to resort to this trick for now
|
122
|
+
@tk.send(attribute)
|
123
|
+
true
|
124
|
+
rescue
|
125
|
+
false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def has_state?(attribute)
|
130
|
+
attribute = attribute.sub(/\?$/, '').sub(/=$/, '')
|
131
|
+
if @tk.respond_to?(:tile_state)
|
132
|
+
begin
|
133
|
+
@tk.tile_instate(attribute)
|
134
|
+
true
|
135
|
+
rescue
|
136
|
+
false
|
137
|
+
end
|
138
|
+
else
|
139
|
+
false
|
140
|
+
end
|
121
141
|
end
|
122
142
|
|
123
143
|
def has_attribute?(attribute, *args)
|
124
|
-
(widget_custom_attribute_mapping[tk.class]
|
125
|
-
tk_widget_has_attribute_setter?(attribute)
|
126
|
-
tk_widget_has_attribute_getter_setter?(attribute)
|
144
|
+
(widget_custom_attribute_mapping[tk.class] and widget_custom_attribute_mapping[tk.class][attribute.to_s]) or
|
145
|
+
tk_widget_has_attribute_setter?(attribute) or
|
146
|
+
tk_widget_has_attribute_getter_setter?(attribute) or
|
147
|
+
has_state?(attribute) or
|
127
148
|
respond_to?(attribute_setter(attribute), args)
|
128
149
|
end
|
129
150
|
|
@@ -135,6 +156,13 @@ module Glimmer
|
|
135
156
|
@tk.send(attribute_setter(attribute), *args) unless @tk.send(attribute) == args.first
|
136
157
|
elsif tk_widget_has_attribute_getter_setter?(attribute)
|
137
158
|
@tk.send(attribute, *args)
|
159
|
+
elsif has_state?(attribute)
|
160
|
+
attribute = attribute.sub(/=$/, '')
|
161
|
+
if !!args.first
|
162
|
+
@tk.tile_state(attribute)
|
163
|
+
else
|
164
|
+
@tk.tile_state("!#{attribute}")
|
165
|
+
end
|
138
166
|
else
|
139
167
|
send(attribute_setter(attribute), args)
|
140
168
|
end
|
@@ -146,6 +174,8 @@ module Glimmer
|
|
146
174
|
widget_custom_attribute[:getter][:invoker].call(@tk, args)
|
147
175
|
elsif tk_widget_has_attribute_getter_setter?(attribute)
|
148
176
|
@tk.send(attribute)
|
177
|
+
elsif has_state?(attribute)
|
178
|
+
@tk.tile_instate(attribute.sub(/\?$/, ''))
|
149
179
|
else
|
150
180
|
send(attribute)
|
151
181
|
end
|
@@ -157,6 +187,12 @@ module Glimmer
|
|
157
187
|
|
158
188
|
def widget_custom_attribute_mapping
|
159
189
|
@widget_custom_attribute_mapping ||= {
|
190
|
+
::Tk::Tile::TButton => {
|
191
|
+
'image' => {
|
192
|
+
getter: {name: 'image', invoker: lambda { |widget, args| @tk.image }},
|
193
|
+
setter: {name: 'image=', invoker: lambda { |widget, args| @tk.image = image_argument(args) }},
|
194
|
+
},
|
195
|
+
},
|
160
196
|
::Tk::Tile::TCombobox => {
|
161
197
|
'text' => {
|
162
198
|
getter: {name: 'text', invoker: lambda { |widget, args| @tk.textvariable&.value }},
|
@@ -168,6 +204,10 @@ module Glimmer
|
|
168
204
|
getter: {name: 'text', invoker: lambda { |widget, args| @tk.textvariable&.value }},
|
169
205
|
setter: {name: 'text=', invoker: lambda { |widget, args| @tk.textvariable&.value = args.first }},
|
170
206
|
},
|
207
|
+
'image' => {
|
208
|
+
getter: {name: 'image', invoker: lambda { |widget, args| @tk.image }},
|
209
|
+
setter: {name: 'image=', invoker: lambda { |widget, args| @tk.image = image_argument(args) }},
|
210
|
+
},
|
171
211
|
},
|
172
212
|
::Tk::Tile::TEntry => {
|
173
213
|
'text' => {
|
@@ -210,6 +250,22 @@ module Glimmer
|
|
210
250
|
}
|
211
251
|
end
|
212
252
|
|
253
|
+
def image_argument(args)
|
254
|
+
if args.first.is_a?(::TkPhotoImage)
|
255
|
+
args.first
|
256
|
+
else
|
257
|
+
image_args = {}
|
258
|
+
image_args.merge!(file: args.first.to_s) if args.first.is_a?(String)
|
259
|
+
the_image = ::TkPhotoImage.new(image_args)
|
260
|
+
if args.last.is_a?(Hash)
|
261
|
+
processed_image = ::TkPhotoImage.new
|
262
|
+
processed_image.copy(the_image, args.last)
|
263
|
+
the_image = processed_image
|
264
|
+
end
|
265
|
+
the_image
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
213
269
|
def add_observer(observer, attribute)
|
214
270
|
attribute_listener_installers = @tk.class.ancestors.map {|ancestor| widget_attribute_listener_installers[ancestor]}.compact
|
215
271
|
widget_listener_installers = attribute_listener_installers.map{|installer| installer[attribute.to_s]}.compact if !attribute_listener_installers.empty?
|
@@ -222,9 +278,9 @@ module Glimmer
|
|
222
278
|
|
223
279
|
def method_missing(method, *args, &block)
|
224
280
|
method = method.to_s
|
225
|
-
if args.empty? && block.nil? && widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method]
|
281
|
+
if args.empty? && block.nil? && ((widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method]) || has_state?(method))
|
226
282
|
get_attribute(method)
|
227
|
-
elsif widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method.sub(/=$/, '')]
|
283
|
+
elsif method.end_with?('=') && block.nil? && ((widget_custom_attribute_mapping[tk.class] && widget_custom_attribute_mapping[tk.class][method.sub(/=$/, '')]) || has_state?(method))
|
228
284
|
set_attribute(method.sub(/=$/, ''), *args)
|
229
285
|
else
|
230
286
|
tk.send(method, *args, &block)
|
@@ -34,12 +34,61 @@ class HelloButton
|
|
34
34
|
root {
|
35
35
|
title 'Hello, Button!'
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
frame {
|
38
|
+
grid row: 0, column: 0
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
label {
|
41
|
+
grid pady: 15
|
42
|
+
text 'Text Button'
|
42
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
|
43
92
|
}
|
44
93
|
}.open
|
45
94
|
end
|
@@ -0,0 +1,71 @@
|
|
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 HelloFrame
|
25
|
+
include Glimmer
|
26
|
+
|
27
|
+
def launch
|
28
|
+
root {
|
29
|
+
title 'Hello, Frame!'
|
30
|
+
|
31
|
+
frame { # frame simply contains widgets for visual organization via a layout
|
32
|
+
relief 'sunken'
|
33
|
+
|
34
|
+
label {
|
35
|
+
grid row: 0, column: 0, columnspan: 4, padx: 5, pady: 5
|
36
|
+
text 'Enter Your Full Name'
|
37
|
+
font 'caption'
|
38
|
+
anchor 'center'
|
39
|
+
}
|
40
|
+
|
41
|
+
label {
|
42
|
+
grid row: 1, column: 0, padx: 5
|
43
|
+
text "First Name:"
|
44
|
+
}
|
45
|
+
|
46
|
+
entry {
|
47
|
+
grid row: 1, column: 1, padx: 5
|
48
|
+
}
|
49
|
+
|
50
|
+
label {
|
51
|
+
grid row: 2, column: 0, padx: 5
|
52
|
+
text "Last Name:"
|
53
|
+
}
|
54
|
+
|
55
|
+
entry {
|
56
|
+
grid row: 2, column: 1, padx: 5
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
frame { # an empty frame can specify width and height
|
61
|
+
grid padx: 7, pady: 7
|
62
|
+
width 200
|
63
|
+
height 100
|
64
|
+
borderwidth 3
|
65
|
+
relief 'sunken'
|
66
|
+
}
|
67
|
+
}.open
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
HelloFrame.new.launch
|
@@ -0,0 +1,110 @@
|
|
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 HelloLabel
|
25
|
+
include Glimmer
|
26
|
+
|
27
|
+
LABEL_FONTS = ['default', 'text', 'fixed', 'menu', 'heading', 'caption', 'small_caption', 'icon', 'tooltip']
|
28
|
+
LABEL_RELIEFS = ['flat', 'raised', 'sunken', 'solid', 'ridge', 'groove']
|
29
|
+
|
30
|
+
def launch
|
31
|
+
root {
|
32
|
+
title 'Hello, Label!'
|
33
|
+
|
34
|
+
notebook {
|
35
|
+
frame(text: 'left-aligned') {
|
36
|
+
3.times do |n|
|
37
|
+
label {
|
38
|
+
text "Field #{n + 1} / default font / flat relief"
|
39
|
+
width 60
|
40
|
+
anchor 'w'
|
41
|
+
}
|
42
|
+
end
|
43
|
+
}
|
44
|
+
|
45
|
+
frame(text: 'centered') {
|
46
|
+
9.times do |n|
|
47
|
+
label {
|
48
|
+
text "Field #{n + 1} / fixed font / raised relief"
|
49
|
+
width 80
|
50
|
+
anchor 'center'
|
51
|
+
font 'fixed'
|
52
|
+
relief 'raised'
|
53
|
+
}
|
54
|
+
end
|
55
|
+
}
|
56
|
+
|
57
|
+
frame(text: 'right-aligned') {
|
58
|
+
9.times do |n|
|
59
|
+
label {
|
60
|
+
text "Field #{n + 1} / small_caption font / ridge relief"
|
61
|
+
width 80
|
62
|
+
anchor 'e'
|
63
|
+
font 'small_caption'
|
64
|
+
relief 'ridge'
|
65
|
+
}
|
66
|
+
end
|
67
|
+
}
|
68
|
+
|
69
|
+
frame(text: 'justified') {
|
70
|
+
label {
|
71
|
+
text <<~MULTI_LINE_STRING
|
72
|
+
This is a very long paragraph that spans multiple lines. It looks better and
|
73
|
+
is easier to read when justified. In fact, this is how to make it look like a
|
74
|
+
new paper column. That results in professional looking text. Magazines use the
|
75
|
+
same sort of justified text. Word processors also support justified text. In
|
76
|
+
fact, this is how text is made for news papers and magainzes, and then published
|
77
|
+
in paper form and digitally.
|
78
|
+
MULTI_LINE_STRING
|
79
|
+
width 60
|
80
|
+
anchor 'center'
|
81
|
+
justify 'center' # other options are: 'left' and 'right'
|
82
|
+
font 'caption' # other options are: 'default', 'text', 'fixed', 'menu', 'heading', 'small_caption', 'icon', 'tooltip'
|
83
|
+
foreground 'blue'
|
84
|
+
relief 'sunken' # other options are: 'flat' (default), 'raised', 'solid', 'ridge', 'groove'
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
frame(text: 'images') {
|
89
|
+
['denmark', 'finland', 'norway'].each do |image_name|
|
90
|
+
label {
|
91
|
+
image File.expand_path("images/#{image_name}.png", __dir__)
|
92
|
+
}
|
93
|
+
end
|
94
|
+
}
|
95
|
+
|
96
|
+
frame(text: 'background images') {
|
97
|
+
['italy', 'france', 'mexico'].each do |image_name|
|
98
|
+
label {
|
99
|
+
text image_name.capitalize
|
100
|
+
image File.expand_path("images/#{image_name}.png", __dir__)
|
101
|
+
compound 'center'
|
102
|
+
}
|
103
|
+
end
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}.open
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
HelloLabel.new.launch
|
@@ -21,12 +21,12 @@
|
|
21
21
|
|
22
22
|
require 'glimmer-dsl-tk'
|
23
23
|
|
24
|
-
class
|
24
|
+
class HelloNotebook
|
25
25
|
include Glimmer
|
26
26
|
|
27
27
|
def launch
|
28
28
|
root {
|
29
|
-
title 'Hello,
|
29
|
+
title 'Hello, Notebook!'
|
30
30
|
|
31
31
|
notebook {
|
32
32
|
frame(text: 'English') {
|
@@ -45,4 +45,4 @@ class HelloTab
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
HelloNotebook.new.launch
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
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.18
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -170,7 +170,7 @@ dependencies:
|
|
170
170
|
- - "~>"
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: 0.7.0
|
173
|
-
description: Glimmer DSL for Tk (Ruby Desktop Development GUI Library)
|
173
|
+
description: Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)
|
174
174
|
email: andy.am@gmail.com
|
175
175
|
executables:
|
176
176
|
- girb
|
@@ -214,11 +214,22 @@ files:
|
|
214
214
|
- samples/hello/hello_combobox.rb
|
215
215
|
- samples/hello/hello_computed.rb
|
216
216
|
- samples/hello/hello_computed/contact.rb
|
217
|
+
- samples/hello/hello_frame.rb
|
218
|
+
- samples/hello/hello_label.rb
|
217
219
|
- samples/hello/hello_list_multi_selection.rb
|
218
220
|
- samples/hello/hello_list_single_selection.rb
|
219
221
|
- samples/hello/hello_message_box.rb
|
220
|
-
- samples/hello/
|
222
|
+
- samples/hello/hello_notebook.rb
|
221
223
|
- samples/hello/hello_world.rb
|
224
|
+
- samples/hello/images/denmark.png
|
225
|
+
- samples/hello/images/finland.png
|
226
|
+
- samples/hello/images/france.png
|
227
|
+
- samples/hello/images/germany.png
|
228
|
+
- samples/hello/images/italy.png
|
229
|
+
- samples/hello/images/mexico.png
|
230
|
+
- samples/hello/images/netherlands.png
|
231
|
+
- samples/hello/images/norway.png
|
232
|
+
- samples/hello/images/usa.png
|
222
233
|
homepage: http://github.com/AndyObtiva/glimmer-dsl-tk
|
223
234
|
licenses:
|
224
235
|
- MIT
|