glimmer-dsl-opal 0.10.3 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +257 -0
  3. data/README.md +188 -1300
  4. data/VERSION +1 -1
  5. data/app/controllers/glimmer/application_controller.rb +4 -0
  6. data/app/controllers/glimmer/image_paths_controller.rb +41 -0
  7. data/app/views/glimmer/image_paths/index.html.erb +1 -0
  8. data/{lib/glimmer-dsl-opal/samples/hello/hello_computed/contact.rb → config/routes.rb} +2 -20
  9. data/lib/display.rb +3 -0
  10. data/lib/glimmer-dsl-opal.rb +8 -3
  11. data/lib/glimmer-dsl-opal/ext/file.rb +31 -0
  12. data/lib/glimmer-dsl-opal/ext/glimmer/dsl/engine.rb +1 -1
  13. data/lib/glimmer-dsl-opal/samples/elaborate/contact_manager.rb +15 -13
  14. data/lib/glimmer-dsl-opal/samples/elaborate/login.rb +55 -28
  15. data/lib/glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb +2 -2
  16. data/lib/glimmer-dsl-opal/samples/elaborate/weather.rb +157 -0
  17. data/lib/glimmer-dsl-opal/samples/hello/hello_button.rb +8 -8
  18. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox.rb +16 -14
  19. data/lib/glimmer-dsl-opal/samples/hello/hello_checkbox_group.rb +14 -9
  20. data/lib/glimmer-dsl-opal/samples/hello/hello_combo.rb +24 -22
  21. data/lib/glimmer-dsl-opal/samples/hello/hello_computed.rb +32 -14
  22. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_shell.rb +16 -12
  23. data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +1 -1
  24. data/lib/glimmer-dsl-opal/samples/hello/hello_date_time.rb +4 -4
  25. data/lib/glimmer-dsl-opal/samples/hello/hello_group.rb +6 -6
  26. data/lib/glimmer-dsl-opal/samples/hello/hello_list_multi_selection.rb +1 -1
  27. data/lib/glimmer-dsl-opal/samples/hello/hello_list_single_selection.rb +1 -1
  28. data/lib/glimmer-dsl-opal/samples/hello/hello_radio.rb +18 -16
  29. data/lib/glimmer-dsl-opal/samples/hello/hello_radio_group.rb +17 -12
  30. data/lib/glimmer-dsl-opal/samples/hello/hello_table.rb +31 -23
  31. data/lib/glimmer-dsl-opal/samples/hello/hello_table/baseball_park.png +0 -0
  32. data/lib/glimmer/data_binding/table_items_binding.rb +3 -2
  33. data/lib/glimmer/dsl/opal/bind_expression.rb +24 -25
  34. data/lib/glimmer/dsl/opal/custom_widget_expression.rb +7 -7
  35. data/lib/glimmer/dsl/opal/dsl.rb +2 -0
  36. data/lib/glimmer/dsl/opal/menu_expression.rb +1 -1
  37. data/lib/glimmer/dsl/opal/property_expression.rb +2 -1
  38. data/lib/glimmer/dsl/opal/shape_expression.rb +1 -1
  39. data/lib/glimmer/dsl/opal/shell_expression.rb +1 -1
  40. data/lib/glimmer/dsl/opal/shine_data_binding_expression.rb +49 -0
  41. data/lib/glimmer/dsl/opal/table_items_data_binding_expression.rb +2 -2
  42. data/lib/glimmer/dsl/opal/widget_expression.rb +1 -1
  43. data/lib/glimmer/engine.rb +21 -0
  44. data/lib/glimmer/swt/combo_proxy.rb +1 -0
  45. data/lib/glimmer/swt/composite_proxy.rb +34 -0
  46. data/lib/glimmer/swt/dialog_proxy.rb +1 -1
  47. data/lib/glimmer/swt/display_proxy.rb +1 -0
  48. data/lib/glimmer/swt/layout_proxy.rb +23 -3
  49. data/lib/glimmer/swt/message_box_proxy.rb +1 -1
  50. data/lib/glimmer/swt/shell_proxy.rb +43 -0
  51. data/lib/glimmer/swt/table_item_proxy.rb +3 -0
  52. data/lib/glimmer/swt/table_proxy.rb +19 -3
  53. data/lib/glimmer/swt/widget_proxy.rb +3 -4
  54. data/lib/glimmer/ui/custom_shell.rb +13 -10
  55. data/lib/glimmer/ui/custom_widget.rb +11 -2
  56. data/lib/net/http.rb +15 -6
  57. metadata +20 -12
