Skip to content

Commit

Permalink
Hello, Custom Shell! sample
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyObtiva committed Oct 2, 2020
1 parent fe5a2e4 commit 4996188
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add `--bundler=group` option to `glimmer` command
- Add `--pd` option to `glimmer` command
- Hello, Custom Widget! sample
- Hello, Custom Shell! sample

### 4.17.2.0

Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3627,6 +3627,25 @@ glimmer sample:run[hello_custom_widget]

![Hello Custom Widget](images/glimmer-hello-custom-widget.gif)

#### Hello, Custom Shell!

This sample demonstrates the use of a custom shell (aka custom window) in Glimmer.

Code:

[samples/hello/hello_custom_shell.rb](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/samples/hello/hello_custom_shell.rb)

Run:

```
glimmer sample:run[hello_custom_shell]
```

![Hello Custom Shell](images/glimmer-hello-custom-shell.png)
![Hello Custom Shell Email1](images/glimmer-hello-custom-shell-email1.png)
![Hello Custom Shell Email2](images/glimmer-hello-custom-shell-email2.png)
![Hello Custom Shell Email3](images/glimmer-hello-custom-shell-email3.png)

### Elaborate Samples

For more elaborate samples, check the following:
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ items <=> binding {
- Link to SWT Maven repositories using jar-dependencies: https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.swt.gtk.linux.aarch64
- Auto-refresh GUI from changes in rb files
- Load development gems for "package" tasks
- Make property setting inside a widget inside a custom shell body block not die silently when there is a Ruby error (e.g. invalid constant)

## Samples

Expand Down
Binary file added images/glimmer-hello-custom-shell-email1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/glimmer-hello-custom-shell-email2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/glimmer-hello-custom-shell-email3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/glimmer-hello-custom-shell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions lib/glimmer/swt/widget_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ def property_type_converters
end
# TODO consider detecting type on widget method and automatically invoking right converter (e.g. :to_s for String, :to_i for Integer)
@property_type_converters ||= {
alignment: -> (*value) {
SWTProxy[*value]
},
:background => color_converter,
:background_image => lambda do |value|
image_proxy = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/glimmer/ui/custom_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def execute_hooks(hook_name)
send(temp_method_name)
singleton_class.send(:remove_method, temp_method_name)
end
end
end
end
end
end
134 changes: 134 additions & 0 deletions samples/hello/hello_custom_shell.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
require 'date'

# This class declares an `email_shell` custom shell, aka custom window (by convention)
# Used to view an email message
class EmailShell
include Glimmer::UI::CustomShell

# multiple options without default values
options :date, :subject, :from, :message

# single option with default value
option :to, default: '"John Irwin" <[email protected]>'

before_body {
@swt_style |= swt(:shell_trim, :modeless)
}

body {
# pass received swt_style through to shell to customize it (e.g. :dialog_trim for a blocking shell)
shell(swt_style) {
grid_layout(2, false)

text subject

label {
text 'Date:'
}
label {
text date
}

label {
text 'From:'
}
label {
text from
}

label {
text 'To:'
}
label {
text to
}

label {
text 'Subject:'
}
label {
text subject
}

label {
layout_data(:fill, :fill, true, true) {
horizontal_span 2
verticalIndent 10
}

background :white
text message
}
}
}

end

class HelloCustomShell
# including Glimmer enables the Glimmer DSL syntax, including auto-discovery of the `email_shell` custom widget
include Glimmer

Email = Struct.new(:date, :subject, :from, :message, keyword_init: true)
EmailSystem = Struct.new(:emails, keyword_init: true)

def initialize
@email_system = EmailSystem.new(
emails: [
Email.new(date: DateTime.new(2029, 10, 22, 11, 3, 0).strftime('%F %I:%M %p'), subject: '3rd Week Report', from: '"Dianne Tux" <[email protected]>', message: "Hello,\n\nI was wondering if you'd like to go over the weekly report sometime this afternoon.\n\nDianne"),
Email.new(date: DateTime.new(2029, 10, 21, 8, 1, 0).strftime('%F %I:%M %p'), subject: 'Glimmer Upgrade v100.0', from: '"Robert McGabbins" <[email protected]>', message: "Team,\n\nWe are upgrading to Glimmer version 100.0.\n\nEveryone pull the latest code!\n\nRegards,\n\nRobert McGabbins"),
Email.new(date: DateTime.new(2029, 10, 19, 16, 58, 0).strftime('%F %I:%M %p'), subject: 'Christmas Party', from: '"Lisa Ferreira" <[email protected]>', 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"),
Email.new(date: DateTime.new(2029, 10, 16, 9, 43, 0).strftime('%F %I:%M %p'), subject: 'Glimmer Upgrade v99.0', from: '"Robert McGabbins" <[email protected]>', message: "Team,\n\nWe are upgrading to Glimmer version 99.0.\n\nEveryone pull the latest code!\n\nRegards,\n\nRobert McGabbins"),
Email.new(date: DateTime.new(2029, 10, 15, 11, 2, 0).strftime('%F %I:%M %p'), subject: '2nd Week Report', from: '"Dianne Tux" <[email protected]>', message: "Hello,\n\nI was wondering if you'd like to go over the weekly report sometime this afternoon.\n\nDianne"),
Email.new(date: DateTime.new(2029, 10, 2, 10, 34, 0).strftime('%F %I:%M %p'), subject: 'Glimmer Upgrade v98.0', from: '"Robert McGabbins" <[email protected]>', message: "Team,\n\nWe are upgrading to Glimmer version 98.0.\n\nEveryone pull the latest code!\n\nRegards,\n\nRobert McGabbins"),
]
)
end

def launch
shell {
grid_layout

text 'Hello, Custom Shell!'

label {
font height: 24, style: :bold
text 'Emails:'
}

label {
font height: 18
text 'Click an email to view its message'
}

table {
layout_data :fill, :fill, true, true

table_column {
text 'Date:'
width 180
}
table_column {
text 'Subject:'
width 180
}
table_column {
text 'From:'
width 360
}

items bind(@email_system, :emails), column_properties(:date, :subject, :from)

on_mouse_up { |event|
email = event.table_item.get_data
Thread.new do
async_exec {
email_shell(date: email.date, subject: email.subject, from: email.from, message: email.message).open
}
end
}
}
}.open
end
end

HelloCustomShell.new.launch
3 changes: 2 additions & 1 deletion samples/hello/hello_custom_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class GreetingLabel
}

body {
label(swt_style) { # pass received swt_style through to label
# pass received swt_style through to label to customize (e.g. :center to center text)
label(swt_style) {
text "#{greeting}, #{name}!"
font @font
foreground bind(self, :color)
Expand Down

0 comments on commit 4996188

Please sign in to comment.