def __init__(self): super(MainWidget, self).__init__() self._lock = QtCore.QMutex() self._controller = ControllerWatcher() self._build_ui() self._controller.on_found(self._refresh_controller, True) self._controller.on_lost(self._no_controller) self._no_controller()
class MainWidget(QtGui.QWidget): def __init__(self): super(MainWidget, self).__init__() self._lock = QtCore.QMutex() self._controller = ControllerWatcher() self._build_ui() self._controller.on_found(self._refresh_controller, True) self._controller.on_lost(self._no_controller) self._no_controller() def showEvent(self, event): self.refresh() event.accept() def _build_ui(self): layout = QtGui.QVBoxLayout(self) btns = QtGui.QHBoxLayout() self._cert_btn = QtGui.QPushButton(m.certificates) self._cert_btn.clicked.connect(self._manage_certs) btns.addWidget(self._cert_btn) self._pin_btn = QtGui.QPushButton(m.manage_pin) self._pin_btn.clicked.connect(self._manage_pin) btns.addWidget(self._pin_btn) layout.addLayout(btns) self._messages = QtGui.QTextEdit() self._messages.setFixedSize(480, 100) self._messages.setReadOnly(True) layout.addWidget(self._messages) def _manage_pin(self): ManageDialog(self._controller, self).exec_() self.refresh() def _manage_certs(self): CertDialog(self._controller, self).exec_() self.refresh() def refresh(self): self._controller.use(self._refresh_controller, True) def _no_controller(self): self._pin_btn.setEnabled(False) self._cert_btn.setEnabled(False) self._messages.setHtml(m.no_key) def _refresh_controller(self, controller, release): if not controller.poll(): self._no_controller() return self._pin_btn.setEnabled(True) self._cert_btn.setDisabled(controller.pin_blocked) messages = [] if controller.pin_blocked: messages.append(IMPORTANT % m.pin_blocked) messages.append(m.key_with_applet_1 % controller.version.decode('ascii')) n_certs = len(controller.certs) messages.append(m.certs_loaded_1 % n_certs or m.no) self._messages.setHtml('<br>'.join(messages)) if controller.is_uninitialized(): dialog = InitDialog(controller, self) if dialog.exec_(): self.refresh() else: QtCore.QCoreApplication.instance().quit() elif controller.is_pin_expired() and not controller.pin_blocked: dialog = SetPinDialog(controller, self, True) if dialog.exec_(): self.refresh() else: QtCore.QCoreApplication.instance().quit()
class MainWidget(QtGui.QWidget): def __init__(self): super(MainWidget, self).__init__() self._lock = QtCore.QMutex() self._controller = ControllerWatcher() self._build_ui() self._controller.on_found(self._refresh_controller, True) self._controller.on_lost(self._no_controller) self._no_controller() def showEvent(self, event): self.refresh() event.accept() def _build_ui(self): layout = QtGui.QVBoxLayout(self) btns = QtGui.QHBoxLayout() self._cert_btn = QtGui.QPushButton(m.certificates) self._cert_btn.clicked.connect(self._manage_certs) btns.addWidget(self._cert_btn) self._pin_btn = QtGui.QPushButton(m.manage_pin) self._pin_btn.clicked.connect(self._manage_pin) btns.addWidget(self._pin_btn) layout.addLayout(btns) self._messages = QtGui.QTextEdit() self._messages.setFixedSize(480, 100) self._messages.setReadOnly(True) layout.addWidget(self._messages) def _manage_pin(self): ManageDialog(self._controller, self).exec_() self.refresh() def _manage_certs(self): CertDialog(self._controller, self).exec_() self.refresh() def refresh(self): self._controller.use(self._refresh_controller, True) def _no_controller(self): self._pin_btn.setEnabled(False) self._cert_btn.setEnabled(False) self._messages.setHtml(m.no_key) def _refresh_controller(self, controller, release): if not controller.poll(): self._no_controller() return self._pin_btn.setEnabled(True) self._cert_btn.setDisabled(controller.pin_blocked) messages = [] if controller.pin_blocked: messages.append(IMPORTANT % m.pin_blocked) messages.append(m.key_with_applet_1 % controller.version) n_certs = len(controller.certs) messages.append(m.certs_loaded_1 % n_certs or m.no) self._messages.setHtml('<br>'.join(messages)) if controller.is_uninitialized(): dialog = InitDialog(controller, self) if dialog.exec_(): self.refresh() else: QtCore.QCoreApplication.instance().quit() elif controller.is_pin_expired() and not controller.pin_blocked: dialog = SetPinDialog(controller, self, True) if dialog.exec_(): self.refresh() else: QtCore.QCoreApplication.instance().quit()