@@ -20,27 +20,27 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  class HelloButton
23
- include Glimmer
23
+ include Glimmer::UI::CustomShell
24
24
 
25
25
  attr_accessor :count
26
26
 
27
- def initialize
27
+ before_body {
28
28
  @count = 0
29
- end
29
+ }
30
30
 
31
- def launch
31
+ body {
32
32
  shell {
33
33
  text 'Hello, Button!'
34
34
 
35
35
  button {
36
- text bind(self, :count) {|value| "Click To Increment: #{value} "}
36
+ text <= [self, :count, on_read: ->(value) { "Click To Increment: #{value} " }]
37
37
 
38
38
  on_widget_selected {
39
39
  self.count += 1
40
40
  }
41
41
  }
42
- }.open
43
- end
42
+ }
43
+ }
44
44
  end
45
45
 
46
- HelloButton.new.launch
46
+ HelloButton.launch
@@ -24,10 +24,10 @@ class HelloCheckbox
24
24
  attr_accessor :skiing, :snowboarding, :snowmobiling, :snowshoeing
25
25
 
26
26
  def initialize
27
- reset_activities
27
+ reset_activities!
28
28
  end
29
29
 
30
- def reset_activities
30
+ def reset_activities!
31
31
  self.skiing = false
32
32
  self.snowboarding = true
33
33
  self.snowmobiling = false
@@ -35,11 +35,13 @@ class HelloCheckbox
35
35
  end
36
36
  end
37
37
 
38
- include Glimmer
38
+ include Glimmer::UI::CustomShell
39
39
 
40
- def launch
41
- person = Person.new
42
-
40
+ before_body {
41
+ @person = Person.new
42
+ }
43
+
44
+ body {
43
45
  shell {
44
46
  text 'Hello, Checkbox!'
45
47
  row_layout :vertical
@@ -52,22 +54,22 @@ class HelloCheckbox
52
54
  composite {
53
55
  checkbox {
54
56
  text 'Skiing'
55
- selection bind(person, :skiing)
57
+ selection <=> [@person, :skiing]
56
58
  }
57
59
 
58
60
  checkbox {
59
61
  text 'Snowboarding'
60
- selection bind(person, :snowboarding)
62
+ selection <=> [@person, :snowboarding]
61
63
  }
62
64
 
63
65
  checkbox {
64
66
  text 'Snowmobiling'
65
- selection bind(person, :snowmobiling)
67
+ selection <=> [@person, :snowmobiling]
66
68
  }
67
69
 
68
70
  checkbox {
69
71
  text 'Snowshoeing'
70
- selection bind(person, :snowshoeing)
72
+ selection <=> [@person, :snowshoeing]
71
73
  }
72
74
  }
73
75
 
@@ -75,11 +77,11 @@ class HelloCheckbox
75
77
  text 'Reset Activities'
76
78
 
77
79
  on_widget_selected do
78
- person.reset_activities
80
+ @person.reset_activities!
79
81
  end
80
82
  }
81
- }.open
82
- end
83
+ }
84
+ }
83
85
  end
84
86
 
