-
Notifications
You must be signed in to change notification settings - Fork 0
/
such_parts_demo
76 lines (66 loc) · 1.9 KB
/
such_parts_demo
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
#! ruby
require 'gtk3'
require 'such'
Such::Things.in Gtk::Widget
Such::Thing.configure(
button_size: {set_size_request: [30,70]},
# The :x! Button
X: [label: 'X'],
x: :button_size,
# The :y! Button
Y: [label: 'Y'],
y: :button_size,
# The :z! Button
Z: [label: 'Z'],
z: :button_size,
# The :mybox! Vertical Box
MYBOX: [:vertical],
mybox!: [:MYBOX, {}, ''],
# The :app! Window
app: {
set_border_width: 10,
set_title: 'Parts',
set_default_size: [260,150],
set_window_position: :center,
},
app!: [:app, 'destroy']
)
# App will be a Window that connects to a MyBox.new(:mybox!)
Such::Parts.make(:App, Such::Window, :mybox_MyBox)
# MyBox will be a Box that connects to a Button.new(:x!) and Button.new(:y!)
Such::Parts.make(:MyBox, Such::Box, :x_Button, :y_Button, :z_Button)
# Note that all connected widgets can respond to the block given.
app = Such::App.new(:app!) do |widget, *w, signal|
case widget
when Such::Window
Gtk.main_quit if signal=='destroy'
when Such::Button
if signal=='clicked'
case widget.label
when /^X/
app.message(:red)
X.set_label 'X: :D'
Y.set_label 'Y: :('
Z.set_label 'Z: Noooo!'
when /^Y/
app.message(:green)
X.set_label 'X: Wut???'
Y.set_label 'Y: Ha ha!'
Z.set_label 'Z: :P'
when /^Z/
app.message(:blue)
X.set_label 'X: Oh no you didnt!!!'
Y.set_label 'Y: Figures...'
Z.set_label 'Z: Yeah baby!'
end
end
end
end
# Demonstrates app's missing_method search for the plugs:
X,Y,Z = app.x_Button,app.y_Button,app.z_Button
# Demonstrates broadcast messaging
def X.message(color) = override_color(:normal,color)
def Y.message(color) = override_color(:normal,{red: :blue, green: :red, blue: :green}[color])
def Z.message(color) = override_color(:normal,{red: :green, green: :blue, blue: :red}[color])
app.show_all
Gtk.main