From eb2d5a7590bbbe91abe5d8f8a79624d6f756daba Mon Sep 17 00:00:00 2001
From: necoro <>
Date: Wed, 25 Apr 2007 23:21:14 +0000
Subject: added systray
---
portato/gui/gtk/windows.py | 45 +++++++++++++--
portato/gui/gui_helper.py | 5 +-
portato/gui/qt/windows.py | 53 +++++++++++++++--
portato/gui/templates/portato.glade | 85 +++++++++++++++++++++++++---
portato/gui/templates/ui/PreferenceWindow.ui | 29 ++++++++++
5 files changed, 198 insertions(+), 19 deletions(-)
(limited to 'portato')
diff --git a/portato/gui/gtk/windows.py b/portato/gui/gtk/windows.py
index 88d9a18..7c6f41b 100644
--- a/portato/gui/gtk/windows.py
+++ b/portato/gui/gtk/windows.py
@@ -186,9 +186,11 @@ class PreferenceWindow (AbstractDialog):
"deepCheck" : "deep_opt",
"newUseCheck" : "newuse_opt",
"maskPerVersionCheck" : "maskPerVersion_opt",
+ "minimizeCheck" : ("minimize_opt", "gui_sec"),
+ "systrayCheck" : ("systray_opt", "gui_sec"),
+ "testPerVersionCheck" : "testingPerVersion_opt",
"usePerVersionCheck" : "usePerVersion_opt",
- "useTipsCheck" : ("useTips_opt", "gtk_sec"),
- "testPerVersionCheck" : "testingPerVersion_opt"
+ "useTipsCheck" : ("useTips_opt", "gtk_sec")
}
# all edits in the window
@@ -800,6 +802,15 @@ class MainWindow (Window):
# popups
self.queuePopup = self.create_popup("queuePopup")
self.consolePopup = self.create_popup("consolePopup")
+ self.trayPopup = self.create_popup("systrayPopup")
+
+ # systray
+ if self.cfg.get_boolean("systray_opt", self.cfg.const["gui_sec"]):
+ self.tray = gtk.status_icon_new_from_file(APP_ICON)
+ self.tray.connect("activate", self.cb_systray_activated)
+ self.tray.connect("popup-menu", lambda icon, btn, time: self.trayPopup.popup(None, None, None, btn, time))
+ else:
+ self.tray = None
# set emerge queue
self.queueTree = GtkTree(self.queueList.get_model())
@@ -903,8 +914,13 @@ class MainWindow (Window):
def title_update (self, title):
- if title == None: title = "Console"
- else: title = ("Console (%s)" % title)
+ if self.tray:
+ self.tray.set_tooltip(title)
+
+ if title == None:
+ title = "Console"
+ else:
+ title = ("Console (%s)" % title)
gobject.idle_add(self.notebook.set_tab_label_text, self.termHB, title)
@@ -1127,6 +1143,27 @@ class MainWindow (Window):
return False
+ def cb_minimized (self, window, event):
+ if self.tray and self.cfg.get_boolean("minimize_opt", self.cfg.const["gui_sec"]):
+ if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED:
+ if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
+ self.window.hide()
+ return True
+
+ return False
+
+ def cb_systray_activated (self, tray):
+ if self.window.iconify_initially:
+ self.window.deiconify()
+ self.window.show()
+ self.window.window.show()
+ else:
+ self.window.iconify()
+
+ def cb_close (self, *args):
+ if not self.cb_delete(): # do the checks
+ self.window.destroy()
+
def cb_destroy (self, widget):
"""Calls main_quit()."""
gtk.main_quit()
diff --git a/portato/gui/gui_helper.py b/portato/gui/gui_helper.py
index 656b83a..a898ea7 100644
--- a/portato/gui/gui_helper.py
+++ b/portato/gui/gui_helper.py
@@ -36,6 +36,7 @@ class Config: # XXX: This needs to be replaced - the const-dict is just messy
"main_sec" : "Main",
"gtk_sec" : "Gtk",
"qt_sec" : "Qt",
+ "gui_sec" : "Gui",
"usePerVersion_opt" : "usePerVersion",
"useFile_opt" : "usefile",
"maskFile_opt" : "maskfile",
@@ -49,7 +50,9 @@ class Config: # XXX: This needs to be replaced - the const-dict is just messy
"syncCmd_opt" : "synccommand",
"useTips_opt" : "showusetips",
"pkgIcons_opt" : "packageIcons",
- "system_opt" : "system"
+ "system_opt" : "system",
+ "systray_opt" : "showsystray",
+ "minimize_opt" : "hideonminimize"
}
def __init__ (self, cfgFile):
diff --git a/portato/gui/qt/windows.py b/portato/gui/qt/windows.py
index 420b9e1..e131bdd 100644
--- a/portato/gui/qt/windows.py
+++ b/portato/gui/qt/windows.py
@@ -181,7 +181,9 @@ class PreferenceWindow (Window):
"maskCheck" : "maskPerVersion_opt",
"useCheck" : "usePerVersion_opt",
"testingCheck" : "testingPerVersion_opt",
- "pkgIconsCheck" : ("pkgIcons_opt", "qt_sec")
+ "pkgIconsCheck" : ("pkgIcons_opt", "qt_sec"),
+ "minimizeCheck" : ("minimize_opt", "gui_sec"),
+ "systrayCheck" : ("systray_opt", "gui_sec")
}
# all edits in the window
@@ -602,7 +604,7 @@ class MainWindow (Window):
plugin.load_plugins("qt")
menus = plugin.get_plugins().get_plugin_menus()
if menus:
- self.pluginMenu = Qt.QMenu("&Plugins")
+ self.pluginMenu = Qt.QMenu("&Plugins", self)
self.menubar.insertMenu(self.helpMenu.menuAction(), self.pluginMenu)
for m in menus:
action = self.pluginMenu.addAction(m.label.replace("_","&"))
@@ -631,6 +633,9 @@ class MainWindow (Window):
Qt.QObject.connect(self.queueList, Qt.SIGNAL("itemActivated (QTreeWidgetItem*, int)"), self.cb_queue_list_item_selected)
Qt.QObject.connect(self.queueList, Qt.SIGNAL("itemDoubleClicked (QTreeWidgetItem*, int)"), self.cb_queue_list_item_selected)
+ # build systray
+ self.build_systray()
+
# set emerge queue
self.queue = EmergeQueue(console = self.console, tree = self.queueTree, db = self.db, title_update = self.title_update)
@@ -640,8 +645,13 @@ class MainWindow (Window):
self.emit(Qt.SIGNAL("doTitleUpdate"), title)
def _title_update (self, title):
- if title == None: title = "Console"
- else: title = ("Console (%s)" % title)
+
+ if title is None:
+ if self.systray: self.systray.setToolTip("")
+ title = "Console"
+ else:
+ if self.systray: self.systray.setToolTip(title)
+ title = ("Console (%s)" % title)
self.tabWidget.setTabText(self.CONSOLE_PAGE, title)
@@ -678,6 +688,18 @@ class MainWindow (Window):
self.catList.setModel(self.catListModel)
self.catList.setSelectionModel(self.selCatListModel)
+ def build_systray (self):
+ if self.cfg.get_boolean("systray_opt", self.cfg.const["gui_sec"]):
+ self.systray = Qt.QSystemTrayIcon(Qt.QIcon(APP_ICON), self)
+ self.trayIconMenu = Qt.QMenu(self)
+ self.trayIconMenu.addAction(self.quitAction)
+ self.systray.setContextMenu(self.trayIconMenu)
+ self.systray.show()
+
+ Qt.QObject.connect(self.systray, Qt.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.cb_systray_activated)
+ else:
+ self.systray = None
+
@Qt.pyqtSignature("")
def on_aboutAction_triggered (self):
queue = plugin.get_plugins()
@@ -854,14 +876,33 @@ class MainWindow (Window):
if not index is None:
self.pkgDetails.update(self.selCatName+"/"+str(index.text()), self.queue)
+ def cb_systray_activated (self, reason):
+ if reason != Qt.QSystemTrayIcon.Context: # do not react on context menu calls
+ if self.windowState() & Qt.Qt.WindowMinimized: # window is minimized
+ self.show()
+ self.showNormal()
+ else: # window is not minimized
+ self.setWindowState(self.windowState() | Qt.Qt.WindowMinimized)
+
def closeEvent (self, event):
if not self.queue.is_empty():
ret = queue_not_empty_dialog(self)
if ret == Qt.QMessageBox.Cancel:
- event.ignore()
return
else:
self.queue.kill_emerge()
- event.accept()
+ if self.systray and self.systray.isVisible():
+ self.systray.hide()
+
+ Qt.QMainWindow.closeEvent(self, event)
+
+ def changeEvent (self, event):
+ if event.type() == Qt.QEvent.WindowStateChange:
+ if self.systray and self.cfg.get_boolean("minimize_opt", self.cfg.const["gui_sec"]):
+ if self.windowState() & Qt.Qt.WindowMinimized: # going to be minimized
+ self.hide()
+ return
+
+ Qt.QMainWindow.changeEvent(self,event)
diff --git a/portato/gui/templates/portato.glade b/portato/gui/templates/portato.glade
index 2443bd1..8037ca9 100644
--- a/portato/gui/templates/portato.glade
+++ b/portato/gui/templates/portato.glade
@@ -7,6 +7,7 @@
GTK_WIN_POS_CENTER
+
True
@@ -66,7 +67,7 @@
True
_Close
True
-
+
True
@@ -877,24 +878,76 @@
True
+
+
+
+
+
+
+ True
+ <b>General Options</b>
+ True
+
+
+ label_item
+
+
+
+
+
+
+ True
+ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+ 0
+
+
+ True
+ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+ 12
+
+
+ True
+ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
True
Turn Use-Tips on
True
+
+
+
+ True
+ True
+ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+ Enable systray
+ True
+
1
+
+
+ True
+ True
+ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+ Hide on minimization (only if systray is enabled)
+ True
+
+
+ 2
+
+
-
+
True
- <b>General Options</b>
+ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+ <b>Visual Options</b>
True
@@ -902,6 +955,9 @@
+
+ 1
+
@@ -963,7 +1019,7 @@
- 1
+ 2
@@ -1012,7 +1068,7 @@
- 2
+ 3
@@ -1063,7 +1119,7 @@
- 3
+ 4
@@ -1289,7 +1345,7 @@
- 4
+ 5
@@ -1318,7 +1374,7 @@
- 5
+ 6
@@ -1337,4 +1393,17 @@
+
diff --git a/portato/gui/templates/ui/PreferenceWindow.ui b/portato/gui/templates/ui/PreferenceWindow.ui
index fd4ccfa..fbc4a37 100644
--- a/portato/gui/templates/ui/PreferenceWindow.ui
+++ b/portato/gui/templates/ui/PreferenceWindow.ui
@@ -41,6 +41,21 @@
+
+
+
+ -
+
+
+ Visual Options
+
+
+
+ 9
+
+
+ 0
+
-
@@ -48,6 +63,20 @@
+ -
+
+
+ Show systray icon
+
+
+
+ -
+
+
+ Minimize to systray (only if systray icon is activated)
+
+
+
--
cgit v1.2.3-70-g09d2