summaryrefslogtreecommitdiff
path: root/portato/gui/windows
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-02-18 23:15:24 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-02-18 23:15:24 +0100
commit1cd876636b1a2470186c36625b61c218654b0033 (patch)
tree713c67d43e9b367aa8ee309614f52b956d09c509 /portato/gui/windows
parentedffa4112136c525e5db84ec1b1a59ebd7a4a5c8 (diff)
parent4dfc7b063ec7dc476462e843bfecd07fd02cb25e (diff)
downloadportato-1cd876636b1a2470186c36625b61c218654b0033.tar.gz
portato-1cd876636b1a2470186c36625b61c218654b0033.tar.bz2
portato-1cd876636b1a2470186c36625b61c218654b0033.zip
Converted to GtkBuilder
Diffstat (limited to 'portato/gui/windows')
-rw-r--r--portato/gui/windows/basic.py64
-rw-r--r--portato/gui/windows/main.py100
2 files changed, 76 insertions, 88 deletions
diff --git a/portato/gui/windows/basic.py b/portato/gui/windows/basic.py
index 1117e5e..a4f8236 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,11 +22,8 @@ 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")
+ __slots__ = ("klass", "tree", "get_widget", "get_ui")
def __init__ (self, klass, tree):
self.tree = tree
self.klass = klass
@@ -39,25 +35,52 @@ 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):
- def __init__ (self):
+ def get_ui (self, name, ui = "uimanager"):
+ uiw = self.get_widget(ui)
+ if uiw is None:
+ return None
- if not hasattr(self, "__tree__"):
- self.__tree__ = self.__class__.__name__
+ if not name.startswith("ui/"):
+ name = "ui/%s" % name
- if not hasattr(self, "__window__"):
- self.__window__ = self.__class__.__name__
+ w = uiw.get_widget(name)
+ if w is None:
+ error("UIItem '%s' of UIManager '%s' could not be found in class '%s'.", name, ui, self.klass)
+ return w
+class UIBuilder (object):
+
+ def __init__ (self, connector = None):
if not hasattr(self, "__file__"):
self.__file__ = self.__class__.__name__
- self.tree = self.get_tree(self.__tree__)
- self.tree.signal_autoconnect(self)
+ 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
+
+ unconnected = self._builder.connect_signals(connector)
+
+ if unconnected is not None:
+ for uc in set(unconnected):
+ error("Signal '%s' not connected in class '%s'.", uc, self.__class__.__name__)
+
+ self.tree = WrappedTree(self.__class__.__name__, self._builder)
+
+class Window (UIBuilder):
+ def __init__ (self):
+
+ UIBuilder.__init__(self)
+
+ if not hasattr(self, "__window__"):
+ self.__window__ = self.__class__.__name__
+
self.window = self.tree.get_widget(self.__window__)
@staticmethod
@@ -82,9 +105,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."""
@@ -114,13 +134,3 @@ class AbstractDialog (Window):
def close (self, *args):
self.window.destroy()
-
-class Popup (object):
-
- 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)
- self._popup = self.tree.get_widget(name)
-
- def popup (self, *args):
- self._popup.popup(*args)
diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py
index 443fa76..2ee4447 100644
--- a/portato/gui/windows/main.py
+++ b/portato/gui/windows/main.py
@@ -43,7 +43,7 @@ from ..dialogs import (blocked_dialog, changed_flags_dialog, io_ex_dialog,
from ..exceptions import PreReqError
# even more GUI stuff
-from .basic import Window, Popup
+from .basic import Window
from .about import AboutWindow
from .plugin import PluginWindow
from .preference import PreferenceWindow
@@ -62,7 +62,6 @@ class PackageTable:
self.main = main
self.tree = main.tree
self.window = main.window
- self.tree.signal_autoconnect(self)
# all the package data is in this one VB
self.vb = self.tree.get_widget("packageVB")
@@ -481,13 +480,24 @@ class MainWindow (Window):
plugin.load_plugins()
menus = [p.menus for p in plugin.get_plugin_queue().get_plugins()]
if menus:
- self.tree.get_widget("pluginMenuItem").set_no_show_all(False)
- pluginMenu = self.tree.get_widget("pluginMenu")
+ uim = self.tree.get_widget("uimanager")
+ ag = self.tree.get_widget("pluginActionGroup")
+ ctr = 0
for m in itt.chain(*menus):
- item = gtk.MenuItem(m.label)
- item.connect("activate", m.call)
- pluginMenu.append(item)
+
+ # create action
+ aname = "plugin%d" % ctr
+ a = gtk.Action(aname, m.label, None, None)
+ a.connect("activate", m.call)
+ ag.add_action(a)
+
+ # add to UI
+ mid = uim.new_merge_id()
+ uim.add_ui(mid, "ui/menubar/pluginMenu", aname, aname, gtk.UI_MANAGER_MENUITEM, False)
+
+ ctr += 1
+
splash(_("Building frontend"))
# set paned position
@@ -554,18 +564,11 @@ class MainWindow (Window):
self.packageTable = PackageTable(self)
# popups
- self.consolePopup = Popup("consolePopup", self, self.__file__)
- self.trayPopup = Popup("systrayPopup", self)
+ self.consolePopup = self.tree.get_ui("consolePopup")
+ self.trayPopup = self.tree.get_ui("systrayPopup")
# pause menu items
self.emergePaused = False
- self.pauseItems = {}
- self.pauseItems["tray"] = self.trayPopup.tree.get_widget("pauseItemTray")
- self.pauseItems["popup"] = self.consolePopup.tree.get_widget("pauseItemPopup")
- self.pauseItems["menu"] = self.tree.get_widget("pauseItemMenu")
-
- for k,v in self.pauseItems.iteritems():
- self.pauseItems[k] = (v, v.connect_after("activate", self.cb_pause_emerge(k)))
# systray
if self.cfg.get_boolean("showSystray", "GUI"):
@@ -1772,50 +1775,13 @@ class MainWindow (Window):
self.queue.append(package, update = True, oneshot = set, forceUpdate = True)
- def cb_pause_emerge (self, curr):
- """
- This method returns a callback for a "pause emerge" toggle button.
- It is needed as there are different toggle buttons of this type and if one is clicked,
- the others should be marked too.
-
- @param curr: The button to return the callback for.
- @type curr: gtk.ToggleButton
- """
- def pause (cb):
- """
- The actual callback.
-
- Mark all other buttons too.
-
- @param cb: The button which got toggled.
- @type cb: gtk.ToggleButton
- """
-
- # pause or continue
- self.emergePaused = cb.get_active()
- if not self.emergePaused:
- self.queue.continue_emerge()
- #self.tray.set_from_file(APP_ICON)
- else:
- self.queue.stop_emerge()
- #self.tray.set_from_file(os.path.join(ICON_DIR, "pausing.png"))
-
- # block the handlers of the other buttons
- # so that calling "set_active" does not call this callback recursivly
- for v in self.pauseItems.itervalues():
- v[0].handler_block(v[1])
-
- # mark the others
- for k, v in self.pauseItems.iteritems():
- if k != curr:
- v[0].set_active(self.emergePaused)
-
- # unblock
- for v in self.pauseItems.itervalues():
- v[0].handler_unblock(v[1])
-
- return False
- return pause
+ def cb_pause_emerge (self, action):
+ # pause or continue
+ self.emergePaused = action.get_active()
+ if not self.emergePaused:
+ self.queue.continue_emerge()
+ else:
+ self.queue.stop_emerge()
def cb_kill_clicked (self, *args):
"""
@@ -1823,7 +1789,7 @@ class MainWindow (Window):
"""
self.queue.kill_emerge()
if self.emergePaused: # unmark the "pause emerge" buttons
- self.pauseItems["menu"][0].set_active(False) # calling one button is enough (see: cb_pause_emerge)
+ self.tree.get_widget("generalActionGroup").get_action("pauseAction").set_active(False)
def cb_copy_clicked (self, *args):
"""
@@ -1879,6 +1845,18 @@ class MainWindow (Window):
else:
self.window.iconify()
+ def cb_testing_toggled (self, *args):
+ return self.packageTable.cb_testing_toggled(*args)
+ def cb_masked_toggled (self, *args):
+ return self.packageTable.cb_masked_toggled(*args)
+ def cb_button_pressed (self, *args):
+ return self.packageTable.cb_button_pressed(*args)
+ def cb_package_revert_clicked (self, *args):
+ return self.packageTable.cb_package_revert_clicked(*args)
+ def cb_package_unmerge_clicked (self, *args):
+ return self.packageTable.cb_package_unmerge_clicked(*args)
+ def cb_package_emerge_clicked (self, *args):
+ return self.packageTable.cb_package_emerge_clicked(*args)
def cb_use_flag_toggled (self, *args):
return self.packageTable.cb_use_flag_toggled(*args)