glimmer-dsl-tk 0.0.17 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/README.md +358 -45
- data/VERSION +1 -1
- data/glimmer-dsl-tk.gemspec +0 -0
- data/lib/glimmer/dsl/tk/on_expression.rb +35 -0
- data/lib/glimmer/tk/button_proxy.rb +11 -0
- data/lib/glimmer/tk/checkbutton_proxy.rb +44 -0
- data/lib/glimmer/tk/root_proxy.rb +122 -2
- data/lib/glimmer/tk/widget_proxy.rb +56 -5
- data/lib/glimmer-dsl-tk.rb +1 -0
- data/samples/hello/hello_checkbutton.rb +89 -0
- data/samples/hello/hello_frame.rb +71 -0
- data/samples/hello/{hello_tab.rb → hello_notebook.rb} +4 -4
- data/samples/hello/hello_root.rb +48 -0
- metadata +42 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1af2971637c33b4dcebacf0de9239fa24402b92325157df38453a1ba535d99c
|
4
|
+
data.tar.gz: f327b2f968225d46be3768dc109aba6799ad4b00cd4c77b2584ed3729de57a7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a94b3eff61254b4b134cd19011c51ea1ec1ca952f6f2a753897840a0586cd39ca41483f4701a6746d8768b186a28790f6a010dfa6ba8f27d38d1698058ee11b4
|
7
|
+
data.tar.gz: d0fba3f64cb7b54f94ae6c00d7d6dbe4c1fe400cbc66c15c55b3648cfa3d05b0cb2eba123e6a4a9b1e79c78e9f0c9376282a2f9829d8f95013aa9804bcc05609
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,43 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.22
|
4
|
+
|
5
|
+
- Hello, Checkbutton!
|
6
|
+
- Support checkbutton data-binding
|
7
|
+
|
8
|
+
## 0.0.21
|
9
|
+
|
10
|
+
- Support event bindings via `on(event) {}` syntax nestable under any widget
|
11
|
+
- Support `root` event binding: `'WM_DELETE_WINDOW'` and alias `'DELETE_WINDOW'`
|
12
|
+
- Support `root` event binding: `'OPEN_WINDOW'`
|
13
|
+
- Support `root` attribute: `background` (any color including `systemTransparent`)
|
14
|
+
- Support `root` boolean attribute: `alpha`
|
15
|
+
- Support `root` boolean attributes: `fullscreen`, `topmost`, `transparent`
|
16
|
+
- Support `root` attributes: `stackorder`, `winfo_screendepth`, `winfo_screenvisual`, `winfo_screenwidth`, `winfo_screenheight`, `winfo_pixels('li')`, `winfo_screen`, `wm_maxsize`
|
17
|
+
- Support `root` attribute: `state` (`'normal', 'iconic', 'withdrawn', 'icon', 'zoomed'`)
|
18
|
+
|
19
|
+
## 0.0.20
|
20
|
+
|
21
|
+
- Hello, Root! sample
|
22
|
+
- Support `root` `width`, `height`, `x`, `y` attributes
|
23
|
+
- Support `root` attribute: `resizable`
|
24
|
+
- Support `root` attribute: `minsize`
|
25
|
+
- Support `root` attribute: `maxsize`
|
26
|
+
- Set minimum width/height on `root` (190 pixels)
|
27
|
+
|
28
|
+
## 0.0.18
|
29
|
+
|
30
|
+
- Hello, Frame! sample
|
31
|
+
- Avoid setting grid geometry manager on `toplevel` widget
|
32
|
+
- Support `frame` `width` and `height` attributes
|
33
|
+
- Support `frame` `borderwidth` attribute
|
34
|
+
- Support `frame` `relief` attribute
|
35
|
+
- Support `frame` `padding` attribute
|
36
|
+
- Rename Hello, Tab! to Hello, Notebook!
|
37
|
+
|
3
38
|
## 0.0.17
|
4
39
|
|
40
|
+
- Hello, Label! sample
|
5
41
|
- Support `label` `anchor` attribute (`'e'`, `'se'`, `'s'`, `'sw'`, `'w'`, `'nw'` or `'center'`)
|
6
42
|
- Support `label` `width` attributes
|
7
43
|
- Support `label` `image` attribute
|
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.21
|
2
2
|
## MRI Ruby Desktop Development GUI Library
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-tk.svg)](http://badge.fury.io/rb/glimmer-dsl-tk)
|
4
4
|
[![Ruby](https://github.com/AndyObtiva/glimmer-dsl-tk/actions/workflows/ruby.yml/badge.svg)](https://github.com/AndyObtiva/glimmer-dsl-tk/actions/workflows/ruby.yml)
|
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
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).
|
12
12
|
|
13
|
-
[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.).
|
14
14
|
|
15
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).
|
16
16
|
|
@@ -79,19 +79,25 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
|
|
79
79
|
- [Smart Defaults and Convensions](#smart-defaults-and-convensions)
|
80
80
|
- [Grid Layout](#grid-layout)
|
81
81
|
- [Label/Button Image](#labelbutton-image)
|
82
|
+
- [Notebook Frame](#notebook-frame)
|
82
83
|
- [Icon Photo](#icon-photo)
|
83
84
|
- [The Grid Geometry Manager](#the-grid-geometry-manager)
|
84
85
|
- [Bidirectional Data-Binding](#bidirectional-data-binding)
|
85
|
-
- [
|
86
|
+
- [Label Data-Binding](#label-data-binding)
|
86
87
|
- [Combobox Data-Binding](#combobox-data-binding)
|
87
88
|
- [List Single Selection Data-Binding](#list-single-selection-data-binding)
|
88
89
|
- [List Multi Selection Data-Binding](#list-multi-selection-data-binding)
|
89
90
|
- [Entry Data-Binding](#entry-data-binding)
|
90
|
-
|
91
|
+
- [Checkbox Data-Binding](#checkbox-data-binding)
|
92
|
+
- [Command Callback](#command-callback)
|
93
|
+
- [Gotchas](#gotchas)
|
91
94
|
- [Samples](#samples)
|
92
95
|
- [Hello, World!](#hello-world)
|
93
96
|
- [Hello, Button!](#hello-button)
|
94
|
-
- [Hello,
|
97
|
+
- [Hello, Checkbutton!](#hello-checkbutton)
|
98
|
+
- [Hello, Frame!](#hello-frame)
|
99
|
+
- [Hello, Root!](#hello-root)
|
100
|
+
- [Hello, Notebook!](#hello-notebook)
|
95
101
|
- [Hello, Label!](#hello-label)
|
96
102
|
- [Hello, Message Box!](#hello-message-box)
|
97
103
|
- [Hello, Combobox!](#hello-combobox)
|
@@ -116,7 +122,7 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
|
|
116
122
|
For example, on the Mac, you can:
|
117
123
|
- Install the ActiveTcl Mac package from [ActiveState.com](https://activestate.com)
|
118
124
|
- Install [RVM](https://rvm.io/) by running `\curl -sSL https://get.rvm.io | bash -s stable` (and run `curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -` if needed for mentioned security reasons)
|
119
|
-
- Run: `rvm install
|
125
|
+
- Run: `rvm install 3.0.2 --enable-shared --enable-pthread --with-tk --with-tcl`
|
120
126
|
- Run: `gem install tk -v0.4.0`
|
121
127
|
|
122
128
|
Afterwards, if you open `irb`, you should be able to run `require 'tk'` successfully.
|
@@ -134,7 +140,7 @@ gem install glimmer-dsl-tk
|
|
134
140
|
|
135
141
|
Add the following to `Gemfile`:
|
136
142
|
```
|
137
|
-
gem 'glimmer-dsl-tk', '~> 0.0.
|
143
|
+
gem 'glimmer-dsl-tk', '~> 0.0.21'
|
138
144
|
```
|
139
145
|
|
140
146
|
And, then run:
|
@@ -176,12 +182,13 @@ The Glimmer GUI DSL follows these simple concepts in mapping from Tk syntax:
|
|
176
182
|
- **Widget Keyword**: Any Tk widget (e.g. `Tk::Tile::Label`) or toplevel window (e.g. `TkRoot`) may be declared by its lower-case underscored name without the namespace (e.g. `label` or `root`). This is called a keyword and is represented in the Glimmer GUI DSL by a Ruby method behind the scenes.
|
177
183
|
- **Args**: Any keyword method may optionally take arguments surrounded by parentheses (e.g. a `frame` nested under a `notebook` may receive tab options like `frame(text: 'Users')`, which gets used behind the scenes by Tk code such as `notebook.add tab, text: 'Users'`)
|
178
184
|
- **Content/Options Block**: Any keyword may optionally be followed by a Ruby curly-brace block containing nested widgets (content) and attributes (options). Attributes are simply Tk option keywords followed by arguments and no block (e.g. `title 'Hello, World!'` under a `root`)
|
185
|
+
- **Event Binding Block**: `on(event) {}` keyword receiving a Tk binding event name (e.g. `KeyPress` or `ComboboxSelected`). No need to surround event by `<>` as [Glimmer DSL for Tk](https://rubygems.org/gems/glimmer-dsl-tk) takes care of that automatically.
|
179
186
|
|
180
187
|
Example of an app written in [Tk](https://www.tcl.tk/) imperative syntax:
|
181
188
|
|
182
189
|
```ruby
|
183
190
|
root = TkRoot.new
|
184
|
-
root.title = 'Hello,
|
191
|
+
root.title = 'Hello, Notebook!'
|
185
192
|
|
186
193
|
notebook = ::Tk::Tile::Notebook.new(root).grid
|
187
194
|
|
@@ -195,6 +202,15 @@ notebook.add tab2, text: 'French'
|
|
195
202
|
label2 = ::Tk::Tile::Label.new(tab2).grid
|
196
203
|
label2.text = 'Bonjour, Univers!'
|
197
204
|
|
205
|
+
root.bind('KeyPress') do |event|
|
206
|
+
case event.keysym
|
207
|
+
when 'e', 'E'
|
208
|
+
notebook.select(0)
|
209
|
+
when 'f', 'F'
|
210
|
+
notebook.select(1)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
198
214
|
root.mainloop
|
199
215
|
```
|
200
216
|
|
@@ -202,9 +218,9 @@ Example of the same app written in [Glimmer](https://github.com/AndyObtiva/glimm
|
|
202
218
|
|
203
219
|
```ruby
|
204
220
|
root {
|
205
|
-
title 'Hello,
|
221
|
+
title 'Hello, Notebook!'
|
206
222
|
|
207
|
-
notebook {
|
223
|
+
@notebook = notebook {
|
208
224
|
frame(text: 'English') {
|
209
225
|
label {
|
210
226
|
text 'Hello, World!'
|
@@ -217,6 +233,15 @@ root {
|
|
217
233
|
}
|
218
234
|
}
|
219
235
|
}
|
236
|
+
|
237
|
+
on('KeyPress') do |event|
|
238
|
+
case event.keysym
|
239
|
+
when 'e', 'E'
|
240
|
+
@notebook.select(0)
|
241
|
+
when 'f', 'F'
|
242
|
+
@notebook.select(1)
|
243
|
+
end
|
244
|
+
end
|
220
245
|
}.open
|
221
246
|
```
|
222
247
|
|
@@ -224,19 +249,52 @@ root {
|
|
224
249
|
|
225
250
|
keyword(args) | attributes | event bindings & callbacks
|
226
251
|
------------- | ---------- | ---------
|
227
|
-
`button` | `text`, `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `default` (`'active', 'normal'`) | `command`
|
252
|
+
`button` | `text`, `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `default` (`'active', 'normal'`) | `command {}`
|
253
|
+
`checkbutton` | `text`, `variable` (Boolean), `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `default` (`'active', 'normal'`) | `command {}`
|
254
|
+
`combobox` | `state`, `text` | `'ComboboxSelected'`
|
228
255
|
`entry` | `width`, `text` | None
|
229
|
-
`frame(text: nil)` |
|
256
|
+
`frame(text: nil)` | `width`, `height`, `borderwidth`, `relief` (`'flat' (default), 'raised', 'sunken', 'solid', 'ridge', 'groove'`) | None
|
230
257
|
`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
|
231
258
|
`list` | `selectmode`, `selection` | None
|
232
259
|
`message_box(type: , message: , detail: , title: , icon: , default: , parent: )` | None | None
|
233
260
|
`notebook` | None | None
|
234
|
-
`root` | `title`, `iconphoto` |
|
261
|
+
`root` | `title`, `iconphoto`, `background`, `alpha`, `fullscreen?`, `topmost?`, `transparent?`, `stackorder`, `winfo_screendepth`, `winfo_screenvisual`, `winfo_screenwidth`, `winfo_screenheight`, `winfo_pixels('li')`, `winfo_screen`, `wm_maxsize`, `state` (`'normal', 'iconic', 'withdrawn', 'icon', 'zoomed'`) | `'DELETE_WINDOW'`, `'OPEN_WINDOW'`
|
235
262
|
|
236
263
|
#### Common Attributes
|
237
264
|
|
238
265
|
- `grid`: `Hash` of `:row`, `:column`, `:padx`, `:pady`, `:sticky` (`'e', 'w', 'n', 's'` or any combination of direction letters)
|
239
266
|
|
267
|
+
#### Common Event Bindings
|
268
|
+
|
269
|
+
- `Activate`
|
270
|
+
- `Deactivate`
|
271
|
+
- `MouseWheel`
|
272
|
+
- `KeyPress`
|
273
|
+
- `KeyRelease`
|
274
|
+
- `ButtonPress`
|
275
|
+
- `ButtonRelease`
|
276
|
+
- `Motion`
|
277
|
+
- `Configure`
|
278
|
+
- `Map`
|
279
|
+
- `Unmap`
|
280
|
+
- `Visibility`
|
281
|
+
- `Expose`
|
282
|
+
- `Destroy`
|
283
|
+
- `FocusIn`
|
284
|
+
- `FocusOut`
|
285
|
+
- `Enter`
|
286
|
+
- `Leave`
|
287
|
+
- `Property`
|
288
|
+
- `Colormap`
|
289
|
+
- `MapRequest`
|
290
|
+
- `CirculateRequest`
|
291
|
+
- `ResizeRequest`
|
292
|
+
- `ConfigureRequest`
|
293
|
+
- `Create`
|
294
|
+
- `Gravity`
|
295
|
+
- `Reparent`
|
296
|
+
- `Circulate`
|
297
|
+
|
240
298
|
#### Common Themed Widget States
|
241
299
|
|
242
300
|
- `active?`
|
@@ -252,6 +310,10 @@ keyword(args) | attributes | event bindings & callbacks
|
|
252
310
|
|
253
311
|
### Smart Defaults and Convensions
|
254
312
|
|
313
|
+
#### Event Bindings
|
314
|
+
|
315
|
+
Any events that normally can be accepted by the Tk `bind` or `protocol` methods can be accepted by the `on(event) {}` listener syntax. There is no need to surround event name by `<>` as [Glimmer DSL for Tk](https://rubygems.org/gems/glimmer-dsl-tk) automatically takes care of that when needed and leaves out when not needed.
|
316
|
+
|
255
317
|
#### Grid Layout
|
256
318
|
|
257
319
|
`grid` layout is the default on most widgets (which support it).
|
@@ -260,6 +322,10 @@ keyword(args) | attributes | event bindings & callbacks
|
|
260
322
|
|
261
323
|
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`)
|
262
324
|
|
325
|
+
#### Notebook Frame
|
326
|
+
|
327
|
+
When nesting `frame` under `notebook`, you can pass a `:text` keyword argument to indicate the tab title.
|
328
|
+
|
263
329
|
#### Icon Photo
|
264
330
|
|
265
331
|
The `iconphoto` attribute on `root` is set to the Glimmer icon by default if no icon photo is supplied.
|
@@ -308,7 +374,7 @@ More details can be found in the [Hello, Computed!](#hello-computed) sample belo
|
|
308
374
|
|
309
375
|
Glimmer supports Shine syntax bidirectional data-binding via the `<=>` operator (read-write) and unidirectional data-binding via the `<=` operator (read-only), which takes a model and an attribute (the `bind` keyword may also be used as the old-style of data-binding).
|
310
376
|
|
311
|
-
###
|
377
|
+
### Label Data-Binding
|
312
378
|
|
313
379
|
Example:
|
314
380
|
|
@@ -316,11 +382,11 @@ This assumes a `Person` model with a `country` attribute.
|
|
316
382
|
|
317
383
|
```ruby
|
318
384
|
label {
|
319
|
-
text
|
385
|
+
text <= [person, :country]
|
320
386
|
}
|
321
387
|
```
|
322
388
|
|
323
|
-
That code binds the `textvariable` value of the `label` to the `country` property on the `person` model.
|
389
|
+
That code binds the `textvariable` value of the `label` unidirectionally (read-only) to the `country` property on the `person` model.
|
324
390
|
|
325
391
|
It automatically handles all the Tk plumbing behind the scenes.
|
326
392
|
|
@@ -361,8 +427,8 @@ This assumes a `Person` model with a `country` attribute representing their curr
|
|
361
427
|
}
|
362
428
|
```
|
363
429
|
|
364
|
-
That code binds the `items` text of the `list` to the `country_options`
|
365
|
-
It also binds the `selection` text of the `list` to the `country`
|
430
|
+
That code binds the `items` text of the `list` to the `country_options` attribute on the `person` model (data-binding attribute + "_options" by convention).
|
431
|
+
It also binds the `selection` text of the `list` to the `country` attribute on the `person` model.
|
366
432
|
|
367
433
|
It automatically handles all the Tk plumbing behind the scenes.
|
368
434
|
|
@@ -382,8 +448,8 @@ This assumes a `Person` model with a `provinces` attribute representing their cu
|
|
382
448
|
}
|
383
449
|
```
|
384
450
|
|
385
|
-
That code binds the `items` text of the `list` to the `provinces_options`
|
386
|
-
It also binds the `selection` text of the `list` to the `provinces`
|
451
|
+
That code binds the `items` text of the `list` to the `provinces_options` attribute on the `person` model (data-binding attribute + "_options" by convention).
|
452
|
+
It also binds the `selection` text of the `list` to the `provinces` attribute on the `person` model.
|
387
453
|
|
388
454
|
It automatically handles all the Tk plumbing behind the scenes.
|
389
455
|
|
@@ -401,30 +467,51 @@ This assumes a `Person` model with a `country` attribute.
|
|
401
467
|
}
|
402
468
|
```
|
403
469
|
|
404
|
-
That code binds the `textvariable` value of the `entry` to the `country`
|
470
|
+
That code binds the `textvariable` value of the `entry` to the `country` attribute on the `person` model.
|
405
471
|
|
406
472
|
It automatically handles all the Tk plumbing behind the scenes.
|
407
473
|
|
408
474
|
More details can be found in the [Hello, Computed!](#hello-computed) sample below.
|
409
475
|
|
410
|
-
|
476
|
+
### Checkbox Data-Binding
|
477
|
+
|
478
|
+
Example:
|
479
|
+
|
480
|
+
This assumes a `Person` model with a boolean `adult` attribute.
|
481
|
+
|
482
|
+
```ruby
|
483
|
+
checkbutton {
|
484
|
+
variable <=> [person, :adult]
|
485
|
+
}
|
486
|
+
```
|
487
|
+
|
488
|
+
That code binds the `variable` value of the `checkbutton` to the boolean `adult` attribute on the `person` model.
|
489
|
+
|
490
|
+
It automatically handles all the Tk plumbing behind the scenes.
|
491
|
+
|
492
|
+
More details can be found in the [Hello, Checkbutton!](#hello-checkbutton) sample below.
|
493
|
+
|
494
|
+
## Command Callback
|
411
495
|
|
412
|
-
|
496
|
+
`button` and `checkbutton` can set a `command` block to trigger when the user clicks the button/checkbutton. This may be done with the `command` keyword, passing in a block directly.
|
413
497
|
|
414
498
|
Example:
|
415
499
|
|
416
500
|
```ruby
|
417
501
|
button {
|
418
502
|
text "Reset Selection"
|
503
|
+
|
419
504
|
command {
|
420
505
|
person.reset_country
|
421
506
|
}
|
422
507
|
}
|
423
508
|
```
|
424
509
|
|
425
|
-
|
510
|
+
More details can be found in the [Hello, Button!](#hello-button) sample below.
|
426
511
|
|
427
|
-
|
512
|
+
## Gotchas
|
513
|
+
|
514
|
+
- Setting `background` attribute on `frame` or `label` does not work in `'aqua'` theme on the Mac (only in `'classic'` theme)
|
428
515
|
|
429
516
|
## Samples
|
430
517
|
|
@@ -561,48 +648,274 @@ Glimmer app:
|
|
561
648
|
|
562
649
|
![glimmer dsl tk screenshot sample hello button](images/glimmer-dsl-tk-screenshot-sample-hello-button.png)
|
563
650
|
|
564
|
-
### Hello,
|
651
|
+
### Hello, Checkbutton!
|
565
652
|
|
566
|
-
Glimmer code (from [samples/hello/
|
653
|
+
Glimmer code (from [samples/hello/hello_checkbutton.rb](samples/hello/hello_checkbutton.rb)):
|
567
654
|
|
568
655
|
```ruby
|
569
|
-
|
656
|
+
require 'glimmer-dsl-tk'
|
570
657
|
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
658
|
+
class HelloCheckbutton
|
659
|
+
class Person
|
660
|
+
attr_accessor :skiing, :snowboarding, :snowmobiling, :snowshoeing
|
661
|
+
|
662
|
+
def initialize
|
663
|
+
reset_activities!
|
664
|
+
end
|
665
|
+
|
666
|
+
def reset_activities!
|
667
|
+
self.skiing = false
|
668
|
+
self.snowboarding = true
|
669
|
+
self.snowmobiling = false
|
670
|
+
self.snowshoeing = false
|
671
|
+
end
|
672
|
+
end
|
673
|
+
|
674
|
+
include Glimmer
|
675
|
+
|
676
|
+
def initialize
|
677
|
+
@person = Person.new
|
678
|
+
end
|
679
|
+
|
680
|
+
def launch
|
681
|
+
root {
|
682
|
+
title 'Hello, Checkbutton!'
|
683
|
+
background '#ececec' if OS.mac?
|
684
|
+
|
576
685
|
label {
|
577
|
-
text '
|
686
|
+
text 'Check all snow activities you are interested in:'
|
687
|
+
font 'caption'
|
578
688
|
}
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
689
|
+
|
690
|
+
frame {
|
691
|
+
checkbutton {
|
692
|
+
text 'Skiing'
|
693
|
+
variable <=> [@person, :skiing]
|
694
|
+
}
|
695
|
+
|
696
|
+
checkbutton {
|
697
|
+
text 'Snowboarding'
|
698
|
+
variable <=> [@person, :snowboarding]
|
699
|
+
}
|
700
|
+
|
701
|
+
checkbutton {
|
702
|
+
text 'Snowmobiling'
|
703
|
+
variable <=> [@person, :snowmobiling]
|
704
|
+
}
|
705
|
+
|
706
|
+
checkbutton {
|
707
|
+
text 'Snowshoeing'
|
708
|
+
variable <=> [@person, :snowshoeing]
|
709
|
+
}
|
584
710
|
}
|
585
|
-
|
586
|
-
|
711
|
+
|
712
|
+
button {
|
713
|
+
text 'Reset Activities'
|
714
|
+
|
715
|
+
command do
|
716
|
+
@person.reset_activities!
|
717
|
+
end
|
718
|
+
}
|
719
|
+
}.open
|
720
|
+
end
|
721
|
+
end
|
722
|
+
|
723
|
+
HelloCheckbutton.new.launch
|
724
|
+
```
|
725
|
+
|
726
|
+
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
727
|
+
|
728
|
+
```
|
729
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_checkbutton'"
|
730
|
+
```
|
731
|
+
|
732
|
+
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
733
|
+
|
734
|
+
```
|
735
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_checkbutton.rb
|
736
|
+
```
|
737
|
+
|
738
|
+
Glimmer app:
|
739
|
+
|
740
|
+
![glimmer dsl tk screenshot sample hello checkbutton](images/glimmer-dsl-tk-screenshot-sample-hello-checkbutton.png)
|
741
|
+
|
742
|
+
### Hello, Frame!
|
743
|
+
|
744
|
+
Glimmer code (from [samples/hello/hello_frame.rb](samples/hello/hello_frame.rb)):
|
745
|
+
|
746
|
+
```ruby
|
747
|
+
require 'glimmer-dsl-tk'
|
748
|
+
|
749
|
+
class HelloFrame
|
750
|
+
include Glimmer
|
751
|
+
|
752
|
+
def launch
|
753
|
+
root {
|
754
|
+
title 'Hello, Frame!'
|
755
|
+
|
756
|
+
frame { # frame simply contains widgets for visual organization via a layout
|
757
|
+
relief 'sunken'
|
758
|
+
|
759
|
+
label {
|
760
|
+
grid row: 0, column: 0, columnspan: 4, padx: 5, pady: 5
|
761
|
+
text 'Enter Your Full Name'
|
762
|
+
font 'caption'
|
763
|
+
anchor 'center'
|
764
|
+
}
|
765
|
+
|
766
|
+
label {
|
767
|
+
grid row: 1, column: 0, padx: 5
|
768
|
+
text "First Name:"
|
769
|
+
}
|
770
|
+
|
771
|
+
entry {
|
772
|
+
grid row: 1, column: 1, padx: 5
|
773
|
+
}
|
774
|
+
|
775
|
+
label {
|
776
|
+
grid row: 2, column: 0, padx: 5
|
777
|
+
text "Last Name:"
|
778
|
+
}
|
779
|
+
|
780
|
+
entry {
|
781
|
+
grid row: 2, column: 1, padx: 5
|
782
|
+
}
|
783
|
+
}
|
784
|
+
|
785
|
+
frame { # an empty frame can specify width and height
|
786
|
+
grid padx: 7, pady: 7
|
787
|
+
width 200
|
788
|
+
height 100
|
789
|
+
borderwidth 3
|
790
|
+
relief 'sunken'
|
791
|
+
}
|
792
|
+
}.open
|
793
|
+
end
|
794
|
+
end
|
795
|
+
|
796
|
+
HelloFrame.new.launch
|
797
|
+
```
|
798
|
+
|
799
|
+
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
800
|
+
|
801
|
+
```
|
802
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_frame'"
|
803
|
+
```
|
804
|
+
|
805
|
+
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
806
|
+
|
807
|
+
```
|
808
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_frame.rb
|
809
|
+
```
|
810
|
+
|
811
|
+
Glimmer app:
|
812
|
+
|
813
|
+
![glimmer dsl tk screenshot sample hello frame](images/glimmer-dsl-tk-screenshot-sample-hello-frame.png)
|
814
|
+
|
815
|
+
### Hello, Root!
|
816
|
+
|
817
|
+
Glimmer code (from [samples/hello/hello_frame.rb](samples/hello/hello_frame.rb)):
|
818
|
+
|
819
|
+
```ruby
|
820
|
+
require 'glimmer-dsl-tk'
|
821
|
+
|
822
|
+
include Glimmer
|
823
|
+
|
824
|
+
root { |r|
|
825
|
+
title 'Hello, Root!'
|
826
|
+
iconphoto File.expand_path('../../icons/glimmer.png', __dir__)
|
827
|
+
width 400
|
828
|
+
height 200
|
829
|
+
x -150
|
830
|
+
y 300
|
831
|
+
resizable true # same as `resizable true, true`, meaning cannot resize horizontally and vertically
|
832
|
+
minsize 200, 100
|
833
|
+
maxsize 600, 400
|
834
|
+
background 'lightgrey'
|
835
|
+
alpha 0.85 # on the mac, you can set `transparent true` as well
|
836
|
+
topmost true
|
837
|
+
|
838
|
+
on('OPEN_WINDOW') do # custom event that runs right after Tk.mainloop
|
839
|
+
message_box(parent: r, title: 'Hi', message: 'Hi')
|
840
|
+
end
|
841
|
+
|
842
|
+
on('DELETE_WINDOW') do |event| # alias for WM_DELETE_WINDOW protocol event
|
843
|
+
message_box(parent: r, title: 'Bye', message: 'Bye')
|
844
|
+
exit(0)
|
845
|
+
end
|
587
846
|
}.open
|
588
847
|
```
|
589
848
|
|
590
849
|
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
591
850
|
|
592
851
|
```
|
593
|
-
ruby -r glimmer-dsl-tk -e "require 'samples/hello/
|
852
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_root'"
|
853
|
+
```
|
854
|
+
|
855
|
+
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
856
|
+
|
857
|
+
```
|
858
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_root.rb
|
859
|
+
```
|
860
|
+
|
861
|
+
Glimmer app:
|
862
|
+
|
863
|
+
![glimmer dsl tk screenshot sample hello root hi](images/glimmer-dsl-tk-screenshot-sample-hello-root-hi.png)
|
864
|
+
|
865
|
+
![glimmer dsl tk screenshot sample hello root](images/glimmer-dsl-tk-screenshot-sample-hello-root.png)
|
866
|
+
|
867
|
+
![glimmer dsl tk screenshot sample hello root bye](images/glimmer-dsl-tk-screenshot-sample-hello-root-bye.png)
|
868
|
+
|
869
|
+
### Hello, Notebook!
|
870
|
+
|
871
|
+
Glimmer code (from [samples/hello/hello_notebook.rb](samples/hello/hello_notebook.rb)):
|
872
|
+
|
873
|
+
```ruby
|
874
|
+
require 'glimmer-dsl-tk'
|
875
|
+
|
876
|
+
class HelloNotebook
|
877
|
+
include Glimmer
|
878
|
+
|
879
|
+
def launch
|
880
|
+
root {
|
881
|
+
title 'Hello, Notebook!'
|
882
|
+
|
883
|
+
notebook {
|
884
|
+
frame(text: 'English') {
|
885
|
+
label {
|
886
|
+
text 'Hello, World!'
|
887
|
+
}
|
888
|
+
}
|
889
|
+
|
890
|
+
frame(text: 'French') {
|
891
|
+
label {
|
892
|
+
text 'Bonjour, Univers!'
|
893
|
+
}
|
894
|
+
}
|
895
|
+
}
|
896
|
+
}.open
|
897
|
+
end
|
898
|
+
end
|
899
|
+
|
900
|
+
HelloNotebook.new.launch
|
901
|
+
```
|
902
|
+
|
903
|
+
Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
904
|
+
|
905
|
+
```
|
906
|
+
ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_notebook'"
|
594
907
|
```
|
595
908
|
|
596
909
|
Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
|
597
910
|
|
598
911
|
```
|
599
|
-
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/
|
912
|
+
ruby -r ./lib/glimmer-dsl-tk.rb ./samples/hello/hello_notebook.rb
|
600
913
|
```
|
601
914
|
|
602
915
|
Glimmer app:
|
603
916
|
|
604
|
-
![glimmer dsl tk screenshot sample hello
|
605
|
-
![glimmer dsl tk screenshot sample hello
|
917
|
+
![glimmer dsl tk screenshot sample hello notebook English](images/glimmer-dsl-tk-screenshot-sample-hello-notebook-english.png)
|
918
|
+
![glimmer dsl tk screenshot sample hello notebook French](images/glimmer-dsl-tk-screenshot-sample-hello-notebook-french.png)
|
606
919
|
|
607
920
|
### Hello, Label!
|
608
921
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.22
|
data/glimmer-dsl-tk.gemspec
CHANGED
Binary file
|