gtk3 1.2.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,78 @@
1
+ # Copyright (c) 2013 Ruby-GNOME2 Project Team
2
+ # This program is licenced under the same licence as Ruby-GNOME2.
3
+ #
4
+ =begin
5
+ = Info bar
6
+
7
+ Info bar widgets are used to report important messages to the user.
8
+ =end
9
+ require 'common'
10
+
11
+ module Demo
12
+ class InfoBar < BasicWindow
13
+ def initialize
14
+ super('Info Bars')
15
+
16
+ self.border_width = 8
17
+
18
+
19
+ vbox = Gtk::Box.new :vertical
20
+ self.add vbox
21
+
22
+ bar = Gtk::InfoBar.new
23
+ vbox.pack_start bar, :expand => false, :fill => false, :padding => 0
24
+ bar.message_type = :info
25
+ label = Gtk::Label.new 'This is an info bar with message type GTK_MESSAGE_INFO'
26
+ bar.content_area.pack_start label, :expand => false, :fill => false, :padding => 0
27
+
28
+ bar = Gtk::InfoBar.new
29
+ vbox.pack_start bar, :expand => false, :fill => false, :padding => 0
30
+ bar.message_type = :warning
31
+ label = Gtk::Label.new 'This is an info bar with message type GTK_MESSAGE_WARNING'
32
+ bar.content_area.pack_start label, :expand => false, :fill => false, :padding => 0
33
+
34
+ bar = Gtk::InfoBar.new [:ok, :ok]
35
+ bar.signal_connect(:response) {|widget, response_id| on_bar_response widget, response_id}
36
+ vbox.pack_start bar, :expand => false, :fill => false, :padding => 0
37
+ bar.message_type = :question
38
+ label = Gtk::Label.new 'This is an info bar with message type GTK_MESSAGE_QUESTION'
39
+ bar.content_area.pack_start label, :expand => false, :fill => false, :padding => 0
40
+
41
+ bar = Gtk::InfoBar.new
42
+ vbox.pack_start bar, :expand => false, :fill => false, :padding => 0
43
+ bar.message_type = :error
44
+ label = Gtk::Label.new 'This is an info bar with message type GTK_MESSAGE_ERROR'
45
+ bar.content_area.pack_start label, :expand => false, :fill => false, :padding => 0
46
+
47
+ bar = Gtk::InfoBar.new
48
+ vbox.pack_start bar, :expand => false, :fill => false, :padding => 0
49
+ bar.message_type = :other
50
+ label = Gtk::Label.new 'This is an info bar with message type GTK_MESSAGE_OTHER'
51
+ bar.content_area.pack_start label, :expand => false, :fill => false, :padding => 0
52
+
53
+
54
+ frame = Gtk::Frame.new 'Info bars'
55
+ vbox.pack_start frame, :expand => false, :fill => false, :padding => 8
56
+
57
+ vbox2 = Gtk::Box.new :vertical, 8
58
+ vbox2.border_width = 8
59
+ frame.add vbox2
60
+
61
+ # Standard message dialog
62
+ label = Gtk::Label.new 'An example of different info bars'
63
+ vbox2.pack_start label, :expand => false, :fill => false, :padding => 0
64
+ end
65
+
66
+ def on_bar_response info_bar, response_id
67
+ dialog = Gtk::MessageDialog.new :parent => self,
68
+ :flags => [:modal, :destroy_with_parent],
69
+ :type => :info,
70
+ :buttons_type => :ok,
71
+ :message => 'You clicked a button on an info bar'
72
+
73
+ dialog.set_secondary_text "Your response has id %d" % response_id
74
+ dialog.signal_connect(:response) {dialog.destroy}
75
+ dialog.show_all
76
+ end
77
+ end
78
+ end
@@ -66,12 +66,12 @@ module Demo
66
66
  box1 = Gtk::VBox.new(false, 0)
67
67
  add(box1)
68
68
 
69
- box1.pack_start(item_factory.get_widget('<main>'), false, false, 0)
69
+ box1.pack_start(item_factory.get_widget('<main>'), :expand => false, :fill => false, :padding => 0)
70
70
 
71
71
  label = Gtk::Label.new("Type\n<alt>\nto start")
72
72
  label.set_size_request(200, 200)
73
73
  label.set_alignment(0.5, 0.5)
74
- box1.pack_start(label, true, true, 0)
74
+ box1.pack_start(label, :expand => true, :fill => true, :padding => 0)
75
75
 
76
76
  separator = Gtk::HSeparator.new
77
77
  box1.pack_start(separator)
