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
|
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import re
from PyQt4.QtGui import QDialog, QLineEdit
from PyQt4.QtCore import Qt
from calibre.gui2.dialogs.password_ui import Ui_Dialog
from calibre.gui2 import dynamic
class PasswordDialog(QDialog, Ui_Dialog):
def __init__(self, window, name, msg):
QDialog.__init__(self, window)
Ui_Dialog.__init__(self)
self.setupUi(self)
self.cfg_key = re.sub(r'[^0-9a-zA-Z]', '_', name)
un = dynamic[self.cfg_key+'__un']
pw = dynamic[self.cfg_key+'__pw']
if not un:
un = ''
if not pw:
pw = ''
self.gui_username.setText(un)
self.gui_password.setText(pw)
self.sname = name
self.msg.setText(msg)
self.show_password.stateChanged[(int)].connect(self.toggle_password)
def toggle_password(self, state):
if state == Qt.Unchecked:
self.gui_password.setEchoMode(QLineEdit.Password)
else:
self.gui_password.setEchoMode(QLineEdit.Normal)
def username(self):
return unicode(self.gui_username.text())
def password(self):
return unicode(self.gui_password.text())
def accept(self):
dynamic.set(self.cfg_key+'__un', unicode(self.gui_username.text()))
dynamic.set(self.cfg_key+'__pw', unicode(self.gui_password.text()))
QDialog.accept(self)
|