~rainct/screenruler/screenruler-gtk3

« back to all changes in this revision

Viewing changes to utils/glade_window.rb

  • Committer: Siegfried-Angel Gevatter Pujals
  • Date: 2011-09-03 19:33:22 UTC
  • Revision ID: siegfried@gevatter.com-20110903193322-g3u5xzcilzf97kyy
Start conversion to Gtk::Builder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
17
 ###############################################################################
18
18
 
19
 
require 'libglade2'
20
19
require 'delegate'
21
20
 
22
21
class GladeWindow < DelegateClass(Gtk::Window)
24
23
        MOUSE_BUTTON_1, MOUSE_BUTTON_2, MOUSE_BUTTON_3 = (1..3).to_a
25
24
 
26
25
        def initialize(root_widget_name, options = {})
27
 
                options = {             # defaults
28
 
                        :glade_file_name => sprintf("%s.glade", File.basename($0, '.rb'))               # script name
29
 
                }.merge(options)
30
 
 
31
26
                # load the widgets below 'root_widget' and auto-hookup all the methods
32
 
                glade = GladeXML.new(options[:glade_file_name], root_widget_name) { | handler_name |
 
27
                builder = Gtk::Builder.new
 
28
                builder.add_from_file(sprintf("interface/%s.ui", root_widget_name))
 
29
                builder.connect_signals { | handler_name |
33
30
                        method(handler_name)
34
31
                }
35
32
 
36
 
                # create instance variables for each widget below us (except root widget, which is handled below)
37
 
                glade.widget_names.each { |name|
38
 
                        instance_variable_set('@' + name, glade.get_widget(name)) unless name == root_widget_name
39
 
                }
40
 
 
41
33
                # in the class, we will refer to the GtkWindow as @window when referencing variables
42
 
                @window = glade.get_widget(root_widget_name)
 
34
                @window = builder.get_object(root_widget_name)
43
35
                @window.realize
44
36
 
 
37
                # and we want access to all widgets below us, so we keep the builder
 
38
                # instance around so we can call .get_object
 
39
                @builder = builder
 
40
 
45
41
                super(@window)          # ...as required by delegation
46
42
        end
47
43