glimmer-dsl-swt 4.20.0.3 → 4.20.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4f8d4338c2993469fc740a390cb380bf9faf4c1c93d3993e517080d5599825f
4
- data.tar.gz: 3e82de8a5c35d17b0e92b741e3a750885842094b9ee4a8c9e5aac56419613551
3
+ metadata.gz: 76c2288c83bde07fd0e5db24556bd986b52c868db3db8dffd1f4cb4a82bd8085
4
+ data.tar.gz: 33f8584fd2ce2efac14d188a5d4753f6a807851529d663b1dbab1b57a4838db8
5
5
  SHA512:
6
- metadata.gz: 12b865d3c8e7e7a5a33928fea59a436d272a30f401171dfdf4e8464b5093c1c50db4f233af61b7af3e51ec8ddb53ebd67bff438f8525e3976acb50386a787fb9
7
- data.tar.gz: 8ce5f6eb7ec30624f9b140cdd994c414222cd0891daf3d212e93dfc76959413bdd53ddf4256a8dd55c530f8964a4b10962278a4b2c03cffc5045052e41a9dac4
6
+ metadata.gz: cbb93aa7d256686e409becd45a4e4a8bc4ca2597923a8b66118f3711aa8922a1b5d2b6ad62d615b6affdcf430533b1539118313c5eea95c81f94766c21a90486
7
+ data.tar.gz: 1c79ebfc57bf52c2d586ce65badaf0643ce37c534261943597d308bbd702e1fa01840f9d75164c80e9597c8e73f26d438ec95528321a8ba8f16b0d2048412814
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.20.0.4
4
+
5
+ - Weather elaborate sample
6
+
7
+ ### 4.20.0.3
8
+
9
+ - Hello, Shell! sample
10
+
11
+ ### 4.20.0.2
12
+
13
+ - Hello, Tool Bar! sample
14
+ - Hello, Cool Bar! sample
15
+
3
16
  ### 4.20.0.1
4
17
 
