super(Gui, self).__init__()
+ self.profiles = []
+
self.createActions()
self.createTrayIcon()
+ self.createMainDialog()
self.trayIcon.show()
-
- self.setWindowTitle("Profile manager / Dboxswitch - dropbox profile switcher")
- self.resize(200, 200)
-
+
self.profileManager = prManager
def main(self):
""" Like Gtk application this main executes the app, thi is somewhat writed for
compatibility in porting the app """
+ self.show()
sys.exit(self.app.exec_())
def closeEvent(self, event):
""" Create actions for the various components """
self.manageprofiles = QtGui.QAction("Manage &Profiles", self,
- triggered=self.hide)
+ triggered=self.show)
self.quitAction = QtGui.QAction("&Quit", self,
triggered=QtGui.qApp.quit)
self.addProfile = QtGui.QAction(" Add &Profile ", self,
triggered=self.addProfile)
+ def createMainDialog(self):
+ """ Build the main dialog layout """
+
+ self.setWindowTitle("Profile manager / Dboxswitch - dropbox profile switcher")
+
+ self.la = QtGui.QFormLayout()
+ self.la.sizePolicy = QtGui.QSizePolicy.Expanding
+ self.la.setVerticalSpacing(15)
+ self.la.setHorizontalSpacing(15)
+ self.formGroupBox = QtGui.QGroupBox("Manage profiles:")
+ self.formGroupBox.setLayout(self.la)
+ mainLayout = QtGui.QVBoxLayout()
+ mainLayout.addWidget(self.formGroupBox)
+ self.setLayout(mainLayout)
+
+
+ def show(self):
+ """ Show the main dialog for dealing with profiles """
+
+ profiles = self.profileManager.getProfilesList()
+
+ for pr in profiles:
+ prname = self.profileManager.getBaseProfileName(pr)
+ delButton = QtGui.QToolButton()
+ label = QtGui.QLabel(prname)
+ self.la.addRow(label, delButton)
+ delAction = QtGui.QAction(QtGui.QIcon(appconf.delpicon),"Delete", self,
+ triggered=self.deleteProfileAction(prname, (label, delButton)))
+ delButton.setDefaultAction(delAction)
+ self.profiles.append((label, delButton))
+
+ self.sizeHint()
+ super(Gui, self).show()
+
+ def hide(self):
+ """ Hides the main dialog """
+
+ #Hides all the profiles in the Dialog
+ #User can deal with profiles like removing the dir manually
+
+ for ws in self.profiles:
+ for w in ws:
+ w.setParent(None)
+ w.close()
+ super(Gui, self).hide()
def createTrayIcon(self):
""" Builds a new tray icon with a context menu and an action for the profile manager menu """
self.showError(str(e))
return f
+ def deleteProfileAction(self, pr, prWidgets):
+ """ Returns a callable to be passed as an action for the profile manager mechanism
+ to self.connect(menuItem_Profile...
+ It compiles a function with a profile name as argument and also handle the displaying of errors."""
+
+ def f():
+ try:
+ #self.profileManager.delProfile(pr)
+ for w in prWidgets:
+ w.setParent(None)
+ w.close()
+ except AppError, e:
+ self.showError(str(e))
+ return f
+
+
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 """
class Settings():
def __init__(self):
path = __file__ if __file__ is not None else sys.argv[0]
- __location__ = os.path.realpath(
- os.path.join(os.getcwd(), os.path.dirname(path)))
+ __location__ = os.path.realpath(os.path.join(os.getcwd(),
+ os.path.dirname(path)))
- print(os.path.join(__location__,"icon.png"))
self.appname = "dboxswitch"
self.appversion = "0.1"
- self.icon = os.path.join(__location__,"icon.png")
- self.cpicon = os.path.join(__location__,"current-profile.png")
+ self.icon = os.path.join(__location__,"icon.png")
+ self.cpicon = os.path.join(__location__,"current-profile.png")
+ self.delpicon = os.path.join(__location__,"delete.png")
global conf
appconf = Settings()