glimmer-dsl-swt 4.17.0.0 → 4.17.2.2

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.
@@ -63,6 +63,7 @@ module Glimmer
63
63
  @swt_widget.set_data('proxy', self)
64
64
  @swt_widget.setLayout(FillLayout.new)
65
65
  @swt_widget.setMinimumSize(WIDTH_MIN, HEIGHT_MIN)
66
+ # TODO make this an option not the default
66
67
  on_swt_show do
67
68
  Thread.new do
68
69
  sleep(0.25)
@@ -678,6 +678,9 @@ module Glimmer
678
678
  end
679
679
  # TODO consider detecting type on widget method and automatically invoking right converter (e.g. :to_s for String, :to_i for Integer)
680
680
  @property_type_converters ||= {
681
+ alignment: -> (*value) {
682
+ SWTProxy[*value]
683
+ },
681
684
  :background => color_converter,
682
685
  :background_image => lambda do |value|
683
686
  image_proxy = nil
@@ -153,6 +153,7 @@ module Glimmer
153
153
  body_block = self.class.instance_variable_get("@body_block")
154
154
  raise Glimmer::Error, 'Invalid custom widget for having no body! Please define body block!' if body_block.nil?
155
155
  @body_root = instance_exec(&body_block)
156
+ raise Glimmer::Error, 'Invalid custom widget for having an empty body! Please fill body block!' if @body_root.nil?
156
157
  @swt_widget = @body_root.swt_widget
157
158
  @swt_widget.set_data('custom_widget', self)
158
159
  execute_hooks('after_body')
@@ -210,9 +211,9 @@ module Glimmer
210
211
 
211
212
  # This method ensures it has an instance method not coming from Glimmer DSL
212
213
  def has_instance_method?(method_name)
213
- respond_to?(method_name) &&
214
- !swt_widget.respond_to?(method_name) &&
215
- !method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb') &&
214
+ respond_to?(method_name) and
215
+ !swt_widget&.respond_to?(method_name) and
216
+ !method(method_name)&.source_location&.first&.include?('glimmer/dsl/engine.rb') and
216
217
  !method(method_name)&.source_location&.first&.include?('glimmer/swt/widget_proxy.rb')
217
218
  end
218
219
 
@@ -272,7 +273,10 @@ module Glimmer
272
273
 
273
274
  def execute_hooks(hook_name)
274
275
  self.class.instance_variable_get("@#{hook_name}_blocks")&.each do |hook_block|
275
- instance_exec(&hook_block)
276
+ temp_method_name = "#{hook_name}_block_#{hook_block.hash.abs}_#{(Time.now.to_f * 1_000_000).to_i}"
277
+ singleton_class.define_method(temp_method_name, &hook_block)
278
+ send(temp_method_name)
279
+ singleton_class.send(:remove_method, temp_method_name)
276
280
  end
277
281
  end
278
282
  end
@@ -19,6 +19,8 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
+ require 'delegate'
23
+
22
24
  module Glimmer
23
25
  module Util
24
26
  class ProcTracker < DelegateClass(Proc)
@@ -124,105 +124,8 @@ class ContactManager
124
124
  Jason
125
125
  Emma
126
126
  Olivia
127
- Ava
128
- Isabella
129
- Sophia
130
- Charlotte
131
- Mia
132
- Amelia
133
- Harper
134
- Evelyn
135
- Abigail
136
- Emily
137
- Elizabeth
138
- Mila
139
- Ella
140
- Avery
141
- Sofia
142
- Camila
143
- Aria
144
- Scarlett
145
- Victoria
146
- Madison
147
- Luna
148
- Grace
149
- Chloe
150
- Penelope
151
- Layla
152
- Riley
153
- Zoey
154
- Nora
155
- Lily
156
- Eleanor
157
- Hannah
158
- Lillian
159
- Addison
160
- Aubrey
161
- Ellie
162
- Stella
163
- Natalie
164
- Zoe
165
- Leah
166
- Hazel
167
- Violet
168
- Aurora
169
- Savannah
170
- Audrey
171
- Brooklyn
172
- Bella
173
- Claire
174
- Skylar
175
- Lucy
176
- Paisley
177
- Everly
178
- Anna
179
- Caroline
180
- Nova
181
- Genesis
182
- Emilia
183
- Kennedy
184
- Samantha
185
- Maya
186
- Willow
187
- Kinsley
188
- Naomi
189
- Aaliyah
190
- Elena
191
- Sarah
192
- Ariana
193
- Allison
194
- Gabriella
195
- Alice
196
- Madelyn
197
- Cora
198
- Ruby
199
- Eva
200
- Serenity
201
- Autumn
202
- Adeline
203
- Hailey
204
- Gianna
205
- Valentina
206
- Isla
207
- Eliana
208
- Quinn
209
- Nevaeh
210
- Ivy
211
- Sadie
212
- Piper
213
- Lydia
214
- Alexa
215
- Josephine
216
- Emery
217
- Julia
218
- Delilah
219
- Arianna
220
- Vivian
221
- Kaylee
222
- Sophie
223
- Brielle
224
- Madeline
225
127
  ]
