glimmer-dsl-tk 0.0.48 → 0.0.49

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c99ac84c772515736f995d5a5ab31aaa38bbbe986d26d1c1566c8d49c5347c9
4
- data.tar.gz: 192d47da74f8630c268f52f7601b67126cbe07d2284defc8a8a6174a068b6274
3
+ metadata.gz: 362c0a5cd2265930f395295435fd7d7b9cc63b20d3c68afba754a57bf6c6dd38
4
+ data.tar.gz: c38b13a059e821f94de00fbb15c979f3fd4a9a8869d33fac0c0b39da38b25717
5
5
  SHA512:
6
- metadata.gz: 950ef28b2882ee22d7adf49528eb8fe0e3aa3c1949ea92ec319274af09bd5c10b5832a78ace63b1e77404fa26c9f0e0fe29ba78d398162150ca235b0441566fa
7
- data.tar.gz: 65f424fc3206e9bbd30bbae63da5a249f259c4619d5e987b1ab19b5e608442f0502f3b9ec5b2aac92c6cf92dfc67fa08727297d8b06aee22c3d910a865458c01
6
+ metadata.gz: 39de4985ef3f10898d7d45d6c336780ad9222e560e20b2d35832f649363fbf60db2d3a2831251c44ba2cc1ca7d34f4adfe3394198c7f95408664976937051a82
7
+ data.tar.gz: 554fffc52441411d7cf81fd0baefb5ca0fbc3406a7f6b61e960599f684bb855a97abfa2892a01bd8ce9f0f0214a6d5664e403ff618ab53fe184c178b83471917
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.49
4
+
5
+ - [API Breaking] Update menu bar support to require `menu_bar` keyword under `root` or `toplevel`
6
+ - Support contextual menu by nesting `menu` keyword under `root` or `toplevel`
7
+
3
8
  ## 0.0.48
4
9
 