5
18
  - Hello, Composite! sample
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 SWT 4.20.0.3
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 SWT 4.20.0.4
2
2
  ## JRuby Desktop Development GUI Framework
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
4
4
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
@@ -15,7 +15,7 @@
15
15
  [<img src="https://covers.oreillystatic.com/images/9780596519650/lrg.jpg" width=105 /><br />
16
16
  Featured in JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do) and [Chalmers/Gothenburg University Software Engineering Master's Lecture Material](http://www.cse.chalmers.se/~bergert/slides/guest_lecture_DSLs.pdf)
17
17
 
18
- [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.0.3 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
18
+ [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.0.4 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
19
19
 
20
20
  **Starting in version 4.20.0.0, [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) comes with the new [***Shine***](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax** for highly intuitive and visually expressive View/Model Attribute Mapping, relying on `<=>` for bidirectional (two-way) data-binding and `<=` for unidirectional (one-way) data-binding, providing an alternative to the `bind` keyword (keep in mind that it is still an early alpha, so default back to `bind` whenever needed).
21
21
 
@@ -341,7 +341,7 @@ jgem install glimmer-dsl-swt
341
341
 
342
342
  Or this command if you want a specific version:
343
343
  ```
344
- jgem install glimmer-dsl-swt -v 4.20.0.3
344
+ jgem install glimmer-dsl-swt -v 4.20.0.4
345
345
  ```
346
346
 
347
347
  `jgem` is JRuby's version of `gem` command.
@@ -369,7 +369,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
369
369
 
370
370
  Add the following to `Gemfile`:
371
371
  ```
372
- gem 'glimmer-dsl-swt', '~> 4.20.0.3'
372
+ gem 'glimmer-dsl-swt', '~> 4.20.0.4'
373
373
  ```
374
374
 
375
375
  And, then run:
@@ -390,7 +390,7 @@ glimmer
390
390
  ```
391
391
 
392
392
  ```
393
- Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.0.3
393
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.0.4
394
394
 
395
395
  Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
396
396
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.20.0.3
1
+ 4.20.0.4
@@ -59,6 +59,7 @@
59
59
  - [Mandelbrot Fractal](#mandelbrot-fractal)
60
60
  - [Stock Ticker](#stock-ticker)
61
61
  - [Metronome](#metronome)
62
+ - [Weather](#weather)
62
63
  - [External Samples](#external-samples)
63
64
  - [Glimmer Calculator](#glimmer-calculator)
64
65
  - [Gladiator](#gladiator)
@@ -1053,6 +1054,26 @@ Code:
1053
1054
 
1054
1055
  [Download video with sound](/videos/glimmer-metronome.mp4?raw=true).
1055
1056
 
1057
+ #### Weather
1058
+
1059
+ This sample demonstrates a Weather app that leverages the Ruby built-in `'net/http'` library, courtesy of openweathermap.org. It provides a good example of tackling JSON hierarchical hash/array data and converting into data-bindable model object attributes for Glimmer GUI synchronization.
1060
+
1061
+ Code:
1062
+
1063
+ [samples/elaborate/weather.rb](/samples/elaborate/weather.rb)
1064
+
1065
+ Montreal - Celsius
1066
+
1067
+ ![Montreal C](/images/glimmer-weather-montreal-celsius.png)
1068
+
1069
+ Montreal - Fahrenheit
1070
+
1071
+ ![Montreal F](/images/glimmer-weather-montreal-fahrenheit.png)
1072
+
1073
+ Atlanta - Fahrenheit
1074
+
1075
+ ![Atlanta F](/images/glimmer-weather-atlanta-fahrenheit.png)
1076
+
1056
1077
  ### External Samples
1057
1078
 
1058
1079
  #### Glimmer Calculator
Binary file
@@ -35,24 +35,19 @@ class LoginPresenter
35
35
 
36
36
  def status=(status)
37
37
  @status = status
38
-
39
- notify_observers("logged_in")
40
- notify_observers("logged_out")
41
38
  end
42
39
 
43
40
  def valid?
44
41
  !@user_name.to_s.strip.empty? && !@password.to_s.strip.empty?
45
42
  end
46
43
 
47
- def logged_in
44
+ def logged_in?
48
45
  self.status == "Logged In"
49
46
  end
50
- alias logged_in? logged_in
51
47
 
52
- def logged_out
53
- !self.logged_in
48
+ def logged_out?
49
+ !self.logged_in?
54
50
  end
55
- alias logged_out? logged_out
56
51
 
57
52
  def login!
58
53
  return unless valid?
@@ -77,13 +72,15 @@ class Login
77
72
  body {
78
73
  shell {
79
74
  text "Login"
75
+
80
76
  composite {
81
77
  grid_layout 2, false #two columns with differing widths
82
78
 
83
79
  label { text "Username:" } # goes in column 1
84
80
  @user_name_text = text { # goes in column 2
85
81
  text <=> [@presenter, :user_name]
86
- enabled <= [@presenter, :logged_out]
82
+ enabled <= [@presenter, :logged_out?, computed_by: :status]
83
+
87
84
  on_key_pressed { |event|
88
85
  @password_text.set_focus if event.keyCode == swt(:cr)
89
86
  }
@@ -92,7 +89,8 @@ class Login
92
89
  label { text "Password:" }
93
90
  @password_text = text(:password, :border) {
94
91
  text <=> [@presenter, :password]
95
- enabled <= [@presenter, :logged_out]
92
+ enabled <= [@presenter, :logged_out?, computed_by: :status]
93
+
96
94
  on_key_pressed { |event|
97
95
  @presenter.login! if event.keyCode == swt(:cr)
98
96
  }
@@ -103,16 +101,20 @@ class Login
103
101
 
104
102
  button {
105
103
  text "Login"
106
- enabled <= [@presenter, :logged_out]
104
+ enabled <= [@presenter, :logged_out?, computed_by: :status]
105
+
107
106
  on_widget_selected { @presenter.login! }
108
107
  on_key_pressed { |event|
109
- @presenter.login! if event.keyCode == swt(:cr)
108
+ if event.keyCode == swt(:cr)
109
+ @presenter.login!
110
+ end
110
111
  }
111
112
  }
112
113
 
113
114
  button {
114
115
  text "Logout"
115
- enabled <= [@presenter, :logged_in]
116
+ enabled <= [@presenter, :logged_in?, computed_by: :status]
117
+
116
118
  on_widget_selected { @presenter.logout! }
117
119
  on_key_pressed { |event|
118
120
  if event.keyCode == swt(:cr)
@@ -0,0 +1,164 @@
1
+ # Copyright (c) 2007-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 'net/http'
23
+ require 'json'
24
+ require 'facets/string/titlecase'
25
+ require 'glimmer-dsl-swt'
26
+
27
+ class Weather
28
+ include Glimmer::UI::CustomShell
29
+
30
+ DEFAULT_FONT_HEIGHT = 30
31
+ DEFAULT_FOREGROUND = :white
32
+
33
+ attr_accessor :city, :temp, :temp_min, :temp_max, :feels_like, :humidity
34
+
35
+ before_body {
36
+ @weather_mutex = Mutex.new
37
+ self.city = 'Montreal, QC, CA'
38
+ fetch_weather!
39
+ }
40
+
41
+ after_body {
42
+ Thread.new do
43
+ loop do
44
+ sleep(10)
45
+ break if body_root.disposed?
46
+ fetch_weather!
47
+ end
48
+ end
49
+ }
50
+
51
+ body {
52
+ shell(:no_resize) {
53
+ grid_layout
54
+
55
+ text 'Glimmer Weather'
56
+ minimum_size 400, 300
57
+ background rgb(135, 176, 235)
58
+
59
+ text {
60
+ layout_data(:center, :center, true, true)
61
+
62
+ text <=> [self, :city]
63
+
64
+ on_key_pressed {|event|
65
+ if event.keyCode == swt(:cr) # carriage return
66
+ Thread.new do
67
+ fetch_weather!
68
+ end
69
+ end
70
+ }
71
+ }
72
+
73
+ tab_folder {
74
+ layout_data(:center, :center, true, true)
75
+
76
+ ['℃', '℉'].each do |temp_unit|
77
+ tab_item {
78
+ grid_layout 2, false
79
+
80
+ text temp_unit
81
+ background :transparent
82
+
83
+ rectangle(0, 0, [:default, -2], [:default, -2], 15, 15) {
84
+ foreground DEFAULT_FOREGROUND
85
+ }
86
+
87
+ %w[temp temp_min temp_max feels_like].each do |field_name|
88
+ temp_field(field_name, temp_unit)
89
+ end
90
+
91
+ humidity_field
92
+ }
93
+ end
94
+ }
95
+ }
96
+ }
97
+
98
+ def temp_field(field_name, temp_unit)
99
+ name_label(field_name)
100
+ label {
101
+ layout_data(:fill, :center, true, false)
102
+ text <= [self, field_name, on_read: ->(t) { "#{kelvin_to_temp_unit(t, temp_unit).to_f.round}°" }]
103
+ font height: DEFAULT_FONT_HEIGHT
104
+ foreground DEFAULT_FOREGROUND
105
+ }
106
+ end
107
+
108
+ def humidity_field
109
+ name_label('humidity')
110
+ label {
111
+ layout_data(:fill, :center, true, false)
112
+ text <= [self, 'humidity', on_read: ->(h) { "#{h.to_f.round}%" }]
113
+ font height: DEFAULT_FONT_HEIGHT
114
+ foreground DEFAULT_FOREGROUND
115
+ }
116
+ end
117
+
118
+ def name_label(field_name)
119
+ label {
120
+ layout_data :fill, :center, false, false
121
+ text field_name.titlecase
122
+ font height: DEFAULT_FONT_HEIGHT
123
+ foreground DEFAULT_FOREGROUND
124
+ }
125
+ end
126
+
127
+ def fetch_weather!
128
+ @weather_mutex.synchronize do
129
+ self.weather_data = JSON.parse(Net::HTTP.get('api.openweathermap.org', "/data/2.5/weather?q=#{city}&appid=1d16d70a9aec3570b5cbd27e6b421330"))
130
+ end
131
+ rescue
132
+ # No Op
133
+ end
134
+
135
+ def weather_data=(data)
136
+ @weather_data = data
137
+ main_data = data['main']
138
+ # temps come back in Kelvin
139
+ self.temp = main_data['temp']
140
+ self.temp_min = main_data['temp_min']
141
+ self.temp_max = main_data['temp_max']
142
+ self.feels_like = main_data['feels_like']
143
+ self.humidity = main_data['humidity']
144
+ end
145
+
146
+ def kelvin_to_temp_unit(kelvin, temp_unit)
147
+ temp_unit == '℃' ? kelvin_to_celsius(kelvin) : kelvin_to_fahrenheit(kelvin)
148
+ end
149
+
150
+ def kelvin_to_celsius(kelvin)
151
+ kelvin - 273.15
152
+ end
153
+
154
+ def celsius_to_fahrenheit(celsius)
155
+ (celsius * 9 / 5 ) + 32
156
+ end
157
+
158
+ def kelvin_to_fahrenheit(kelvin)
159
+ celsius_to_fahrenheit(kelvin_to_celsius(kelvin))
160
+ end
161
+
162
+ end
163
+
164
+ Weather.launch
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swt
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.20.0.3
4
+ version: 4.20.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-04 00:00:00.000000000 Z
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -529,6 +529,7 @@ files:
529
529
  - samples/elaborate/tic_tac_toe/board.rb
530
530
  - samples/elaborate/tic_tac_toe/cell.rb
531
531
  - samples/elaborate/user_profile.rb
532
+ - samples/elaborate/weather.rb
532
533
  - samples/hello/hello_browser.rb
533
534
  - samples/hello/hello_button.rb
534
535
  - samples/hello/hello_c_combo.rb