summaryrefslogtreecommitdiff
path: root/portato/gui
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--portato/gui/windows/basic.py45
1 files changed, 25 insertions, 20 deletions
diff --git a/portato/gui/windows/basic.py b/portato/gui/windows/basic.py
index 1117e5e..330f823 100644
--- a/portato/gui/windows/basic.py
+++ b/portato/gui/windows/basic.py
@@ -14,7 +14,6 @@ from __future__ import absolute_import
# gtk stuff
import gtk
-import gtk.glade
import gobject
from functools import wraps
@@ -23,9 +22,6 @@ import os.path
from ...constants import TEMPLATE_DIR, APP, LOCALE_DIR
from ...helper import error
-gtk.glade.bindtextdomain (APP, LOCALE_DIR)
-gtk.glade.textdomain (APP)
-
class WrappedTree (object):
__slots__ = ("klass", "tree", "get_widget")
def __init__ (self, klass, tree):
@@ -39,25 +35,35 @@ class WrappedTree (object):
return getattr(self.tree, name)
def get_widget(self, name):
- w = self.tree.get_widget(name)
+ w = self.tree.get_object(name)
if w is None:
error("Widget '%s' could not be found in class '%s'.", name, self.klass)
return w
-class Window (object):
+class UIBuilder (object):
+
+ def __init__ (self, connector = None):
+ if not hasattr(self, "__file__"):
+ self.__file__ = self.__class__.__name__
+
+ self._builder = gtk.Builder()
+ self._builder.add_from_file(os.path.join(TEMPLATE_DIR, self.__file__+".ui"))
+ self._builder.set_translation_domain(APP)
+
+ if connector is None: connector = self
+
+ self._builder.connect_signals(connector)
+
+ self.tree = WrappedTree(self.__class__.__name__, self._builder)
+
+class Window (UIBuilder):
def __init__ (self):
- if not hasattr(self, "__tree__"):
- self.__tree__ = self.__class__.__name__
+ UIBuilder.__init__(self)
if not hasattr(self, "__window__"):
self.__window__ = self.__class__.__name__
- if not hasattr(self, "__file__"):
- self.__file__ = self.__class__.__name__
-
- self.tree = self.get_tree(self.__tree__)
- self.tree.signal_autoconnect(self)
self.window = self.tree.get_widget(self.__window__)
@staticmethod
@@ -82,9 +88,6 @@ class Window (object):
return wrapper
- def get_tree (self, name):
- return WrappedTree(self.__class__.__name__, gtk.glade.XML(os.path.join(TEMPLATE_DIR, self.__file__+".glade"), name))
-
class AbstractDialog (Window):
"""A class all our dialogs get derived from. It sets useful default vars and automatically handles the ESC-Button."""
@@ -115,11 +118,13 @@ class AbstractDialog (Window):
def close (self, *args):
self.window.destroy()
-class Popup (object):
+class Popup (UIBuilder):
+
+ __file__ = "popups"
+
+ def __init__ (self, name, parent):
- def __init__ (self, name, parent, file = "popups"):
- self.tree = WrappedTree(self.__class__.__name__, gtk.glade.XML(os.path.join(TEMPLATE_DIR, file+".glade"), root = name))
- self.tree.signal_autoconnect(parent)
+ UIBuilder.__init__(self, connector = parent)
self._popup = self.tree.get_widget(name)
def popup (self, *args):