@@ -79,14 +79,14 @@ module Demo
79
79
 
80
80
  box2 = Gtk::VBox.new(false, 10)
81
81
  box2.set_border_width(10)
82
- box1.pack_start(box2, false, true, 0)
82
+ box1.pack_start(box2, :expand => false, :fill => true, :padding => 0)
83
83
 
84
84
  button = Gtk::Button.new('close')
85
85
  # TODO: Need signal_connect_swapped?
86
86
  button.signal_connect('clicked') do
87
87
  quit
88
88
  end
89
- box2.pack_start(button, true, true, 0)
89
+ box2.pack_start(button, :expand => true, :fill => true, :padding => 0)
90
90
  button.set_flags(Gtk::Widget::CAN_DEFAULT)
91
91
  button.grab_default
92
92
  end
@@ -0,0 +1,53 @@
1
+ # Copyright (c) 2013 Ruby-GNOME2 Project Team
2
+ # This program is licenced under the same licence as Ruby-GNOME2.
3
+ #
4
+ =begin
5
+ = Links
6
+
7
+ GtkLabel can show hyperlinks. The default action is to call gtk_show_uri() on their URI, but it is possible to override this with a custom handler.
8
+ =end
9
+ require 'common'
10
+
11
+ module Demo
12
+ class Links < BasicWindow
13
+ def initialize
14
+ super('Links')
15
+
16
+ title = 'Links'
17
+ border_width = 12
18
+ signal_connect(:destroy) {self.destroy}
19
+
20
+ label = Gtk::Label.new "Some <a href=\"http://en.wikipedia.org/wiki/Text\"" +
21
+ "title=\"plain text\">text</a> may be marked up\n" +
22
+ "as hyperlinks, which can be clicked\n" +
23
+ "or activated via <a href=\"keynav\">keynav</a>\n" +
24
+ "and they work fine with other markup, like when\n" +
25
+ "searching on <a href=\"http://www.google.com/\">" +
26
+ "<span color=\"#0266C8\">G</span><span color=\"#F90101\">o</span>" +
27
+ "<span color=\"#F2B50F\">o</span><span color=\"#0266C8\">g</span>" +
28
+ "<span color=\"#00933B\">l</span><span color=\"#F90101\">e</span>" +
29
+ "</a>."
30
+ label.use_markup = true
31
+ label.signal_connect(:activate_link) {|widget, uri| activate_link uri}
32
+ add label
33
+ label.show
34
+ end
35
+
36
+ def activate_link uri
37
+ if uri == 'keynav'
38
+ dialog = Gtk::MessageDialog.new :parent => self,
39
+ :flags => :destroy_with_parent,
40
+ :type => :info,
41
+ :buttons_type => :ok
42
+
43
+ dialog.markup = "The term <i>keynav</i> is a shorthand for " +
44
+ "keyboard navigation and refers to the process of using " +
45
+ "a program (exclusively) via keyboard input."
46
+ dialog.present
47
+ dialog.signal_connect(:response) {dialog.destroy}
48
+ return true
49
+ end
50
+ false
51
+ end
52
+ end
53
+ end
@@ -43,12 +43,12 @@ module Demo
43
43
  add(vbox)
44
44
 
45
45
  label = Gtk::Label.new('This is the bug list (note: not based on real data, it would be nice to have a nice ODBC interface to bugzilla or so, though).')
46
- vbox.pack_start(label, false, false, 0)
46
+ vbox.pack_start(label, :expand => false, :fill => false, :padding => 0)
47
47
 
48
48
  sw = Gtk::ScrolledWindow.new(nil, nil)
49
49
  sw.shadow_type = Gtk::SHADOW_ETCHED_IN
50
- sw.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC)
51
- vbox.pack_start(sw, true, true, 0)
50
+ sw.set_policy(Gtk::POLICY_NEVER, :automatic)
51
+ vbox.pack_start(sw, :expand => true, :fill => true, :padding => 0)
52
52
 
53
53
  # create tree model
54
54
  model = create_model
@@ -31,7 +31,7 @@ module Demo
31
31
  end
32
32
 
33
33
  signal_connect("key_press_event") do |widget, event|
34
- if event.state.control_mask? and event.keyval == Gdk::Keyval::GDK_q
34
+ if event.state.control_mask? and event.keyval == Gdk::Keyval::GDK_KEY_q
35
35
  destroy
36
36
  true
37
37
  else
@@ -39,16 +39,17 @@ module Demo
39
39
  end
40
40
  end
41
41
 
