glimmer-dsl-tk 0.0.32 → 0.0.33

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84f9643bc9497d251b1b17d52734874c954ce8ff085aee06f5a59bb98a79a1af
4
- data.tar.gz: 2a1a77e76cfbd54fa463bc8c1ea3cb2e3e175b2996471bb3e80caf588f77f1dc
3
+ metadata.gz: 33884eabc43f9c6b019d12a45f75e19212e2969d447f743e29e9db5cf81c615b
4
+ data.tar.gz: 0f0e3558279a70b03aaaf3e7733125eee5bfb5cce320ea34a6bc838803227755
5
5
  SHA512:
6
- metadata.gz: 5af953ed2716d179f70b6b844bde3fa67d808406f5796c0cedb06625e04a05945eba0ff00e8f1783603d6f5509b1abb2d31c6e10033bf0caf46e345172abff01
7
- data.tar.gz: 6f2316a161c55c14acca0da4e6704908617bdec23058245d74352a3eb118bf26bb3671bfa78065aefd5ca23a985a9acbae547fdea7c571dc0ab103f462527d4d
6
+ metadata.gz: f9dac142530aa07249e92dc4cc314a028f7652582562031b415eaab33ac5c0a1207ef2d4f7bbe330bf62715d78f71727a3ef9f26eb761e52efdcc03778a39ac7
7
+ data.tar.gz: 117a6cd4b7fd8472c87b8e4817097d3b6f1c0ff1f765c8fa851b239fff453bbcc2bc7dc69a800d1c9fbee6669b87f821f2d2fa8cef4a407b59c1607c582a0aaf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.33
4
+
5
+ - Support `text` widget `InsertMarkMoved` listener event to track insert mark movement (or alises `InsertMarkMove`, `insert_mark_move`, `insert_mark_moved`, all case-insensitive)
6
+ - Support `entry` widget `changed` and `modified` listener event aliases for `change` event
7
+ - Autodiscover format options when moving cursor in `text` widget (auto-derive from applied tags and widget font) and show in top Hello, Text! toolbar comboboxes and buttons
8
+ - Fix issue with encountering error 'NoMethodError: undefined method "size" for' when launching Hello, Text!, performing Select-All (CMD+A or CONTROL+A) and then attempting to Bold all the text.
9
+ - Fix issue in Hello, Text! whereby bolding a small region of text affects the font of the following region of text till the end of the document
10
+ - Fix issue in Hello, Text! where if all text is copied and then pasted multiple times, the `text` widget loses its keyboard/mouse listeners and CMD+F does not work anymore to bring Find dialog
11
+
3
12
  ## 0.0.32
4
13
 
5
14
  - Hello, Text! Find Dialog toolbar button
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.32
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.33
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)
@@ -158,7 +158,7 @@ gem install glimmer-dsl-tk
158
158
 
159
159
  Add the following to `Gemfile`:
160
160
  ```
161
- gem 'glimmer-dsl-tk', '~> 0.0.32'
161
+ gem 'glimmer-dsl-tk', '~> 0.0.33'
162
162
  ```
163
163
 
164
164
  And, then run:
@@ -273,7 +273,7 @@ keyword(args) | attributes | event bindings & callbacks
273
273
  `choose_directory(options = nil)` | None | None
274
274
  `choose_font(options = nil) {|font| ... }` | None | None
275
275
  `combobox` | `state`, `text` | `'ComboboxSelected'`
276
- `entry` | `width`, `text`, `validate`, `show` (`'none', 'focus', 'focusin', 'focusout', 'key', or 'all'`) | `'validate'`, `'invalid'`, `'change'`, `validatecommand {}`, `invalidcommand {}`
276
+ `entry` | `width`, `text`, `validate`, `show` (`'none', 'focus', 'focusin', 'focusout', 'key', or 'all'`) | `'validate'`, `'invalid'`, `'change'` (alias: `'changed'`), `validatecommand {}`, `invalidcommand {}`
277
277
  `get_multiple_open_file(options = nil)` | None | None
278
278
  `get_open_file(options = nil)` | None | None
279
279
  `get_save_file(options = nil)` | None | None
@@ -286,7 +286,7 @@ keyword(args) | attributes | event bindings & callbacks
286
286
  `radiobutton` | `text`, `variable` (Boolean), `image` (optional keyword args: `subsample`, `zoom`, `from`, `to`, `shrink`, `compositingrule`), `compound` (`'center', 'top', 'bottom', 'left', 'right'`), `value` (default: `text`) | `command {}`
