def __init__(self, parent=None): super().__init__(parent) self.setAttribute(Qt.WA_QuitOnClose, False) self.setWindowFlags(Qt.Dialog | Qt.WindowTitleHint | Qt.WindowSystemMenuHint) self.setWindowTitle(_('Base Conversions')) self.value = 0 self.numBits = 32 self.twosComplement = False layout = QVBoxLayout(self) layout.setSpacing(0) decimalLabel = QLabel(_('&Decmal')) layout.addWidget(decimalLabel) decimalEdit = QLineEdit() decimalLabel.setBuddy(decimalEdit) decimalEdit.base = 10 decRegEx = QRegularExpression('[-0-9]*') decimalEdit.setValidator(QRegularExpressionValidator(decRegEx)) layout.addWidget(decimalEdit) layout.addSpacing(8) hexLabel = QLabel(_('&Hex')) layout.addWidget(hexLabel) hexEdit = QLineEdit() hexLabel.setBuddy(hexEdit) hexEdit.base = 16 hexRegEx = QRegularExpression('[-0-9a-fA-F]*') hexEdit.setValidator(QRegularExpressionValidator(hexRegEx)) layout.addWidget(hexEdit) layout.addSpacing(8) octalLabel = QLabel(_('&Octal')) layout.addWidget(octalLabel) octalEdit = QLineEdit() octalLabel.setBuddy(octalEdit) octalEdit.base = 8 octRegEx = QRegularExpression('[-0-7]*') octalEdit.setValidator(QRegularExpressionValidator(octRegEx)) layout.addWidget(octalEdit) layout.addSpacing(8) binaryLabel = QLabel(_('&Binary')) layout.addWidget(binaryLabel) binaryEdit = QLineEdit() binaryLabel.setBuddy(binaryEdit) binaryEdit.base = 2 binRegEx = QRegularExpression('[-01]*') binaryEdit.setValidator(QRegularExpressionValidator(binRegEx)) layout.addWidget(binaryEdit) layout.addSpacing(8) self.bitsButton = QPushButton('') self.setButtonLabel() layout.addWidget(self.bitsButton) self.bitsButton.clicked.connect(self.changeBitSettings) layout.addSpacing(8) closeButton = QPushButton(_('&Close')) layout.addWidget(closeButton) closeButton.clicked.connect(self.close) self.editors = (decimalEdit, hexEdit, octalEdit, binaryEdit) for editor in self.editors: editor.textEdited.connect(self.updateValue)