42
- hbox = Gtk::HBox.new
42
+ hbox = Gtk::Box.new(:horizontal)
43
43
  add(hbox)
44
44
 
45
45
  tree = create_tree
46
46
  scrolled_window = Gtk::ScrolledWindow.new
47
+ scrolled_window.set_policy :never, :automatic
47
48
  scrolled_window.add(tree)
48
- hbox.pack_start(scrolled_window, false, false, 0)
49
+ hbox.pack_start(scrolled_window, :expand => false, :fill => false, :padding => 0)
49
50
 
50
51
  notebook = Gtk::Notebook.new
51
- hbox.pack_start(notebook, true, true, 0)
52
+ hbox.pack_start(notebook, :expand => true, :fill => true, :padding => 0)
52
53
 
53
54
  notebook.append_page(create_text(@info_buffer, false),
54
55
  Gtk::Label.new('_Info', true))
@@ -103,14 +104,15 @@ module Demo
103
104
 
104
105
  def generate_index
105
106
  # Target scripts
106
- scripts = Dir.glob('*.rb') - %w(common.rb main.rb)
107
+ scripts = Dir.glob(File.join(File.dirname(__FILE__), '*.rb'))
107
108
 
108
109
  # Generate index tree
109
110
  children = {}
110
111
  index = []
111
112
 
112
- scripts.each do |fn|
113
- title, klass, depend = script_info(fn)
113
+ scripts.each do |script|
114
+ next if ["common.rb", "main.rb"].include?(File.basename(script))
115
+ title, klass, depend = script_info(script)
114
116
 
115
117
  if depend and not Gtk.const_defined?(depend)
116
118
  next
@@ -125,9 +127,9 @@ module Demo
125
127
  index += [[parent, nil, nil, []]]
126
128
  end
127
129
 
128
- children[parent] += [[child, fn, klass]]
130
+ children[parent] += [[child, script, klass]]
129
131
  else
130
- index += [[title, fn, klass]]
132
+ index += [[title, script, klass]]
131
133
  end
132
134
  end
133
135
 
@@ -161,7 +163,7 @@ module Demo
161
163
  tree_view.set_model(model)
162
164
  selection = tree_view.selection
163
165
 
164
- selection.set_mode(Gtk::SELECTION_BROWSE)
166
+ selection.set_mode(:browse)
165
167
  tree_view.set_size_request(200, -1)
166
168
 
167
169
  append_children(model, generate_index)
@@ -169,7 +171,7 @@ module Demo
169
171
  cell = Gtk::CellRendererText.new
170
172
  cell.style = Pango::FontDescription::STYLE_ITALIC
171
173
  column = Gtk::TreeViewColumn.new("Widget (double click for demo)", cell,
172
- {
174
+ {
173
175
  'text' => TITLE_COLUMN,
174
176
  'style_set' => ITALIC_COLUMN,
175
177
  })
@@ -225,9 +227,9 @@ module Demo
225
227
 
226
228
  def create_text(buffer, is_source)
227
229
  scrolled_window = Gtk::ScrolledWindow.new
228
- scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC,
229
- Gtk::POLICY_AUTOMATIC)
230
- scrolled_window.set_shadow_type(Gtk::SHADOW_IN)
230
+ scrolled_window.set_policy(:automatic,
231
+ :automatic)
232
+ scrolled_window.set_shadow_type(:in)
231
233
 
232
234
  text_view = Gtk::TextView.new
233
235
 
@@ -239,11 +241,11 @@ module Demo
239
241
 
240
242
  if is_source
241
243
  font_desc = Pango::FontDescription.new('Monospace 12')
242
- text_view.modify_font(font_desc)
244
+ text_view.override_font(font_desc)
243
245
 
244
- text_view.set_wrap_mode(Gtk::TextTag::WRAP_NONE)
246
+ text_view.set_wrap_mode(:none)
245
247
  else
246
- text_view.set_wrap_mode(Gtk::TextTag::WRAP_WORD)
248
+ text_view.set_wrap_mode(:word)
247
249
  text_view.set_pixels_above_lines(2)
248
250
  text_view.set_pixels_below_lines(2)
249
251
  end
@@ -258,8 +260,8 @@ module Demo
258
260
  tokenizer = RubyTokonizer.new
259
261
  tokenizer.tokenize(str, start_iter.offset) do |tag, start, last|
260
262
  @source_buffer.apply_tag(tag.to_s,
261
- @source_buffer.get_iter_at_offset(start),
262
- @source_buffer.get_iter_at_offset(last))
263
+ @source_buffer.get_iter_at(:offset => start),
264
+ @source_buffer.get_iter_at(:offset => last))
263
265
  end
