From: stack Date: Sun, 8 Jul 2012 16:17:48 +0000 (+0200) Subject: added initial profiles switch implementation X-Git-Url: https://v.licheni.net/stack/code/dboxswitch.git/commitdiff_plain/8a7062fd368c9edb98b5a1c03239f4eebe4550a1?ds=inline added initial profiles switch implementation 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()) --- diff --git a/gui.py b/gui.py index c4a1866..d8c33a1 100755 --- 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")