add Qt5 support for PinMatrixWidget

pull/25/head
Pavol Rusnak 8 years ago
parent 06cedd2150
commit c86201dc5b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -1,9 +1,17 @@
from __future__ import print_function
import sys
import math
from PyQt4.QtGui import (QPushButton, QLineEdit, QSizePolicy, QRegExpValidator, QLabel,
QApplication, QWidget, QGridLayout, QVBoxLayout, QHBoxLayout)
from PyQt4.QtCore import QObject, SIGNAL, QRegExp, Qt
try:
from PyQt4.QtGui import (QPushButton, QLineEdit, QSizePolicy, QRegExpValidator, QLabel,
QApplication, QWidget, QGridLayout, QVBoxLayout, QHBoxLayout)
from PyQt4.QtCore import QObject, SIGNAL, QRegExp, Qt, QT_VERSION_STR
except:
from PyQt5.QtWidgets import (QPushButton, QLineEdit, QSizePolicy, QLabel,
QApplication, QWidget, QGridLayout, QVBoxLayout, QHBoxLayout)
from PyQt5.QtGui import QRegExpValidator
from PyQt5.QtCore import QRegExp, Qt
from PyQt5.Qt import QT_VERSION_STR
class PinButton(QPushButton):
def __init__(self, password, encoded_value):
@ -11,7 +19,12 @@ class PinButton(QPushButton):
self.password = password
self.encoded_value = encoded_value
QObject.connect(self, SIGNAL('clicked()'), self._pressed)
if QT_VERSION_STR >= '5':
self.clicked.connect(self._pressed)
elif QT_VERSION_STR >= '4':
QObject.connect(self, SIGNAL('clicked()'), self._pressed)
else:
raise Exception('Unsupported Qt version')
def _pressed(self):
self.password.setText(self.password.text() + str(self.encoded_value))
@ -31,7 +44,13 @@ class PinMatrixWidget(QWidget):
self.password = QLineEdit()
self.password.setValidator(QRegExpValidator(QRegExp('[1-9]+'), None))
self.password.setEchoMode(QLineEdit.Password)
QObject.connect(self.password, SIGNAL('textChanged(QString)'), self._password_changed)
if QT_VERSION_STR >= '5':
self.password.textChanged.connect(self._password_changed)
elif QT_VERSION_STR >= '4':
QObject.connect(self.password, SIGNAL('textChanged(QString)'), self._password_changed)
else:
raise Exception('Unsupported Qt version')
self.strength = QLabel()
self.strength.setMinimumWidth(75)
@ -86,7 +105,7 @@ if __name__ == '__main__':
'''
Demo application showing PinMatrix widget in action
'''
a = QApplication(sys.argv)
app = QApplication(sys.argv)
matrix = PinMatrixWidget()
@ -96,7 +115,12 @@ if __name__ == '__main__':
sys.exit()
ok = QPushButton('OK')
QObject.connect(ok, SIGNAL('clicked()'), clicked)
if QT_VERSION_STR >= '5':
ok.clicked.connect(clicked)
elif QT_VERSION_STR >= '4':
QObject.connect(ok, SIGNAL('clicked()'), clicked)
else:
raise Exception('Unsupported Qt version')
vbox = QVBoxLayout()
vbox.addWidget(matrix)
@ -107,4 +131,4 @@ if __name__ == '__main__':
w.move(100, 100)
w.show()
a.exec_()
app.exec_()

Loading…
Cancel
Save