264
266
  end
265
267
 
@@ -279,7 +281,7 @@ module Demo
279
281
  $stderr.puts "Cannot open: #{$!}" if $DEBUG
280
282
  return
281
283
  end
282
- start = @info_buffer.get_iter_at_offset(0)
284
+ start = @info_buffer.get_iter_at(:offset => 0)
283
285
  state = :before_header
284
286
 
285
287
  file.each do |line|
@@ -291,7 +293,7 @@ module Demo
291
293
  when :in_header
292
294
  if line =~ /^=end$/
293
295
  state = :body
294
- start = @source_buffer.get_iter_at_offset(0)
296
+ start = @source_buffer.get_iter_at(:offset => 0)
295
297
  elsif line =~ /^=\s+(.*)$/
296
298
  title = $1
297
299
  title.gsub!(/\s*\(.*\)$/, '') # Delete depend field
@@ -47,7 +47,7 @@ module Demo
47
47
  add(box1)
48
48
 
49
49
  menubar = Gtk::MenuBar.new
50
- box1.pack_start(menubar, false, true, 0)
50
+ box1.pack_start(menubar, :expand => false, :fill => true, :padding => 0)
51
51
 
52
52
  menu = create_menu(2, true)
53
53
 
@@ -69,7 +69,7 @@ module Demo
69
69
 
70
70
  box2 = Gtk::VBox.new(false, 10)
71
71
  box2.border_width = 10
72
- box1.pack_start(box2, true, true, 0)
72
+ box1.pack_start(box2, :expand => true, :fill => true, :padding => 0)
73
73
  box2.show
74
74
 
75
75
  menu = create_menu(1, false)
@@ -112,23 +112,23 @@ module Demo
112
112
  optionmenu = Gtk::OptionMenu.new
113
113
  optionmenu.menu = menu
114
114
  optionmenu.history = 3
115
- box2.pack_start(optionmenu, true, true, 0)
115
+ box2.pack_start(optionmenu, :expand => true, :fill => true, :padding => 0)
116
116
  optionmenu.show
117
117
 
118
118
  separator = Gtk::HSeparator.new
119
- box1.pack_start(separator, false, true, 0)
119
+ box1.pack_start(separator, :expand => false, :fill => true, :padding => 0)
120
120
  separator.show
121
121
 
122
122
  box2 = Gtk::VBox.new(false, 10)
123
123
  box2.border_width = 10
124
- box1.pack_start(box2, false, true, 0)
124
+ box1.pack_start(box2, :expand => false, :fill => true, :padding => 0)
125
125
  box2.show
126
126
 
127
127
  button = Gtk::Button.new('close')
128
128
  button.signal_connect('clicked') do
129
129
  quit
130
130
  end
131
- box2.pack_start(button, true, true, 0)
131
+ box2.pack_start(button, :expand => true, :fill => true, :padding => 0)
132
132
  button.flags = Gtk::Widget::CAN_DEFAULT
133
133
  button.grab_default
134
134
  button.show
@@ -27,14 +27,14 @@ module Demo
27
27
  add(vbox)
28
28
 
29
29
  vpaned = Gtk::VPaned.new
30
- vbox.pack_start(vpaned, true, true, 0)
30
+ vbox.pack_start(vpaned, :expand => true, :fill => true, :padding => 0)
31
31
  vpaned.border_width = 5
32
32
 
33
33
  hpaned = Gtk::HPaned.new
34
34
  vpaned.add1(hpaned)
35
35
 
36
36
  frame = Gtk::Frame.new
37
- frame.shadow_type = Gtk::SHADOW_IN
37
+ frame.shadow_type = :in
38
38
  frame.set_size_request(60, 60)
39
39
  hpaned.add1(frame)
40
40
 
@@ -42,12 +42,12 @@ module Demo
42
42
  frame.add(button)
43
43
 
44
44
  frame = Gtk::Frame.new
45
- frame.shadow_type = Gtk::SHADOW_IN
45
+ frame.shadow_type = :in
46
46
  frame.set_size_request(80, 60)
47
47
  hpaned.add2(frame)
48
48
 
49
49
  frame = Gtk::Frame.new
50
- frame.shadow_type = Gtk::SHADOW_IN
50
+ frame.shadow_type = :in
51
51
  frame.set_size_request(60, 80)
52
52
  vpaned.add2(frame)
53
53
 
@@ -55,11 +55,11 @@ module Demo
55
55
 
