glimmer-dsl-tk 0.0.24 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -0
- data/README.md +548 -100
- 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/root_expression.rb +1 -1
- data/lib/glimmer/tk/drag_and_drop_extension.rb +112 -0
- data/lib/glimmer/tk/frame_proxy.rb +8 -0
- data/lib/glimmer/tk/label_proxy.rb +0 -9
- data/lib/glimmer/tk/radiobutton_proxy.rb +1 -1
- 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 +350 -0
- data/lib/glimmer/tk/widget_proxy.rb +109 -35
- data/samples/elaborate/meta_sample.rb +138 -0
- data/samples/hello/hello_checkbutton.rb +0 -1
- data/samples/hello/hello_combobox.rb +2 -1
- data/samples/hello/hello_drag_and_drop.rb +159 -0
- data/samples/hello/hello_entry.rb +2 -2
- data/samples/hello/hello_radiobutton.rb +21 -1
- data/samples/hello/hello_spinbox.rb +75 -0
- data/samples/hello/hello_text.rb +222 -0
- data/samples/hello/images/copy.png +0 -0
- data/samples/hello/images/cut.png +0 -0
- data/samples/hello/images/paste.png +0 -0
- data/samples/hello/images/redo.png +0 -0
- data/samples/hello/images/undo.png +0 -0
- metadata +19 -6
@@ -0,0 +1,138 @@
|
|
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
|
+
require 'facets'
|
24
|
+
require 'fileutils'
|
25
|
+
|
26
|
+
class MetaSample
|
27
|
+
include Glimmer
|
28
|
+
|
29
|
+
attr_accessor :selected_sample_index
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
@selected_sample_index = 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def samples
|
36
|
+
if @samples.nil?
|
37
|
+
sample_files = Dir.glob(File.join(File.expand_path('../hello', __dir__), '**', 'hello_*.rb'))
|
38
|
+
sample_file_names = sample_files.map { |f| File.basename(f, '.rb') }
|
39
|
+
sample_file_names = sample_file_names.reject { |f| f == 'meta_sample' || f.match(/\d$/) }
|
40
|
+
@samples = sample_file_names.map { |f| f.underscore.titlecase }
|
41
|
+
end
|
42
|
+
@samples
|
43
|
+
end
|
44
|
+
|
45
|
+
def file_path_for(sample)
|
46
|
+
File.join(File.expand_path('../hello', __dir__), "#{sample.underscore}.rb")
|
47
|
+
end
|
48
|
+
|
49
|
+
def glimmer_dsl_tk_file
|
50
|
+
File.expand_path('../../lib/glimmer-dsl-tk', __dir__)
|
51
|
+
end
|
52
|
+
|
53
|
+
def selected_sample
|
54
|
+
samples[@selected_sample_index]
|
55
|
+
end
|
56
|
+
|
57
|
+
def run_sample(sample)
|
58
|
+
Thread.new do
|
59
|
+
command = "ruby -r #{glimmer_dsl_tk_file} #{sample} 2>&1"
|
60
|
+
result = ''
|
61
|
+
IO.popen(command) do |f|
|
62
|
+
f.each_line do |line|
|
63
|
+
result << line
|
64
|
+
puts line
|
65
|
+
$stdout.flush
|
66
|
+
end
|
67
|
+
end
|
68
|
+
::Tk.after(100) do
|
69
|
+
message_box(parent: @root, title: 'Error Running Sample', message: result) if result.downcase.include?('error')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def launch
|
75
|
+
@root = root {
|
76
|
+
title 'Glimmer Meta-Sample'
|
77
|
+
width 1280
|
78
|
+
height 720
|
79
|
+
|
80
|
+
frame {
|
81
|
+
grid row: 0, column: 0, column_weight: 0, row_weight: 1
|
82
|
+
|
83
|
+
samples.each_with_index do |sample, index|
|
84
|
+
radiobutton {
|
85
|
+
text sample
|
86
|
+
variable <=> [self, :selected_sample_index, on_write: ->(v) {v ? index : selected_sample_index}, on_read: ->(v) {v == index}]
|
87
|
+
|
88
|
+
on('command') do
|
89
|
+
@selected_sample_index = index
|
90
|
+
@code_text.text = File.read(file_path_for(selected_sample))
|
91
|
+
end
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
frame {
|
96
|
+
button {
|
97
|
+
grid row: 0, column: 0
|
98
|
+
text 'Launch'
|
99
|
+
|
100
|
+
on('command') do
|
101
|
+
begin
|
102
|
+
parent_dir = File.join(Dir.home, '.glimmer-dsl-tk', 'samples', 'hello')
|
103
|
+
FileUtils.mkdir_p(parent_dir)
|
104
|
+
sample_file = File.join(parent_dir, "#{selected_sample.underscore}.rb")
|
105
|
+
File.write(sample_file, @code_text.text)
|
106
|
+
FileUtils.cp_r(File.expand_path('../../icons', __dir__), File.dirname(File.dirname(parent_dir)))
|
107
|
+
FileUtils.cp_r(File.expand_path('../hello/images', __dir__), parent_dir)
|
108
|
+
sample_namespace_directory = File.expand_path("../hello/#{selected_sample.underscore}", __dir__)
|
109
|
+
FileUtils.cp_r(sample_namespace_directory, parent_dir) if Dir.exist?(sample_namespace_directory)
|
110
|
+
run_sample(sample_file)
|
111
|
+
rescue => e
|
112
|
+
puts e.full_message
|
113
|
+
puts 'Unable to write code changes! Running original sample...'
|
114
|
+
run_sample(file_path_for(selected_sample))
|
115
|
+
end
|
116
|
+
end
|
117
|
+
}
|
118
|
+
button {
|
119
|
+
grid row: 0, column: 1
|
120
|
+
text 'Reset'
|
121
|
+
|
122
|
+
on('command') do
|
123
|
+
@code_text.text = File.read(file_path_for(selected_sample))
|
124
|
+
end
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
@code_text = text {
|
130
|
+
grid row: 0, column: 1, column_weight: 1
|
131
|
+
text File.read(file_path_for(selected_sample))
|
132
|
+
}
|
133
|
+
}
|
134
|
+
@root.open
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
MetaSample.new.launch
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
# Copyright (c) 2020-2021 Andy Maleh
|
2
3
|
#
|
3
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
@@ -44,7 +45,7 @@ class HelloCombobox
|
|
44
45
|
title 'Hello, Combobox!'
|
45
46
|
|
46
47
|
combobox {
|
47
|
-
|
48
|
+
readonly true # this applies to text editing only (item selection still triggers a write to model)
|
48
49
|
text <=> [person, :country]
|
49
50
|
}
|
50
51
|
|
@@ -0,0 +1,159 @@
|
|
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
|
+
require "glimmer/tk/drag_and_drop_extension"
|
24
|
+
|
25
|
+
include Glimmer
|
26
|
+
|
27
|
+
root {
|
28
|
+
title "Hello, Drag and Drop!"
|
29
|
+
frame {
|
30
|
+
padding 5
|
31
|
+
labelframe {
|
32
|
+
text "Drag sources"
|
33
|
+
padding 5
|
34
|
+
label {
|
35
|
+
text "Entry"
|
36
|
+
grid :row => 0, :column => 0
|
37
|
+
}
|
38
|
+
entry {
|
39
|
+
text "Drag entry text"
|
40
|
+
width 30
|
41
|
+
grid :row => 0, :column => 1, :pady => 5, :sticky => "e"
|
42
|
+
on_drag_start { |event|
|
43
|
+
event.data = event.source.textvariable&.value
|
44
|
+
event.source.configure(:cursor => "hand2")
|
45
|
+
TkLabel.new(event.tooltip) {
|
46
|
+
text event.data + " "
|
47
|
+
bg "yellow"
|
48
|
+
bitmap "warning"
|
49
|
+
compound "right"
|
50
|
+
}.pack
|
51
|
+
}
|
52
|
+
on_drag_motion { |event|
|
53
|
+
if event.drop_accepted
|
54
|
+
event.source.configure(:cursor => "hand1")
|
55
|
+
else
|
56
|
+
event.source.configure(:cursor => "hand2")
|
57
|
+
end
|
58
|
+
event.tooltip.geometry("+#{event.x_root + 10}+#{event.y_root - 4}")
|
59
|
+
}
|
60
|
+
}
|
61
|
+
label {
|
62
|
+
text "Label"
|
63
|
+
grid :row => 1, :column => 0
|
64
|
+
}
|
65
|
+
label {
|
66
|
+
text "Drag label text"
|
67
|
+
width 30
|
68
|
+
grid :row => 1, :column => 1, :pady => 10, :sticky => "e"
|
69
|
+
drag_source true
|
70
|
+
}
|
71
|
+
label {
|
72
|
+
text "Combobox"
|
73
|
+
grid :row => 2, :column => 0
|
74
|
+
}
|
75
|
+
combobox {
|
76
|
+
text "Spain"
|
77
|
+
values %w[USA Canada Mexico Columbia UK Australia Germany Italy Spain]
|
78
|
+
width 27
|
79
|
+
grid :row => 2, :column => 1, :pady => 5, :sticky => "e"
|
80
|
+
on_drag_start { |event|
|
81
|
+
event.data = event.source.textvariable&.value
|
82
|
+
}
|
83
|
+
}
|
84
|
+
label {
|
85
|
+
text "Button"
|
86
|
+
grid :row => 3, :column => 0
|
87
|
+
}
|
88
|
+
button {
|
89
|
+
text "Drag it"
|
90
|
+
grid :row => 3, :column => 1, :pady => 5, :sticky => "w"
|
91
|
+
drag_source true
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
labelframe {
|
96
|
+
text "Drop targets"
|
97
|
+
grid :sticky => "nsew", :pady => 15
|
98
|
+
padding 5
|
99
|
+
label {
|
100
|
+
text "Entry"
|
101
|
+
grid :row => 0, :column => 0
|
102
|
+
}
|
103
|
+
entry {
|
104
|
+
width 30
|
105
|
+
grid :row => 0, :column => 1, :pady => 5, :sticky => "e"
|
106
|
+
on_drop { |event|
|
107
|
+
event.target.textvariable.value = event.data
|
108
|
+
}
|
109
|
+
}
|
110
|
+
label {
|
111
|
+
text "Label"
|
112
|
+
grid :row => 1, :column => 0
|
113
|
+
}
|
114
|
+
label {
|
115
|
+
width 30
|
116
|
+
grid :row => 1, :column => 1, :pady => 10, :sticky => "e"
|
117
|
+
borderwidth 2
|
118
|
+
relief "solid"
|
119
|
+
on_drop { |event|
|
120
|
+
event.target.textvariable.value = event.data
|
121
|
+
}
|
122
|
+
}
|
123
|
+
label {
|
124
|
+
text "Combobox"
|
125
|
+
grid :row => 2, :column => 0
|
126
|
+
}
|
127
|
+
combobox {
|
128
|
+
width 27
|
129
|
+
grid :row => 2, :column => 1, :pady => 5, :sticky => "e"
|
130
|
+
on_drop { |event|
|
131
|
+
event.target.textvariable.value = event.data
|
132
|
+
}
|
133
|
+
}
|
134
|
+
label {
|
135
|
+
text "Button"
|
136
|
+
grid :row => 3, :column => 0
|
137
|
+
}
|
138
|
+
button {
|
139
|
+
text "Drop here"
|
140
|
+
grid :row => 3, :column => 1, :pady => 5, :sticky => "w"
|
141
|
+
on_drop { |event|
|
142
|
+
event.target.text = event.data
|
143
|
+
}
|
144
|
+
}
|
145
|
+
label {
|
146
|
+
text "Checkbutton"
|
147
|
+
grid :row => 4, :column => 0
|
148
|
+
}
|
149
|
+
checkbutton {
|
150
|
+
text "Drop here to destroy a widget\n(except button)"
|
151
|
+
grid :row => 4, :column => 1, :pady => 5, :sticky => "w"
|
152
|
+
on_drop { |event|
|
153
|
+
event.target.text = event.data
|
154
|
+
event.source.destroy unless event.source.is_a? Tk::Button
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}.open
|
@@ -38,7 +38,7 @@ class HelloEntry
|
|
38
38
|
title 'Hello, Entry!'
|
39
39
|
|
40
40
|
label {
|
41
|
-
grid sticky: 'ew'
|
41
|
+
grid sticky: 'ew'
|
42
42
|
text 'default entry'
|
43
43
|
}
|
44
44
|
entry {
|
@@ -72,7 +72,7 @@ class HelloEntry
|
|
72
72
|
|
73
73
|
## this event kicks in just after the text variable is validated and before it is modified
|
74
74
|
on('invalid') do |validate_args|
|
75
|
-
@validated_entry_label.text = "#{validate_args.
|
75
|
+
@validated_entry_label.text = "#{validate_args.value} is not valid!"
|
76
76
|
@validated_entry_label.foreground = 'red'
|
77
77
|
end
|
78
78
|
|
@@ -1,3 +1,24 @@
|
|
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
|
+
|
1
22
|
require 'glimmer-dsl-tk'
|
2
23
|
|
3
24
|
class HelloRadiobutton
|
@@ -27,7 +48,6 @@ class HelloRadiobutton
|
|
27
48
|
def launch
|
28
49
|
root {
|
29
50
|
title 'Hello, Radio!'
|
30
|
-
background '#ececec' if OS.mac?
|
31
51
|
|
32
52
|
label {
|
33
53
|
text 'Gender:'
|
@@ -0,0 +1,75 @@
|
|
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
|
+
class HelloSpinbox
|
25
|
+
class Person
|
26
|
+
attr_accessor :donation
|
27
|
+
end
|
28
|
+
|
29
|
+
include Glimmer
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
@person = Person.new
|
33
|
+
@person.donation = 5.0 # in dollars
|
34
|
+
end
|
35
|
+
|
36
|
+
def launch
|
37
|
+
root {
|
38
|
+
title 'Hello, Spinbox!'
|
39
|
+
|
40
|
+
label {
|
41
|
+
text 'Please select the amount you would like to donate to the poor:'
|
42
|
+
}
|
43
|
+
|
44
|
+
frame {
|
45
|
+
label {
|
46
|
+
grid row: 0, column: 0
|
47
|
+
text 'Amount:'
|
48
|
+
font 'caption'
|
49
|
+
}
|
50
|
+
|
51
|
+
label {
|
52
|
+
grid row: 0, column: 1
|
53
|
+
text '$'
|
54
|
+
}
|
55
|
+
|
56
|
+
spinbox {
|
57
|
+
grid row: 0, column: 2
|
58
|
+
from 1.0 # minimum value
|
59
|
+
to 150.0 # maximum value
|
60
|
+
increment 5.0 # increment on up and down
|
61
|
+
format '%0.2f'
|
62
|
+
text <=> [@person, :donation]
|
63
|
+
}
|
64
|
+
|
65
|
+
label {
|
66
|
+
grid row: 1, column: 0, columnspan: 3
|
67
|
+
text <=> [@person, :donation, on_read: ->(value) { "Thank you for your donation of $#{"%.2f" % value.to_f}"}]
|
68
|
+
}
|
69
|
+
|
70
|
+
}
|
71
|
+
}.open
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
HelloSpinbox.new.launch
|
@@ -0,0 +1,222 @@
|
|
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
|
+
class HelloText
|
25
|
+
include Glimmer
|
26
|
+
|
27
|
+
COLOR_OPTIONS = %w[black purple blue green orange yellow red white].map(&:capitalize)
|
28
|
+
FONT_FAMILY_OPTIONS = ::TkFont.families
|
29
|
+
FOREGROUND_PROMPT = '<foreground>'
|
30
|
+
BACKGROUND_PROMPT = '<background>'
|
31
|
+
FONT_FAMILY_PROMPT = '<font family>'
|
32
|
+
FONT_SIZE_PROMPT = '<font size>'
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@foreground = FOREGROUND_PROMPT
|
36
|
+
@background = BACKGROUND_PROMPT
|
37
|
+
@font_family = FONT_FAMILY_PROMPT
|
38
|
+
@font_size = FONT_SIZE_PROMPT
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_accessor :foreground
|
42
|
+
|
43
|
+
def foreground_options
|
44
|
+
[FOREGROUND_PROMPT] + COLOR_OPTIONS
|
45
|
+
end
|
46
|
+
|
47
|
+
attr_accessor :background
|
48
|
+
|
49
|
+
def background_options
|
50
|
+
[BACKGROUND_PROMPT] + COLOR_OPTIONS
|
51
|
+
end
|
52
|
+
|
53
|
+
attr_accessor :font_family
|
54
|
+
|
55
|
+
def font_family_options
|
56
|
+
[FONT_FAMILY_PROMPT] + FONT_FAMILY_OPTIONS
|
57
|
+
end
|
58
|
+
|
59
|
+
attr_accessor :font_size
|
60
|
+
|
61
|
+
def font_size_options
|
62
|
+
[FONT_SIZE_PROMPT] + (9..64).to_a.map(&:to_s)
|
63
|
+
end
|
64
|
+
|
65
|
+
def launch
|
66
|
+
root {
|
67
|
+
title 'Hello, Text!'
|
68
|
+
|
69
|
+
frame {
|
70
|
+
grid row: 0, column: 0
|
71
|
+
|
72
|
+
combobox {
|
73
|
+
grid row: 0, column: 0, column_weight: 1
|
74
|
+
readonly true
|
75
|
+
text <=> [self, :font_family, after_write: ->(value) { @text.toggle_selection_font_format('family', value == FONT_FAMILY_PROMPT ? 'Courier New' : value) }]
|
76
|
+
}
|
77
|
+
|
78
|
+
combobox {
|
79
|
+
grid row: 0, column: 1, column_weight: 1
|
80
|
+
readonly true
|
81
|
+
text <=> [self, :font_size, after_write: ->(value) { @text.toggle_selection_font_format('size', value == FONT_SIZE_PROMPT ? 13 : value) }]
|
82
|
+
}
|
83
|
+
|
84
|
+
combobox {
|
85
|
+
grid row: 0, column: 2, column_weight: 1
|
86
|
+
readonly true
|
87
|
+
text <=> [self, :foreground, after_write: ->(value) { @text.add_selection_format('foreground', value == FOREGROUND_PROMPT ? 'black' : value) }]
|
88
|
+
}
|
89
|
+
|
90
|
+
combobox {
|
91
|
+
grid row: 0, column: 3, column_weight: 1
|
92
|
+
readonly true
|
93
|
+
text <=> [self, :background, after_write: ->(value) { @text.add_selection_format('background', value == BACKGROUND_PROMPT ? 'white' : value) }]
|
94
|
+
}
|
95
|
+
|
96
|
+
separator {
|
97
|
+
grid row: 0, column: 4, column_weight: 0
|
98
|
+
orient 'vertical'
|
99
|
+
}
|
100
|
+
|
101
|
+
button {
|
102
|
+
grid row: 0, column: 5, column_weight: 0
|
103
|
+
text 'B'
|
104
|
+
style font: {weight: 'bold'}
|
105
|
+
|
106
|
+
on('command') do
|
107
|
+
@text.toggle_selection_font_format('weight', 'bold')
|
108
|
+
end
|
109
|
+
}
|
110
|
+
|
111
|
+
button {
|
112
|
+
grid row: 0, column: 6, column_weight: 0
|
113
|
+
text 'I'
|
114
|
+
style font: {slant: 'italic'}
|
115
|
+
|
116
|
+
on('command') do
|
117
|
+
@text.toggle_selection_font_format('slant', 'italic')
|
118
|
+
end
|
119
|
+
}
|
120
|
+
|
121
|
+
button {
|
122
|
+
grid row: 0, column: 7, column_weight: 0
|
123
|
+
text 'U'
|
124
|
+
style font: {underline: true}
|
125
|
+
|
126
|
+
on('command') do
|
127
|
+
@text.toggle_selection_font_format('underline', true)
|
128
|
+
end
|
129
|
+
}
|
130
|
+
|
131
|
+
separator {
|
132
|
+
grid row: 0, column: 8, column_weight: 0
|
133
|
+
orient 'vertical'
|
134
|
+
}
|
135
|
+
|
136
|
+
button {
|
137
|
+
grid row: 0, column: 9, column_weight: 0
|
138
|
+
image File.expand_path("images/cut.png", __dir__), subsample: 32
|
139
|
+
|
140
|
+
on('command') do
|
141
|
+
@text.text_cut
|
142
|
+
end
|
143
|
+
}
|
144
|
+
|
145
|
+
button {
|
146
|
+
grid row: 0, column: 10, column_weight: 0
|
147
|
+
image File.expand_path("images/copy.png", __dir__), subsample: 32
|
148
|
+
|
149
|
+
on('command') do
|
150
|
+
@text.text_copy
|
151
|
+
end
|
152
|
+
}
|
153
|
+
|
154
|
+
button {
|
155
|
+
grid row: 0, column: 11, column_weight: 0
|
156
|
+
image File.expand_path("images/paste.png", __dir__), subsample: 32
|
157
|
+
|
158
|
+
on('command') do
|
159
|
+
@text.text_paste
|
160
|
+
end
|
161
|
+
}
|
162
|
+
|
163
|
+
separator {
|
164
|
+
grid row: 0, column: 12, column_weight: 0
|
165
|
+
orient 'vertical'
|
166
|
+
}
|
167
|
+
|
168
|
+
button {
|
169
|
+
grid row: 0, column: 13, column_weight: 1
|
170
|
+
image File.expand_path("images/undo.png", __dir__), subsample: 32
|
171
|
+
|
172
|
+
on('command') do
|
173
|
+
@text.edit_undo
|
174
|
+
end
|
175
|
+
}
|
176
|
+
|
177
|
+
button {
|
178
|
+
grid row: 0, column: 14, column_weight: 1
|
179
|
+
image File.expand_path("images/redo.png", __dir__), subsample: 32
|
180
|
+
|
181
|
+
on('command') do
|
182
|
+
@text.edit_redo
|
183
|
+
end
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
@text = text {
|
188
|
+
grid row: 1, column: 0, row_weight: 1
|
189
|
+
wrap 'word'
|
190
|
+
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
|
217
|
+
}
|
218
|
+
}.open
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
HelloText.new.launch
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|