From: stack Date: Sun, 8 Jul 2012 16:44:27 +0000 (+0200) Subject: gui.py better function documentation X-Git-Url: https://v.licheni.net/stack/code/dboxswitch.git/commitdiff_plain/86b7bff5277f8681b1dcb4d722481e5173fe590f?ds=inline;hp=8a7062fd368c9edb98b5a1c03239f4eebe4550a1 gui.py better function documentation added more function documentation in Gui and also documented some passage --- diff --git a/gui.py b/gui.py index d8c33a1..5f16273 100755 --- a/gui.py +++ b/gui.py @@ -42,6 +42,10 @@ from settings import appconf class Gui(QtGui.QDialog): def __init__(self, prManager): + """ Gui init, an QApplication is created and stored here, also a main window and a trayIcon + are created. + Default actions are builded and profile manager stored from argument (instance of ProfHandler """ + self.app = QtGui.QApplication(sys.argv) #check if system tray is avaiable on the system @@ -65,14 +69,21 @@ class Gui(QtGui.QDialog): self.profileManager = prManager def main(self): + """ Like Gtk application this main executes the app, thi is somewhat writed for + compatibility in porting the app """ + sys.exit(self.app.exec_()) def closeEvent(self, event): + """ Handle application closing """ + if self.trayIcon.isVisible(): self.hide() event.ignore() def createActions(self): + """ Create actions for the various components """ + self.manageprofiles = QtGui.QAction("Manage &Profiles", self, triggered=self.hide) self.quitAction = QtGui.QAction("&Quit", self, @@ -80,26 +91,33 @@ class Gui(QtGui.QDialog): def createTrayIcon(self): + """ Builds a new tray icon with a context menu and an action for the profile manager menu """ + #context menu build, right click self.trayIconMenu = QtGui.QMenu(self) self.trayIconMenu.addAction(self.manageprofiles) self.trayIconMenu.addSeparator() self.trayIconMenu.addAction(self.quitAction) + #create the tray with an incon self.trayIcon = QtGui.QSystemTrayIcon(QtGui.QIcon(appconf.icon), self.app) + #attach a context menu for the right click to the tray self.trayIcon.setContextMenu(self.trayIconMenu) - #baloon on hover + #baloon on hover for the tray self.trayIcon.setToolTip(appconf.appname+" "+appconf.appversion+"\nRight Click to manage profiles.") - #left click profiles show + #left click profiles show for the tray self.trayIcon.activated.connect(self.showTrayProfiles) def showTrayProfiles(self,reason): + """ Pops up a system tray profile Manager with a list of activable profiles and an + action to add a new One """ + if reason in (QtGui.QSystemTrayIcon.Trigger, QtGui.QSystemTrayIcon.DoubleClick): - print "Catched left click" self.menuProfiles = QtGui.QMenu() self.menuProfiles.setTitle("Profiles") + #Get profiles from the ProfHandler embedded in the gui profiles = self.profileManager.getProfilesList() for pr in profiles: @@ -123,11 +141,13 @@ class Gui(QtGui.QDialog): self.menuProfiles.popup(QtGui.QCursor.pos()) def addProfile(self): + """ Gui frontend to add a new Profile, it requests the user a profile name + through a QInputDialog and creates a new profile with the help of the ProfHandler embedded in the Gui """ + 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)) @@ -135,10 +155,8 @@ class Gui(QtGui.QDialog): self.showError(str(e)) def showError(self, err): - """ Display an error message """ + """ Display an error message through a QErrorMessage """ + self.setWindowTitle("Error - Dboxswitch - dropbox profile switcher") self.resize(200, 100) err = QtGui.QErrorMessage.showMessage(QtGui.QErrorMessage.qtHandler(), "Error: "+err) - - -