56
56
  vbox.pack_start(create_pane_options(hpaned,
57
57
  'Horizontal', 'Left', 'Right'),
58
- false, false, 0)
58
+ :expand => false, :fill => false, :padding => 0)
59
59
 
60
60
  vbox.pack_start(create_pane_options(vpaned,
61
61
  'Vertical', 'Top', 'Bottom'),
62
- false, false, 0)
62
+ :expand => false, :fill => false, :padding => 0)
63
63
  end
64
64
 
65
65
  def create_pane_options(paned, frame_label, label1, label2)
@@ -36,14 +36,14 @@ module Demo
36
36
  end
37
37
 
38
38
  vbox = Gtk::VBox.new(false, 5)
39
- self.vbox.pack_start(vbox, true, true, 0)
39
+ self.vbox.pack_start(vbox, :expand => true, :fill => true, :padding => 0)
40
40
  vbox.set_border_width(5)
41
41
 
42
42
  size_group = Gtk::SizeGroup.new(Gtk::SizeGroup::HORIZONTAL)
43
43
 
44
44
  ## Create one frame holding color options
45
45
  frame = Gtk::Frame.new('Color Options')
46
- vbox.pack_start(frame, true, true, 0)
46
+ vbox.pack_start(frame, :expand => true, :fill => true, :padding => 0)
47
47
 
48
48
  table = Gtk::Table.new(2, 2, false)
49
49
  table.set_border_width(5)
@@ -56,7 +56,7 @@ module Demo
56
56
 
57
57
  ## And another frame holding line style options
58
58
  frame = Gtk::Frame.new('Line Options')
59
- vbox.pack_start(frame, false, false, 0)
59
+ vbox.pack_start(frame, :expand => false, :fill => false, :padding => 0)
60
60
 
61
61
  table = Gtk::Table.new(2, 2, false)
62
62
  table.set_border_width(5)
@@ -69,7 +69,7 @@ module Demo
69
69
 
70
70
  # And a check button to turn grouping on and off
71
71
  check_button = Gtk::CheckButton.new('_Enable grouping', true)
72
- vbox.pack_start(check_button, false, false, 0)
72
+ vbox.pack_start(check_button, :expand => false, :fill => false, :padding => 0)
73
73
 
74
74
  check_button.set_active(true)
75
75
  check_button.signal_connect('toggled', size_group) do |check_button, size_group|
@@ -0,0 +1,59 @@
1
+ # Copyright (c) 2013 Ruby-GNOME2 Project Team
2
+ # This program is licenced under the same licence as Ruby-GNOME2.
3
+ #
4
+ =begin
5
+ = Spinner
6
+
7
+ GtkSpinner allows to show that background activity is on-going.
8
+ =end
9
+ require 'common'
10
+
11
+ module Demo
12
+ class Spinner < Gtk::Dialog
13
+ def initialize
14
+ super(:title => 'Spinner',
15
+ :parent => nil,
16
+ :flags => nil,
17
+ :buttons => [[:close, :none]])
18
+
19
+ signal_connect(:response) {self.destroy}
20
+ signal_connect(:destroy) {self.destroy}
21
+
22
+ self.resizable = false
23
+
24
+ vbox = Gtk::Box.new :vertical, 5
25
+
26
+ self.content_area.pack_start vbox, :expand => true, :fill => true, :padding => 0
27
+ vbox.border_width = 5
28
+
29
+ # Sensitive
30
+ hbox = Gtk::Box.new :horizontal, 5
31
+ @spinner_sensitive = Gtk::Spinner.new
32
+ hbox.add @spinner_sensitive
33
+ hbox.add Gtk::Entry.new
34
+ vbox.add hbox
35
+
36
+ # Disabled
37
+ hbox = Gtk::Box.new :horizontal, 5
38
+ @spinner_insensitive = Gtk::Spinner.new
39
+ hbox.add @spinner_insensitive
40
+ hbox.add Gtk::Entry.new
41
+ vbox.add hbox
42
+ hbox.sensitive = false
43
+
44
+ button = Gtk::Button.new :stock_id => :media_play
45
+ button.signal_connect(:clicked) do
46
+ @spinner_sensitive.start
47
+ @spinner_insensitive.start
48
+ end
49
+ vbox.add button
50
+
51
+ button = Gtk::Button.new :stock_id => :media_stop
52
+ button.signal_connect(:clicked) do
53
+ @spinner_sensitive.stop
54
+ @spinner_insensitive.stop
55
+ end
56
+ vbox.add button
57
+ end
58
+ end
59
+ end