1
# PiTiVi , Non-linear video editor
5
# Copyright (C) 2004,2005 Fluendo, S.L. (www.fluendo.com). All rights reserved.
6
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
8
# This program is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU Lesser General Public
10
# License as published by the Free Software Foundation; either
11
# version 2.1 of the License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
# Lesser General Public License for more details.
18
# You should have received a copy of the GNU Lesser General Public
19
# License along with this program; if not, write to the
20
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
# Boston, MA 02111-1307, USA.
31
# proc := module1.module2.moduleN.proc1().maybe_another_proc()
32
# -> eval proc1().maybe_another_proc() in module1.module2.moduleN
33
def flumotion_glade_custom_handler(xml, proc, name, *args):
34
def takewhile(proc, l):
36
while l and proc(l[0]):
42
parts = proc.split('.')
44
modparts = takewhile(str.isalnum, parts)
45
assert modparts and parts
46
return '.'.join(modparts), '.'.join(parts)
48
module, code = parse_proc(proc)
52
raise RuntimeError('Failed to load module %s: %s' % (module, e))
55
w = eval(code, sys.modules[module].__dict__)
57
raise RuntimeError('Failed call %s in module %s: %s'
62
gtk.glade.set_custom_handler(flumotion_glade_custom_handler)
65
class GladeWidget(gtk.VBox):
67
Base class for composite widgets backed by glade interface definitions.
70
class MyWidget(GladeWidget):
71
glade_file = 'my_glade_file.glade'
74
Remember to chain up if you customize __init__().
77
glade_dir = os.path.dirname(os.path.abspath(__file__))
82
gtk.VBox.__init__(self)
84
assert self.glade_file
85
filepath = os.path.join(self.glade_dir, self.glade_file)
86
if self.glade_typedict:
87
wtree = gtk.glade.XML(filepath, typedict=self.glade_typedict)
89
# pygtk 2.4 doesn't like typedict={} ?
90
wtree = gtk.glade.XML(filepath)
91
except RuntimeError, e:
92
raise RuntimeError('Failed to load file %s from directory %s: %s'
93
% (self.glade_file, self.glade_dir, e))
96
for widget in wtree.get_widget_prefix(''):
97
wname = widget.get_name()
98
if isinstance(widget, gtk.Window):
103
if hasattr(self, wname) and getattr(self, wname):
104
raise AssertionError (
105
"There is already an attribute called %s in %r" %
107
setattr(self, wname, widget)
114
wtree.signal_autoconnect(self)
117
class GladeWindow(gobject.GObject):
119
Base class for dialogs or windows backed by glade interface definitions.
122
class MyWindow(GladeWindow):
123
glade_file = 'my_glade_file.glade'
126
Remember to chain up if you customize __init__(). Also note that GladeWindow
127
does *not* descend from GtkWindow, so you can't treat the resulting object
128
as a GtkWindow. The show, hide, destroy, and present methods are provided as
129
convenience wrappers.
132
glade_dir = os.path.dirname(os.path.abspath(__file__))
134
glade_typedict = None
138
def __init__(self, parent=None):
139
gobject.GObject.__init__(self)
141
assert self.glade_file
142
filepath = os.path.join(self.glade_dir, self.glade_file)
143
if self.glade_typedict:
144
wtree = gtk.glade.XML(filepath, typedict=self.glade_typedict)
146
# pygtk 2.4 doesn't like typedict={} ?
147
wtree = gtk.glade.XML(filepath)
148
except RuntimeError, e:
149
raise RuntimeError('Failed to load file %s from directory %s: %s'
150
% (self.glade_file, self.glade_dir, e))
153
for widget in wtree.get_widget_prefix(''):
154
wname = widget.get_name()
155
if isinstance(widget, gtk.Window):
156
assert self.window == None
160
if wname in self.widgets:
161
raise AssertionError("Two objects with same name (%s): %r %r"
162
% (wname, self.widgets[wname], widget))
163
self.widgets[wname] = widget
166
self.window.set_transient_for(parent)
168
wtree.signal_autoconnect(self)
170
self.show = self.window.show
171
self.hide = self.window.hide
172
self.present = self.window.present
173
self.run = self.window.run
176
self.window.destroy()