-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserWindow.py
More file actions
118 lines (97 loc) · 4.08 KB
/
UserWindow.py
File metadata and controls
118 lines (97 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
import os
import sys
from PyQt4 import uic
from PyQt4.QtCore import SIGNAL, SLOT
from PyQt4.QtGui import QApplication, QMainWindow, QDialog
import Compte
import PyQt4.QtCore as Core
import PyQt4.QtGui as Gui
from os import path
UiUserWindow, Klass = uic.loadUiType(path.join("dep",'UserWindow.ui'))
class Window(QDialog, UiUserWindow):
def __init__(self, conteneur=None,contain=None):
self.contain=contain
if conteneur is None : conteneur = self
QDialog.__init__(conteneur)
self.setupUi(conteneur)
self.selected=""
self.user=None
self.account=Compte.Account()
for x in self.account.getNames():
if self.selected=="":
self.selected=x
self.comboBoxAccount.addItem(x)
if self.selected=="":
self.selected="Nouveau"
self.lineEditNewName.setEnabled(True)
self.comboBoxAccount.addItem("Nouveau")
self.createConnexions()
self.bool=True
self.optionOn()
if self.selected in ["","Nouveau"]:
self.pushButtonDelete.setEnabled(False)
self.pushButtonExport.setEnabled(False)
self.show()
def actionOK(self):
if self.lineEditNewName.isEnabled() and self.lineEditNewName.text()!="":
self.selected=self.lineEditNewName.text()
self.selected=str(self.selected)
if self.selected not in ["","Nouveau","nouveau","new","New","neu","neues"]:
if self.selected in self.account.getUsers().keys():
self.user=self.account.getUsers()[self.selected]
else : self.user=Compte.User(self.selected)
self.done(1)
#fin
def changedSelect(self):
if str(self.comboBoxAccount.currentText())=="Nouveau":
self.lineEditNewName.setEnabled(True)
self.pushButtonDelete.setEnabled(False)
self.pushButtonExport.setEnabled(False)
self.selected=""
else:
self.lineEditNewName.clear()
self.lineEditNewName.setEnabled(False)
self.pushButtonDelete.setEnabled(True)
self.pushButtonExport.setEnabled(True)
self.selected=str(self.comboBoxAccount.currentText())
def createConnexions(self):
self.connect(self.lineEditNewName,SIGNAL("returnPressed()"),self.actionOK )
self.connect(self.pushButtonOK, SIGNAL("clicked()"), self.actionOK )
self.connect(self.pushButtonOption, SIGNAL("clicked()"), self.optionOn )
self.connect(self.pushButtonDelete, SIGNAL("clicked()"), self.delete )
self.connect(self.comboBoxAccount, SIGNAL("activated(int)"), self.changedSelect )
def optionOn(self):
if self.bool:
self.pushButtonOption.setText("Options >>>")
self.setFixedSize(540,180)
self.pushButtonDelete.hide()
self.pushButtonImport.hide()
self.pushButtonExport.hide()
self.bool= not(self.bool)
else :
self.pushButtonOption.setText("Options <<<")
self.setFixedSize(540,211)
self.pushButtonDelete.show()
self.pushButtonImport.show()
self.pushButtonExport.show()
self.bool= not(self.bool)
def delete(self):
locale = Core.QLocale.system().name()
translator=Core.QTranslator ()
translator.load(Core.QString("qt_") + locale, Core.QLibraryInfo.location(Core.QLibraryInfo.TranslationsPath))
self.contain.installTranslator(translator)
if Gui.QMessageBox.Yes== Gui.QMessageBox.question(self, 'Message',
u"Êtes-vous sûr de vouloir supprimer ce profil ?", Gui.QMessageBox.Yes, Gui.QMessageBox.No):
self.comboBoxAccount.removeItem(self.comboBoxAccount.currentIndex())
os.remove("users/"+self.selected+".bin")
del self.account.users[self.selected]
self.account.names.remove(self.selected)
self.changedSelect()
def getUser(self):
return self.user
if __name__ == "__main__":
a = QApplication(sys.argv)
f = Window(contain=a)
f.show()
r = a.exec_()