85
- HelloCheckbox.new.launch
87
+ HelloCheckbox.launch
@@ -19,6 +19,9 @@
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
+ # This sample demonstrates the use of a `checkbox_group` (aka `check_group`) in Glimmer, which provides terser syntax
23
+ # than HelloCheckbox for representing multiple checkbox buttons (`button(:check)`) by relying on data-binding to
24
+ # automatically spawn the `checkbox` widgets (`button(:check)`) based on available options on the model.
22
25
  class HelloCheckboxGroup
23
26
  class Person
24
27
  attr_accessor :activities
@@ -36,11 +39,13 @@ class HelloCheckboxGroup
36
39
  end
37
40
  end
38
41
 
39
- include Glimmer
42
+ include Glimmer::UI::CustomShell
40
43
 
41
- def launch
42
- person = Person.new
43
-
44
+ before_body {
45
+ @person = Person.new
46
+ }
47
+
48
+ body {
44
49
  shell {
45
50
  text 'Hello, Checkbox Group!'
46
51
  row_layout :vertical
@@ -51,18 +56,18 @@ class HelloCheckboxGroup
51
56
  }
52
57
 
53
58
  checkbox_group {
54
- selection bind(person, :activities)
59
+ selection <=> [@person, :activities]
55
60
  }
56
61
 
57
62
  button {
58
63
  text 'Reset Activities'
59
64
 
60
65
  on_widget_selected do
61
- person.reset_activities
66
+ @person.reset_activities
62
67
  end
63
68
  }
64
- }.open
65
- end
69
+ }
70
+ }
66
71
  end
67
72
 
68
- HelloCheckboxGroup.new.launch
73
+ HelloCheckboxGroup.launch
@@ -19,45 +19,47 @@
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
- class Person
23
- attr_accessor :country, :country_options
24
-
25
- def initialize
26
- self.country_options = ['', 'Canada', 'US', 'Mexico']
27
- reset_country
28
- end
29
-
30
- def reset_country
31
- self.country = 'Canada'
22
+ class HelloCombo
23
+ class Person
24
+ attr_accessor :country, :country_options
25
+
26
+ def initialize
27
+ self.country_options = ['', 'Canada', 'US', 'Mexico']
28
+ reset_country!
29
+ end
30
+
31
+ def reset_country!
32
+ self.country = 'Canada'
33
+ end
32
34
  end
33
- end
34
35
 
35
- class HelloCombo
36
- include Glimmer
36
+ include Glimmer::UI::CustomShell
37
37
 
38
- def launch
39
- person = Person.new
40
-
38
+ before_body {
39
+ @person = Person.new
40
+ }
41
+
42
+ body {
41
43
  shell {
42
44
  row_layout(:vertical) {
43
- pack false
45
+ fill true
44
46
  }
45
47
 
46
48
  text 'Hello, Combo!'
47
49
 
48
50
  combo(:read_only) {
49
- selection bind(person, :country)
51
+ selection <=> [@person, :country] # also binds to country_options by convention
50
52
  }
51
53
 
52
54
  button {
53
55
  text 'Reset Selection'
54
56
 
55
57
  on_widget_selected do
56
- person.reset_country
58
+ @person.reset_country!
57
59
  end
58
60
  }
59
- }.open
60
- end
61
+ }
62
+ }
61
63
  end
62
64
 
63
- HelloCombo.new.launch
65
+ HelloCombo.launch
@@ -19,20 +19,38 @@
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_relative 'hello_computed/contact'
23
-
24
22
  class HelloComputed
25
- include Glimmer
23
+ class Contact
24
+ attr_accessor :first_name, :last_name, :year_of_birth
25
+
26
+ def initialize(attribute_map)
27
+ @first_name = attribute_map[:first_name]
28
+ @last_name = attribute_map[:last_name]
29
+ @year_of_birth = attribute_map[:year_of_birth]
30
+ end
31
+
32
+ def name
33
+ "#{last_name}, #{first_name}"
34
+ end
35
+
36
+ def age
37
+ Time.now.year - year_of_birth.to_i
38
+ rescue
39
+ 0
40
+ end
41
+ end
42
+
43
+ include Glimmer::UI::CustomShell
26
44
 
