Debian Codegraph @

gui.py

raw
1 #!/usr/bin/python3
2
3 ## system-config-printer
4
5 ## Copyright (C) 2006, 2007, 2008, 2009, 2010, 2012 Red Hat, Inc.
6 ## Authors:
7 ## Florian Festi <[email protected]>
8 ## Tim Waugh <[email protected]>
9
10 ## This program is free software; you can redistribute it and/or modify
11 ## it under the terms of the GNU General Public License as published by
12 ## the Free Software Foundation; either version 2 of the License, or
13 ## (at your option) any later version.
14
15 ## This program is distributed in the hope that it will be useful,
16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ## GNU General Public License for more details.
19
20 ## You should have received a copy of the GNU General Public License
21 ## along with this program; if not, write to the Free Software
22 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
24 from gi.repository import GObject
25 from gi.repository import Gtk
26 import os
27
28 import config
29 pkgdata = config.pkgdatadir
30
31 class GtkGUI(GObject.GObject):
32 def getWidgets(self, widgets, domain=None):
33 ui_dir = os.environ.get ("SYSTEM_CONFIG_PRINTER_UI",
34 os.path.join (pkgdata, "ui"))
35 self._bld = []
36 for xmlfile, names in widgets.items ():
37 bld = Gtk.Builder ()
38 self._bld.append (bld)
39
40 if domain:
41 bld.set_translation_domain (domain)
42
43 bld.add_from_file (os.path.join (ui_dir, xmlfile + ".ui"))
44 for name in names:
45 widget = bld.get_object(name)
46 if widget is None:
47 raise ValueError("Widget '%s' not found" % name)
48 setattr(self, name, widget)
49
50 try:
51 win = widget.get_top_level()
52 except AttributeError:
53 win = None
54
55 if win is not None:
56 Gtk.Window.set_focus_on_map(widget.get_top_level (),
57 self.focus_on_map)
58 widget.show()
59
60 def connect_signals (self):
61 for bld in self._bld:
62 bld.connect_signals (self)