glimmer-dsl-tk 0.0.28 → 0.0.32

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,68 @@
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 { |w|
27
+ title 'Hello, Built-in Dialog!'
28
+ width 400
29
+ height 400
30
+ x 150
31
+ y 150
32
+
33
+ frame {
34
+ %w[get_open_file get_multiple_open_file get_save_file choose_directory choose_color].each do |dialog|
35
+ button {
36
+ text dialog.split('_').map(&:capitalize).join(' ')
37
+
38
+ on('command') do
39
+ result = send(dialog, parent: w)
40
+ @result_label.text = [result].flatten.join("\n")
41
+ end
42
+ }
43
+ end
44
+
45
+ button {
46
+ text 'Choose Font'
47
+
48
+ on('command') do
49
+ choose_font(family: 'Courier New', size: '30', weight: 'bold') do |chosen_font|
50
+ @result_label.text = chosen_font
51
+ end
52
+ end
53
+ }
54
+ }
55
+
56
+ frame {
57
+ grid sticky: 'nsew', padx: 15, pady: 15
58
+
59
+ label {
60
+ grid row: 0, column: 0
61
+ text 'Result:'
62
+ }
63
+
64
+ @result_label = label {
65
+ grid row: 0, column: 1
66
+ }
67
+ }
68
+ }.open
@@ -27,8 +27,6 @@ root { |r|
27
27
  title 'Hello, Message Box!'
28
28
 
29
29
  frame {
30
- grid sticky: 'nsew', padx: 15, pady: 15
31
-
32
30
  button {
33
31
  text 'Please Click To Win a Surprise'
34
32
 
@@ -80,8 +78,6 @@ root { |r|
80
78
  }
81
79
 
82
80
  frame {
83
- grid sticky: 'nsew', padx: 15, pady: 15
84
-
85
81
  label {
86
82
  grid row: 0, column: 0
87
83
  text 'Result:'
@@ -0,0 +1,69 @@
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, Separator!'
28
+ width 200
29
+ height 200
30
+
31
+ label {
32
+ grid row: 0, column: 0, min_width: 100, min_height: 100, column_weight: 0, sticky: 'nsew'
33
+ text 'Label 1'
34
+ anchor 'center'
35
+ }
36
+
37
+ separator {
38
+ grid row: 0, column: 1
39
+ orient 'vertical'
40
+ }
41
+
42
+ label {
43
+ grid row: 0, column: 2, min_width: 100, min_height: 100, sticky: 'nsew'
44
+ text 'Label 2'
45
+ anchor 'center'
46
+ }
47
+
48
+ separator {
49
+ grid row: 1, column: 0, column_span: 3
50
+ # orient 'horizontal' # default
51
+ }
52
+
53
+ label {
54
+ grid row: 2, column: 0, min_width: 100, min_height: 100, sticky: 'nsew'
55
+ text 'Label 3'
56
+ anchor 'center'
57
+ }
58
+
59
+ separator {
60
+ grid row: 2, column: 1
61
+ orient 'vertical'
62
+ }
63
+
64
+ label {
65
+ grid row: 2, column: 2, min_width: 100, min_height: 100, sticky: 'nsew'
66
+ text 'Label 4'
67
+ anchor 'center'
68
+ }
69
+ }.open
@@ -36,8 +36,36 @@ class HelloText
36
36
  @background = BACKGROUND_PROMPT
37
37
  @font_family = FONT_FAMILY_PROMPT
38
38
  @font_size = FONT_SIZE_PROMPT
39
+ @document = <<~MULTI_LINE_STRING
40
+ According to the National Post, a heavy metal-loving high school principal in Canada will be allowed to keep her job, days after a public campaign to oust her made headlines around the globe.
41
+
42
+ Parents at Eden High School in St. Catharines, Ontario launched a petition to remove principal Sharon Burns after discovering she's an IRON MAIDEN fan.
43
+
44
+ The petition, titled "Eden High School Principal, Sharon Burns, Needs to Be Transferred Immediately!" read, "We are deeply disturbed that the principal assigned to the school blatantly showed Satanic symbols and her allegiance to Satanic practices on her public social media platforms where all the students can see them under @edenprincipal (not her personal account)."
45
+
46
+ More than 500 people signed the petition to transfer Burns after she posted a picture of herself flashing the "devil horns" hand sign with a doll of the MAIDEN zombie mascot Eddie behind her as well as a personalized license plate reading "IRNMADEN" and a handwritten note that reads "Eddie 666" on a car's dashboard.
47
+
48
+
49
+ The number 666 is used to represent the devil, and is featured prominently in MAIDEN's artwork by the band, whose classic third album is titled "The Number Of The Beast".
50
+
51
+ The petition was later updated to state that the demand for her transfer is not because of her love for metal, but for "openly displaying her own handmade sign with the 666 clearly displayed on it".
52
+
53
+ The creator of the original petition wrote: "Sharon knows full well what she did was simply inappropriate, unnecessary and not professional but has yet to publicly admit so and is willing to allow people to believe a completely different story, making very real concerns seem petty."
54
+
55
+ Meanwhile, a counter-petition supporting Burns garnered over 20,000 signatures.
56
+
57
+ "It is ridiculous that a couple of parents judge her role as a principal only based on an Instagram post. (About liking the band IRON MAIDEN. That's it.) Eden High School is a public school. Not a Christian school," the petition titled "We need Mrs Burns" stated. "She has made Eden a safe space for so many people. She spreads nothing but love and kindness."
58
+
59
+ After the complaints were aired, the District School Board of Niagara spoke with Burns and the parents who launched the petition, and the issue is over as far as the board is concerned, Kim Sweeney, the board's chief communications officer, told the National Post. No disciplinary action or policy changes were needed.
60
+
61
+ "Our belief is that taste in music is subjective and we support that both students and staff enjoy a wide variety of genres," Sweeney said.
62
+
63
+ The original petition has since been removed.
64
+ MULTI_LINE_STRING
39
65
  end
40
66
 
67
+ attr_accessor :document, :find_text
68
+
41
69
  attr_accessor :foreground
42
70
 
43
71
  def foreground_options
@@ -62,44 +90,61 @@ class HelloText
62
90
  [FONT_SIZE_PROMPT] + (9..64).to_a.map(&:to_s)
63
91
  end
64
92
 
93
+ def find
94
+ text_index = @text.search(/#{find_text}/i, @text.tag_ranges('sel')&.first&.last || @text.index('insert'))
95
+ unless text_index.to_s.empty?
96
+ @text.tag_remove('sel', '1.0', 'end')
97
+ @text.tag_add('sel', text_index, "#{text_index} + #{find_text.size} chars")
98
+ end
99
+ end
100
+
65
101
  def launch
66
- root {
102
+ @root = root {
67
103
  title 'Hello, Text!'
104
+ width 1280
105
+ height 800
68
106
 
69
107
  frame {
70
108
  grid row: 0, column: 0
71
109
 
110
+ label {
111
+ grid row: 0, column: 0, columnspan: 17
112
+ text 'Select a region of text and then apply formatting from the toolbar'
113
+ }
114
+
115
+ column_index = -1
116
+
72
117
  combobox {
73
- grid row: 0, column: 0, column_weight: 1
118
+ grid row: 1, column: column_index += 1, column_weight: 1
74
119
  readonly true
75
120
  text <=> [self, :font_family, after_write: ->(value) { @text.toggle_selection_font_format('family', value == FONT_FAMILY_PROMPT ? 'Courier New' : value) }]
76
121
  }
77
122
 
78
123
  combobox {
79
- grid row: 0, column: 1, column_weight: 1
124
+ grid row: 1, column: column_index += 1, column_weight: 1
80
125
  readonly true
81
126
  text <=> [self, :font_size, after_write: ->(value) { @text.toggle_selection_font_format('size', value == FONT_SIZE_PROMPT ? 13 : value) }]
82
127
  }
83
128
 
84
129
  combobox {
85
- grid row: 0, column: 2, column_weight: 1
130
+ grid row: 1, column: column_index += 1, column_weight: 1
86
131
  readonly true
87
132
  text <=> [self, :foreground, after_write: ->(value) { @text.add_selection_format('foreground', value == FOREGROUND_PROMPT ? 'black' : value) }]
88
133
  }
89
134
 
90
135
  combobox {
91
- grid row: 0, column: 3, column_weight: 1
136
+ grid row: 1, column: column_index += 1, column_weight: 1
92
137
  readonly true
93
138
  text <=> [self, :background, after_write: ->(value) { @text.add_selection_format('background', value == BACKGROUND_PROMPT ? 'white' : value) }]
94
139
  }
95
140
 
96
141
  separator {
97
- grid row: 0, column: 4, column_weight: 0
142
+ grid row: 1, column: column_index += 1, column_weight: 0
98
143
  orient 'vertical'
99
144
  }
100
145
 
101
146
  button {
102
- grid row: 0, column: 5, column_weight: 0
147
+ grid row: 1, column: column_index += 1, column_weight: 0
103
148
  text 'B'
104
149
  style font: {weight: 'bold'}
105
150
 
@@ -109,7 +154,7 @@ class HelloText
109
154
  }
110
155
 
111
156
  button {
112
- grid row: 0, column: 6, column_weight: 0
157
+ grid row: 1, column: column_index += 1, column_weight: 0
113
158
  text 'I'
114
159
  style font: {slant: 'italic'}
115
160
 
@@ -119,7 +164,7 @@ class HelloText
119
164
  }
120
165
 
121
166
  button {
122
- grid row: 0, column: 7, column_weight: 0
167
+ grid row: 1, column: column_index += 1, column_weight: 0
123
168
  text 'U'
124
169
  style font: {underline: true}
125
170
 
@@ -129,12 +174,12 @@ class HelloText
129
174
  }
130
175
 
131
176
  separator {
132
- grid row: 0, column: 8, column_weight: 0
177
+ grid row: 1, column: column_index += 1, column_weight: 0
133
178
  orient 'vertical'
134
179
  }
135
180
 
136
181
  button {
137
- grid row: 0, column: 9, column_weight: 0
182
+ grid row: 1, column: column_index += 1, column_weight: 0
138
183
  image File.expand_path("images/cut.png", __dir__), subsample: 32
139
184
 
140
185
  on('command') do
@@ -143,7 +188,7 @@ class HelloText
143
188
  }
144
189
 
145
190
  button {
146
- grid row: 0, column: 10, column_weight: 0
191
+ grid row: 1, column: column_index += 1, column_weight: 0
147
192
  image File.expand_path("images/copy.png", __dir__), subsample: 32
148
193
 
149
194
  on('command') do
@@ -152,7 +197,7 @@ class HelloText
152
197
  }
153
198
 
154
199
  button {
155
- grid row: 0, column: 11, column_weight: 0
200
+ grid row: 1, column: column_index += 1, column_weight: 0
156
201
  image File.expand_path("images/paste.png", __dir__), subsample: 32
157
202
 
158
203
  on('command') do
@@ -161,12 +206,44 @@ class HelloText
161
206
  }
162
207
 
163
208
  separator {
164
- grid row: 0, column: 12, column_weight: 0
209
+ grid row: 1, column: column_index += 1, column_weight: 0
210
+ orient 'vertical'
211
+ }
212
+
213
+ button {
214
+ grid row: 1, column: column_index += 1, column_weight: 0
215
+ image File.expand_path("images/align-left.png", __dir__), subsample: 32
216
+
217
+ on('command') do
218
+ @text.add_selection_format('justify', 'left')
219
+ end
220
+ }
221
+
222
+ button {
223
+ grid row: 1, column: column_index += 1, column_weight: 0
224
+ image File.expand_path("images/align-center.png", __dir__), subsample: 32
225
+
226
+ on('command') do
227
+ @text.add_selection_format('justify', 'center')
228
+ end
229
+ }
230
+
231
+ button {
232
+ grid row: 1, column: column_index += 1, column_weight: 0
233
+ image File.expand_path("images/align-right.png", __dir__), subsample: 32
234
+
235
+ on('command') do
236
+ @text.add_selection_format('justify', 'right')
237
+ end
238
+ }
239
+
240
+ separator {
241
+ grid row: 1, column: column_index += 1, column_weight: 0
165
242
  orient 'vertical'
166
243
  }
167
244
 
168
245
  button {
169
- grid row: 0, column: 13, column_weight: 1
246
+ grid row: 1, column: column_index += 1, column_weight: 0
170
247
  image File.expand_path("images/undo.png", __dir__), subsample: 32
171
248
 
172
249
  on('command') do
@@ -175,47 +252,91 @@ class HelloText
175
252
  }
176
253
 
177
254
  button {
178
- grid row: 0, column: 14, column_weight: 1
255
+ grid row: 1, column: column_index += 1, column_weight: 0
179
256
  image File.expand_path("images/redo.png", __dir__), subsample: 32
180
257
 
181
258
  on('command') do
182
259
  @text.edit_redo
183
260
  end
184
261
  }
262
+
263
+ separator {
264
+ grid row: 1, column: column_index += 1, column_weight: 0
265
+ orient 'vertical'
266
+ }
267
+
268
+ button {
269
+ grid row: 1, column: column_index += 1, column_weight: 0
270
+ image File.expand_path("images/picture.png", __dir__), subsample: 32
271
+
272
+ on('command') do
273
+ @text.get_open_file_to_insert_image
274
+ end
275
+ }
276
+
277
+ button {
278
+ grid row: 1, column: column_index += 1, column_weight: 0
279
+ image File.expand_path("images/search.png", __dir__), subsample: 32
280
+
281
+ on('command') do
282
+ show_find_dialog
283
+ end
284
+ }
185
285
  }
186
286
 
187
287
  @text = text {
188
288
  grid row: 1, column: 0, row_weight: 1
189
289
  wrap 'word'
190
290
  undo true
191
- text <<~MULTI_LINE_STRING
192
- According to the National Post, a heavy metal-loving high school principal in Canada will be allowed to keep her job, days after a public campaign to oust her made headlines around the globe.
193
-
194
- Parents at Eden High School in St. Catharines, Ontario launched a petition to remove principal Sharon Burns after discovering she's an IRON MAIDEN fan.
195
-
196
- The petition, titled "Eden High School Principal, Sharon Burns, Needs to Be Transferred Immediately!" read, "We are deeply disturbed that the principal assigned to the school blatantly showed Satanic symbols and her allegiance to Satanic practices on her public social media platforms where all the students can see them under @edenprincipal (not her personal account)."
197
-
198
- More than 500 people signed the petition to transfer Burns after she posted a picture of herself flashing the "devil horns" hand sign with a doll of the MAIDEN zombie mascot Eddie behind her as well as a personalized license plate reading "IRNMADEN" and a handwritten note that reads "Eddie 666" on a car's dashboard.
199
-
200
-
201
- The number 666 is used to represent the devil, and is featured prominently in MAIDEN's artwork by the band, whose classic third album is titled "The Number Of The Beast".
202
-
203
- The petition was later updated to state that the demand for her transfer is not because of her love for metal, but for "openly displaying her own handmade sign with the 666 clearly displayed on it".
204
-
205
- The creator of the original petition wrote: "Sharon knows full well what she did was simply inappropriate, unnecessary and not professional but has yet to publicly admit so and is willing to allow people to believe a completely different story, making very real concerns seem petty."
206
-
207
- Meanwhile, a counter-petition supporting Burns garnered over 20,000 signatures.
208
-
209
- "It is ridiculous that a couple of parents judge her role as a principal only based on an Instagram post. (About liking the band IRON MAIDEN. That's it.) Eden High School is a public school. Not a Christian school," the petition titled "We need Mrs Burns" stated. "She has made Eden a safe space for so many people. She spreads nothing but love and kindness."
210
-
211
- After the complaints were aired, the District School Board of Niagara spoke with Burns and the parents who launched the petition, and the issue is over as far as the board is concerned, Kim Sweeney, the board's chief communications officer, told the National Post. No disciplinary action or policy changes were needed.
212
-
213
- "Our belief is that taste in music is subjective and we support that both students and staff enjoy a wide variety of genres," Sweeney said.
214
-
215
- The original petition has since been removed.
216
- MULTI_LINE_STRING
291
+ value <=> [self, :document]
292
+
293
+ on('KeyPress') do |event|
294
+ show_find_dialog if (event.keysym == 'f') && ((OS.mac? && event.state == 8) || (!OS.mac? && event.state == 4))
295
+ end
296
+ }
297
+ }
298
+ @root.open
299
+ end
300
+
301
+ def show_find_dialog
302
+ toplevel(@root) { |tl|
303
+ title 'Find'
304
+
305
+ label {
306
+ text 'Text:'
307
+ }
308
+ entry { |e|
309
+ focus true
310
+ text <=> [
311
+ self,
312
+ :find_text,
313
+ after_write: lambda do
314
+ text_index = @text.search(/#{find_text}/i, 'insert')
315
+ unless text_index.to_s.empty?
316
+ @text.tag_remove('sel', '1.0', 'end')
317
+ @text.tag_add('sel', text_index, "#{text_index} + #{find_text.size} chars")
318
+ end
319
+ end
320
+ ]
321
+
322
+ on('KeyPress') do |event|
323
+ if event.keysym == 'Return'
324
+ find
325
+ elsif event.keysym == 'Escape'
326
+ tl.grab_release
327
+ tl.destroy
328
+ end
329
+ end
330
+ }
331
+ button {
332
+ text 'Find'
333
+ default 'active'
334
+
335
+ on('command') do
336
+ find
337
+ end
217
338
  }
218
- }.open
339
+ }
219
340
  end
220
341
  end
221
342
 
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.28
4
+ version: 0.0.32
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-22 00:00:00.000000000 Z
11
+ date: 2021-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -211,10 +211,12 @@ files:
211
211
  - icons/glimmer.png
212
212
  - lib/glimmer-dsl-tk.rb
213
213
  - lib/glimmer/data_binding/tk/list_selection_binding.rb
214
+ - lib/glimmer/data_binding/tk/one_time_observer.rb
214
215
  - lib/glimmer/data_binding/tk/widget_binding.rb
215
216
  - lib/glimmer/dsl/tk/attribute_expression.rb
216
217
  - lib/glimmer/dsl/tk/bind_expression.rb
217
218
  - lib/glimmer/dsl/tk/block_attribute_expression.rb
219
+ - lib/glimmer/dsl/tk/built_in_dialog_expression.rb
218
220
  - lib/glimmer/dsl/tk/data_binding_expression.rb
219
221
  - lib/glimmer/dsl/tk/dsl.rb
220
222
  - lib/glimmer/dsl/tk/format_expression.rb
@@ -239,10 +241,12 @@ files:
239
241
  - lib/glimmer/tk/spinbox_proxy.rb
240
242
  - lib/glimmer/tk/text_proxy.rb
241
243
  - lib/glimmer/tk/text_variable_owner.rb
244
+ - lib/glimmer/tk/toplevel_proxy.rb
242
245
  - lib/glimmer/tk/treeview_proxy.rb
243
246
  - lib/glimmer/tk/variable_owner.rb
244
247
  - lib/glimmer/tk/widget_proxy.rb
245
248
  - samples/elaborate/meta_sample.rb
249
+ - samples/hello/hello_built_in_dialog.rb
246
250
  - samples/hello/hello_button.rb
247
251
  - samples/hello/hello_checkbutton.rb
248
252
  - samples/hello/hello_combobox.rb
@@ -258,9 +262,13 @@ files:
258
262
  - samples/hello/hello_notebook.rb
259
263
  - samples/hello/hello_radiobutton.rb
260
264
  - samples/hello/hello_root.rb
265
+ - samples/hello/hello_separator.rb
261
266
  - samples/hello/hello_spinbox.rb
262
267
  - samples/hello/hello_text.rb
263
268
  - samples/hello/hello_world.rb
269
+ - samples/hello/images/align-center.png
270
+ - samples/hello/images/align-left.png
271
+ - samples/hello/images/align-right.png
264
272
  - samples/hello/images/copy.png
265
273
  - samples/hello/images/cut.png
266
274
  - samples/hello/images/denmark.png
@@ -272,7 +280,9 @@ files:
272
280
  - samples/hello/images/netherlands.png
273
281
  - samples/hello/images/norway.png
274
282
  - samples/hello/images/paste.png
283
+ - samples/hello/images/picture.png
275
284
  - samples/hello/images/redo.png
285
+ - samples/hello/images/search.png
276
286
  - samples/hello/images/undo.png
277
287
  - samples/hello/images/usa.png
278
288
  homepage: http://github.com/AndyObtiva/glimmer-dsl-tk
@@ -295,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
305
  - !ruby/object:Gem::Version
296
306
  version: '0'
297
307
  requirements: []
298
- rubygems_version: 3.2.29
308
+ rubygems_version: 3.2.22
299
309
  signing_key:
300
310
  specification_version: 4
301
311
  summary: Glimmer DSL for Tk