glimmer-dsl-tk 0.0.38 → 0.0.42

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.
@@ -25,7 +25,7 @@ include Glimmer
25
25
 
26
26
  COLORS = [:white, :red, :yellow, :green, :blue, :magenta, :gray, :black]
27
27
 
28
- Tk::Tile::Style.theme_use "classic" # this enables setting background on label just for demo purposes
28
+ Tk::Tile::Style.theme_use 'classic' if OS.mac? # this enables setting background on label just for demo purposes
29
29
 
30
30
  root { |r|
31
31
  title 'Hello, Menu Bar!'
@@ -38,51 +38,87 @@ root { |r|
38
38
  }
39
39
 
40
40
  menu {
41
+ # Mac-specific application menu (right next to the Apple menu)
42
+ if OS.mac?
43
+ menu(:application) {
44
+ menu_item(:about, label: 'About My Application') {
45
+ accelerator 'Command+A'
46
+
47
+ on('command') do
48
+ message_box(parent: r, title: 'About', message: 'About my application.')
49
+ end
50
+ }
51
+
52
+ menu_item(:preferences) {
53
+ on('command') do
54
+ message_box(parent: r, title: 'Preferences', message: 'Preferences of my application.')
55
+ end
56
+ }
57
+
58
+ # If not defined, application simply quits upon selecting Quit menu item
59
+ menu_item(:quit) {
60
+ on('command') do
61
+ message_box(parent: r, title: 'Quit', message: 'Quitting my application...')
62
+ exit(0)
63
+ end
64
+ }
65
+ }
66
+ end
67
+
41
68
  menu(label: 'File', underline: 0) {
42
69
  menu_item(label: 'New', underline: 0) {
43
- accelerator 'Command+N'
70
+ accelerator OS.mac? ? 'Command+N' : 'Control+N'
44
71
 
45
72
  on('command') do
46
73
  message_box(parent: r, title: 'New', message: 'New file created.')
47
74
  end
48
75
  }
76
+
49
77
  menu_item(label: 'Open...', underline: 0) {
50
- accelerator 'Command+O'
78
+ accelerator OS.mac? ? 'Command+O' : 'Control+O'
51
79
 
52
80
  on('command') do
53
81
  message_box(parent: r, title: 'Open', message: 'Opening File...')
54
82
  end
55
83
  }
84
+
56
85
  menu(label: 'Open Recent', underline: 5) {
57
86
  menu_item(label: 'File 1') {
58
87
  on('command') do
59
88
  message_box(parent: r, title: 'File 1', message: 'File 1 Contents')
60
89
  end
61
90
  }
91
+
62
92
  menu_item(label: 'File 2') {
63
93
  on('command') do
64
94
  message_box(parent: r, title: 'File 2', message: 'File 2 Contents')
65
95
  end
66
96
  }
67
97
  }
98
+
68
99
  menu_item(:separator)
100
+
69
101
  menu_item(label: 'Exit', underline: 1) {
70
102
  on('command') do
71
103
  exit(0)
72
104
  end
73
105
  }
74
106
  }
107
+
75
108
  menu(label: 'Edit', underline: 0) {
76
109
  menu_item(label: 'Cut', underline: 2) {
77
- accelerator 'Command+X'
110
+ accelerator OS.mac? ? 'Command+X' : 'Control+X'
78
111
  }
112
+
79
113
  menu_item(label: 'Copy', underline: 0) {
80
- accelerator 'Command+C'
114
+ accelerator OS.mac? ? 'Command+C' : 'Control+C'
81
115
  }
116
+
82
117
  menu_item(label: 'Paste', underline: 0) {
83
- accelerator 'Command+V'
118
+ accelerator OS.mac? ? 'Command+V' : 'Control+V'
84
119
  }
85
120
  }
121
+
86
122
  menu(label: 'Options', underline: 0) {
87
123
  menu_item(:checkbutton, label: 'Enabled', underline: 0) {
88
124
  on('command') do
@@ -90,7 +126,8 @@ root { |r|
90
126
  @select_multiple_menu.children.each { |menu_item| menu_item.state = menu_item.state == 'disabled' ? 'normal' : 'disabled' }
91
127
  end
92
128
  }
93
- @select_one_menu = menu(label: 'Select One', underline: 0) {
129
+
130
+ @select_one_menu = menu(label: 'Select One', underline: 7) {
94
131
  menu_item(:radiobutton, label: 'Option 1') {
95
132
  state 'disabled'
96
133
  }
@@ -101,7 +138,8 @@ root { |r|
101
138
  state 'disabled'
102
139
  }
103
140
  }
104
- @select_multiple_menu = menu(label: 'Select Multiple', underline: 0) {
141
+
142
+ @select_multiple_menu = menu(label: 'Select Multiple', underline: 7) {
105
143
  menu_item(:checkbutton, label: 'Option 4') {
106
144
  state 'disabled'
107
145
  }
@@ -113,7 +151,27 @@ root { |r|
113
151
  }
114
152
  }
115
153
  }
116
- menu(label: 'Format', underline: 0) {
154
+
155
+ menu(label: 'Language', underline: 3) {
156
+ ['denmark', 'finland', 'france', 'germany', 'italy', 'mexico', 'netherlands', 'norway', 'usa'].each do |image_name|
157
+ menu_item(:radiobutton, label: image_name.capitalize) {
158
+ selection image_name == 'usa'
159
+ image File.expand_path("images/#{image_name}.png", __dir__)
160
+ }
161
+ end
162
+ }
163
+
164
+ menu(label: 'Country', underline: 0) {
165
+ ['denmark', 'finland', 'france', 'germany', 'italy', 'mexico', 'netherlands', 'norway', 'usa'].each do |image_name|
166
+ menu_item(:radiobutton, label: image_name.capitalize) {
167
+ selection image_name == 'usa'
168
+ image File.expand_path("images/#{image_name}.png", __dir__)
169
+ compound 'left'
170
+ }
171
+ end
172
+ }
173
+
174
+ menu(label: 'Format', underline: 3) {
117
175
  menu(label: 'Background Color', underline: 0) {
118
176
  COLORS.each { |color_style|
119
177
  menu_item(:radiobutton, label: color_style.to_s.split('_').map(&:capitalize).join(' ')) {
@@ -123,6 +181,7 @@ root { |r|
123
181
  }
124
182
  }
125
183
  }
184
+
126
185
  menu(label: 'Foreground Color', underline: 11) {
127
186
  COLORS.each { |color_style|
128
187
  menu_item(:radiobutton, label: color_style.to_s.split('_').map(&:capitalize).join(' ')) {
@@ -133,46 +192,64 @@ root { |r|
133
192
  }
134
193
  }
135
194
  }
195
+
136
196
  menu(label: 'View', underline: 0) {
137
197
  menu_item(:radiobutton, label: 'Small', underline: 0) {
138
- accelerator 'Command+S'
198
+ accelerator OS.mac? ? 'Command+S' : 'Control+S'
139
199
 
140
200
  on('command') do
141
201
  @label.font = {size: 25}
142
202
  end
143
203
  }
204
+
144
205
  menu_item(:radiobutton, label: 'Medium', underline: 0) {
145
- accelerator 'Command+M'
206
+ accelerator OS.mac? ? 'Command+M' : 'Control+M'
146
207
  selection true
147
208
 
148
209
  on('command') do
149
210
  @label.font = {size: 50}
150
211
  end
151
212
  }
213
+
152
214
  menu_item(:radiobutton, label: 'Large', underline: 0) {
153
- accelerator 'Command+L'
215
+ accelerator OS.mac? ? 'Command+L' : 'Control+L'
154
216
 
155
217
  on('command') do
156
218
  @label.font = {size: 75}
157
219
  end
158
220
  }
159
221
  }
222
+
223
+ # Mac-specific window menu (containing zooming/resizing menu items)
224
+ menu(label: 'Window', underline: 0) if OS.mac?
225
+
160
226
  menu(label: 'Help', underline: 0) {
227
+ if OS.mac?
228
+ menu_item(:help) {
229
+ on('command') do
230
+ message_box(parent: r, title: 'Help', message: 'Help for my application.')
231
+ end
232
+ }
233
+ end
234
+
161
235
  menu_item(label: 'Manual', underline: 0) {
162
- accelerator 'Command+Shift+M'
236
+ accelerator OS.mac? ? 'Command+Shift+M' : 'Control+U'
163
237
 
164
238
  on('command') do
165
239
  message_box(parent: r, title: 'Manual', message: 'Manual Contents')
166
240
  end
167
241
  }
242
+
168
243
  menu_item(label: 'Tutorial', underline: 0) {
169
- accelerator 'Command+Shift+T'
244
+ accelerator OS.mac? ? 'Command+Shift+T' : 'Control+T'
170
245
 
171
246
  on('command') do
172
247
  message_box(parent: r, title: 'Tutorial', message: 'Tutorial Contents')
173
248
  end
174
249
  }
250
+
175
251
  menu_item(:separator)
252
+
176
253
  menu_item(label: 'Report an Issue...', underline: 0) {
177
254
  on('command') do
178
255
  message_box(parent: r, title: 'Report an Issue', message: 'Reporting an issue...')
@@ -19,24 +19,48 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- require 'glimmer/tk/widget_proxy'
22
+ require 'glimmer-dsl-tk'
23
23
 
24
- module Glimmer
25
- module Tk
26
- # Represents widgets that can invoke a command
27
- module Commandable
28
- def command_block=(proc)
29
- tk.command(proc)
30
- end
24
+ include Glimmer
25
+
26
+ root {
27
+ title 'Hello, Scrollbar!'
28
+ width 400
29
+ height 500
30
+
31
+ notebook {
32
+ grid sticky: 'nsew'
33
+
34
+ frame(text: 'Scrollable List') {
35
+ @list = list {
36
+ grid sticky: 'nsew', row: 0, column: 0, row_weight: 1, column_weight: 1
37
+ items 40.times.map {|n| "Item #{n + 1} of a very long list" }
38
+ }
39
+
40
+ @scrollbar = scrollbar {
41
+ grid row: 0, column: 1
42
+ # orient 'vertical' # default
43
+ }
44
+ @list.yscrollbar @scrollbar
45
+ }
46
+
47
+ frame(text: 'Scrollable Text') {
48
+ @text = text {
49
+ grid sticky: 'nsew', row: 0, column: 0, row_weight: 1, column_weight: 1
50
+ value ("This is a random sample of text that will repeat over and over and over"*2 + "\n")*40
51
+ }
31
52
 
32
- def handle_listener(listener_name, &listener)
33
- case listener_name.to_s.downcase
34
- when 'command'
35
- command(listener)
36
- else
37
- super
38
- end
39
- end
40
- end
41
- end
42
- end
53
+ @yscrollbar = scrollbar {
54
+ grid row: 0, column: 1
55
+ # orient 'vertical' # default
56
+ }
57
+ @text.yscrollbar @yscrollbar
58
+
59
+ @xscrollbar = scrollbar {
60
+ grid row: 1, column: 0, column_span: 2, row_weight: 0
61
+ orient 'horizontal'
62
+ }
63
+ @text.xscrollbar @xscrollbar
64
+ }
65
+ }
66
+ }.open
@@ -0,0 +1,77 @@
1
+ # Copyright (c) 2020-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer-dsl-tk'
23
+
24
+ include Glimmer
25
+
26
+ root {
27
+ title 'Hello, Scrollbar Frame!'
28
+ width 400
29
+ height 400
30
+
31
+ notebook {
32
+ grid sticky: 'nsew'
33
+
34
+ frame(text: 'X/Y Scroll') {
35
+ scrollbar_frame {
36
+ 30.times do |row|
37
+ 10.times do |column|
38
+ button {
39
+ grid row: row, column: column, row_weight: 0, column_weight: 0
40
+ text "Row #{row} | Column #{column}"
41
+ }
42
+ end
43
+ end
44
+ }
45
+ }
46
+
47
+ frame(text: 'Y Scroll') {
48
+ scrollbar_frame {
49
+ xscrollbar false
50
+
51
+ 30.times do |row|
52
+ 2.times do |column|
53
+ button {
54
+ grid row: row, column: column, row_weight: 0, column_weight: 0
55
+ text "Row #{row} | Column #{column}"
56
+ }
57
+ end
58
+ end
59
+ }
60
+ }
61
+
62
+ frame(text: 'X Scroll') {
63
+ scrollbar_frame {
64
+ yscrollbar false
65
+
66
+ 13.times do |row|
67
+ 10.times do |column|
68
+ button {
69
+ grid row: row, column: column, row_weight: 0, column_weight: 0
70
+ text "Row #{row} | Column #{column}"
71
+ }
72
+ end
73
+ end
74
+ }
75
+ }
76
+ }
77
+ }.open
@@ -105,32 +105,32 @@ class HelloText
105
105
  height 800
106
106
 
107
107
  frame {
108
- grid row: 0, column: 0
108
+ grid row: 0, column: 0, column_span: 2
109
109
 
110
110
  column_index = -1
111
111
 
112
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, focus: 100) }]
115
+ text <=> [self, :font_family, after_write: ->(value) { @text.toggle_selection_font_format('family', value == FONT_FAMILY_PROMPT ? 'Courier New' : value, focus: OS.mac? ? 100 : true) }]
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, focus: 100) }]
121
+ text <=> [self, :font_size, after_write: ->(value) { @text.toggle_selection_font_format('size', value == FONT_SIZE_PROMPT ? 13 : value, focus: OS.mac? ? 100 : true) }]
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, focus: 100) }]
127
+ text <=> [self, :foreground, after_write: ->(value) { @text.add_selection_format('foreground', value == FOREGROUND_PROMPT ? 'black' : value, focus: OS.mac? ? 100 : true) }]
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, focus: 100) }]
133
+ text <=> [self, :background, after_write: ->(value) { @text.add_selection_format('background', value == BACKGROUND_PROMPT ? 'white' : value, focus: OS.mac? ? 100 : true) }]
134
134
  }