27
- def initialize
45
+ before_body {
28
46
  @contact = Contact.new(
29
47
  first_name: 'Barry',
30
48
  last_name: 'McKibbin',
31
49
  year_of_birth: 1985
32
50
  )
33
- end
51
+ }
34
52
 
35
- def launch
53
+ body {
36
54
  shell {
37
55
  text 'Hello, Computed!'
38
56
 
@@ -46,7 +64,7 @@ class HelloComputed
46
64
 
47
65
  label {text 'First &Name: '}
48
66
  text {
49
- text bind(@contact, :first_name)
67
+ text <=> [@contact, :first_name]
50
68
  layout_data {
51
69
  horizontal_alignment :fill
52
70
  grab_excess_horizontal_space true
@@ -55,7 +73,7 @@ class HelloComputed
55
73
 
56
74
  label {text '&Last Name: '}
57
75
  text {
58
- text bind(@contact, :last_name)
76
+ text <=> [@contact, :last_name]
59
77
  layout_data {
60
78
  horizontal_alignment :fill
61
79
  grab_excess_horizontal_space true
@@ -64,7 +82,7 @@ class HelloComputed
64
82
 
65
83
  label {text '&Year of Birth: '}
66
84
  text {
67
- text bind(@contact, :year_of_birth)
85
+ text <=> [@contact, :year_of_birth]
68
86
  layout_data {
69
87
  horizontal_alignment :fill
70
88
  grab_excess_horizontal_space true
@@ -73,7 +91,7 @@ class HelloComputed
73
91
 
74
92
  label {text 'Name: '}
75
93
  label {
76
- text bind(@contact, :name, computed_by: [:first_name, :last_name])
94
+ text <= [@contact, :name, computed_by: [:first_name, :last_name]]
77
95
  layout_data {
78
96
  horizontal_alignment :fill
79
97
  grab_excess_horizontal_space true
@@ -82,15 +100,15 @@ class HelloComputed
82
100
 
83
101
  label {text 'Age: '}
84
102
  label {
85
- text bind(@contact, :age, on_write: :to_i, computed_by: [:year_of_birth])
103
+ text <= [@contact, :age, on_write: :to_i, computed_by: [:year_of_birth]]
86
104
  layout_data {
87
105
  horizontal_alignment :fill
88
106
  grab_excess_horizontal_space true
89
107
  }
90
108
  }
91
109
  }
92
- }.open
93
- end
110
+ }
111
+ }
94
112
  end
95
113
 
96
- HelloComputed.new.launch
114
+ HelloComputed.launch
@@ -24,10 +24,11 @@ require 'date'
24
24
  # This class declares an `email_shell` custom shell, aka custom window (by convention)
25
25
  # Used to view an email message
26
26
  class EmailShell
27
+ # including Glimmer::UI::CustomShell enables declaring as an `email_shell` custom widget Glimmer GUI DSL keyword
27
28
  include Glimmer::UI::CustomShell
28
29
 
29
30
  # multiple options without default values
30
- options :date, :subject, :from, :message
31
+ options :parent_shell, :date, :subject, :from, :message
31
32
 
32
33
  # single option with default value
33
34
  option :to, default: '"John Irwin" <john.irwin@example.com>'
@@ -38,7 +39,7 @@ class EmailShell
38
39
 
39
40
  body {
40
41
  # pass received swt_style through to shell to customize it (e.g. :dialog_trim for a blocking shell)
41
- shell(swt_style) {
42
+ shell(parent_shell, swt_style) {
42
43
  grid_layout(2, false)
43
44
 
44
45
  text subject
@@ -73,7 +74,7 @@ class EmailShell
73
74
 
74
75
  label {
75
76
  layout_data(:fill, :fill, true, true) {
76
- horizontal_span 2 #TODO implement
77
+ horizontal_span 2
77
78
  vertical_indent 10
78
79
  }
79
80
 
@@ -86,9 +87,8 @@ class EmailShell
86
87
  end
87
88
 
88
89
  class HelloCustomShell
89
- # including Glimmer enables the Glimmer DSL syntax, including auto-discovery of the `email_shell` custom widget
90
90
  include Glimmer
91
-
91
+
92
92
  Email = Struct.new(:date, :subject, :from, :message, keyword_init: true)
93
93
  EmailSystem = Struct.new(:emails, keyword_init: true)
94
94
 
@@ -106,7 +106,7 @@ class HelloCustomShell
106
106
  end
107
107
 
108
108
  def launch
109
- shell {
109
+ shell { |shell_proxy|
110
110
  grid_layout
111
111
 
112
112
  text 'Hello, Custom Shell!'
@@ -137,15 +137,19 @@ class HelloCustomShell
137
137
  width 360
138
138
  }
139
139
 
140
- items bind(@email_system, :emails), column_properties(:date, :subject, :from)
140
+ items <=> [@email_system, :emails, column_attributes: [:date, :subject, :from]]
141
141
 
142
142
  on_mouse_up { |event|
143
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
144
+
145
+ # open a custom email shell
146
+ email_shell(
147
+ parent_shell: shell_proxy,
148
+ date: email.date,
149
+ subject: email.subject,
150
+ from: email.from,
151
+ message: email.message
152
+ ).open
149
153
  }
150
154
  }
151
155
  }.open
@@ -55,7 +55,7 @@ class GreetingLabel
55
55
  label(swt_style) {
56
56
  text "#{greeting}, #{name}!"
57
57
  font @font
58
- foreground bind(self, :color)
58
+ foreground <= [self, :color]
59
59
  }
60
60
  }
61
61
 
@@ -42,19 +42,19 @@ class HelloDateTime
42
42
  }
43
43
 
44
44
  date { # alias for date_time(:date)
45
- date_time bind(person, :date_of_birth)
45
+ date_time <=> [person, :date_of_birth]
46
46
  }
47
47
 
48
48
  date_drop_down { # alias for date_time(:date, :drop_down)
49
- date_time bind(person, :date_of_birth)
49
+ date_time <=> [person, :date_of_birth]
50
50
  }
51
51
 
52
52
  time { # alias for date_time(:time)
53
- date_time bind(person, :date_of_birth)
53
+ date_time <=> [person, :date_of_birth]
54
54
  }
55
55
 
56
56
  calendar { # alias for date_time(:calendar)
57
- date_time bind(person, :date_of_birth)
57
+ date_time <=> [person, :date_of_birth]
58
58
  }
59
59
  }.open
60
60
  end
@@ -54,12 +54,12 @@ class HelloGroup
54
54
 
55
55
  radio {
56
56
  text 'Male'
57
- selection bind(person, :male)
57
+ selection <=> [person, :male]
58
58
  }
59
59
 
60
60
  radio {
61
61
  text 'Female'
62
- selection bind(person, :female)
62
+ selection <=> [person, :female]
63
63
  }
64
64
  }
65
65
 
@@ -71,22 +71,22 @@ class HelloGroup
71
71
 
72
72
  radio {
73
73
  text 'Child'
74
- selection bind(person, :child)
74
+ selection <=> [person, :child]
75
75
  }
76
76
 
77
77
  radio {
78
78
  text 'Teen'
79
- selection bind(person, :teen)
79
+ selection <=> [person, :teen]
80
80
  }
81
81
 
82
82
  radio {
83
83
  text 'Adult'
84
- selection bind(person, :adult)
84
+ selection <=> [person, :adult]
85
85
  }
86
86
 
87
87
  radio {
88
88
  text 'Senior'
89
- selection bind(person, :senior)
89
+ selection <=> [person, :senior]
90
90
  }
91
91
  }
92
92