added initial profiles switch implementation
authorstack <stack@inventati.org>
Sun, 8 Jul 2012 16:17:48 +0000 (18:17 +0200)
committerstack <stack@inventati.org>
Sun, 8 Jul 2012 16:21:53 +0000 (18:21 +0200)
when left clicking on the systray a list of profiles is shown, clicking
on a profile a "activateProfile" is called and an action to create a new
profile is displayed.
This is handled through a QMenu and lambda functions to pass additional
paramenters to the receiver, also interesting are the functions:
            self.menuProfiles.activateWindow()
            self.menuProfiles.popup(QtGui.QCursor.pos())

gui.py

diff --git a/gui.py b/gui.py
index c4a1866..d8c33a1 100755 (executable)
--- a/gui.py
+++ b/gui.py
@@ -90,6 +90,50 @@ class Gui(QtGui.QDialog):
          self.trayIcon.setContextMenu(self.trayIconMenu)
          #baloon on hover
          self.trayIcon.setToolTip(appconf.appname+" "+appconf.appversion+"\nRight Click to manage profiles.")
+         #left click profiles show
+         self.trayIcon.activated.connect(self.showTrayProfiles)
+
+
+    def showTrayProfiles(self,reason):
+        if reason in (QtGui.QSystemTrayIcon.Trigger, QtGui.QSystemTrayIcon.DoubleClick):
+            print "Catched left click"
+            self.menuProfiles = QtGui.QMenu()
+            self.menuProfiles.setTitle("Profiles")
+
+            profiles = self.profileManager.getProfilesList()
+
+            for pr in profiles:
+                pr = os.path.basename(pr)
+                menuItem_Profile = self.menuProfiles.addAction(pr)
+
+                #Using lambda function to pass additional arguments to the function, in this case the path of the profile
+                receiver = lambda pr=pr: self.profileManager.activateProfile(pr)
+                self.connect(menuItem_Profile, SIGNAL('triggered()'), receiver)
+
+                self.menuProfiles.addAction(menuItem_Profile)
+
+            #menuItem_Profile = self.menuProfiles.addAction("")
+            #self.menuProfiles.addAction(menuItem_Profile)
+            self.menuProfiles.addSeparator()
+            menuItem_Profile = QtGui.QAction("  Add &Profile  ", self,
+            triggered=self.addProfile, icon=QtGui.QIcon(appconf.icon))
+            self.menuProfiles.addAction(menuItem_Profile)
+
+            self.menuProfiles.activateWindow()
+            self.menuProfiles.popup(QtGui.QCursor.pos())
+
+    def addProfile(self):
+        self.setWindowTitle("Add New Profile - Dboxswitch - dropbox profile switcher")
+        self.resize(300, 100)
+        text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog', 
+                            'Enter profile name:')
+                
+        if ok:
+            try:
+                self.profileManager.addProfile(unicode(text))
+            except AppError, e:
+                self.showError(str(e))
+
     def showError(self, err):
         """ Display an error message """
         self.setWindowTitle("Error - Dboxswitch - dropbox profile switcher")