287
287
  `root` | `title`, `iconphoto`, `background`, `alpha`, `fullscreen?`, `topmost?`, `transparent?`, `stackorder`, `winfo_screendepth`, `winfo_screenvisual`, `winfo_screenwidth`, `winfo_screenheight`, `winfo_pixels('li')`, `winfo_screen`, `wm_maxsize`, `state` (`'normal', 'iconic', 'withdrawn', 'icon', 'zoomed'`) | `'DELETE_WINDOW'`, `'OPEN_WINDOW'`
288
288
  `separator` | `orient` (`'horizontal' (default) or 'vertical'`) | None
289
- `text` | `value`, [many more attributes](https://tcl.tk/man/tcl8.6/TkCmd/text.htm#M116) | `'modified'`, `'selection'`
289
+ `text` | `value`, [many more attributes](https://tcl.tk/man/tcl8.6/TkCmd/text.htm#M116) | `'modified'`, `'selection'`, `'insert_mark_moved'` (alias: `'insert_mark_move', 'InsertMarkMove', 'InsertMarkMoved'`)
290
290
 
291
291
  Options for `get_open_file` and `get_multiple_open_file` include:
292
292
  - `filetypes`: `Hash` of `'Group Name' => '.ext'` entries (e.g. `filetypes: {'PNG Images' => '.png'}`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.32
1
+ 0.0.33
Binary file
@@ -40,7 +40,7 @@ module Glimmer
40
40
 
41
41
  def handle_listener(listener_name, &listener)
42
42
  case listener_name.to_s.downcase
43
- when 'change'
43
+ when 'change', 'changed', 'modified'
44
44
  tk.textvariable.trace('write') {
45
45
  listener.call(@tk.textvariable)
46
46
  }
@@ -27,33 +27,63 @@ module Glimmer
27
27
  #
28
28
  # Follows the Proxy Design Pattern
29
29
  class TextProxy < WidgetProxy
30
+ ALL_TAG = '__all__'
31
+ FORMAT_DEFAULT_MAP = {
32
+ 'justify' => 'left',
33
+ }
34
+
30
35
  def handle_listener(listener_name, &listener)
31
36
  case listener_name.to_s.downcase
32
37
  when '<<modified>>', '<modified>', 'modified'
33
38
  modified_listener = Proc.new do |*args|
34
39
  listener.call(*args)
40
+ apply_all_tag
41
+ @insert_mark_moved_proc.call
35
42
  @tk.modified = false
36
43
  end
37
- bind('<Modified>', modified_listener)
44
+ @tk.bind('<Modified>', modified_listener)
38
45
  when '<<selection>>', '<selection>', 'selection'
39
- bind('<Selection>', listener)
46
+ @tk.bind('<Selection>', listener)
40
47
  when 'destroy'
41
48
  super
49
+ when 'insertmarkmove', 'insertmarkmoved', 'insert_mark_move', 'insert_mark_moved'
50
+ if @insert_mark_moved_proc.nil?
51
+ handle_listener('KeyPress') do |event|
52
+ @insert_mark_moved_proc.call
53
+ end
54
+ handle_listener('KeyRelease') do |event|
55
+ @insert_mark_moved_proc.call
56
+ end
57
+ handle_listener('ButtonPress') do |event|
58
+ @insert_mark_moved_proc.call
59
+ end
60
+ handle_listener('ButtonRelease') do |event|
61
+ @insert_mark_moved_proc.call
62
+ end
63
+ end
64
+ @insert_mark = @tk.index('insert')
65
+ @insert_mark_moved_proc = Proc.new do
66
+ new_insert_mark = @tk.index('insert')
67
+ if new_insert_mark != @insert_mark
68
+ @insert_mark = new_insert_mark
69
+ listener.call(new_insert_mark)
70
+ end
71
+ end
42
72
  else
43
- @tk.tag_add('__all__', '1.0', 'end') unless @tk.tag_names.include?('__all__')
73
+ apply_all_tag
44
74
  # TODO make listener pass an event that has a modifiers attribute for easy representation of :shift, :meta, :control, etc... while a letter button is pressed
45
75
  begin
46
- @tk.tag_bind('__all__', listener_name, &listener)
76
+ @tk.tag_bind(ALL_TAG, listener_name, &listener)
47
77
  rescue => e
48
78
  Glimmer::Config.logger.debug {"Unable to bind to #{listener_name} .. attempting to surround with <>"}
49
79
  Glimmer::Config.logger.debug {e.full_message}
50
80
  listener_name = "<#{listener_name}" if !listener_name.start_with?('<')
51
81
  listener_name = "#{listener_name}>" if !listener_name.end_with?('>')
52
- @tk.tag_bind('__all__', listener_name, &listener)
82
+ @tk.tag_bind(ALL_TAG, listener_name, &listener)
53
83
  end
54
84
  end
55
85
  end
56
-
86
+
57
87
  def add_selection_format(option, value)
58
88
  process_selection_ranges { |range_start, range_end| add_format(range_start, range_end, option, value) }
59
89
  end
@@ -91,7 +121,7 @@ module Glimmer
91
121
  end
92
122
 
93
123
  def applied_format_tags(region_start, region_end, option, value)
94
- tag_names = @tk.tag_names - ['sel']
124
+ tag_names = @tk.tag_names - ['sel', ALL_TAG]
95
125
 
96
126
  tag_names.select do |tag_name|
97
127
  @tk.tag_ranges(tag_name).any? do |range|
@@ -102,6 +132,23 @@ module Glimmer
102
132
  end
103
133
  end
104
134
 
135
+ def applied_format_value(text_index = nil, option)
136
+ text_index ||= @tk.index('insert')
137
+ region_start = text_index
138
+ region_end = text_index
139
+ tag_names = @tk.tag_names - ['sel', ALL_TAG]
140
+
141
+ values = tag_names.map do |tag_name|
142
+ @tk.tag_ranges(tag_name).map do |range|
143
+ if text_index_less_than_or_equal_to_other_text_index?(range.first, region_start) && text_index_greater_than_or_equal_to_other_text_index?(range.last, region_end)
144
+ @tk.tag_cget(tag_name, option)
145
+ end
146
+ end
147
+ end.flatten.reject {|value| value.to_s.empty?}
148
+
149
+ values.last || (@tk.send(option) rescue FORMAT_DEFAULT_MAP[option])
150
+ end
151
+
105
152
  def add_format(region_start, region_end, option, value)
106
153
  @@tag_number = 0 unless defined?(@@tag_number)
107
154
  tag = "tag#{@@tag_number += 1}"
@@ -155,15 +202,14 @@ module Glimmer
155
202
  def applied_font_format_tags_and_regions(region_start, region_end)
156
203
  lines = value.split("\n")
157
204
  tags_and_regions = []
158
- all_tag_names = @tk.tag_names - ['sel']
205
+ all_tag_names = @tk.tag_names - ['sel', ALL_TAG]
159
206
  (region_start.to_i..region_end.to_i).each do |line_number|
160
207
  start_character_index = 0
161
208
  start_character_index = region_start.to_s.split('.').last.to_i if line_number == region_start.to_i
162
- end_character_index = lines[line_number - 1].size
209
+ end_character_index = lines[line_number - 1].to_s.size
163
210
  end_character_index = region_end.to_s.split('.').last.to_i if line_number == region_end.to_i
164
211
  (start_character_index...end_character_index).each do |character_index|
165
212
  text_index = "#{line_number}.#{character_index}"
166
- # TODO reimplement the following using @tk.tag_names without arg since passing an arg seems broken and returns inaccurate results
167
213
  region_tag = all_tag_names.reverse.find do |tag|
168
214
  @tk.tag_cget(tag, 'font') && @tk.tag_ranges(tag).any? do |range_start, range_end|
169
215
  text_index_less_than_or_equal_to_other_text_index?(range_start, text_index) && text_index_greater_than_or_equal_to_other_text_index?(range_end, text_index)
@@ -179,6 +225,27 @@ module Glimmer
179
225
  end
180
226
  tags_and_regions
181
227
  end
228
+
229
+ def applied_font_format_value(text_index = nil, font_option)
230
+ text_index ||= @tk.index('insert')
231
+ region_start = text_index
232
+ region_end = @tk.index("#{text_index} + 1 chars")
233
+ tag_names = applied_font_format_tags_and_regions(region_start, region_end).map(&:first)
234
+
235
+ values = tag_names.map do |tag_name|
236
+ @tk.tag_ranges(tag_name).map do |range|
237
+ if text_index_less_than_or_equal_to_other_text_index?(range.first, region_start) && text_index_greater_than_or_equal_to_other_text_index?(range.last, region_end)
238
+ @tk.tag_cget(tag_name, 'font')
239
+ end
240
+ end
241
+ end.flatten.reject {|value| value.to_s.empty?}
242
+
243
+ font = values.last
244
+
245
+ value = font && font.send(font_option)
246
+
247
+ value || Hash[@tk.font.actual][font_option]
248
+ end
182
249
 
183
250
  def add_font_format(region_start, region_end, font_option, value)
184
251
  applied_font_format_tags_and_regions(region_start, region_end).each do |tag, tag_region_start, tag_region_end|
@@ -348,11 +415,16 @@ module Glimmer
348
415
  self.wrap = 'none'
349
416
  self.padx = 5
350
417
  self.pady = 5
418
+ on('Modified') { apply_all_tag }
351
419
  end
352
420
 
353
421
  def clone_font(font)
354
422
  ::TkFont.new(Hash[font.actual])
355
423
  end
424
+
425
+ def apply_all_tag
426
+ @tk.tag_add(ALL_TAG, '1.0', 'end')
427
+ end
356
428
  end
357
429
  end
358
430
  end
@@ -143,7 +143,7 @@ class HelloText
143
143
  orient 'vertical'
144
144
  }
145
145
 
146
- button {
146
+ @bold_button = button {
147
147
  grid row: 1, column: column_index += 1, column_weight: 0
148
148
  text 'B'
149
149
  style font: {weight: 'bold'}
@@ -153,7 +153,7 @@ class HelloText
153
153
  end
154
154
  }
155
155
 
156
- button {
156
+ @italic_button = button {
157
157
  grid row: 1, column: column_index += 1, column_weight: 0
158
158
  text 'I'
159
159
  style font: {slant: 'italic'}
@@ -163,7 +163,7 @@ class HelloText
163
163
  end
164
164
  }
165
165
 
166
- button {
166
+ @underline_button = button {
167
167
  grid row: 1, column: column_index += 1, column_weight: 0
168
168
  text 'U'
169
169
  style font: {underline: true}
@@ -210,7 +210,7 @@ class HelloText
210
210
  orient 'vertical'
211
211
  }
212
212
 
213
- button {
213
+ @justify_left_button = button {
214
214
  grid row: 1, column: column_index += 1, column_weight: 0
215
215
  image File.expand_path("images/align-left.png", __dir__), subsample: 32
216
216
 
@@ -219,7 +219,7 @@ class HelloText
219
219
  end
220
220
  }
221
221
 
222
- button {
222
+ @justify_center_button = button {
223
223
  grid row: 1, column: column_index += 1, column_weight: 0
224
224
  image File.expand_path("images/align-center.png", __dir__), subsample: 32
225
225
 
@@ -228,7 +228,7 @@ class HelloText
228
228
  end
229
229
  }
230
230
 
231
- button {
231
+ @justify_right_button = button {
232
232
  grid row: 1, column: column_index += 1, column_weight: 0
233
233
  image File.expand_path("images/align-right.png", __dir__), subsample: 32
234
234
 
@@ -293,6 +293,19 @@ class HelloText
293
293
  on('KeyPress') do |event|
294
294
  show_find_dialog if (event.keysym == 'f') && ((OS.mac? && event.state == 8) || (!OS.mac? && event.state == 4))
295
295
  end
296
+
297
+ on('InsertMarkMoved') do
298
+ self.font_family = @text.applied_font_format_value('family')
299
+ self.font_size = @text.applied_font_format_value('size')
300
+ @bold_button.default = @text.applied_font_format_value('weight') == 'bold' ? 'active' : 'normal'
301
+ @italic_button.default = @text.applied_font_format_value('slant') == 'italic' ? 'active' : 'normal'
302
+ @underline_button.default = @text.applied_font_format_value('underline') == true ? 'active' : 'normal'
303
+ self.background = @text.applied_format_value('background')
304
+ self.foreground = @text.applied_format_value('foreground')
305
+ @justify_left_button.default = @text.applied_format_value('justify') == 'left' ? 'active' : 'normal'
306
+ @justify_center_button.default = @text.applied_format_value('justify') == 'center' ? 'active' : 'normal'
307
+ @justify_right_button.default = @text.applied_format_value('justify') == 'right' ? 'active' : 'normal'
308
+ end
296
309
  }
297
310
  }
298
311
  @root.open
@@ -318,7 +331,7 @@ class HelloText
318
331
  end
319
332
  end
320
333
  ]
321
-
334
+
322
335
  on('KeyPress') do |event|
323
336
  if event.keysym == 'Return'
324
337
  find
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.32
4
+ version: 0.0.33
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-29 00:00:00.000000000 Z
11
+ date: 2021-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer