GtkSimpleLayout 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +339 -0
- data/README +47 -0
- data/Rakefile +18 -0
- data/example/auto_event_map.rb +60 -0
- data/example/basic.rb +36 -0
- data/example/calculator.rb +64 -0
- data/example/composit_layout.rb +26 -0
- data/example/expose_components.rb +35 -0
- data/example/group.rb +70 -0
- data/example/hello_world.rb +23 -0
- data/example/menu.rb +54 -0
- data/example/serial_port_setup.rb +85 -0
- data/example/with_attr.rb +44 -0
- data/lib/simple_layout.rb +488 -0
- metadata +78 -0
data/example/basic.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
my_layout
|
9
|
+
signal_connect('destroy') do
|
10
|
+
Gtk.main_quit
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def my_layout
|
15
|
+
vbox do
|
16
|
+
frame 'frame 1' do
|
17
|
+
hbox do
|
18
|
+
label 'Label 1'
|
19
|
+
button 'Button 1, fixed'
|
20
|
+
button "Button 2, I'm flexiable", :layout => [true, true]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
frame 'frame 2' do
|
24
|
+
vbox do
|
25
|
+
label 'Label 2'
|
26
|
+
label 'Label 3'
|
27
|
+
button 'Button 3'
|
28
|
+
button 'Button 4'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
MyWin.new.show_all
|
36
|
+
Gtk.main
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
my_layout
|
10
|
+
signal_connect('destroy') do
|
11
|
+
Gtk.main_quit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def my_layout
|
16
|
+
vbox do
|
17
|
+
with_attr :border_width => 3 do
|
18
|
+
hbox do
|
19
|
+
entry :id => :ent_input, :layout => [true, true, 5]
|
20
|
+
end
|
21
|
+
hbox do
|
22
|
+
frame do
|
23
|
+
label 'M', :set_size_request => [20, 20]
|
24
|
+
end
|
25
|
+
hbutton_box do
|
26
|
+
button 'Backspace'
|
27
|
+
button 'CE'
|
28
|
+
button 'C'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
hbox do
|
32
|
+
vbutton_box do
|
33
|
+
button 'MC'
|
34
|
+
button 'MR'
|
35
|
+
button 'MS'
|
36
|
+
button 'M+'
|
37
|
+
end
|
38
|
+
with_attr :layout => [true, true] do
|
39
|
+
number_and_operators_layout
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def number_and_operators_layout
|
47
|
+
vbox do
|
48
|
+
[ ['7', '8', '9', '/', 'sqt'],
|
49
|
+
['4', '5', '6', '*', '%'],
|
50
|
+
['1', '2', '3', '-', '1/x'],
|
51
|
+
['0', '+/-', '.', '+', '=']].each do |cols|
|
52
|
+
hbox :layout => [true, true] do
|
53
|
+
cols.each do |txt|
|
54
|
+
button txt, :id => txt.to_sym, :set_size_request => [30, 30], :layout => [true, true]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
MyWin.new.show_all
|
64
|
+
Gtk.main
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
my_layout
|
9
|
+
signal_connect('destroy') do
|
10
|
+
Gtk.main_quit
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def my_layout
|
15
|
+
vbox do
|
16
|
+
with_attr :border_width => 10 do
|
17
|
+
label_in_hbox "I'm a label, in a hbox"
|
18
|
+
button_in_frame "I'm a button, in a frame", :border_width => 10
|
19
|
+
label_in_hbox "I'm a label, in a hbox, with inner_layout[:end, false, false]", :inner_layout => [:end, false, false]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
MyWin.new.show_all
|
26
|
+
Gtk.main
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
|
7
|
+
def my_layout
|
8
|
+
hbutton_box do
|
9
|
+
button 'A', :id => :btn_a
|
10
|
+
button 'B', :id => :btn_b
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
super
|
16
|
+
my_layout
|
17
|
+
|
18
|
+
expose_components()
|
19
|
+
# after call expose_components(), btn_a and btn_b become available
|
20
|
+
btn_a.signal_connect('clicked') do
|
21
|
+
btn_b.sensitive = (not btn_b.sensitive?)
|
22
|
+
end
|
23
|
+
btn_b.signal_connect('clicked') do
|
24
|
+
btn_a.sensitive = (not btn_a.sensitive?)
|
25
|
+
end
|
26
|
+
|
27
|
+
signal_connect('destroy') do
|
28
|
+
Gtk.main_quit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
MyWin.new.show_all
|
35
|
+
Gtk.main
|
data/example/group.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
|
7
|
+
def my_layout
|
8
|
+
vbox do
|
9
|
+
hbox do
|
10
|
+
button 'Change group A', :id => :btn_change_a
|
11
|
+
button 'Change group B', :id => :btn_change_b
|
12
|
+
end
|
13
|
+
hbutton_box do
|
14
|
+
group :A do # set group A
|
15
|
+
button 'A'
|
16
|
+
button 'A'
|
17
|
+
button 'A'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
hbutton_box do
|
21
|
+
group :B do # set group B
|
22
|
+
button 'B'
|
23
|
+
button 'B'
|
24
|
+
button 'B'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
hbutton_box do
|
28
|
+
group :A do # you can set group A again !
|
29
|
+
button 'A'
|
30
|
+
button 'A'
|
31
|
+
end
|
32
|
+
group :B do # you can set group B again !
|
33
|
+
button 'B'
|
34
|
+
button 'B'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize
|
41
|
+
super
|
42
|
+
@count_a = 0
|
43
|
+
@count_b = 0
|
44
|
+
my_layout
|
45
|
+
|
46
|
+
register_auto_events()
|
47
|
+
|
48
|
+
signal_connect('destroy') do
|
49
|
+
Gtk.main_quit
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def btn_change_a_on_clicked(w)
|
54
|
+
@count_a += 1
|
55
|
+
component_children(:A).each do |g|
|
56
|
+
g.label = "A: #{@count_a}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def btn_change_b_on_clicked(w)
|
61
|
+
@count_b += 1
|
62
|
+
component_children(:B).each do |g|
|
63
|
+
g.label = "B: #{@count_b}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
MyWin.new.show_all
|
70
|
+
Gtk.main
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
my_layout
|
9
|
+
signal_connect('destroy') do
|
10
|
+
Gtk.main_quit
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def my_layout
|
15
|
+
hbox do
|
16
|
+
label 'Hello, '
|
17
|
+
button 'World !'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
MyWin.new.show_all
|
23
|
+
Gtk.main
|
data/example/menu.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
my_layout
|
9
|
+
signal_connect('destroy') do
|
10
|
+
Gtk.main_quit
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def my_layout
|
15
|
+
vbox do
|
16
|
+
factory_menu_bar "main", :type => :menu do
|
17
|
+
factory_menu_item "<_File>" do
|
18
|
+
factory_menu_item "_Open"
|
19
|
+
factory_menu_item "_Close"
|
20
|
+
factory_menu_item "---"
|
21
|
+
factory_menu_item "_Quit", :id => :quit, :accel => "<control>Q"
|
22
|
+
end
|
23
|
+
factory_menu_item "<_Edit>" do
|
24
|
+
factory_menu_item "<--->"
|
25
|
+
factory_menu_item "Copy", :accel => "<control>C"
|
26
|
+
factory_menu_item "Cut", :accel => "<control>X"
|
27
|
+
factory_menu_item "Paste", :accel => "<control>V"
|
28
|
+
factory_menu_item "<Advanced>", :accel => "<control>S" do
|
29
|
+
factory_menu_item "<--->", :accel => "<control>A"
|
30
|
+
factory_menu_item "Zoom In", :image => Gtk::Stock::ZOOM_IN, :accel => "<control>plus"
|
31
|
+
factory_menu_item "Zoom Out", :image => Gtk::Stock::ZOOM_OUT, :accel => "<control>minus"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
factory_menu_item ">>Help>>" do
|
35
|
+
factory_menu_item "About"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
scrolled_window :layout => [true, true] do
|
39
|
+
text_view :set_size_request => [300, 200]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def menu_main_on_active(id, path, w)
|
45
|
+
puts "menu: #{id}, path: #{path}"
|
46
|
+
if id == :quit
|
47
|
+
self.destroy
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
MyWin.new.show_all
|
54
|
+
Gtk.main
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
|
7
|
+
def my_layout
|
8
|
+
frame 'Serial Port Setup', :border_width => 5 do
|
9
|
+
vbox :border_width => 5 do
|
10
|
+
with_attr :border_width => 3, :layout => [true, true] do
|
11
|
+
hbox do
|
12
|
+
label 'Port name: '
|
13
|
+
combobox :id => :comb_port, :layout => [true, true]
|
14
|
+
end
|
15
|
+
hbox do
|
16
|
+
label 'Baud rate: '
|
17
|
+
combobox :id => :comb_baudrate, :layout => [true, true]
|
18
|
+
end
|
19
|
+
hbutton_box do
|
20
|
+
button 'Open', :id => :btn_open, :sensitive => false
|
21
|
+
button 'Close', :id => :btn_close, :sensitive => false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
super
|
30
|
+
|
31
|
+
my_layout
|
32
|
+
|
33
|
+
register_auto_events()
|
34
|
+
expose_components()
|
35
|
+
|
36
|
+
init_ui
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def init_ui
|
41
|
+
if RUBY_PLATFORM =~ /(mswin|mingw)/
|
42
|
+
(1..10).each do |n|
|
43
|
+
comb_port.append_text "COM#{n}"
|
44
|
+
end
|
45
|
+
else
|
46
|
+
Dir.glob("/dev/ttyS*").each do |name|
|
47
|
+
comb_port.append_text name
|
48
|
+
end
|
49
|
+
Dir.glob("/dev/ttyUSB*").each do |name|
|
50
|
+
comb_port.append_text name
|
51
|
+
end
|
52
|
+
end
|
53
|
+
[9600, 19200, 57600, 115200].each do |speed|
|
54
|
+
comb_baudrate.append_text speed.to_s
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def comb_port_on_changed(*_)
|
59
|
+
btn_open.sensitive = true if comb_baudrate.active >= 0
|
60
|
+
end
|
61
|
+
|
62
|
+
def comb_baudrate_on_changed(*_)
|
63
|
+
btn_open.sensitive = true if comb_port.active >= 0
|
64
|
+
end
|
65
|
+
|
66
|
+
def btn_open_on_clicked(*_)
|
67
|
+
[comb_baudrate, comb_port, btn_open].each {|w| w.sensitive = false}
|
68
|
+
btn_close.sensitive = true
|
69
|
+
end
|
70
|
+
|
71
|
+
def btn_close_on_clicked(*_)
|
72
|
+
[comb_baudrate, comb_port, btn_open].each {|w| w.sensitive = true}
|
73
|
+
btn_close.sensitive = false
|
74
|
+
end
|
75
|
+
|
76
|
+
def self_on_destroy(*_)
|
77
|
+
Gtk.main_quit
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
MyWin.new.show_all
|
84
|
+
Gtk.main
|
85
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'gtk2'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/simple_layout'
|
3
|
+
|
4
|
+
class MyWin < Gtk::Window
|
5
|
+
include SimpleLayout::Base
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
my_layout
|
9
|
+
signal_connect('destroy') do
|
10
|
+
Gtk.main_quit
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def my_layout
|
15
|
+
vbox do
|
16
|
+
frame 'default' do
|
17
|
+
hbutton_box do
|
18
|
+
button 'A'
|
19
|
+
button 'B'
|
20
|
+
button 'C'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
frame 'set :border_width => 10 for each button' do
|
24
|
+
hbutton_box do
|
25
|
+
button 'A', :border_width => 10
|
26
|
+
button 'B', :border_width => 10
|
27
|
+
button 'C', :border_width => 10
|
28
|
+
end
|
29
|
+
end
|
30
|
+
frame 'using with_attr :border_width => 10' do
|
31
|
+
hbutton_box do
|
32
|
+
with_attr :border_width => 10 do
|
33
|
+
button 'A'
|
34
|
+
button 'B'
|
35
|
+
button 'C'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
MyWin.new.show_all
|
44
|
+
Gtk.main
|