From ed21cea32a80572106e5776a44e1b1edd7baa580 Mon Sep 17 00:00:00 2001 From: stack Date: Wed, 11 Jul 2012 18:44:36 +0200 Subject: [PATCH] FirstImplementation of main dialog profile manager Profiles could be deleted from a main dialog with a layout that has still some resizong problem. The layout builds a label and a qtoolbutton that calls the action that hides those widgets and deletes the profile. The actual call to profHandler.delProfile is commented out. --- delete.png | Bin 0 -> 1031 bytes gui.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++---- settings.py | 10 ++++---- 3 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 delete.png diff --git a/delete.png b/delete.png new file mode 100644 index 0000000000000000000000000000000000000000..ec35ed2c6a1bc4f959d74e64dafb0aab721b4f84 GIT binary patch literal 1031 zcmV+i1o-=jP)4h9c_2`7WoBh^Wo~0-b1m?* zJpcdz7IZ~ebU}4=Xm4@=L2hJnWnpt5PHAj&b8l`d@8qKZ0013yMObuGZ*_8GWdLY& zbZ|N^FL!r$E@5tDa%Ew2ZZ30Wq3e3h0009HNkl~t@GQ$uZ zkP-zYV_-@^Om{UT{tex9(=_eEv{*y0EDUO; zNEBrpC`pI8Q)XZ~_kA80U?uU{KEHD|=NzM|9KNkwuGh8pq*WcYVK^)zsK}BH!v(AQ zW$)J3Z-;qv*x+$4H|EBoAKRC@x7eGTL%O@z{^r}dT07`jk(2TEOw?3&a9-{qc43^En=^!= z<-$AThzQp|xkg(i!`S&Tnm^pbY;F)c@?v!7_qEfWh>Vhmd$v*`cIgs0hR5YHYiob- z;gt^%Rf@$T`FtJ>#Lu3gIys5ww|Ky)W5aOR#9~mZ;|vU-s!U#-q9fbEU+e1>i$%J+ zx;Xdt7^;es&%;g)*H0qW4tmyF#0rR@Du@W6IIi<7UdI?fk$)LgGz|BDYVA@O1Q3nT zTqz(T-2U_yrBaE`&Q3bAS=Nh1Zrr?qh|pYFL8B3xK@|f9r`c>SJgo#)lL>aexQo~j z*YoJ<>EZI!H1AGL)7RIBpG+WP+5P+u#!u3$1XfiS%p&w@B(l^#Jd`x$GLciKh@U?P z#^E4E_PeI+eKt#Db{1`Kr+k00Cf1G^Rb|nbi*Bm*N;*H_%jP58{(jZ* zW%tfq!sR8r&JHRM9@d&c_3DV~wf!m^W9}RCbtIKK*3$o)ZyF6WsG_y{ewF zG|JA;zt(IJEDfu^iK_fJCS%NxFkxKxBmYQO)J>;6FP#D)tOVHYimm@$+EZ(Mw`+e*mJOn#vfLu1f#_002ovPDHLkV1hqq B+PVM$ literal 0 HcmV?d00001 diff --git a/gui.py b/gui.py index 920ee85..a0c10f5 100644 --- a/gui.py +++ b/gui.py @@ -58,20 +58,21 @@ class Gui(QtGui.QDialog): 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): @@ -85,7 +86,7 @@ class Gui(QtGui.QDialog): """ 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) @@ -93,6 +94,51 @@ class Gui(QtGui.QDialog): 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 """ @@ -158,6 +204,22 @@ class Gui(QtGui.QDialog): 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 """ diff --git a/settings.py b/settings.py index 43d7bb7..7e8e1f0 100644 --- a/settings.py +++ b/settings.py @@ -37,14 +37,14 @@ import os, sys 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() -- 2.20.1