File: infobar.rb

package info (click to toggle)
ruby-gnome2 3.1.0-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,072 kB
  • ctags: 17,433
  • sloc: ansic: 93,621; ruby: 62,273; xml: 335; sh: 246; makefile: 25
file content (78 lines) | stat: -rw-r--r-- 3,025 bytes parent folder | download | duplicates (6)
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
# Copyright (c) 2013 Ruby-GNOME2 Project Team
# This program is licenced under the same licence as Ruby-GNOME2.
#
=begin
= Info bar

Info bar widgets are used to report important messages to the user.
=end
require 'common'

module Demo
  class InfoBar < BasicWindow
    def initialize
      super('Info Bars')

      self.border_width = 8


      vbox = Gtk::Box.new :vertical
      self.add vbox

      bar = Gtk::InfoBar.new
      vbox.pack_start bar, :expand => false, :fill => false, :padding => 0
      bar.message_type = :info
      label = Gtk::Label.new 'This is an info bar with message type GTK_MESSAGE_INFO'
      bar.content_area.pack_start label, :expand => false, :fill => false, :padding => 0

      bar = Gtk::InfoBar.new
      vbox.pack_start bar, :expand => false, :fill => false, :padding => 0
      bar.message_type = :warning
      label = Gtk::Label.new 'This is an info bar with message type GTK_MESSAGE_WARNING'
      bar.content_area.pack_start label, :expand => false, :fill => false, :padding => 0

      bar = Gtk::InfoBar.new [:ok, :ok]
      bar.signal_connect(:response) {|widget, response_id| on_bar_response widget, response_id}
      vbox.pack_start bar, :expand => false, :fill => false, :padding => 0
      bar.message_type = :question
      label = Gtk::Label.new 'This is an info bar with message type GTK_MESSAGE_QUESTION'
      bar.content_area.pack_start label, :expand => false, :fill => false, :padding => 0

      bar = Gtk::InfoBar.new
      vbox.pack_start bar, :expand => false, :fill => false, :padding => 0
      bar.message_type = :error
      label = Gtk::Label.new 'This is an info bar with message type GTK_MESSAGE_ERROR'
      bar.content_area.pack_start label, :expand => false, :fill => false, :padding => 0

      bar = Gtk::InfoBar.new
      vbox.pack_start bar, :expand => false, :fill => false, :padding => 0
      bar.message_type = :other
      label = Gtk::Label.new 'This is an info bar with message type GTK_MESSAGE_OTHER'
      bar.content_area.pack_start label, :expand => false, :fill => false, :padding => 0


      frame = Gtk::Frame.new 'Info bars'
      vbox.pack_start frame, :expand => false, :fill => false, :padding => 8

      vbox2 = Gtk::Box.new :vertical, 8
      vbox2.border_width = 8
      frame.add vbox2

      # Standard message dialog
      label = Gtk::Label.new 'An example of different info bars'
      vbox2.pack_start label, :expand => false, :fill => false, :padding => 0
    end

    def on_bar_response info_bar, response_id
      dialog = Gtk::MessageDialog.new :parent => self,
                                      :flags => [:modal, :destroy_with_parent],
                                      :type => :info,
                                      :buttons_type => :ok,
                                      :message => 'You clicked a button on an info bar'

      dialog.set_secondary_text "Your response has id %d" % response_id
      dialog.signal_connect(:response) {dialog.destroy}
      dialog.show_all
    end
  end
end