-
Notifications
You must be signed in to change notification settings - Fork 6
/
hello_tray_item.rb
129 lines (115 loc) · 3.76 KB
/
hello_tray_item.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright (c) 2007-2024 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'glimmer-dsl-swt'
class HelloTrayItem
include Glimmer::UI::CustomShell
# boolean that indicates if application is visible
attr_accessor :show_application
before_body do
# application starts visible
@show_application = true
# pre-render an icon image using the Canvas Shape DSL
@image = image(16, 16) {
rectangle(0, 0, 16, 16) {
background :black
}
oval(1, 1, [:default, - 2], [:default, - 2]) {
foreground :white
}
oval(3, 3, [:default, - 6], [:default, - 6]) {
foreground :white
}
oval(5, 5, [:default, - 10], [:default, - 10]) {
foreground :white
}
oval(7, 7, [:default, - 14], [:default, - 14]) {
foreground :white
}
}
end
body {
shell(:shell_trim, :on_top) { # make it always appear on top of everything
row_layout(:vertical) {
center true
}
text 'Hello, Tray Item!'
on_shell_closed do |event|
# do not perform event that closes app when shell is closed
event.doit = false
# body_root is the root shell
body_root.hide
self.show_application = false # updates Show Application checkbox menu item indirectly
end
tray_item {
tool_tip_text 'Glimmer'
image @image # could use an image path instead
menu {
menu_item {
text 'About'
on_widget_selected do
message_box {
text 'Glimmer - About'
message 'This is a Glimmer DSL for SWT Tray Item'
}.open
end
}
menu_item(:separator)
menu_item(:check) {
text 'Show Application'
selection <=> [self, :show_application]
on_widget_selected do
# body_root is the root shell
if body_root.visible?
body_root.hide
else
body_root.show
end
end
}
menu_item(:separator)
menu_item {
text 'Exit'
on_widget_selected do
exit(0)
end
}
}
# supported tray item listeners (you can try to add actions to them when needed)
# on_widget_selected do
# end
#
# on_menu_detected do
# end
}
label(:center) {
text 'This is the application'
font height: 30
}
label {
text 'Click on the tray item (circles icon) to open its menu'
}
label {
text 'Uncheck Show Application to hide the app and recheck it to show the app'
}
}
}
end
HelloTrayItem.launch