glimmer-dsl-tk 0.0.35 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,260 @@
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" # this enables setting background on label just for demo purposes
29
+
30
+ root { |r|
31
+ title 'Hello, Menu Bar!'
32
+
33
+ @label = label {
34
+ grid row_weight: 1, column_weight: 1
35
+ text 'Check Out The Menu Bar Above!'
36
+ font size: 50
37
+ anchor 'center'
38
+ }
39
+
40
+ menu {
41
+ if OS.mac?
42
+ menu(:application) {
43
+ menu_item(:about, label: 'About My Application') {
44
+ accelerator 'Command+A'
45
+
46
+ on('command') do
47
+ message_box(parent: r, title: 'About', message: 'About my application.')
48
+ end
49
+ }
50
+
51
+ menu_item(:preferences) {
52
+ on('command') do
53
+ message_box(parent: r, title: 'Preferences', message: 'Preferences of my application.')
54
+ end
55
+ }
56
+
57
+ # If not defined, application simply quits upon selecting Quit menu item
58
+ menu_item(:quit) {
59
+ on('command') do
60
+ message_box(parent: r, title: 'Quit', message: 'Quitting my application...')
61
+ exit(0)
62
+ end
63
+ }
64
+ }
65
+ end
66
+
67
+ if OS.windows?
68
+ menu(label: 'System')
69
+ end
70
+
71
+ menu(label: 'File', underline: 0) {
72
+ menu_item(label: 'New', underline: 0) {
73
+ accelerator 'Command+N'
74
+
75
+ on('command') do
76
+ message_box(parent: r, title: 'New', message: 'New file created.')
77
+ end
78
+ }
79
+
80
+ menu_item(label: 'Open...', underline: 0) {
81
+ accelerator 'Command+O'
82
+
83
+ on('command') do
84
+ message_box(parent: r, title: 'Open', message: 'Opening File...')
85
+ end
86
+ }
87
+
88
+ menu(label: 'Open Recent', underline: 5) {
89
+ menu_item(label: 'File 1') {
90
+ on('command') do
91
+ message_box(parent: r, title: 'File 1', message: 'File 1 Contents')
92
+ end
93
+ }
94
+
95
+ menu_item(label: 'File 2') {
96
+ on('command') do
97
+ message_box(parent: r, title: 'File 2', message: 'File 2 Contents')
98
+ end
99
+ }
100
+ }
101
+
102
+ menu_item(:separator)
103
+
104
+ menu_item(label: 'Exit', underline: 1) {
105
+ on('command') do
106
+ exit(0)
107
+ end
108
+ }
109
+ }
110
+
111
+ menu(label: 'Edit', underline: 0) {
112
+ menu_item(label: 'Cut', underline: 2) {
113
+ accelerator 'Command+X'
114
+ }
115
+
116
+ menu_item(label: 'Copy', underline: 0) {
117
+ accelerator 'Command+C'
118
+ }
119
+
120
+ menu_item(label: 'Paste', underline: 0) {
121
+ accelerator 'Command+V'
122
+ }
123
+ }
124
+
125
+ menu(label: 'Options', underline: 0) {
126
+ menu_item(:checkbutton, label: 'Enabled', underline: 0) {
127
+ on('command') do
128
+ @select_one_menu.children.each { |menu_item| menu_item.state = menu_item.state == 'disabled' ? 'normal' : 'disabled' }
129
+ @select_multiple_menu.children.each { |menu_item| menu_item.state = menu_item.state == 'disabled' ? 'normal' : 'disabled' }
130
+ end
131
+ }
132
+
133
+ @select_one_menu = menu(label: 'Select One', underline: 0) {
134
+ menu_item(:radiobutton, label: 'Option 1') {
135
+ state 'disabled'
136
+ }
137
+ menu_item(:radiobutton, label: 'Option 2') {
138
+ state 'disabled'
139
+ }
140
+ menu_item(:radiobutton, label: 'Option 3') {
141
+ state 'disabled'
142
+ }
143
+ }
144
+
145
+ @select_multiple_menu = menu(label: 'Select Multiple', underline: 0) {
146
+ menu_item(:checkbutton, label: 'Option 4') {
147
+ state 'disabled'
148
+ }
149
+ menu_item(:checkbutton, label: 'Option 5') {
150
+ state 'disabled'
151
+ }
152
+ menu_item(:checkbutton, label: 'Option 6') {
153
+ state 'disabled'
154
+ }
155
+ }
156
+ }
157
+
158
+ menu(label: 'Language', underline: 3) {
159
+ ['denmark', 'finland', 'france', 'germany', 'italy', 'mexico', 'netherlands', 'norway', 'usa'].each do |image_name|
160
+ menu_item(:radiobutton, label: image_name.capitalize) {
161
+ selection image_name == 'usa'
162
+ image File.expand_path("images/#{image_name}.png", __dir__)
163
+ }
164
+ end
165
+ }
166
+
167
+ menu(label: 'Language Name', underline: 3) {
168
+ ['denmark', 'finland', 'france', 'germany', 'italy', 'mexico', 'netherlands', 'norway', 'usa'].each do |image_name|
169
+ menu_item(:radiobutton, label: image_name.capitalize) {
170
+ selection image_name == 'usa'
171
+ image File.expand_path("images/#{image_name}.png", __dir__)
172
+ compound 'left'
173
+ }
174
+ end
175
+ }
176
+
177
+ menu(label: 'Format', underline: 0) {
178
+ menu(label: 'Background Color', underline: 0) {
179
+ COLORS.each { |color_style|
180
+ menu_item(:radiobutton, label: color_style.to_s.split('_').map(&:capitalize).join(' ')) {
181
+ on('command') do
182
+ @label.background = color_style
183
+ end
184
+ }
185
+ }
186
+ }
187
+
188
+ menu(label: 'Foreground Color', underline: 11) {
189
+ COLORS.each { |color_style|
190
+ menu_item(:radiobutton, label: color_style.to_s.split('_').map(&:capitalize).join(' ')) {
191
+ on('command') do
192
+ @label.foreground = color_style
193
+ end
194
+ }
195
+ }
196
+ }
197
+ }
198
+
199
+ menu(label: 'View', underline: 0) {
200
+ menu_item(:radiobutton, label: 'Small', underline: 0) {
201
+ accelerator 'Command+S'
202
+
203
+ on('command') do
204
+ @label.font = {size: 25}
205
+ end
206
+ }
207
+
208
+ menu_item(:radiobutton, label: 'Medium', underline: 0) {
209
+ accelerator 'Command+M'
210
+ selection true
211
+
212
+ on('command') do
213
+ @label.font = {size: 50}
214
+ end
215
+ }
216
+
217
+ menu_item(:radiobutton, label: 'Large', underline: 0) {
218
+ accelerator 'Command+L'
219
+
220
+ on('command') do
221
+ @label.font = {size: 75}
222
+ end
223
+ }
224
+ }
225
+
226
+ menu(label: 'Window', underline: 0)
227
+
228
+ menu(label: 'Help', underline: 0) {
229
+ menu_item(:help) {
230
+ on('command') do
231
+ message_box(parent: r, title: 'Help', message: 'Help for my application.')
232
+ end
233
+ }
234
+
235
+ menu_item(label: 'Manual', underline: 0) {
236
+ accelerator 'Command+Shift+M'
237
+
238
+ on('command') do
239
+ message_box(parent: r, title: 'Manual', message: 'Manual Contents')
240
+ end
241
+ }
242
+
243
+ menu_item(label: 'Tutorial', underline: 0) {
244
+ accelerator 'Command+Shift+T'
245
+
246
+ on('command') do
247
+ message_box(parent: r, title: 'Tutorial', message: 'Tutorial Contents')
248
+ end
249
+ }
250
+
251
+ menu_item(:separator)
252
+
253
+ menu_item(label: 'Report an Issue...', underline: 0) {
254
+ on('command') do
255
+ message_box(parent: r, title: 'Report an Issue', message: 'Reporting an issue...')
256
+ end
257
+ }
258
+ }
259
+ }
260
+ }.open
@@ -109,28 +109,28 @@ class HelloText
109
109
 
