1
# Copyright (C) 2009 Canonical
6
# This program is free software; you can redistribute it and/or modify it under
7
# the terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 3 of the License, or (at your option) any later
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
# You should have received a copy of the GNU General Public License along with
17
# this program; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28
class GtkbuilderWidget(gtk.HBox):
29
"""A widget that gets loaded from a Gtkbuilder UI file
31
If no "toplevel_name" paramter is given, the name of
32
the class is used to find a UI file of that name and
33
load the object with that name
35
def __init__(self, datadir, toplevel_name=None):
36
gtk.HBox.__init__(self)
37
if toplevel_name is None:
38
toplevel_name = self.__class__.__name__
39
ui_file = "%s/ui/%s.ui" % (datadir, toplevel_name)
40
builder = gtk.Builder()
41
builder.add_objects_from_file(ui_file, [toplevel_name])
42
builder.connect_signals(self)
43
for o in builder.get_objects():
44
if issubclass(type(o), gtk.Buildable):
45
name = gtk.Buildable.get_name(o)
46
setattr(self, name, o)
48
logging.warn("WARNING: can not get name for '%s'" % o)
50
w = getattr(self, self.__class__.__name__)
53
w = getattr(self, self.__class__.__name__)
56
# test widget that just loads the
57
class GBTestWidget(GtkbuilderWidget):
59
def on_button_clicked(self, button):
60
print "on_button_clicked"
63
if __name__ == "__main__":
64
logging.basicConfig(level=logging.DEBUG)
68
elif os.path.exists("./data"):
71
datadir = "/usr/share/software-store"
73
w = GBTestWidget(datadir)
78
#win.set_size_request(600,400)