def script_engine_test(): app = QApplication(sys.argv) # 创建js引擎 engine = QScriptEngine() fun = engine.evaluate("(function(a, b) { return a + b; })") args = [QScriptValue(1), QScriptValue(3)] three_again = fun.call(QScriptValue(), args) print three_again.toInt32() # 创建qt对象到js引擎,js可调用这个实例对象 button1 = QCheckBox('test---1') button2 = QCheckBox('test---2') button3 = QCheckBox('test---3') script_button1 = engine.newQObject(button1) script_button2 = engine.newQObject(button2) script_button3 = engine.newQObject(button3) engine.globalObject().setProperty("button1", script_button1) engine.globalObject().setProperty("button2", script_button2) engine.globalObject().setProperty("button3", script_button3) # 三种方式调用 # 1、用js的方式调用 engine.evaluate("button1.show()") engine.evaluate("button1.setChecked(true)") engine.evaluate("button1.setEnabled(false)") # 2、用js对象的方式调用 script_button2.property("show").call() script_button2.property("setChecked").call(QScriptValue(), [QScriptValue(True)]) script_button2.property("setEnabled").call(QScriptValue(), [QScriptValue(False)]) # 3、用qt对象的方式调用 button3.show() button3.setChecked(True) button3.setEnabled(False) sys.exit(app.exec_())
class LaserRangeFinder(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletLaserRangeFinder, *args) self.lrf = self.device self.cbe_distance = CallbackEmulator(self.lrf.get_distance, self.cb_distance, self.increase_error_count) self.cbe_velocity = CallbackEmulator(self.lrf.get_velocity, self.cb_velocity, self.increase_error_count) self.current_distance = None # int, cm self.current_velocity = None # float, m/s plots_distance = [('Distance', Qt.red, lambda: self.current_distance, format_distance)] plots_velocity = [('Velocity', Qt.red, lambda: self.current_velocity, '{:.2f} m/s'.format)] self.plot_widget_distance = PlotWidget('Distance [cm]', plots_distance) self.plot_widget_velocity = PlotWidget('Velocity [m/s]', plots_velocity) self.mode_label = QLabel('Mode:') self.mode_combo = QComboBox() self.mode_combo.addItem("Distance: 1cm resolution, 40m max") self.mode_combo.addItem("Velocity: 0.10 m/s resolution, 12.70m/s max") self.mode_combo.addItem("Velocity: 0.25 m/s resolution, 31.75m/s max") self.mode_combo.addItem("Velocity: 0.50 m/s resolution, 63.50m/s max") self.mode_combo.addItem("Velocity: 1.00 m/s resolution, 127.00m/s max") self.mode_combo.currentIndexChanged.connect(self.mode_changed) self.mode_combo.hide() self.label_average_distance = QLabel('Moving Average for Distance:') self.spin_average_distance = QSpinBox() self.spin_average_distance.setMinimum(0) self.spin_average_distance.setMaximum(50) self.spin_average_distance.setSingleStep(1) self.spin_average_distance.setValue(10) self.spin_average_distance.editingFinished.connect( self.spin_average_finished) self.label_average_velocity = QLabel('Moving Average for Velocity:') self.spin_average_velocity = QSpinBox() self.spin_average_velocity.setMinimum(0) self.spin_average_velocity.setMaximum(50) self.spin_average_velocity.setSingleStep(1) self.spin_average_velocity.setValue(10) self.spin_average_velocity.editingFinished.connect( self.spin_average_finished) self.enable_laser = QCheckBox("Enable Laser") self.enable_laser.stateChanged.connect(self.enable_laser_changed) self.label_acquisition_count = QLabel('Acquisition Count:') self.spin_acquisition_count = QSpinBox() self.spin_acquisition_count.setMinimum(1) self.spin_acquisition_count.setMaximum(255) self.spin_acquisition_count.setSingleStep(1) self.spin_acquisition_count.setValue(128) self.enable_qick_termination = QCheckBox("Quick Termination") self.label_threshold = QLabel('Threshold:') self.threshold = QCheckBox("Automatic Threshold") self.spin_threshold = QSpinBox() self.spin_threshold.setMinimum(1) self.spin_threshold.setMaximum(255) self.spin_threshold.setSingleStep(1) self.spin_threshold.setValue(1) self.label_frequency = QLabel('Frequency [Hz]:') self.frequency = QCheckBox( "Automatic Frequency (Disable for Velocity)") self.spin_frequency = QSpinBox() self.spin_frequency.setMinimum(10) self.spin_frequency.setMaximum(500) self.spin_frequency.setSingleStep(1) self.spin_frequency.setValue(10) self.spin_acquisition_count.editingFinished.connect( self.configuration_changed) self.enable_qick_termination.stateChanged.connect( self.configuration_changed) self.spin_threshold.editingFinished.connect(self.configuration_changed) self.threshold.stateChanged.connect(self.configuration_changed) self.spin_frequency.editingFinished.connect(self.configuration_changed) self.frequency.stateChanged.connect(self.configuration_changed) layout_h1 = QHBoxLayout() layout_h1.addWidget(self.plot_widget_distance) layout_h1.addWidget(self.plot_widget_velocity) layout_h2 = QHBoxLayout() layout_h2.addWidget(self.mode_label) layout_h2.addWidget(self.mode_combo) layout_h2.addWidget(self.label_average_distance) layout_h2.addWidget(self.spin_average_distance) layout_h2.addWidget(self.label_average_velocity) layout_h2.addWidget(self.spin_average_velocity) layout_h2.addStretch() layout_h2.addWidget(self.enable_laser) layout_h3 = QHBoxLayout() layout_h3.addWidget(self.label_frequency) layout_h3.addWidget(self.spin_frequency) layout_h3.addWidget(self.frequency) layout_h3.addStretch() layout_h3.addWidget(self.enable_qick_termination) layout_h4 = QHBoxLayout() layout_h4.addWidget(self.label_threshold) layout_h4.addWidget(self.spin_threshold) layout_h4.addWidget(self.threshold) layout_h4.addStretch() layout_h4.addWidget(self.label_acquisition_count) layout_h4.addWidget(self.spin_acquisition_count) self.widgets_distance = [ self.plot_widget_distance, self.spin_average_distance, self.label_average_distance ] self.widgets_velocity = [ self.plot_widget_velocity, self.spin_average_velocity, self.label_average_velocity ] for w in self.widgets_distance: w.hide() for w in self.widgets_velocity: w.hide() line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addLayout(layout_h1) layout.addWidget(line) layout.addLayout(layout_h2) layout.addLayout(layout_h3) layout.addLayout(layout_h4) self.has_sensor_hardware_version_api = self.firmware_version >= (2, 0, 3) self.has_configuration_api = self.firmware_version >= (2, 0, 3) def start(self): if self.has_sensor_hardware_version_api: async_call(self.lrf.get_sensor_hardware_version, None, self.get_sensor_hardware_version_async, self.increase_error_count) else: self.get_sensor_hardware_version_async(1) if self.has_configuration_api: async_call(self.lrf.get_configuration, None, self.get_configuration_async, self.increase_error_count) async_call(self.lrf.get_mode, None, self.get_mode_async, self.increase_error_count) async_call(self.lrf.is_laser_enabled, None, self.is_laser_enabled_async, self.increase_error_count) async_call(self.lrf.get_moving_average, None, self.get_moving_average_async, self.increase_error_count) async_call(self.lrf.get_distance, None, self.cb_distance, self.increase_error_count) async_call(self.lrf.get_velocity, None, self.cb_velocity, self.increase_error_count) self.cbe_distance.set_period(25) self.cbe_velocity.set_period(25) self.plot_widget_distance.stop = False self.plot_widget_velocity.stop = False def stop(self): self.cbe_distance.set_period(0) self.cbe_velocity.set_period(0) self.plot_widget_distance.stop = True self.plot_widget_velocity.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLaserRangeFinder.DEVICE_IDENTIFIER def is_laser_enabled_async(self, enabled): if enabled: self.enable_laser.setChecked(True) else: self.enable_laser.setChecked(False) def enable_laser_changed(self, state): if state == Qt.Checked: self.lrf.enable_laser() else: self.lrf.disable_laser() def mode_changed(self, value): if value < 0 or value > 4: return self.lrf.set_mode(value) if value == 0: for w in self.widgets_velocity: w.hide() for w in self.widgets_distance: w.show() else: for w in self.widgets_distance: w.hide() for w in self.widgets_velocity: w.show() def cb_distance(self, distance): self.current_distance = distance def cb_velocity(self, velocity): self.current_velocity = velocity / 100.0 def configuration_changed(self): acquisition_count = self.spin_acquisition_count.value() enable_quick_termination = self.enable_qick_termination.isChecked() if self.threshold.isChecked(): threshold = 0 else: threshold = self.spin_threshold.value() if self.frequency.isChecked(): frequency = 0 for w in self.widgets_velocity: w.hide() else: frequency = self.spin_frequency.value() for w in self.widgets_velocity: w.show() self.spin_threshold.setDisabled(threshold == 0) self.spin_frequency.setDisabled(frequency == 0) self.lrf.set_configuration(acquisition_count, enable_quick_termination, threshold, frequency) def get_configuration_async(self, conf): self.spin_acquisition_count.blockSignals(True) self.spin_acquisition_count.setValue(conf.acquisition_count) self.spin_acquisition_count.blockSignals(False) self.enable_qick_termination.blockSignals(True) self.enable_qick_termination.setChecked(conf.enable_quick_termination) self.enable_qick_termination.blockSignals(False) self.spin_threshold.blockSignals(True) self.spin_threshold.setValue(conf.threshold_value) self.spin_threshold.setDisabled(conf.threshold_value == 0) self.spin_threshold.blockSignals(False) self.spin_frequency.blockSignals(True) self.spin_frequency.setValue(conf.measurement_frequency) self.spin_frequency.setDisabled(conf.measurement_frequency == 0) self.spin_frequency.blockSignals(False) self.threshold.blockSignals(True) self.threshold.setChecked(conf.threshold_value == 0) self.threshold.blockSignals(False) self.frequency.blockSignals(True) self.frequency.setChecked(conf.measurement_frequency == 0) self.frequency.blockSignals(False) self.configuration_changed() def get_sensor_hardware_version_async(self, value): if value == 1: self.mode_combo.show() self.mode_label.show() self.label_acquisition_count.hide() self.spin_acquisition_count.hide() self.enable_qick_termination.hide() self.label_threshold.hide() self.spin_threshold.hide() self.threshold.hide() self.label_frequency.hide() self.spin_frequency.hide() self.frequency.hide() else: self.mode_combo.hide() self.mode_label.hide() self.label_acquisition_count.show() self.spin_acquisition_count.show() self.enable_qick_termination.show() self.label_threshold.show() self.spin_threshold.show() self.threshold.show() self.label_frequency.show() self.spin_frequency.show() self.frequency.show() for w in self.widgets_distance: w.show() for w in self.widgets_velocity: w.show() def get_mode_async(self, value): self.mode_combo.setCurrentIndex(value) self.mode_changed(value) def get_moving_average_async(self, avg): self.spin_average_distance.setValue(avg.distance_average_length) self.spin_average_velocity.setValue(avg.velocity_average_length) def spin_average_finished(self): self.lrf.set_moving_average(self.spin_average_distance.value(), self.spin_average_velocity.value())
class Main(plugin.Plugin): " Main Class " def initialize(self, *args, **kwargs): " Init Main Class " super(Main, self).initialize(*args, **kwargs) self.infile = QLineEdit(path.expanduser("~")) self.infile.setPlaceholderText(' /full/path/to/file ') self.infile.returnPressed.connect(self.run) self.completer, self.dirs = QCompleter(self), QDirModel(self) self.dirs.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot) self.completer.setModel(self.dirs) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.completer.setCompletionMode(QCompleter.PopupCompletion) self.infile.setCompleter(self.completer) self.menu = QMenu('Base64') self.menu.aboutToShow.connect(self.build_submenu) self.ex_locator = self.locator.get_service('explorer') self.ex_locator.add_project_menu(self.menu, lang='all') self.open = QPushButton(QIcon.fromTheme("folder-open"), 'Open') self.open.setCursor(QCursor(Qt.PointingHandCursor)) self.open.clicked.connect(lambda: self.infile.setText(str( QFileDialog.getOpenFileName(self.dock, "Open a File to Encode...", path.expanduser("~"), ';;'.join(['{}(*.{})'.format(e.upper(), e) for e in ['*', 'jpg', 'png', 'webp', 'svg', 'gif', 'webm']]))))) self.chckbx1 = QCheckBox('Use basic Caesar Cipher (ROT13)') self.chckbx1.setToolTip('Use "string".decode("rot13") to Decipher ! ') self.chckbx2 = QCheckBox('Use "data:type/subtype;base64,..."') self.chckbx2.setChecked(True) self.chckbx3 = QCheckBox('Copy encoded output to Clipboard') self.chckbx4 = QCheckBox('Use URL-Safe Base64 Encoder') self.combo1 = QComboBox() self.combo1.addItems(['Do Not Generate Code', 'Generate CSS embed Code', 'Generate Python Embed Code', 'Generate HTML embed Code', 'Generate JS embed Code', 'Generate QML embed Code']) self.combo1.currentIndexChanged.connect(self.combo_changed) self.output = QTextEdit(''' We can only see a short distance ahead, but we can see plenty there that needs to be done. - Alan Turing ''') self.output.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.button = QPushButton(QIcon.fromTheme("face-cool"), 'Encode BASE64') self.button.setCursor(QCursor(Qt.PointingHandCursor)) self.button.setMinimumSize(100, 50) self.button.clicked.connect(self.run) glow = QGraphicsDropShadowEffect(self) glow.setOffset(0) glow.setBlurRadius(99) glow.setColor(QColor(99, 255, 255)) self.button.setGraphicsEffect(glow) glow.setEnabled(True) class TransientWidget(QWidget): ' persistant widget thingy ' def __init__(self, widget_list): ' init sub class ' super(TransientWidget, self).__init__() vbox = QVBoxLayout(self) for each_widget in widget_list: vbox.addWidget(each_widget) tw = TransientWidget((QLabel('<i>Encode file as plain text string</i>'), QLabel('<b>File to Encode:'), self.infile, self.open, self.chckbx2, self.chckbx3, self.chckbx1, self.chckbx4, QLabel('<b>Embedding Template Code:'), self.combo1, QLabel(' <b>Base64 String Output: '), self.output, QLabel('<center><small><i>' + ''.join((__doc__, __version__, __license__, 'by', __author__))), self.button )) self.scrollable, self.dock = QScrollArea(), QDockWidget() self.scrollable.setWidgetResizable(True) self.scrollable.setWidget(tw) self.dock.setWindowTitle(__doc__) self.dock.setStyleSheet('QDockWidget::title{text-align: center;}') self.dock.setWidget(self.scrollable) ExplorerContainer().addTab(self.dock, "Base64") self.guimode = QComboBox(self.dock) self.guimode.addItems(['Full Mode', 'Simple Mode']) self.guimode.currentIndexChanged.connect(self.guimode_change) def guimode_change(self): """ Change from Simple Mode to Full Mode by Hide or Show Widgets """ if self.guimode.currentIndex() is 0: self.chckbx1.show() self.chckbx2.show() self.chckbx3.show() self.chckbx4.show() else: self.chckbx1.hide() self.chckbx2.hide() self.chckbx3.hide() self.chckbx4.hide() self.chckbx1.setChecked(False) self.chckbx2.setChecked(True) self.chckbx3.setChecked(False) self.chckbx4.setChecked(False) def build_submenu(self): ''' build sub menu on the fly based on file path ''' self.menu.clear() if self.ex_locator.get_current_project_item().isFolder is not True: filenam = self.ex_locator.get_current_project_item().get_full_path() self.menu.addActions([ QAction('Copy {} as Base64'.format(path.basename(filenam)[:50]), self, triggered=lambda: QApplication.clipboard().setText( '"data:{};charset=utf-8;base64,{}"'.format( guess_type(filenam, strict=False)[0], b64encode(open(filenam, "rb").read())))), QAction('Copy {} as Base64 URL-Safe'.format( path.basename(filenam)[:50]), self, triggered=lambda: QApplication.clipboard().setText( '"data:{};charset=utf-8;base64,{}"'.format( guess_type(filenam, strict=False)[0], urlsafe_b64encode(open(filenam, "rb").read()))))]) self.menu.show() def run(self): ' run the encoding ' mimetype = guess_type(str(self.infile.text()).strip(), strict=False)[0] _mime = mimetype if mimetype is not None else self.ask_mime() fle = str(self.infile.text()).strip().replace('file:///', '/') encoder = urlsafe_b64encode if self.chckbx4.isChecked() else b64encode if int(path.getsize(fle)) / 1024 / 1024 >= 1: QMessageBox.information(self.dock, __doc__, '''<b style="color:red"> WARNING!: File size is > 1 Megabyte!,<br> this will take some time, depending your CPU Processing power!.''') output = '"{}{}{}{}"'.format( 'data:' if self.chckbx2.isChecked() is True else '', _mime if self.chckbx2.isChecked() is True else '', ';charset=utf-8;base64,' if self.chckbx2.isChecked() is True else '', encoder(open(fle, "rb").read())) if self.combo1.currentIndex() is 1: output = ('html, body { margin:0; padding:0; background: url(' + output + ') no-repeat center center fixed; background-size:cover }') elif self.combo1.currentIndex() is 2: output = PY_EMBED.format(getuser(), datetime.now().isoformat().split('.')[0], output) elif self.combo1.currentIndex() is 3: output = '<img src={} alt="{}" title="{}"/>'.format(output, fle.split(sep)[-1], fle.split(sep)[-1]) elif self.combo1.currentIndex() is 4: output = 'var embedded_file = window.atob({}); '.format(output) elif self.combo1.currentIndex() is 5: output = 'Image { source: ' + output + ' } ' if self.chckbx1.isChecked() is True: output = str(output).encode('rot13') if self.chckbx3.isChecked() is True: QApplication.clipboard().setText(output) self.output.setPlainText(output) self.output.setFocus() self.output.selectAll() def ask_mime(self): ' ask user for mime type ' return str(QInputDialog.getText(self.dock, __doc__, 'Write a MIME-Type', QLineEdit.Normal, 'application/octet-stream')[0]).strip().lower() def combo_changed(self): ' on combo changed ' if self.combo1.currentIndex() is 1 or self.combo1.currentIndex() is 3: self.chckbx1.setChecked(False) self.chckbx2.setChecked(True) elif self.combo1.currentIndex() is 2 or self.combo1.currentIndex() is 4: self.chckbx1.setChecked(False) self.chckbx2.setChecked(False)
class WizardDialog(QDialog): """The dialog for update.""" def __init__(self, main_window): super(WizardDialog, self).__init__() self.mw = main_window vbox = QVBoxLayout(self) # label and checkbox self.main_text = QLabel(u"init text") vbox.addWidget(self.main_text) self.notthisagain = QCheckBox(u"No mostrar automáticamente esta ayuda") nowizard = config.get('nowizard', False) self.notthisagain.setCheckState(nowizard) self.notthisagain.stateChanged.connect(self._notthisagain_toggled) vbox.addWidget(self.notthisagain) # buttons bbox = QDialogButtonBox() self.navbut_actn = QPushButton(u"init text") bbox.addButton(self.navbut_actn, QDialogButtonBox.ActionRole) self.navbut_prev = QPushButton(u"Anterior") bbox.addButton(self.navbut_prev, QDialogButtonBox.ActionRole) self.navbut_next = QPushButton(u"Siguiente") bbox.addButton(self.navbut_next, QDialogButtonBox.ActionRole) vbox.addWidget(bbox) self.show() self.step = 0 self._move(0) def _notthisagain_toggled(self, state): """The "not this again" checkbutton togled state.""" logger.info("Configuring 'nowizard' to %s", state) config['nowizard'] = state def _move(self, delta_step): """The engine for the wizard steps.""" self.step += delta_step logger.debug("Entering into step %d", self.step) (text, ign_func, act_label, act_func) = STEPS[self.step] # if this step should be ignored, just leave if ign_func is not None: m = getattr(self, "_ign_" + ign_func) if m(): # keep going return self._move(delta_step) # adjust navigation buttons if self.step == 0: self.navbut_prev.setEnabled(False) self.navbut_next.setText(u"Siguiente") self.navbut_next.clicked.disconnect() self.navbut_next.clicked.connect(lambda: self._move(1)) self.notthisagain.show() elif self.step == len(STEPS) - 1: self.navbut_prev.setEnabled(True) self.navbut_prev.clicked.disconnect() self.navbut_prev.clicked.connect(lambda: self._move(-1)) self.navbut_next.setText(u"Terminar") self.navbut_next.clicked.disconnect() self.navbut_next.clicked.connect(self.accept) self.notthisagain.hide() else: self.navbut_prev.setEnabled(True) self.navbut_prev.clicked.disconnect() self.navbut_prev.clicked.connect(lambda: self._move(-1)) self.navbut_next.setText(u"Siguiente") self.navbut_next.clicked.disconnect() self.navbut_next.clicked.connect(lambda: self._move(1)) self.notthisagain.hide() # adjust main text and action button if self.step == len(STEPS) - 1: if self.mw.have_metadata() and self.mw.have_config(): self.main_text.setText(TEXT_HAPPY_END) else: self.main_text.setText(TEXT_SAD_END) else: self.main_text.setText(text) if act_label is None: self.navbut_actn.hide() else: self.navbut_actn.show() self.navbut_actn.setText(act_label) method_to_call = getattr(self, "_act_" + act_func) self.navbut_actn.clicked.disconnect() self.navbut_actn.clicked.connect(method_to_call) def _act_configure(self, _): """Open the config dialog.""" self.mw.open_preferences() def _act_update(self, *a): """Open the update dialog.""" self.mw.refresh_episodes() def _ign_episode(self): """Tell if the episode step should be ignored.""" return self.mw.have_metadata() def _ign_config(self): """Tell if the configure step should be ignored.""" return self.mw.have_config()
class WizardDialog(QDialog): """The dialog for update.""" def __init__(self, main_window): super(WizardDialog, self).__init__() self.mw = main_window vbox = QVBoxLayout(self) # label and checkbox self.main_text = QLabel(u"init text") vbox.addWidget(self.main_text) self.notthisagain = QCheckBox(u"No mostrar automáticamente esta ayuda") nowizard = config.get('nowizard', False) self.notthisagain.setCheckState(nowizard) self.notthisagain.stateChanged.connect(self._notthisagain_toggled) vbox.addWidget(self.notthisagain) # buttons bbox = QDialogButtonBox() self.navbut_actn = QPushButton(u"init text") bbox.addButton(self.navbut_actn, QDialogButtonBox.ActionRole) self.navbut_prev = QPushButton(u"Anterior") bbox.addButton(self.navbut_prev, QDialogButtonBox.ActionRole) self.navbut_next = QPushButton(u"Siguiente") bbox.addButton(self.navbut_next, QDialogButtonBox.ActionRole) vbox.addWidget(bbox) self.show() self.step = 0 self._move(0) def _notthisagain_toggled(self, state): """The "not this again" checkbutton togled state.""" logger.info("Configuring 'nowizard' to %s", state) config['nowizard'] = state def _move(self, delta_step): """The engine for the wizard steps.""" self.step += delta_step logger.debug("Entering into step %d", self.step) (text, ign_func, act_label, act_func) = STEPS[self.step] # if this step should be ignored, just leave if ign_func is not None: m = getattr(self, "_ign_" + ign_func) if m(): # keep going return self._move(delta_step) # adjust navigation buttons if self.step == 0: self.navbut_prev.setEnabled(False) self.navbut_next.setText(u"Siguiente") self.navbut_next.clicked.disconnect() self.navbut_next.clicked.connect(lambda: self._move(1)) self.notthisagain.show() elif self.step == len(STEPS) - 1: self.navbut_prev.setEnabled(True) self.navbut_prev.clicked.disconnect() self.navbut_prev.clicked.connect(lambda: self._move(-1)) self.navbut_next.setText(u"Terminar") self.navbut_next.clicked.disconnect() self.navbut_next.clicked.connect(self.accept) self.notthisagain.hide() else: self.navbut_prev.setEnabled(True) self.navbut_prev.clicked.disconnect() self.navbut_prev.clicked.connect(lambda: self._move(-1)) self.navbut_next.setText(u"Siguiente") self.navbut_next.clicked.disconnect() self.navbut_next.clicked.connect(lambda: self._move(1)) self.notthisagain.hide() # adjust main text and action button if self.step == len(STEPS) - 1: if self.mw.have_metadata() and self.mw.have_config(): self.main_text.setText(TEXT_HAPPY_END) else: self.main_text.setText(TEXT_SAD_END) else: self.main_text.setText(text) if act_label is None: self.navbut_actn.hide() else: self.navbut_actn.show() self.navbut_actn.setText(act_label) method_to_call = getattr(self, "_act_" + act_func) self.navbut_actn.clicked.disconnect() self.navbut_actn.clicked.connect(method_to_call) def _act_configure(self, _): """Open the config dialog.""" self.mw.open_preferences() def _act_update(self, *a): """Open the update dialog.""" self.mw.refresh_episodes() def _ign_episode(self): """Tell if the episode step should be ignored.""" return self.mw.have_metadata() def _ign_config(self): """Tell if the configure step should be ignored.""" return self.mw.have_config()