5
10
  - Moved `OS` class to `Glimmer::Tk::OS` to avoid clashing with os gem when installed for users
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.48
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.49
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)
@@ -125,6 +125,7 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems you might be int
125
125
  - [Hello, Scrollbar!](#hello-scrollbar)
126
126
  - [Hello, Scrollbar Frame!](#hello-scrollbar-frame)
127
127
  - [Hello, Menu Bar!](#hello-menu-bar)
128
+ - [Hello, Contextual Menu!](#hello-contextual-menu)
128
129
  - [Applications](#applications)
129
130
  - [Glimmer Tk Calculator](#glimmer-tk-calculator)
130
131
  - [Y3network Ruby UI](#y3network-ruby-ui)
@@ -182,7 +183,7 @@ gem install glimmer-dsl-tk
182
183
 
183
184
  Add the following to `Gemfile`:
184
185
  ```
185
- gem 'glimmer-dsl-tk', '0.0.48'
186
+ gem 'glimmer-dsl-tk', '0.0.49'
186
187
  ```
187
188
 
188
189
  And, then run:
@@ -310,6 +311,7 @@ keyword(args) | attributes | event bindings & callbacks
310
311
  `list` | `selectmode`, `selection` | None
311
312
  `message_box(type: , message: , detail: , title: , icon: , default: , parent: )` | None | None
312
313
  `menu(label: nil) (label is nil if nested under root/toplevel for menu bar)` | None | None
314
+ `menu_bar` | None | None
313
315
  `menu_item(style = :command, label: , underline: )` (style also can be `:radiobutton`, `:checkbutton`, `:separator`, `:about`, `:preferences`, `:quit`, `:help`) | `state`, `accelerator`, `selection` & `variable` (if `:radiobutton` or `:checkbutton`), `image`, `compound` | `command`
314
316
  `notebook` | None | None
315
317
  `radiobutton` | `text`, `variable` (Boolean), `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `value` (default: `text`) | `command {}`
@@ -3496,6 +3498,164 @@ Glimmer app:
3496
3498
 
3497
3499
  ![glimmer dsl tk screenshot sample hello menu-bar](images/glimmer-dsl-tk-screenshot-sample-hello-menu-bar-help.png)
3498
3500
 
3501
+ ### Hello, Contextual Menu!
3502
+
3503
+ Glimmer code (from [samples/hello/hello_contextual_menu.rb](samples/hello/hello_contextual_menu.rb)):
3504
+
3505
+ ```ruby
3506
+ require 'glimmer-dsl-tk'
3507
+
3508
+ include Glimmer
3509
+
3510
+ COLORS = [:white, :red, :yellow, :green, :blue, :magenta, :gray, :black]
3511
+
3512
+ Tk::Tile::Style.theme_use 'classic' if OS.mac? # this enables setting background on label just for demo purposes
3513
+
3514
+ root { |r|
3515
+ title 'Hello, Contextual Menu!'
3516
+
3517
+ @label = label {
3518
+ grid row_weight: 1, column_weight: 1
3519
+ text 'Right-Click To Pop Up Contextual Menu!'
3520
+ font size: 50
3521
+ anchor 'center'
3522
+ }
3523
+
3524
+ menu {
3525
+ menu(label: 'Edit', underline: 0) {
3526
+ menu_item(label: 'Cut', underline: 2) {
3527
+ accelerator OS.mac? ? 'Command+X' : 'Control+X'
3528
+ }
3529
+
3530
+ menu_item(label: 'Copy', underline: 0) {
3531
+ accelerator OS.mac? ? 'Command+C' : 'Control+C'
3532
+ }
3533
+
3534
+ menu_item(label: 'Paste', underline: 0) {
3535
+ accelerator OS.mac? ? 'Command+V' : 'Control+V'
3536
+ }
3537
+ }
3538
+
3539
+ menu(label: 'Options', underline: 0) {
3540
+ menu_item(:checkbutton, label: 'Enabled', underline: 0) {
3541
+ on('command') do
3542
+ @select_one_menu.children.each { |menu_item| menu_item.state = menu_item.state == 'disabled' ? 'normal' : 'disabled' }
3543
+ @select_multiple_menu.children.each { |menu_item| menu_item.state = menu_item.state == 'disabled' ? 'normal' : 'disabled' }
3544
+ end
3545
+ }
3546
+
3547
+ @select_one_menu = menu(label: 'Select One', underline: 7) {
3548
+ menu_item(:radiobutton, label: 'Option 1') {
3549
+ state 'disabled'
3550
+ }
3551
+ menu_item(:radiobutton, label: 'Option 2') {
3552
+ state 'disabled'
3553
+ }
3554
+ menu_item(:radiobutton, label: 'Option 3') {
3555
+ state 'disabled'
3556
+ }
3557
+ }
3558
+
3559
+ @select_multiple_menu = menu(label: 'Select Multiple', underline: 7) {
3560
+ menu_item(:checkbutton, label: 'Option 4') {
3561
+ state 'disabled'
3562
+ }
3563
+ menu_item(:checkbutton, label: 'Option 5') {
3564
+ state 'disabled'
3565
+ }
3566
+ menu_item(:checkbutton, label: 'Option 6') {
3567
+ state 'disabled'
3568
+ }
3569
+ }
3570
+ }
3571
+
3572
+ menu(label: 'Language', underline: 3) {
3573
+ ['denmark', 'finland', 'france', 'germany', 'italy', 'mexico', 'netherlands', 'norway', 'usa'].each do |image_name|
3574
+ menu_item(:radiobutton, label: image_name.capitalize) {
3575
+ selection image_name == 'usa'
3576
+ image File.expand_path("images/#{image_name}.png", __dir__)
3577
+ }
3578
+ end
3579
+ }
3580
+
3581
+ menu(label: 'Country', underline: 0) {
3582
+ ['denmark', 'finland', 'france', 'germany', 'italy', 'mexico', 'netherlands', 'norway', 'usa'].each do |image_name|
3583
+ menu_item(:radiobutton, label: image_name.capitalize) {
3584
+ selection image_name == 'usa'
3585
+ image File.expand_path("images/#{image_name}.png", __dir__)
3586
+ compound 'left'
3587
+ }
3588
+ end
3589
+ }
3590
+
3591
+ menu(label: 'Format', underline: 3) {
3592
+ menu(label: 'Background Color', underline: 0) {
3593
+ COLORS.each { |color_style|
3594
+ menu_item(:radiobutton, label: color_style.to_s.split('_').map(&:capitalize).join(' ')) {
3595
+ on('command') do
3596
+ @label.background = color_style
3597
+ end
3598
+ }
3599
+ }
3600
+ }
3601
+
3602
+ menu(label: 'Foreground Color', underline: 11) {
3603
+ COLORS.each { |color_style|
3604
+ menu_item(:radiobutton, label: color_style.to_s.split('_').map(&:capitalize).join(' ')) {
3605
+ on('command') do
3606
+ @label.foreground = color_style
3607
+ end
3608
+ }
3609
+ }
3610
+ }
3611
+ }
3612
+
3613
+ menu(label: 'View', underline: 0) {
3614
+ menu_item(:radiobutton, label: 'Small', underline: 0) {
3615
+ accelerator 'Control+S'
3616
+
3617
+ on('command') do
3618
+ @label.font = {size: 25}
3619
+ end
3620
+ }
3621
+
3622
+ menu_item(:radiobutton, label: 'Medium', underline: 0) {
3623
+ accelerator 'Control+M'
3624
+ selection true
3625
+
3626
+ on('command') do
3627
+ @label.font = {size: 50}
3628
+ end
3629
+ }
3630
+
3631
+ menu_item(:radiobutton, label: 'Large', underline: 0) {
3632
+ accelerator 'Control+L'
3633
+
3634
+ on('command') do
3635
+ @label.font = {size: 75}
3636
+ end
3637
+ }
3638
+ }
3639
+ }
3640
+ }.open
3641
+ ```
3642
+
3643
+ Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
3644
+
3645
+ ```
3646
+ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_contextual_menu'"
3647
+ ```
3648
+
3649
+ Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
3650
+
3651
+ ```
3652
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_contextual_menu.rb
3653
+ ```
3654
+
3655
+ Glimmer app:
3656
+
3657
+ ![glimmer dsl tk screenshot sample hello contextual-menu](images/glimmer-dsl-tk-screenshot-sample-hello-contextual-menu.png)
3658
+
3499
3659
  ## Applications
3500
3660
 
3501
3661
  ### Glimmer Tk Calculator
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.48
1
+ 0.0.49
data/bin/girb CHANGED
File without changes
Binary file
@@ -34,7 +34,16 @@ module Glimmer
34
34
  def post_add_content
35
35
  case @parent_proxy
36
36
  when ToplevelProxy
37
- @parent_proxy.tk['menu'] = @tk
37
+ if @keyword == 'menu_bar'
38
+ @parent_proxy.tk['menu'] = @tk
39
+ else
40
+ if OS.mac?
41
+ @parent_proxy.tk.bind '2', proc{|x,y| tk.popup(x,y)}, "%X %Y"
42
+ @parent_proxy.tk.bind 'Control-1', proc{|x,y| tk.popup(x,y)}, "%X %Y"
43
+ else
44
+ @parent_proxy.tk.bind '3', proc{|x,y| tk.popup(x,y)}, "%X %Y"
45
+ end
46
+ end
38
47
  end
39
48
  end
40
49
 
@@ -75,8 +84,7 @@ module Glimmer
75
84
  # elsif @parent_proxy.parent_proxy.is_a?(ToplevelProxy) && OS.windows? && system?
76
85
  # @tk = ::TkSysMenu_System.new(@parent_proxy.tk).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
77
86
  else
78
- tk_widget_class = self.class.tk_widget_class_for(@keyword)
79
- @tk = tk_widget_class.new(@parent_proxy.tk).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
87
+ @tk = ::Tk::Menu.new(@parent_proxy.tk).tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
80
88
  end
81
89
  case @parent_proxy
82
90
  when MenuProxy
@@ -85,5 +93,6 @@ module Glimmer
85
93
  end
86
94
  end
87
95
  end
96
+ MenuBarProxy = MenuProxy
88
97
  end
89
98
  end
@@ -0,0 +1,156 @@
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
+ COLORS = [:white, :red, :yellow, :green, :blue, :magenta, :gray, :black]
27
+
28
+ Tk::Tile::Style.theme_use 'classic' if OS.mac? # this enables setting background on label just for demo purposes
29
+
30
+ root { |r|
31
+ title 'Hello, Contextual Menu!'
32
+
33
+ @label = label {
34
+ grid row_weight: 1, column_weight: 1
35
+ text 'Right-Click To Pop Up Contextual Menu!'
36
+ font size: 50
37
+ anchor 'center'
38
+ }
39
+
40
+ menu {
41
+ menu(label: 'Edit', underline: 0) {
42
+ menu_item(label: 'Cut', underline: 2) {
43
+ accelerator OS.mac? ? 'Command+X' : 'Control+X'
44
+ }
45
+
46
+ menu_item(label: 'Copy', underline: 0) {
47
+ accelerator OS.mac? ? 'Command+C' : 'Control+C'
48
+ }
49
+
50
+ menu_item(label: 'Paste', underline: 0) {
51
+ accelerator OS.mac? ? 'Command+V' : 'Control+V'
52
+ }
53
+ }
54
+
55
+ menu(label: 'Options', underline: 0) {
56
+ menu_item(:checkbutton, label: 'Enabled', underline: 0) {
57
+ on('command') do
58
+ @select_one_menu.children.each { |menu_item| menu_item.state = menu_item.state == 'disabled' ? 'normal' : 'disabled' }
59
+ @select_multiple_menu.children.each { |menu_item| menu_item.state = menu_item.state == 'disabled' ? 'normal' : 'disabled' }
60
+ end
61
+ }
62
+
63
+ @select_one_menu = menu(label: 'Select One', underline: 7) {
64
+ menu_item(:radiobutton, label: 'Option 1') {
65
+ state 'disabled'
66
+ }
67
+ menu_item(:radiobutton, label: 'Option 2') {
68
+ state 'disabled'
69
+ }
70
+ menu_item(:radiobutton, label: 'Option 3') {
71
+ state 'disabled'
72
+ }
73
+ }
74
+
75
+ @select_multiple_menu = menu(label: 'Select Multiple', underline: 7) {
76
+ menu_item(:checkbutton, label: 'Option 4') {
77
+ state 'disabled'
78
+ }
79
+ menu_item(:checkbutton, label: 'Option 5') {
80
+ state 'disabled'
81
+ }
82
+ menu_item(:checkbutton, label: 'Option 6') {
83
+ state 'disabled'
84
+ }
85
+ }
86
+ }
87
+
88
+ menu(label: 'Language', underline: 3) {
89
+ ['denmark', 'finland', 'france', 'germany', 'italy', 'mexico', 'netherlands', 'norway', 'usa'].each do |image_name|
90
+ menu_item(:radiobutton, label: image_name.capitalize) {
91
+ selection image_name == 'usa'
92
+ image File.expand_path("images/#{image_name}.png", __dir__)
93
+ }
94
+ end
95
+ }
96
+
97
+ menu(label: 'Country', underline: 0) {
98
+ ['denmark', 'finland', 'france', 'germany', 'italy', 'mexico', 'netherlands', 'norway', 'usa'].each do |image_name|
99
+ menu_item(:radiobutton, label: image_name.capitalize) {
100
+ selection image_name == 'usa'
101
+ image File.expand_path("images/#{image_name}.png", __dir__)
102
+ compound 'left'
103
+ }
104
+ end
105
+ }
106
+
107
+ menu(label: 'Format', underline: 3) {
108
+ menu(label: 'Background Color', underline: 0) {
109
+ COLORS.each { |color_style|
110
+ menu_item(:radiobutton, label: color_style.to_s.split('_').map(&:capitalize).join(' ')) {
111
+ on('command') do
112
+ @label.background = color_style
113
+ end
114
+ }
115
+ }
116
+ }
117
+
118
+ menu(label: 'Foreground Color', underline: 11) {
119
+ COLORS.each { |color_style|
120
+ menu_item(:radiobutton, label: color_style.to_s.split('_').map(&:capitalize).join(' ')) {
121
+ on('command') do
122
+ @label.foreground = color_style
123
+ end
124
+ }
125
+ }
126
+ }
127
+ }
128
+
129
+ menu(label: 'View', underline: 0) {
130
+ menu_item(:radiobutton, label: 'Small', underline: 0) {
131
+ accelerator 'Control+S'
132
+
133
+ on('command') do
134
+ @label.font = {size: 25}
135
+ end
136
+ }
137
+
138
+ menu_item(:radiobutton, label: 'Medium', underline: 0) {
139
+ accelerator 'Control+M'
140
+ selection true
141
+
142
+ on('command') do
143
+ @label.font = {size: 50}
144
+ end
145
+ }
146
+
147
+ menu_item(:radiobutton, label: 'Large', underline: 0) {
148
+ accelerator 'Control+L'
149
+
150
+ on('command') do
151
+ @label.font = {size: 75}
152
+ end
153
+ }
154
+ }
155
+ }
156
+ }.open
@@ -37,7 +37,7 @@ root { |r|
37
37
  anchor 'center'
38
38
  }
39
39
 
40
- menu {
40
+ menu_bar {
41
41
  # Mac-specific application menu (right next to the Apple menu)
42
42
  if OS.mac?
43
43
  menu(:application) {
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.48
4
+ version: 0.0.49
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-25 00:00:00.000000000 Z
11
+ date: 2021-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -237,6 +237,7 @@ files:
237
237
  - samples/hello/hello_combobox.rb
238
238
  - samples/hello/hello_computed.rb
239
239
  - samples/hello/hello_computed/contact.rb
240
+ - samples/hello/hello_contextual_menu.rb
240
241
  - samples/hello/hello_drag_and_drop.rb
241
242
  - samples/hello/hello_entry.rb
242
243
  - samples/hello/hello_frame.rb
@@ -294,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
295
  - !ruby/object:Gem::Version
295
296
  version: '0'
296
297
  requirements: []
297
- rubygems_version: 3.2.22
298
+ rubygems_version: 3.2.31
298
299
  signing_key:
299
300
  specification_version: 4
300
301
  summary: Glimmer DSL for Tk