def on_reset_all(self): if ui.show_question("Do you want to reset all contact positions?"): for sample_item in self.contacts_tree: for contact_item in sample_item.children: contact_item.position = float('nan'), float('nan'), float( 'nan') self.contacts_tree.fit()
def on_move(self): item = self.positions_tree.current if item: if ui.show_question( f"Do you want to move table to position '{item.name}'?"): x, y, z = item.position self.emit(self.absolute_move, x, y, z)
def on_measure_restore(self): if not ui.show_question( title="Restore Defaults", text="Do you want to restore to default parameters?" ): return measurement = self.sequence_tree.current panel = self.panels.get(measurement.type) panel.restore()
def on_remove_sample_clicked(self): item = self.sequence_tree.current if item in self.sequence_tree: if ui.show_question( title="Remove Sample", text=f"Do you want to remove '{item.name}'?" ): self.sequence_tree.remove(item)
def on_remove_clicked(self): index = self.operator_combo_box.qt.currentIndex() if index >= 0: if ui.show_question( title="Remove operator", text= f"Do you want to remove operator '{self.operator_combo_box.qt.currentText()}' from the list?" ): self.operator_combo_box.qt.removeItem(index)
def on_move(self): current_item = self.contacts_tree.current if isinstance(current_item, TableContactItem): if current_item.has_position: if ui.show_question( f"Do you want to move tabel to contact {current_item.name}?" ): x, y, z = current_item.position self.emit(self.absolute_move, x, y, z)
def on_remove_sequence(self): item = self._sequence_tree.current if item and not item.sequence.builtin: if ui.show_question( title="Remove Sequence", text= f"Do yo want to remove sequence '{item.sequence.name}'?"): self._sequence_tree.remove(item) self._remove_button.enabled = len(self._sequence_tree)
def on_remove_step_clicked(self): item = self._steps_tree.current if item: if ui.show_question( f"Do you want to remove step size '{item[0].value}'?"): self._steps_tree.remove(item) if not len(self._steps_tree): self._edit_step_button.enabled = False self._remove_step_button.enabled = False self._steps_tree.qt.sortByColumn(0, QtCore.Qt.AscendingOrder)
def on_reload_clicked(self): if not ui.show_question( title="Reload Configuration", text="Do you want to reload sequence configuration from file?" ): return if self.context.sequence: filename = self.context.sequence.filename sequence = config.load_sequence(filename) self.context.load_sequence(sequence)
def on_reload_config_clicked(self): if not ui.show_question( title="Reload Configuration", text="Do you want to reload sequence configurations from file?" ): return for sample_item in self.sequence_tree: if sample_item.sequence: filename = sample_item.sequence.filename sequence = config.load_sequence(filename) sample_item.load_sequence(sequence)
def on_remove_position(self): item = self.positions_tree.current if item: if ui.show_question( f"Do you want to remove position '{item.name}'?"): self.positions_tree.remove(item) if not len(self.positions_tree): self.edit_button.enabled = False self.remove_button.enabled = False self.positions_tree.fit()
def on_remove_clicked(self): self.update_locations() if len(self.location_combo_box) > 1: index = self.location_combo_box.qt.currentIndex() if index >= 0: if ui.show_question( title="Remove directory", text= f"Do you want to remove directory '{self.location_combo_box.qt.currentText()}' from the list?" ): self.location_combo_box.qt.removeItem(index)
def on_pick_position(self): item = self.positions_tree.current if item: if ui.show_question( f"Do you want to assign current position to '{item.name}'?" ): def callback(x, y, z): item.position = x, y, z self.positions_tree.fit() self.emit(self.position_picked, callback)
def on_reset_sequence_state(self): if not ui.show_question( title="Reset State", text="Do you want to reset all sequence states?" ): return current_item = self.sequence_tree.current self.panels.unmount() self.panels.clear_readings() self.panels.hide() for sample_item in self.sequence_tree: sample_item.reset() if current_item is not None: panel = self.panels.get(current_item.type) panel.visible = True panel.mount(current_item)
def on_start(self): current_item = self.sequence_tree.current if isinstance(current_item, MeasurementTreeItem): contact_item = current_item.contact if not ui.show_question( title="Run Measurement", text=f"Are you sure to run measurement '{current_item.name}' for '{contact_item.name}'?" ): return self._on_start(current_item) elif isinstance(current_item, ContactTreeItem): dialog = StartSequenceDialog( context=current_item, table_enabled=self.use_table() ) self.operator_widget.store_settings() self.output_widget.store_settings() dialog.load_settings() if not dialog.run(): return dialog.store_settings() self.operator_widget.load_settings() self.output_widget.load_settings() self._on_start( current_item, move_to_contact=dialog.move_to_contact(), move_to_after_position=dialog.move_to_position() ) elif isinstance(current_item, SampleTreeItem): dialog = StartSequenceDialog( context=current_item, table_enabled=self.use_table() ) self.operator_widget.store_settings() self.output_widget.store_settings() dialog.load_settings() if not dialog.run(): return dialog.store_settings() self.operator_widget.load_settings() self.output_widget.load_settings() move_to_after_position = dialog.move_to_position() self._on_start( current_item, move_to_contact=dialog.move_to_contact(), move_to_after_position=dialog.move_to_position() )
def on_save_clicked(self): filename = ui.filename_save(path=self.current_path, filter="JSON (*.json)") if filename: samples = [sample.to_settings() for sample in self._sequence_tree] data = {'version': self.config_version, 'sequence': samples} # Auto filename extension if os.path.splitext(filename)[-1] not in ['.json']: filename = f'{filename}.json' if os.path.exists(filename): if not ui.show_question( f"Do you want to overwrite existing file {filename}?" ): return with open(filename, 'w') as f: logger.info("Writing sequence... %s", filename) json.dump(data, f) logger.info("Writing sequence... done.") self.current_path = os.path.dirname(filename)