2016-06-17 00:10:26 +03:00
|
|
|
from widgets import CenteredWidget, LineEdit
|
2016-05-24 21:22:21 +03:00
|
|
|
try:
|
|
|
|
from PySide import QtCore, QtGui
|
|
|
|
except ImportError:
|
|
|
|
from PyQt4 import QtCore, QtGui
|
2016-05-15 17:39:49 +03:00
|
|
|
|
|
|
|
|
2016-06-17 00:10:26 +03:00
|
|
|
class PasswordArea(LineEdit):
|
2016-05-19 00:38:21 +03:00
|
|
|
|
|
|
|
def __init__(self, parent):
|
|
|
|
super(PasswordArea, self).__init__(parent)
|
|
|
|
self.parent = parent
|
|
|
|
self.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
|
|
|
|
|
|
|
|
def keyPressEvent(self, event):
|
|
|
|
if event.key() == QtCore.Qt.Key_Return:
|
|
|
|
self.parent.button_click()
|
|
|
|
else:
|
|
|
|
super(PasswordArea, self).keyPressEvent(event)
|
|
|
|
|
|
|
|
|
2016-05-15 17:39:49 +03:00
|
|
|
class PasswordScreen(CenteredWidget):
|
|
|
|
|
2016-05-15 19:54:44 +03:00
|
|
|
def __init__(self, encrypt, data):
|
2016-05-15 17:39:49 +03:00
|
|
|
super(PasswordScreen, self).__init__()
|
|
|
|
self._encrypt = encrypt
|
2016-05-15 19:54:44 +03:00
|
|
|
self._data = data
|
2016-05-15 17:39:49 +03:00
|
|
|
self.initUI()
|
|
|
|
|
|
|
|
def initUI(self):
|
2016-05-15 19:54:44 +03:00
|
|
|
self.resize(360, 170)
|
|
|
|
self.setMinimumSize(QtCore.QSize(360, 170))
|
|
|
|
self.setMaximumSize(QtCore.QSize(360, 170))
|
2016-05-15 17:39:49 +03:00
|
|
|
|
|
|
|
self.enter_pass = QtGui.QLabel(self)
|
|
|
|
self.enter_pass.setGeometry(QtCore.QRect(30, 10, 300, 30))
|
|
|
|
|
2016-05-19 00:38:21 +03:00
|
|
|
self.password = PasswordArea(self)
|
2016-05-15 19:54:44 +03:00
|
|
|
self.password.setGeometry(QtCore.QRect(30, 50, 300, 30))
|
2016-05-15 17:39:49 +03:00
|
|
|
|
|
|
|
self.button = QtGui.QPushButton(self)
|
2016-05-15 19:54:44 +03:00
|
|
|
self.button.setGeometry(QtCore.QRect(30, 90, 300, 30))
|
2016-05-15 17:39:49 +03:00
|
|
|
self.button.setText('OK')
|
2016-05-15 19:54:44 +03:00
|
|
|
self.button.clicked.connect(self.button_click)
|
|
|
|
|
|
|
|
self.warning = QtGui.QLabel(self)
|
|
|
|
self.warning.setGeometry(QtCore.QRect(30, 130, 300, 30))
|
|
|
|
self.warning.setStyleSheet('QLabel { color: #F70D1A; }')
|
|
|
|
self.warning.setVisible(False)
|
2016-05-15 17:39:49 +03:00
|
|
|
|
|
|
|
self.retranslateUi()
|
2016-05-19 00:38:21 +03:00
|
|
|
self.center()
|
2016-05-15 17:39:49 +03:00
|
|
|
QtCore.QMetaObject.connectSlotsByName(self)
|
|
|
|
|
2016-05-15 19:54:44 +03:00
|
|
|
def button_click(self):
|
|
|
|
if self.password.text():
|
|
|
|
try:
|
|
|
|
self._encrypt.set_password(self.password.text())
|
|
|
|
new_data = self._encrypt.pass_decrypt(self._data[0])
|
2016-05-19 00:38:21 +03:00
|
|
|
except Exception:
|
2016-05-15 19:54:44 +03:00
|
|
|
self.warning.setVisible(True)
|
|
|
|
else:
|
|
|
|
self._data[0] = new_data
|
|
|
|
self.close()
|
|
|
|
|
2016-05-19 00:38:21 +03:00
|
|
|
def keyPressEvent(self, event):
|
|
|
|
if event.key() == QtCore.Qt.Key_Enter:
|
|
|
|
self.button_click()
|
|
|
|
else:
|
|
|
|
super(PasswordScreen, self).keyPressEvent(event)
|
|
|
|
|
2016-05-15 17:39:49 +03:00
|
|
|
def retranslateUi(self):
|
|
|
|
self.setWindowTitle(QtGui.QApplication.translate("pass", "Enter password", None, QtGui.QApplication.UnicodeUTF8))
|
|
|
|
self.enter_pass.setText(QtGui.QApplication.translate("pass", "Password:", None, QtGui.QApplication.UnicodeUTF8))
|
2016-05-15 19:54:44 +03:00
|
|
|
self.warning.setText(QtGui.QApplication.translate("pass", "Incorrect password", None, QtGui.QApplication.UnicodeUTF8))
|
2016-05-15 17:39:49 +03:00
|
|
|
|