1
###############################################################################
2
# Copyright 2008 Ian McIntosh <ian@openanswers.org>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Library General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
###############################################################################
22
class GladeWindow < DelegateClass(Gtk::Window)
24
MOUSE_BUTTON_1, MOUSE_BUTTON_2, MOUSE_BUTTON_3 = (1..3).to_a
26
def initialize(root_widget_name, options = {})
27
options = { # defaults
28
:glade_file_name => sprintf("%s.glade", File.basename($0, '.rb')) # script name
31
# 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 |
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
41
# in the class, we will refer to the GtkWindow as @window when referencing variables
42
@window = glade.get_widget(root_widget_name)
45
super(@window) # ...as required by delegation
49
def ModalConfirmationDialog(type, message)
50
dialog = Gtk::MessageDialog.new(@window, Gtk::Dialog::MODAL, type, Gtk::MessageDialog::BUTTONS_OK, message)
51
dialog.run { dialog.destroy }
54
def ErrorDialog(message)
55
ModalConfirmationDialog(Gtk::MessageDialog::ERROR, message)