def algorithm_screenshot(name: str, directory: str, version: int = -1, ext: str = ".png") -> str: """ Takes a snapshot of an algorithm dialog and saves it as an image named "name_dlg.png" Args: name: The name of the algorithm directory: An directory path where the image should be saved version: A version of the algorithm to use (default=latest) ext: An optional extension (including the period). Default=.png Returns: A full path to the image file """ ensure_directory_exists(directory) suffix = "" if version != -1: suffix = f"-v{version}" filename = os.path.join(directory, f"{name}{suffix}_dlg{ext}") manager = InterfaceManager() dialog = manager.createDialogFromName(name, version, None, True) dialog.adjustSize() try: take_picture(dialog, filename) picture = Screenshot(filename, dialog.width(), dialog.height()) finally: dialog.close() return picture
def test_interface_manager(self): manager = InterfaceManager() dialog = manager.createDialogFromName("AlgorithmDialogMockAlgorithm", -1) self.assertTrue(dialog is not None) input_widgets = dialog.findChildren(QLineEdit) self.assertEqual(len(input_widgets), 3)
def execute_algorithm(self): """ Send a signal to a subscriber to execute the selected algorithm """ algorithm = self.get_selected_algorithm() if algorithm is not None: manager = InterfaceManager() dialog = manager.createDialogFromName(algorithm.name, algorithm.version) dialog.show()
def set_material(self): """ Open a SetSampleMaterial algorithm dialog. """ presets = {"InputWorkspace": self.workspace.name()} manager = InterfaceManager() dialog = manager.createDialogFromName("SetSampleMaterial", -1, self.view, False, presets) # Subscribe to the algorithm so we can update the view when the values are changed. dialog.addAlgorithmObserver(self) dialog.setModal(True) dialog.show()
def execute_algorithm(self): """ Send a signal to a subscriber to execute the selected algorithm """ algorithm = self.get_selected_algorithm() presets = {} enabled = [] if algorithm is not None: if self._selected_workspaces_fn: selected_ws_names = self._selected_workspaces_fn() if selected_ws_names: property_name = self.presenter.find_input_workspace_property(algorithm) if property_name: presets[property_name] = selected_ws_names[0] # Keep it enabled enabled.append(property_name) manager = InterfaceManager() dialog = manager.createDialogFromName(algorithm.name, algorithm.version, None, False, presets, "", enabled) dialog.show()
def copy_material(self): """ Open a CopySample algorithm dialog with the CopyMaterial option. """ presets = { "InputWorkspace": self.workspace.name(), "CopyName": "0", "CopyMaterial": "1", "CopyEnvironment": "0", "CopyShape": "0", "CopyLattice": "0", "CopyOrientationOnly": "0" } manager = InterfaceManager() dialog = manager.createDialogFromName("CopySample", -1, self.view, False, presets) # Subscribe to the algorithm so we can update the view when the values are changed. dialog.addAlgorithmObserver(self) dialog.setModal(True) dialog.show()