128
+
226
129
  NAMES_LAST = %w[
227
130
  Smith
228
131
  Johnson
@@ -235,8 +138,9 @@ class ContactManager
235
138
  Anderson
236
139
  Taylor
237
140
  ]
141
+
238
142
  def initialize(contacts = nil)
239
- @contacts = contacts || 1000.times.map do |n|
143
+ @contacts = contacts || 100.times.map do |n|
240
144
  random_first_name_index = (rand*NAMES_FIRST.size).to_i
241
145
  random_last_name_index = (rand*NAMES_LAST.size).to_i
242
146
  first_name = NAMES_FIRST[random_first_name_index]
@@ -24,6 +24,6 @@ include Glimmer
24
24
  shell {
25
25
  minimum_size 1024, 860
26
26
  browser {
27
- url 'http://brightonresort.com/about'
27
+ url 'https://brightonresort.com/about'
28
28
  }
29
29
  }.open
@@ -23,30 +23,34 @@ class Person
23
23
  attr_accessor :country, :country_options
24
24
 
25
25
  def initialize
26
- self.country_options=["", "Canada", "US", "Mexico"]
27
- self.country = "Canada"
26
+ self.country_options = ['', 'Canada', 'US', 'Mexico']
27
+ reset_country
28
28
  end
29
29
 
30
30
  def reset_country
31
- self.country = "Canada"
31
+ self.country = 'Canada'
32
32
  end
33
33
  end
34
34
 
35
35
  class HelloCombo
36
36
  include Glimmer
37
+
37
38
  def launch
38
39
  person = Person.new
39
40
 
