glimmer-dsl-tk 0.0.30 → 0.0.34
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -2
- data/README.md +143 -57
- data/VERSION +1 -1
- data/glimmer-dsl-tk.gemspec +0 -0
- data/lib/glimmer/data_binding/tk/one_time_observer.rb +39 -0
- data/lib/glimmer/dsl/tk/data_binding_expression.rb +3 -2
- data/lib/glimmer/dsl/tk/widget_expression.rb +5 -1
- data/lib/glimmer/tk/entry_proxy.rb +1 -1
- data/lib/glimmer/tk/root_proxy.rb +2 -77
- data/lib/glimmer/tk/text_proxy.rb +137 -25
- data/lib/glimmer/tk/toplevel_proxy.rb +119 -0
- data/lib/glimmer/tk/widget_proxy.rb +57 -13
- data/samples/hello/hello_text.rb +110 -38
- metadata +4 -2
data/samples/hello/hello_text.rb
CHANGED
@@ -64,7 +64,7 @@ class HelloText
|
|
64
64
|
MULTI_LINE_STRING
|
65
65
|
end
|
66
66
|
|
67
|
-
attr_accessor :document
|
67
|
+
attr_accessor :document, :find_text
|
68
68
|
|
69
69
|
attr_accessor :foreground
|
70
70
|
|
@@ -90,8 +90,16 @@ class HelloText
|
|
90
90
|
[FONT_SIZE_PROMPT] + (9..64).to_a.map(&:to_s)
|
91
91
|
end
|
92
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
|
+
|
93
101
|
def launch
|
94
|
-
root {
|
102
|
+
@root = root {
|
95
103
|
title 'Hello, Text!'
|
96
104
|
width 1280
|
97
105
|
height 800
|
@@ -99,11 +107,6 @@ class HelloText
|
|
99
107
|
frame {
|
100
108
|
grid row: 0, column: 0
|
101
109
|
|
102
|
-
label {
|
103
|
-
grid row: 0, column: 0, columnspan: 17
|
104
|
-
text 'Select a region of text and then apply formatting from the toolbar'
|
105
|
-
}
|
106
|
-
|
107
110
|
column_index = -1
|
108
111
|
|
109
112
|
combobox {
|
@@ -135,7 +138,7 @@ class HelloText
|
|
135
138
|
orient 'vertical'
|
136
139
|
}
|
137
140
|
|
138
|
-
button {
|
141
|
+
@bold_button = button {
|
139
142
|
grid row: 1, column: column_index += 1, column_weight: 0
|
140
143
|
text 'B'
|
141
144
|
style font: {weight: 'bold'}
|
@@ -145,7 +148,7 @@ class HelloText
|
|
145
148
|
end
|
146
149
|
}
|
147
150
|
|
148
|
-
button {
|
151
|
+
@italic_button = button {
|
149
152
|
grid row: 1, column: column_index += 1, column_weight: 0
|
150
153
|
text 'I'
|
151
154
|
style font: {slant: 'italic'}
|
@@ -155,7 +158,7 @@ class HelloText
|
|
155
158
|
end
|
156
159
|
}
|
157
160
|
|
158
|
-
button {
|
161
|
+
@underline_button = button {
|
159
162
|
grid row: 1, column: column_index += 1, column_weight: 0
|
160
163
|
text 'U'
|
161
164
|
style font: {underline: true}
|
@@ -164,36 +167,36 @@ class HelloText
|
|
164
167
|
@text.toggle_selection_font_format('underline', true)
|
165
168
|
end
|
166
169
|
}
|
167
|
-
|
170
|
+
|
168
171
|
separator {
|
169
172
|
grid row: 1, column: column_index += 1, column_weight: 0
|
170
173
|
orient 'vertical'
|
171
174
|
}
|
172
175
|
|
173
|
-
button {
|
176
|
+
@justify_left_button = button {
|
174
177
|
grid row: 1, column: column_index += 1, column_weight: 0
|
175
|
-
image File.expand_path("images/
|
178
|
+
image File.expand_path("images/align-left.png", __dir__), subsample: 32
|
176
179
|
|
177
180
|
on('command') do
|
178
|
-
@text.
|
181
|
+
@text.add_selection_format('justify', 'left')
|
179
182
|
end
|
180
183
|
}
|
181
184
|
|
182
|
-
button {
|
185
|
+
@justify_center_button = button {
|
183
186
|
grid row: 1, column: column_index += 1, column_weight: 0
|
184
|
-
image File.expand_path("images/
|
187
|
+
image File.expand_path("images/align-center.png", __dir__), subsample: 32
|
185
188
|
|
186
189
|
on('command') do
|
187
|
-
@text.
|
190
|
+
@text.add_selection_format('justify', 'center')
|
188
191
|
end
|
189
192
|
}
|
190
193
|
|
191
|
-
button {
|
194
|
+
@justify_right_button = button {
|
192
195
|
grid row: 1, column: column_index += 1, column_weight: 0
|
193
|
-
image File.expand_path("images/
|
196
|
+
image File.expand_path("images/align-right.png", __dir__), subsample: 32
|
194
197
|
|
195
198
|
on('command') do
|
196
|
-
@text.
|
199
|
+
@text.add_selection_format('justify', 'right')
|
197
200
|
end
|
198
201
|
}
|
199
202
|
|
@@ -204,51 +207,51 @@ class HelloText
|
|
204
207
|
|
205
208
|
button {
|
206
209
|
grid row: 1, column: column_index += 1, column_weight: 0
|
207
|
-
image File.expand_path("images/
|
210
|
+
image File.expand_path("images/picture.png", __dir__), subsample: 32
|
208
211
|
|
209
212
|
on('command') do
|
210
|
-
@text.
|
213
|
+
@text.get_open_file_to_insert_image
|
211
214
|
end
|
212
215
|
}
|
213
216
|
|
214
217
|
button {
|
215
218
|
grid row: 1, column: column_index += 1, column_weight: 0
|
216
|
-
image File.expand_path("images/
|
219
|
+
image File.expand_path("images/search.png", __dir__), subsample: 32
|
217
220
|
|
218
221
|
on('command') do
|
219
|
-
|
222
|
+
show_find_dialog
|
220
223
|
end
|
221
224
|
}
|
222
225
|
|
226
|
+
separator {
|
227
|
+
grid row: 1, column: column_index += 1, column_weight: 0
|
228
|
+
orient 'vertical'
|
229
|
+
}
|
230
|
+
|
223
231
|
button {
|
224
232
|
grid row: 1, column: column_index += 1, column_weight: 0
|
225
|
-
image File.expand_path("images/
|
233
|
+
image File.expand_path("images/cut.png", __dir__), subsample: 32
|
226
234
|
|
227
235
|
on('command') do
|
228
|
-
@text.
|
236
|
+
@text.text_cut
|
229
237
|
end
|
230
238
|
}
|
231
239
|
|
232
|
-
separator {
|
233
|
-
grid row: 1, column: column_index += 1, column_weight: 0
|
234
|
-
orient 'vertical'
|
235
|
-
}
|
236
|
-
|
237
240
|
button {
|
238
241
|
grid row: 1, column: column_index += 1, column_weight: 0
|
239
|
-
image File.expand_path("images/
|
242
|
+
image File.expand_path("images/copy.png", __dir__), subsample: 32
|
240
243
|
|
241
244
|
on('command') do
|
242
|
-
@text.
|
245
|
+
@text.text_copy
|
243
246
|
end
|
244
247
|
}
|
245
248
|
|
246
249
|
button {
|
247
250
|
grid row: 1, column: column_index += 1, column_weight: 0
|
248
|
-
image File.expand_path("images/
|
251
|
+
image File.expand_path("images/paste.png", __dir__), subsample: 32
|
249
252
|
|
250
253
|
on('command') do
|
251
|
-
@text.
|
254
|
+
@text.text_paste
|
252
255
|
end
|
253
256
|
}
|
254
257
|
|
@@ -257,12 +260,22 @@ class HelloText
|
|
257
260
|
orient 'vertical'
|
258
261
|
}
|
259
262
|
|
263
|
+
|
260
264
|
button {
|
261
265
|
grid row: 1, column: column_index += 1, column_weight: 0
|
262
|
-
image File.expand_path("images/
|
266
|
+
image File.expand_path("images/undo.png", __dir__), subsample: 32
|
263
267
|
|
264
268
|
on('command') do
|
265
|
-
@text.
|
269
|
+
@text.edit_undo
|
270
|
+
end
|
271
|
+
}
|
272
|
+
|
273
|
+
button {
|
274
|
+
grid row: 1, column: column_index += 1, column_weight: 0
|
275
|
+
image File.expand_path("images/redo.png", __dir__), subsample: 32
|
276
|
+
|
277
|
+
on('command') do
|
278
|
+
@text.edit_redo
|
266
279
|
end
|
267
280
|
}
|
268
281
|
}
|
@@ -272,8 +285,67 @@ class HelloText
|
|
272
285
|
wrap 'word'
|
273
286
|
undo true
|
274
287
|
value <=> [self, :document]
|
288
|
+
|
289
|
+
on('KeyPress') do |event|
|
290
|
+
show_find_dialog if (event.keysym == 'f') && ((OS.mac? && event.state == 8) || (!OS.mac? && event.state == 4))
|
291
|
+
end
|
292
|
+
|
293
|
+
on('InsertMarkMoved') do
|
294
|
+
self.font_family = @text.applied_font_format_value('family')
|
295
|
+
self.font_size = @text.applied_font_format_value('size')
|
296
|
+
@bold_button.default = @text.applied_font_format_value('weight') == 'bold' ? 'active' : 'normal'
|
297
|
+
@italic_button.default = @text.applied_font_format_value('slant') == 'italic' ? 'active' : 'normal'
|
298
|
+
@underline_button.default = @text.applied_font_format_value('underline') == true ? 'active' : 'normal'
|
299
|
+
self.background = @text.applied_format_value('background')
|
300
|
+
self.foreground = @text.applied_format_value('foreground')
|
301
|
+
@justify_left_button.default = @text.applied_format_value('justify') == 'left' ? 'active' : 'normal'
|
302
|
+
@justify_center_button.default = @text.applied_format_value('justify') == 'center' ? 'active' : 'normal'
|
303
|
+
@justify_right_button.default = @text.applied_format_value('justify') == 'right' ? 'active' : 'normal'
|
304
|
+
end
|
305
|
+
}
|
306
|
+
}
|
307
|
+
@root.open
|
308
|
+
end
|
309
|
+
|
310
|
+
def show_find_dialog
|
311
|
+
toplevel(@root) { |tl|
|
312
|
+
title 'Find'
|
313
|
+
|
314
|
+
label {
|
315
|
+
text 'Text:'
|
316
|
+
}
|
317
|
+
entry { |e|
|
318
|
+
focus true
|
319
|
+
text <=> [
|
320
|
+
self,
|
321
|
+
:find_text,
|
322
|
+
after_write: lambda do
|
323
|
+
text_index = @text.search(/#{find_text}/i, 'insert')
|
324
|
+
unless text_index.to_s.empty?
|
325
|
+
@text.tag_remove('sel', '1.0', 'end')
|
326
|
+
@text.tag_add('sel', text_index, "#{text_index} + #{find_text.size} chars")
|
327
|
+
end
|
328
|
+
end
|
329
|
+
]
|
330
|
+
|
331
|
+
on('KeyPress') do |event|
|
332
|
+
if event.keysym == 'Return'
|
333
|
+
find
|
334
|
+
elsif event.keysym == 'Escape'
|
335
|
+
tl.grab_release
|
336
|
+
tl.destroy
|
337
|
+
end
|
338
|
+
end
|
339
|
+
}
|
340
|
+
button {
|
341
|
+
text 'Find'
|
342
|
+
default 'active'
|
343
|
+
|
344
|
+
on('command') do
|
345
|
+
find
|
346
|
+
end
|
275
347
|
}
|
276
|
-
}
|
348
|
+
}
|
277
349
|
end
|
278
350
|
end
|
279
351
|
|
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.
|
4
|
+
version: 0.0.34
|
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
|
+
date: 2021-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -211,6 +211,7 @@ 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
|
@@ -240,6 +241,7 @@ files:
|
|
240
241
|
- lib/glimmer/tk/spinbox_proxy.rb
|
241
242
|
- lib/glimmer/tk/text_proxy.rb
|
242
243
|
- lib/glimmer/tk/text_variable_owner.rb
|
244
|
+
- lib/glimmer/tk/toplevel_proxy.rb
|
243
245
|
- lib/glimmer/tk/treeview_proxy.rb
|
244
246
|
- lib/glimmer/tk/variable_owner.rb
|
245
247
|
- lib/glimmer/tk/widget_proxy.rb
|