135
135
 
136
136
  separator {
@@ -303,6 +303,11 @@ class HelloText
303
303
  show_find_dialog if (event.keysym == 'f') && ((OS.mac? && event.state == 8) || (!OS.mac? && event.state == 4))
304
304
  end
305
305
  }
306
+
307
+ @yscrollbar = scrollbar {
308
+ grid row: 1, column: 1
309
+ }
310
+ @text.yscrollbar @yscrollbar
306
311
  }
307
312
  @root.open
308
313
  end
@@ -74,7 +74,7 @@ root { |root_window|
74
74
 
75
75
  frame {
76
76
  label {
77
- text "This is a transparent window\nYou can hit ESCAPE to close."
77
+ text "This is a transparent window\n(Varies per platform)\nYou can hit ESCAPE to close."
78
78
  anchor 'center'
79
79
  }
80
80
  }
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.38
4
+ version: 0.0.42
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-10 00:00:00.000000000 Z
11
+ date: 2021-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -226,10 +226,8 @@ files:
226
226
  - lib/glimmer/dsl/tk/root_expression.rb
227
227
  - lib/glimmer/dsl/tk/shine_data_binding_expression.rb
228
228
  - lib/glimmer/dsl/tk/widget_expression.rb
229
- - lib/glimmer/tk/button_proxy.rb
230
229
  - lib/glimmer/tk/checkbutton_proxy.rb
231
230
  - lib/glimmer/tk/combobox_proxy.rb
232
- - lib/glimmer/tk/commandable.rb
233
231
  - lib/glimmer/tk/drag_and_drop_extension.rb
234
232
  - lib/glimmer/tk/entry_proxy.rb
235
233
  - lib/glimmer/tk/frame_proxy.rb
@@ -240,6 +238,7 @@ files:
240
238
  - lib/glimmer/tk/notebook_proxy.rb
241
239
  - lib/glimmer/tk/radiobutton_proxy.rb
242
240
  - lib/glimmer/tk/root_proxy.rb
241
+ - lib/glimmer/tk/scrollbar_frame_proxy.rb
243
242
  - lib/glimmer/tk/spinbox_proxy.rb
244
243
  - lib/glimmer/tk/text_proxy.rb
245
244
  - lib/glimmer/tk/text_variable_owner.rb
@@ -265,6 +264,8 @@ files:
265
264
  - samples/hello/hello_notebook.rb
266
265
  - samples/hello/hello_radiobutton.rb
267
266
  - samples/hello/hello_root.rb
267
+ - samples/hello/hello_scrollbar.rb
268
+ - samples/hello/hello_scrollbar_frame.rb
268
269
  - samples/hello/hello_separator.rb
269
270
  - samples/hello/hello_spinbox.rb
270
271
  - samples/hello/hello_text.rb
@@ -309,7 +310,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
309
310
  - !ruby/object:Gem::Version
310
311
  version: '0'
311
312
  requirements: []
312
- rubygems_version: 3.2.22
313
+ rubygems_version: 3.2.31
313
314
  signing_key:
314
315
  specification_version: 4
315
316
  summary: Glimmer DSL for Tk
@@ -1,34 +0,0 @@
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/tk/widget_proxy'
23
- require 'glimmer/tk/commandable'
24
-
25
- module Glimmer
26
- module Tk
27
- # Proxy for Tk::Tile::Button
28
- #
29
- # Follows the Proxy Design Pattern
30
- class ButtonProxy < WidgetProxy
31
- include Commandable
32
- end
33
- end
34
- end