110
110
  column_index = -1
111
111
 
112
- combobox {
112
+ combobox { |cb|
113
113
  grid row: 1, column: column_index += 1, column_weight: 1
114
114
  readonly true
115
- text <=> [self, :font_family, after_write: ->(value) { @text.toggle_selection_font_format('family', value == FONT_FAMILY_PROMPT ? 'Courier New' : value) }]
115
+ text <=> [self, :font_family, after_write: ->(value) { @text.toggle_selection_font_format('family', value == FONT_FAMILY_PROMPT ? 'Courier New' : value, focus: 100) }]
116
116
  }
117
117
 
118
118
  combobox {
119
119
  grid row: 1, column: column_index += 1, column_weight: 1
120
120
  readonly true
121
- text <=> [self, :font_size, after_write: ->(value) { @text.toggle_selection_font_format('size', value == FONT_SIZE_PROMPT ? 13 : value) }]
121
+ text <=> [self, :font_size, after_write: ->(value) { @text.toggle_selection_font_format('size', value == FONT_SIZE_PROMPT ? 13 : value, focus: 100) }]
122
122
  }
123
123
 
124
124
  combobox {
125
125
  grid row: 1, column: column_index += 1, column_weight: 1
126
126
  readonly true
127
- text <=> [self, :foreground, after_write: ->(value) { @text.add_selection_format('foreground', value == FOREGROUND_PROMPT ? 'black' : value) }]
127
+ text <=> [self, :foreground, after_write: ->(value) { @text.add_selection_format('foreground', value == FOREGROUND_PROMPT ? 'black' : value, focus: 100) }]
128
128
  }
129
129
 
130
130
  combobox {
131
131
  grid row: 1, column: column_index += 1, column_weight: 1
132
132
  readonly true
133
- text <=> [self, :background, after_write: ->(value) { @text.add_selection_format('background', value == BACKGROUND_PROMPT ? 'white' : value) }]
133
+ text <=> [self, :background, after_write: ->(value) { @text.add_selection_format('background', value == BACKGROUND_PROMPT ? 'white' : value, focus: 100) }]
134
134
  }
135
135
 
136
136
  separator {
@@ -0,0 +1,178 @@
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
+ def toplevel_content
27
+ frame {
28
+ label {
29
+ text "This is a fully custom toplevel, meaning you can add any widgets here!\nYou can press the ESCAPE button on the keyboard to close."
30
+ }
31
+ separator
32
+ checkbutton {
33
+ text 'This is a checkbutton'
34
+ }
35
+ radiobutton {
36
+ text 'This is a radiobutton'
37
+ }
38
+ }
39
+ end
40
+
41
+ root { |root_window|
42
+ title 'Hello, Toplevel!'
43
+
44
+ button {
45
+ text 'Nested Window'
46
+
47
+ on('command') do
48
+ toplevel(root_window) {
49
+ title 'Custom Window'
50
+ escapable true
51
+ x 150
52
+ y 180
53
+ width 500
54
+ height 200
55
+ minsize 500, 100
56
+ maxsize 1000, 300
57
+
58
+ toplevel_content
59
+ }
60
+ end
61
+ }
62
+
63
+ button {
64
+ text 'Transparent Window'
65
+
66
+ on('command') do
67
+ toplevel(root_window) {
68
+ title 'Transparent Window'
69
+ escapable true
70
+ alpha 0.85
71
+ width 250
72
+ height 100
73
+ resizable false, false # not resizable horizontally or vertically
74
+
75
+ frame {
76
+ label {
77
+ text "This is a transparent window\nYou can hit ESCAPE to close."
78
+ anchor 'center'
79
+ }
80
+ }
81
+ }
82
+ end
83
+ }
84
+
85
+ button {
86
+ text 'Fullscreen Window'
87
+
88
+ on('command') do
89
+ toplevel(root_window) {
90
+ title 'Fullscreen Window'
91
+ escapable true
92
+ fullscreen true
93
+
94
+ frame {
95
+ label {
96
+ text "This is a fullscreen window\nYou can hit ESCAPE to close."
97
+ anchor 'center'
98
+ }
99
+ }
100
+ }
101
+ end
102
+ }
103
+
104
+ if OS.mac?
105
+ # Mac has special support for mac styles in Tk `toplevel`
106
+ # `mac_style` first argument (`mac_class`) and second argument (`mac_attribute_list`) can be chosen from this page: https://wiki.tcl-lang.org/page/MacWindowStyle
107
+
108
+ button {
109
+ text 'Mac Plain (No-Button-Modeless) Window'
110
+
111
+ on('command') do
112
+ toplevel(root_window) { |t|
113
+ title 'Mac Plain (No-Button-Modeless) Window'
114
+ escapable true
115
+ mac_style 'plain'
116
+
117
+ toplevel_content
118
+ }
119
+ end
120
+ }
121
+
122
+ button {
123
+ text 'Mac Floating (Close-Button-Modeless) Window'
124
+
125
+ on('command') do
126
+ toplevel(root_window) { |t|
127
+ title 'Mac Floating (Close-Button-Modeless) Window'
128
+ escapable true
129
+ mac_style 'floating'
130
+
131
+ toplevel_content
132
+ }
133
+ end
134
+ }
135
+
136
+ button {
137
+ text 'Mac Document (All-Button-Modeless) Window'
138
+
139
+ on('command') do
140
+ toplevel(root_window) { |t|
141
+ title 'Mac Document (All-Button-Modeless) Window'
142
+ escapable true
143
+ mac_style 'document'
144
+
145
+ toplevel_content
146
+ }
147
+ end
148
+ }
149
+
150
+ button {
151
+ text 'Mac Utility (Close-Button-Modal) Dialog'
152
+
153
+ on('command') do
154
+ toplevel(root_window) { |t|
155
+ title 'Mac Utility (Close-Button-Modal) Dialog'
156
+ escapable true
157
+ mac_style 'utility'
158
+
159
+ toplevel_content
160
+ }
161
+ end
162
+ }
163
+
164
+ button {
165
+ text 'Mac Utility with Attribute List (All-Button-Modal) Dialog'
166
+
167
+ on('command') do
168
+ toplevel(root_window) { |t|
169
+ title 'Mac Utility with Attribute List (All-Button-Modal) Dialog'
170
+ escapable true
171
+ mac_style 'utility', 'closeBox collapseBox resizable horizontalZoom verticalZoom sideTitlebar'
172
+
173
+ toplevel_content
174
+ }
175
+ end
176
+ }
177
+ end
178
+ }.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.35
4
+ version: 0.0.39
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-06 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -235,6 +235,8 @@ files:
235
235
  - lib/glimmer/tk/frame_proxy.rb
236
236
  - lib/glimmer/tk/label_proxy.rb
237
237
  - lib/glimmer/tk/list_proxy.rb
238
+ - lib/glimmer/tk/menu_item_proxy.rb
239
+ - lib/glimmer/tk/menu_proxy.rb
238
240
  - lib/glimmer/tk/notebook_proxy.rb
239
241
  - lib/glimmer/tk/radiobutton_proxy.rb
240
242
  - lib/glimmer/tk/root_proxy.rb
@@ -258,6 +260,7 @@ files:
258
260
  - samples/hello/hello_label.rb
259
261
  - samples/hello/hello_list_multi_selection.rb
260
262
  - samples/hello/hello_list_single_selection.rb
263
+ - samples/hello/hello_menu_bar.rb
261
264
  - samples/hello/hello_message_box.rb
262
265
  - samples/hello/hello_notebook.rb
263
266
  - samples/hello/hello_radiobutton.rb
@@ -265,6 +268,7 @@ files:
265
268
  - samples/hello/hello_separator.rb
266
269
  - samples/hello/hello_spinbox.rb
267
270
  - samples/hello/hello_text.rb
271
+ - samples/hello/hello_toplevel.rb
268
272
  - samples/hello/hello_world.rb
269
273
  - samples/hello/images/align-center.png
270
274
  - samples/hello/images/align-left.png