Repository navigation
Expand file tree
/
Copy pathAccountEdit.py
More file actions
104 lines (81 loc) · 3.08 KB
/
Copy pathAccountEdit.py
File metadata and controls
104 lines (81 loc) · 3.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
# -*- coding: utf-8 -*-
"""
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
@author: mkaay
"""
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from os.path import join
class AccountEdit(QWidget):
"""
account editor widget
"""
def __init__(self):
QMainWindow.__init__(self)
self.setWindowTitle(_("Edit account"))
self.setWindowIcon(QIcon(join(pypath, "icons","logo.png")))
self.setLayout(QGridLayout())
l = self.layout()
typeLabel = QLabel(_("Type"))
loginLabel = QLabel(_("Login"))
passwordLabel = QLabel(_("New password"))
changePw = QCheckBox()
changePw.setChecked(False)
self.changePw = changePw
password = QLineEdit()
password.setEnabled(False)
password.setEchoMode(QLineEdit.Password)
self.password = password
login = QLineEdit()
self.login = login
acctype = QComboBox()
self.acctype = acctype
save = QPushButton(_("Save"))
self.connect(changePw, SIGNAL("toggled(bool)"), password, SLOT("setEnabled(bool)"))
l.addWidget(save, 3, 0, 1, 3)
l.addWidget(acctype, 0, 1, 1, 2)
l.addWidget(login, 1, 1, 1, 2)
l.addWidget(password, 2, 2)
l.addWidget(changePw, 2, 1)
l.addWidget(passwordLabel, 2, 0)
l.addWidget(loginLabel, 1, 0)
l.addWidget(typeLabel, 0, 0)
self.connect(save, SIGNAL("clicked()"), self.slotSave)
def slotSave(self):
"""
save entered data
"""
data = {"login": str(self.login.text()), "acctype": str(self.acctype.currentText()), "password": False}
if self.changePw.isChecked():
data["password"] = str(self.password.text())
self.emit(SIGNAL("done"), data)
@staticmethod
def newAccount(types):
"""
create empty editor instance
"""
w = AccountEdit()
w.setWindowTitle(_("Create account"))
w.changePw.setChecked(True)
w.password.setEnabled(True)
w.acctype.addItems(types)
return w
@staticmethod
def editAccount(types, base):
"""
create editor instance with given data
"""
w = AccountEdit()
w.acctype.addItems(types)
w.acctype.setCurrentIndex(types.index(base["type"]))
w.login.setText(base["login"])
return w