glimmer-dsl-tk 0.0.22 → 0.0.26
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 +40 -0
- data/README.md +612 -46
- data/VERSION +1 -1
- data/glimmer-dsl-tk.gemspec +0 -0
- data/lib/glimmer/dsl/tk/format_expression.rb +39 -0
- data/lib/glimmer/dsl/tk/message_box_expression.rb +4 -1
- data/lib/glimmer/dsl/tk/root_expression.rb +1 -1
- data/lib/glimmer/dsl/tk/widget_expression.rb +0 -7
- data/lib/glimmer/tk/button_proxy.rb +2 -14
- data/lib/glimmer/tk/checkbutton_proxy.rb +5 -13
- data/lib/glimmer/tk/combobox_proxy.rb +34 -0
- data/lib/glimmer/tk/commandable.rb +42 -0
- data/lib/glimmer/tk/entry_proxy.rb +20 -0
- data/lib/glimmer/tk/frame_proxy.rb +9 -0
- data/lib/glimmer/tk/label_proxy.rb +8 -4
- data/lib/glimmer/tk/notebook_proxy.rb +3 -8
- data/lib/glimmer/tk/radiobutton_proxy.rb +46 -0
- data/lib/glimmer/tk/root_proxy.rb +17 -35
- data/lib/glimmer/tk/spinbox_proxy.rb +52 -0
- data/lib/glimmer/tk/text_proxy.rb +187 -0
- data/lib/glimmer/tk/text_variable_owner.rb +31 -0
- data/lib/glimmer/tk/variable_owner.rb +31 -0
- data/lib/glimmer/tk/widget_proxy.rb +167 -62
- data/lib/glimmer-dsl-tk.rb +1 -0
- data/samples/elaborate/meta_sample.rb +138 -0
- data/samples/hello/hello_checkbutton.rb +58 -17
- data/samples/hello/hello_combobox.rb +2 -1
- data/samples/hello/hello_entry.rb +104 -0
- data/samples/hello/hello_radiobutton.rb +107 -0
- data/samples/hello/hello_spinbox.rb +75 -0
- data/samples/hello/hello_text.rb +101 -0
- metadata +17 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.26
|
data/glimmer-dsl-tk.gemspec
CHANGED
Binary file
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright (c) 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/static_expression'
|
23
|
+
require 'glimmer/tk/spinbox_proxy'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module DSL
|
27
|
+
module Tk
|
28
|
+
class FormatExpression < StaticExpression
|
29
|
+
def can_interpret?(parent, keyword, *args, &block)
|
30
|
+
super && parent.is_a?(Glimmer::Tk::SpinboxProxy) && args.size == 1 && block.nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
def interpret(parent, keyword, *args, &block)
|
34
|
+
parent.tk.format(*args)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -27,7 +27,10 @@ module Glimmer
|
|
27
27
|
module Tk
|
28
28
|
class MessageBoxExpression < StaticExpression
|
29
29
|
def interpret(parent, keyword, *args, &block)
|
30
|
-
|
30
|
+
if args.first.is_a?(Hash)
|
31
|
+
args.first[:parent] = args.first[:parent].tk if args.first[:parent].is_a?(Glimmer::Tk::RootProxy)
|
32
|
+
args.first[:title] = args.first.delete(:text) if args.first.keys.include?(:text)
|
33
|
+
end
|
31
34
|
::Tk::messageBox(*args)
|
32
35
|
end
|
33
36
|
end
|
@@ -52,10 +52,3 @@ module Glimmer
|
|
52
52
|
end
|
53
53
|
|
54
54
|
require 'glimmer/tk/widget_proxy'
|
55
|
-
require 'glimmer/tk/notebook_proxy'
|
56
|
-
require 'glimmer/tk/frame_proxy'
|
57
|
-
require 'glimmer/tk/button_proxy'
|
58
|
-
require 'glimmer/tk/label_proxy'
|
59
|
-
require 'glimmer/tk/list_proxy'
|
60
|
-
require 'glimmer/tk/entry_proxy'
|
61
|
-
require 'glimmer/tk/treeview_proxy'
|
@@ -20,6 +20,7 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/tk/widget_proxy'
|
23
|
+
require 'glimmer/tk/commandable'
|
23
24
|
|
24
25
|
module Glimmer
|
25
26
|
module Tk
|
@@ -27,20 +28,7 @@ module Glimmer
|
|
27
28
|
#
|
28
29
|
# Follows the Proxy Design Pattern
|
29
30
|
class ButtonProxy < WidgetProxy
|
30
|
-
|
31
|
-
|
32
|
-
def command_block=(proc)
|
33
|
-
tk.command(proc)
|
34
|
-
end
|
35
|
-
|
36
|
-
def handle_listener(listener_name, &listener)
|
37
|
-
case listener_name.to_s.downcase
|
38
|
-
when 'command'
|
39
|
-
command(listener)
|
40
|
-
else
|
41
|
-
super
|
42
|
-
end
|
43
|
-
end
|
31
|
+
include Commandable
|
44
32
|
end
|
45
33
|
end
|
46
34
|
end
|
@@ -20,25 +20,17 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/tk/widget_proxy'
|
23
|
+
require 'glimmer/tk/commandable'
|
24
|
+
require 'glimmer/tk/variable_owner'
|
23
25
|
|
24
26
|
module Glimmer
|
25
27
|
module Tk
|
26
28
|
# Proxy for Tk::Tile::Checkbutton
|
27
29
|
#
|
28
30
|
# Follows the Proxy Design Pattern
|
29
|
-
class
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
def handle_listener(listener_name, &listener)
|
35
|
-
case listener_name.to_s.downcase
|
36
|
-
when 'command'
|
37
|
-
command(listener)
|
38
|
-
else
|
39
|
-
super
|
40
|
-
end
|
41
|
-
end
|
31
|
+
class CheckbuttonProxy < WidgetProxy
|
32
|
+
include Commandable
|
33
|
+
include VariableOwner
|
42
34
|
end
|
43
35
|
end
|
44
36
|
end
|
@@ -0,0 +1,34 @@
|
|
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/text_variable_owner'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module Tk
|
27
|
+
# Proxy for Tk::Tile::Combobox
|
28
|
+
#
|
29
|
+
# Follows the Proxy Design Pattern
|
30
|
+
class ComboboxProxy < WidgetProxy
|
31
|
+
include TextVariableOwner
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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
|
+
|
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
|
31
|
+
|
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
|
@@ -20,6 +20,7 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/tk/widget_proxy'
|
23
|
+
require 'glimmer/tk/text_variable_owner'
|
23
24
|
|
24
25
|
module Glimmer
|
25
26
|
module Tk
|
@@ -27,12 +28,31 @@ module Glimmer
|
|
27
28
|
#
|
28
29
|
# Follows the Proxy Design Pattern
|
29
30
|
class EntryProxy < WidgetProxy
|
31
|
+
include TextVariableOwner
|
32
|
+
|
30
33
|
def validatecommand_block=(proc)
|
31
34
|
tk.validatecommand(proc)
|
32
35
|
end
|
36
|
+
|
33
37
|
def invalidcommand_block=(proc)
|
34
38
|
tk.invalidcommand(proc)
|
35
39
|
end
|
40
|
+
|
41
|
+
def handle_listener(listener_name, &listener)
|
42
|
+
case listener_name.to_s.downcase
|
43
|
+
when 'change'
|
44
|
+
tk.textvariable.trace('write') {
|
45
|
+
listener.call(@tk.textvariable)
|
46
|
+
}
|
47
|
+
when 'validatecommand', 'validate'
|
48
|
+
self.validatecommand_block = listener
|
49
|
+
when 'invalidcommand', 'invalid'
|
50
|
+
self.invalidcommand_block = listener
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
36
56
|
end
|
37
57
|
end
|
38
58
|
end
|
@@ -20,6 +20,7 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/tk/widget_proxy'
|
23
|
+
require 'glimmer/tk/notebook_proxy'
|
23
24
|
|
24
25
|
module Glimmer
|
25
26
|
module Tk
|
@@ -33,10 +34,18 @@ module Glimmer
|
|
33
34
|
if parent_proxy.is_a?(NotebookProxy)
|
34
35
|
@tab_options, args[0] = args[0].to_h.partition {|key, value| NotebookProxy::TAB_OPTIONS.include?(key.to_s)}
|
35
36
|
@tab_options = Hash[@tab_options]
|
37
|
+
@tab_options[:text] = @tab_options.delete(:title) if @tab_options.keys.include?(:title)
|
36
38
|
args.delete_at(0) if args[0].to_a.empty?
|
37
39
|
end
|
38
40
|
super
|
39
41
|
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def initialize_defaults
|
46
|
+
super unless @parent_proxy.is_a?(NotebookProxy)
|
47
|
+
self.padding = 15
|
48
|
+
end
|
40
49
|
end
|
41
50
|
end
|
42
51
|
end
|
@@ -20,6 +20,7 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/tk/widget_proxy'
|
23
|
+
require 'glimmer/tk/text_variable_owner'
|
23
24
|
|
24
25
|
module Glimmer
|
25
26
|
module Tk
|
@@ -27,10 +28,13 @@ module Glimmer
|
|
27
28
|
#
|
28
29
|
# Follows the Proxy Design Pattern
|
29
30
|
class LabelProxy < WidgetProxy
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
include TextVariableOwner
|
32
|
+
|
33
|
+
FONTS_PREDEFINED = %w[default text fixed menu heading caption small_caption icon tooltip]
|
34
|
+
|
35
|
+
def font=(value)
|
36
|
+
if (value.is_a?(Symbol) || value.is_a?(String)) && FONTS_PREDEFINED.include?(value.to_s.downcase)
|
37
|
+
@tk.font = "tk_#{value}_font".camelcase(:upper)
|
34
38
|
else
|
35
39
|
super
|
36
40
|
end
|
@@ -27,17 +27,12 @@ module Glimmer
|
|
27
27
|
#
|
28
28
|
# Follows the Proxy Design Pattern
|
29
29
|
class NotebookProxy < WidgetProxy
|
30
|
-
TAB_OPTIONS = ['state', 'sticky', 'padding', 'text', 'image', 'compound', 'underline']
|
30
|
+
TAB_OPTIONS = ['state', 'sticky', 'padding', 'text', 'title', 'image', 'compound', 'underline']
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
def initialize(*args)
|
35
|
-
@tab_proxies = []
|
36
|
-
super
|
37
|
-
end
|
32
|
+
alias tab_proxies children
|
38
33
|
|
39
34
|
def post_initialize_child(child)
|
40
|
-
|
35
|
+
super
|
41
36
|
@tk.add child.tk, child.tab_options
|
42
37
|
end
|
43
38
|
end
|
@@ -0,0 +1,46 @@
|
|
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::Radiobutton
|
28
|
+
#
|
29
|
+
# Follows the Proxy Design Pattern
|
30
|
+
class RadiobuttonProxy < WidgetProxy
|
31
|
+
include Commandable
|
32
|
+
|
33
|
+
def sibling_radio_buttons
|
34
|
+
@parent_proxy.children.select {|child| child.is_a?(RadiobuttonProxy) && child != self}
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def initialize_defaults
|
40
|
+
super
|
41
|
+
sibling_variable = sibling_radio_buttons.map(&:tk).map(&:variable).compact.first
|
42
|
+
tk.variable = sibling_variable.nil? ? ::TkVariable.new : sibling_variable
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -31,9 +31,11 @@ module Glimmer
|
|
31
31
|
DEFAULT_WIDTH = 190
|
32
32
|
DEFAULT_HEIGHT = 95
|
33
33
|
|
34
|
-
def initialize(*args)
|
34
|
+
def initialize(*args, &block)
|
35
35
|
@tk = ::TkRoot.new
|
36
36
|
@tk.minsize = DEFAULT_WIDTH, DEFAULT_HEIGHT
|
37
|
+
initialize_defaults
|
38
|
+
post_add_content if block.nil?
|
37
39
|
end
|
38
40
|
|
39
41
|
def post_add_content
|
@@ -57,16 +59,6 @@ module Glimmer
|
|
57
59
|
when 'iconphoto'
|
58
60
|
args[0..-1] = [image_argument(args)]
|
59
61
|
super
|
60
|
-
when 'width'
|
61
|
-
@width = args.first.to_i
|
62
|
-
self.geometry = "#{args.first.to_i}x#{@height || DEFAULT_HEIGHT}#{x_sign}#{abs_x}#{y_sign}#{abs_y}"
|
63
|
-
when 'height'
|
64
|
-
@height = args.first.to_i
|
65
|
-
self.geometry = "#{@width || DEFAULT_WIDTH}x#{args.first.to_i}#{x_sign}#{abs_x}#{y_sign}#{abs_y}"
|
66
|
-
when 'x'
|
67
|
-
self.geometry = "#{@width || DEFAULT_WIDTH}x#{@height || DEFAULT_HEIGHT}#{args.first.to_i > 0 ? '+' : '-'}#{args.first.to_i.abs}#{y_sign}#{abs_y}"
|
68
|
-
when 'y'
|
69
|
-
self.geometry = "#{@width || DEFAULT_WIDTH}x#{@height || DEFAULT_HEIGHT}#{x_sign}#{abs_x}#{args.first.to_i > 0 ? '+' : '-'}#{args.first.to_i.abs}"
|
70
62
|
when 'resizable'
|
71
63
|
if args.size == 1 && !args.first.is_a?(Array)
|
72
64
|
self.resizable = [args.first]*2
|
@@ -78,52 +70,38 @@ module Glimmer
|
|
78
70
|
end
|
79
71
|
end
|
80
72
|
|
81
|
-
def get_attribute(attribute)
|
82
|
-
attribute = attribute.to_s
|
83
|
-
case attribute
|
84
|
-
when 'width'
|
85
|
-
geometry.split(REGEX_GEOMETRY)[0].to_i
|
86
|
-
when 'height'
|
87
|
-
geometry.split(REGEX_GEOMETRY)[1].to_i
|
88
|
-
when 'x'
|
89
|
-
sign_number(x_sign, geometry.split(REGEX_GEOMETRY)[2].to_i)
|
90
|
-
when 'y'
|
91
|
-
sign_number(y_sign, geometry.split(REGEX_GEOMETRY)[3].to_i)
|
92
|
-
else
|
93
|
-
super
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
73
|
def width
|
98
|
-
|
74
|
+
geometry.split(REGEX_GEOMETRY)[0].to_i
|
99
75
|
end
|
100
76
|
|
101
77
|
def height
|
102
|
-
|
78
|
+
geometry.split(REGEX_GEOMETRY)[1].to_i
|
103
79
|
end
|
104
80
|
|
105
81
|
def x
|
106
|
-
|
82
|
+
sign_number(x_sign, geometry.split(REGEX_GEOMETRY)[2].to_i)
|
107
83
|
end
|
108
84
|
|
109
85
|
def y
|
110
|
-
|
86
|
+
sign_number(y_sign, geometry.split(REGEX_GEOMETRY)[3].to_i)
|
111
87
|
end
|
112
88
|
|
113
89
|
def width=(value)
|
114
|
-
|
90
|
+
@width = value.to_i
|
91
|
+
self.geometry = "#{value.to_i}x#{@height || DEFAULT_HEIGHT}#{x_sign}#{abs_x}#{y_sign}#{abs_y}"
|
115
92
|
end
|
116
93
|
|
117
94
|
def height=(value)
|
118
|
-
|
95
|
+
@height = value.to_i
|
96
|
+
self.geometry = "#{@width || DEFAULT_WIDTH}x#{value.to_i}#{x_sign}#{abs_x}#{y_sign}#{abs_y}"
|
119
97
|
end
|
120
98
|
|
121
99
|
def x=(value)
|
122
|
-
|
100
|
+
self.geometry = "#{@width || DEFAULT_WIDTH}x#{@height || DEFAULT_HEIGHT}#{value.to_i > 0 ? '+' : '-'}#{value.to_i.abs}#{y_sign}#{abs_y}"
|
123
101
|
end
|
124
102
|
|
125
103
|
def y=(value)
|
126
|
-
|
104
|
+
self.geometry = "#{@width || DEFAULT_WIDTH}x#{@height || DEFAULT_HEIGHT}#{x_sign}#{abs_x}#{value.to_i > 0 ? '+' : '-'}#{value.to_i.abs}"
|
127
105
|
end
|
128
106
|
|
129
107
|
def handle_listener(listener_name, &listener)
|
@@ -176,6 +154,10 @@ module Glimmer
|
|
176
154
|
def geometry_signs
|
177
155
|
geometry.chars.select {|char| char.match(/[+-]/)}
|
178
156
|
end
|
157
|
+
|
158
|
+
def initialize_defaults
|
159
|
+
self.background = '#ececec' if OS.mac?
|
160
|
+
end
|
179
161
|
end
|
180
162
|
end
|
181
163
|
end
|
@@ -0,0 +1,52 @@
|
|
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/text_variable_owner'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module Tk
|
27
|
+
# Proxy for Tk::Tile::TSpinbox
|
28
|
+
#
|
29
|
+
# Follows the Proxy Design Pattern
|
30
|
+
class SpinboxProxy < WidgetProxy
|
31
|
+
include TextVariableOwner
|
32
|
+
|
33
|
+
def command_block=(proc)
|
34
|
+
tk.command(proc)
|
35
|
+
end
|
36
|
+
|
37
|
+
def handle_listener(listener_name, &listener)
|
38
|
+
case listener_name.to_s.downcase
|
39
|
+
when 'command', 'change'
|
40
|
+
command(&listener)
|
41
|
+
when 'increment', '<increment>', '<<increment>>'
|
42
|
+
bind('<Increment>', listener)
|
43
|
+
when 'decrement', '<decrement>', '<<decrement>>'
|
44
|
+
bind('<Decrement>', listener)
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|