40
41
  shell {
41
- fill_layout :vertical
42
- text 'Hello, Combo!'
42
+ row_layout(:vertical) {
43
+ pack false
44
+ }
45
+
46
+ text 'Hello, Combo!'
43
47
 
44
48
  combo(:read_only) {
45
49
  selection bind(person, :country)
46
50
  }
47
51
 
48
52
  button {
49
- text "Reset Selection"
53
+ text 'Reset Selection'
50
54
 
51
55
  on_widget_selected do
52
56
  person.reset_country
@@ -0,0 +1,155 @@
1
+ # Copyright (c) 2007-2020 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 'date'
23
+
24
+ # This class declares an `email_shell` custom shell, aka custom window (by convention)
25
+ # Used to view an email message
26
+ class EmailShell
27
+ include Glimmer::UI::CustomShell
28
+
29
+ # multiple options without default values
30
+ options :date, :subject, :from, :message
31
+
32
+ # single option with default value
33
+ option :to, default: '"John Irwin" <john.irwin@example.com>'
34
+
35
+ before_body {
36
+ @swt_style |= swt(:shell_trim, :modeless)
37
+ }
38
+
39
+ body {
40
+ # pass received swt_style through to shell to customize it (e.g. :dialog_trim for a blocking shell)
41
+ shell(swt_style) {
42
+ grid_layout(2, false)
43
+
44
+ text subject
45
+
46
+ label {
47
+ text 'Date:'
48
+ }
49
+ label {
50
+ text date
51
+ }
52
+
53
+ label {
54
+ text 'From:'
55
+ }
56
+ label {
57
+ text from
58
+ }
59
+
60
+ label {
61
+ text 'To:'
62
+ }
63
+ label {
64
+ text to
65
+ }
66
+
67
+ label {
68
+ text 'Subject:'
69
+ }
70
+ label {
71
+ text subject
72
+ }
73
+
74
+ label {
75
+ layout_data(:fill, :fill, true, true) {
76
+ horizontal_span 2
77
+ vertical_indent 10
78
+ }
79
+
80
+ background :white
81
+ text message
82
+ }
83
+ }
84
+ }
85
+
86
+ end
87
+
88
+ class HelloCustomShell
89
+ # including Glimmer enables the Glimmer DSL syntax, including auto-discovery of the `email_shell` custom widget
90
+ include Glimmer
91
+
92
+ Email = Struct.new(:date, :subject, :from, :message, keyword_init: true)
93
+ EmailSystem = Struct.new(:emails, keyword_init: true)
94
+
95
+ def initialize
96
+ @email_system = EmailSystem.new(
97
+ emails: [
98
+ Email.new(date: DateTime.new(2029, 10, 22, 11, 3, 0).strftime('%F %I:%M %p'), subject: '3rd Week Report', from: '"Dianne Tux" <dianne.tux@example.com>', message: "Hello,\n\nI was wondering if you'd like to go over the weekly report sometime this afternoon.\n\nDianne"),
99
+ Email.new(date: DateTime.new(2029, 10, 21, 8, 1, 0).strftime('%F %I:%M %p'), subject: 'Glimmer Upgrade v100.0', from: '"Robert McGabbins" <robert.mcgabbins@example.com>', message: "Team,\n\nWe are upgrading to Glimmer version 100.0.\n\nEveryone pull the latest code!\n\nRegards,\n\nRobert McGabbins"),
100
+ Email.new(date: DateTime.new(2029, 10, 19, 16, 58, 0).strftime('%F %I:%M %p'), subject: 'Christmas Party', from: '"Lisa Ferreira" <lisa.ferreira@example.com>', message: "Merry Christmas,\n\nAll office Christmas Party arrangements have been set\n\nMake sure to bring a Secret Santa gift\n\nBest regards,\n\nLisa Ferreira"),
101
+ Email.new(date: DateTime.new(2029, 10, 16, 9, 43, 0).strftime('%F %I:%M %p'), subject: 'Glimmer Upgrade v99.0', from: '"Robert McGabbins" <robert.mcgabbins@example.com>', message: "Team,\n\nWe are upgrading to Glimmer version 99.0.\n\nEveryone pull the latest code!\n\nRegards,\n\nRobert McGabbins"),
102
+ Email.new(date: DateTime.new(2029, 10, 15, 11, 2, 0).strftime('%F %I:%M %p'), subject: '2nd Week Report', from: '"Dianne Tux" <dianne.tux@example.com>', message: "Hello,\n\nI was wondering if you'd like to go over the weekly report sometime this afternoon.\n\nDianne"),
103
+ Email.new(date: DateTime.new(2029, 10, 2, 10, 34, 0).strftime('%F %I:%M %p'), subject: 'Glimmer Upgrade v98.0', from: '"Robert McGabbins" <robert.mcgabbins@example.com>', message: "Team,\n\nWe are upgrading to Glimmer version 98.0.\n\nEveryone pull the latest code!\n\nRegards,\n\nRobert McGabbins"),
104
+ ]
105
+ )
106
+ end
107
+
108
+ def launch
109
+ shell {
110
+ grid_layout
111
+
112
+ text 'Hello, Custom Shell!'
113
+
114
+ label {
115
+ font height: 24, style: :bold
116
+ text 'Emails:'
117
+ }
118
+
119
+ label {
120
+ font height: 18
121
+ text 'Click an email to view its message'
122
+ }
123
+
124
+ table {
125
+ layout_data :fill, :fill, true, true
126
+
127
+ table_column {
128
+ text 'Date:'
129
+ width 180
130
+ }
131
+ table_column {
132
+ text 'Subject:'
133
+ width 180
134
+ }
135
+ table_column {
136
+ text 'From:'
137
+ width 360
138
+ }
139
+
140
+ items bind(@email_system, :emails), column_properties(:date, :subject, :from)
141
+
142
+ on_mouse_up { |event|
143
+ email = event.table_item.get_data
144
+ Thread.new do
145
+ async_exec {
146
+ email_shell(date: email.date, subject: email.subject, from: email.from, message: email.message).open
147
+ }
148
+ end
149
+ }
150
+ }
151
+ }.open
152
+ end
153
+ end
154
+
155
+ HelloCustomShell.new.launch
@@ -0,0 +1,86 @@
1
+ # Copyright (c) 2007-2020 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
+ # This class declares a `greeting_label` custom widget (by convention)
23
+ class GreetingLabel
24
+ include Glimmer::UI::CustomWidget
25
+
26
+ # multiple options without default values
27
+ options :name, :colors
28
+
29
+ # single option with default value
30
+ option :greeting, default: 'Hello'
31
+
32
+ # internal attribute (not a custom widget option)
33
+ attr_accessor :color
34
+
35
+ before_body {
36
+ @font = {height: 24, style: :bold}
37
+ @color = :black
38
+ }
39
+
40
+ after_body {
41
+ return if colors.nil?
42
+
43
+ Thread.new {
44
+ colors.cycle { |color|
45
+ async_exec {
46
+ self.color = color
47
+ }
48
+ sleep(1)
49
+ }
50
+ }
51
+ }
52
+
53
+ body {
54
+ # pass received swt_style through to label to customize (e.g. :center to center text)
55
+ label(swt_style) {
56
+ text "#{greeting}, #{name}!"
57
+ font @font
58
+ foreground bind(self, :color)
59
+ }
60
+ }
61
+
62
+ end
63
+
64
+ # including Glimmer enables the Glimmer DSL syntax, including auto-discovery of the `greeting_label` custom widget
65
+ include Glimmer
66
+
67
+ shell {
68
+ fill_layout :vertical
69
+
70
+ minimum_size 215, 215
71
+ text 'Hello, Custom Widget!'
72
+
73
+ # custom widget options are passed in a hash
74
+ greeting_label(name: 'Sean')
75
+
76
+ # pass :center SWT style followed by custom widget options hash
77
+ greeting_label(:center, name: 'Laura', greeting: 'Aloha') #
78
+
79
+ greeting_label(:right, name: 'Rick') {
80
+ # you can nest attributes under custom widgets just like any standard widget
81
+ foreground :red
82
+ }
83
+
84
+ # the colors option cycles between colors for the label foreground every second
85
+ greeting_label(:center, name: 'Mary', greeting: 'Aloha', colors: [:red, :dark_green, :blue])
86
+ }.open