def test_push(): operation_stack = OperationStack(MagicMock()) operation_stack.changed.emit = MagicMock() test_operation = GroupedOperation() test_operation_2 = GroupedOperation() operation_stack.push(test_operation) operation_stack.push(test_operation_2) # Since we added two operations that can be merged, we should end up with one operation! assert len(operation_stack.getOperations()) == 1 test_operation_3 = GroupedOperation() # Fake call to notify the operation stack that the tool has stopped doing something operation_stack._onToolOperationStopped(None) # Pretend like another operation was added but with a lot of time in between. test_operation_3._timestamp = time.time() + 2000000 operation_stack.push(test_operation_3) assert len(operation_stack.getOperations()) == 2 operation_stack.undo() # The count should be at 4, since we added 3 operations and then undid the last one. assert operation_stack.changed.emit.call_count == 4 operation_stack.undo() assert operation_stack.changed.emit.call_count == 5 # There is nothing to undo! assert not operation_stack.canUndo() operation_stack.undo() assert operation_stack.changed.emit.call_count == 5 operation_stack.redo() assert operation_stack.changed.emit.call_count == 6 operation_stack.redo() assert operation_stack.changed.emit.call_count == 7 assert not operation_stack.canRedo()
def initialize(self) -> None: # For Ubuntu Unity this makes Qt use its own menu bar rather than pass it on to Unity. os.putenv("UBUNTU_MENUPROXY", "0") # Custom signal handling Signal._app = self Signal._signalQueue = self # Initialize Resources. Set the application name and version here because we can only know the actual info # after the __init__() has been called. Resources.ApplicationIdentifier = self._app_name Resources.ApplicationVersion = self._version Resources.addSearchPath( os.path.join(os.path.dirname(sys.executable), "resources")) Resources.addSearchPath( os.path.join(self._app_install_dir, "share", "uranium", "resources")) Resources.addSearchPath( os.path.join(self._app_install_dir, "Resources", "uranium", "resources")) Resources.addSearchPath( os.path.join(self._app_install_dir, "Resources", self._app_name, "resources")) if not hasattr(sys, "frozen"): Resources.addSearchPath( os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "resources")) i18nCatalog.setApplication(self) PluginRegistry.addType("backend", self.setBackend) PluginRegistry.addType("logger", Logger.addLogger) PluginRegistry.addType("extension", self.addExtension) self._preferences = Preferences() self._preferences.addPreference("general/language", self._default_language) self._preferences.addPreference("general/visible_settings", "") self._preferences.addPreference("general/plugins_to_remove", "") self._preferences.addPreference("general/disabled_plugins", "") self._controller = Controller(self) self._output_device_manager = OutputDeviceManager() self._operation_stack = OperationStack( self._controller) # type: OperationStack self._plugin_registry = PluginRegistry(self) #type: PluginRegistry self._plugin_registry.addPluginLocation( os.path.join(self._app_install_dir, "lib", "uranium")) self._plugin_registry.addPluginLocation( os.path.join(self._app_install_dir, "lib64", "uranium")) self._plugin_registry.addPluginLocation( os.path.join(self._app_install_dir, "lib32", "uranium")) self._plugin_registry.addPluginLocation( os.path.join(os.path.dirname(sys.executable), "plugins")) self._plugin_registry.addPluginLocation( os.path.join(self._app_install_dir, "Resources", "uranium", "plugins")) self._plugin_registry.addPluginLocation( os.path.join(self._app_install_dir, "Resources", self._app_name, "plugins")) # Locally installed plugins local_path = os.path.join( Resources.getStoragePath(Resources.Resources), "plugins") # Ensure the local plugins directory exists try: os.makedirs(local_path) except OSError: pass self._plugin_registry.addPluginLocation(local_path) if not hasattr(sys, "frozen"): self._plugin_registry.addPluginLocation( os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "plugins")) self._container_registry = self._container_registry_class(self) UM.Settings.InstanceContainer.setContainerRegistry( self._container_registry) UM.Settings.ContainerStack.setContainerRegistry( self._container_registry) # Initialize the package manager to remove and install scheduled packages. self._package_manager = self._package_manager_class(self) self.showMessageSignal.connect(self.showMessage) self.hideMessageSignal.connect(self.hideMessage)
def __init__(self, name, version, **kwargs): if (Application._instance != None): raise ValueError("Duplicate singleton creation") # If the constructor is called and there is no instance, set the instance to self. # This is done because we can't make constructor private Application._instance = self self._application_name = name self._version = version os.putenv( "UBUNTU_MENUPROXY", "0" ) #For Ubuntu Unity this makes Qt use its own menu bar rather than pass it on to Unity. Signal._app = self Resources.ApplicationIdentifier = name i18nCatalog.setApplication(self) Resources.addSearchPath(os.path.dirname(sys.executable)) Resources.addSearchPath( os.path.join(Application.getInstallPrefix(), "share", "uranium")) Resources.addSearchPath( os.path.join(Application.getInstallPrefix(), "Resources", "uranium")) Resources.addSearchPath( os.path.join(Application.getInstallPrefix(), "Resources", self.getApplicationName())) if not hasattr(sys, "frozen"): Resources.addSearchPath( os.path.join(os.path.abspath(os.path.dirname(__file__)), "..")) self._main_thread = threading.current_thread() super().__init__( **kwargs) # Call super to make multiple inheritence work. self._renderer = None PluginRegistry.addType("backend", self.setBackend) PluginRegistry.addType("logger", Logger.addLogger) PluginRegistry.addType("extension", self.addExtension) preferences = Preferences.getInstance() preferences.addPreference("general/language", "en") try: preferences.readFromFile( Resources.getPath(Resources.Preferences, self._application_name + ".cfg")) except FileNotFoundError: pass self._controller = Controller(self) self._mesh_file_handler = MeshFileHandler() self._extensions = [] self._backend = None self._output_device_manager = OutputDeviceManager() self._machine_manager = MachineManager(self._application_name) self._required_plugins = [] self._operation_stack = OperationStack() self._plugin_registry = PluginRegistry.getInstance() self._plugin_registry.addPluginLocation( os.path.join(Application.getInstallPrefix(), "lib", "uranium")) self._plugin_registry.addPluginLocation( os.path.join(os.path.dirname(sys.executable), "plugins")) self._plugin_registry.addPluginLocation( os.path.join(Application.getInstallPrefix(), "Resources", "uranium", "plugins")) self._plugin_registry.addPluginLocation( os.path.join(Application.getInstallPrefix(), "Resources", self.getApplicationName(), "plugins")) # Locally installed plugins self._plugin_registry.addPluginLocation( os.path.join(Resources.getStoragePath(Resources.Resources), "plugins")) if not hasattr(sys, "frozen"): self._plugin_registry.addPluginLocation( os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "plugins")) self._plugin_registry.setApplication(self) self._parsed_command_line = None self.parseCommandLine() self._visible_messages = [] self._message_lock = threading.Lock() self.showMessageSignal.connect(self.showMessage) self.hideMessageSignal.connect(self.hideMessage)
def __init__(self, name: str, version: str, build_type: str = "", is_debug_mode: bool = False, parser: argparse.ArgumentParser = None, parsed_command_line: Dict[str, Any] = None, **kwargs) -> None: if Application._instance is not None: raise ValueError("Duplicate singleton creation") if parsed_command_line is None: parsed_command_line = {} # If the constructor is called and there is no instance, set the instance to self. # This is done because we can't make constructor private Application._instance = self self._application_name = name #type: str self._version = version #type: str self._build_type = build_type #type: str if "debug" in parsed_command_line.keys(): if not parsed_command_line["debug"] and is_debug_mode: parsed_command_line["debug"] = is_debug_mode os.putenv("UBUNTU_MENUPROXY", "0") # For Ubuntu Unity this makes Qt use its own menu bar rather than pass it on to Unity. Signal._app = self Signal._signalQueue = self Resources.ApplicationIdentifier = name Resources.ApplicationVersion = version Resources.addSearchPath(os.path.join(os.path.dirname(sys.executable), "resources")) Resources.addSearchPath(os.path.join(Application.getInstallPrefix(), "share", "uranium", "resources")) Resources.addSearchPath(os.path.join(Application.getInstallPrefix(), "Resources", "uranium", "resources")) Resources.addSearchPath(os.path.join(Application.getInstallPrefix(), "Resources", self.getApplicationName(), "resources")) if not hasattr(sys, "frozen"): Resources.addSearchPath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "resources")) self._main_thread = threading.current_thread() #type: threading.Thread super().__init__() # Call super to make multiple inheritance work. i18nCatalog.setApplication(self) self._renderer = None #type: Renderer PluginRegistry.addType("backend", self.setBackend) PluginRegistry.addType("logger", Logger.addLogger) PluginRegistry.addType("extension", self.addExtension) self.default_theme = self.getApplicationName() #type: str preferences = Preferences.getInstance() preferences.addPreference("general/language", "en_US") preferences.addPreference("general/visible_settings", "") preferences.addPreference("general/plugins_to_remove", "") preferences.addPreference("general/disabled_plugins", "") try: preferences.readFromFile(Resources.getPath(Resources.Preferences, self._application_name + ".cfg")) except FileNotFoundError: pass self._controller = Controller(self) #type: Controller self._extensions = [] #type: List[Extension] self._backend = None #type: Backend self._output_device_manager = OutputDeviceManager() #type: OutputDeviceManager self._required_plugins = [] #type: List[str] self._operation_stack = OperationStack(self.getController()) #type: OperationStack self._plugin_registry = PluginRegistry.getInstance() #type: PluginRegistry self._plugin_registry.addPluginLocation(os.path.join(Application.getInstallPrefix(), UraniumLibraryDir, "uranium")) self._plugin_registry.addPluginLocation(os.path.join(os.path.dirname(sys.executable), "plugins")) self._plugin_registry.addPluginLocation(os.path.join(Application.getInstallPrefix(), "Resources", "uranium", "plugins")) self._plugin_registry.addPluginLocation(os.path.join(Application.getInstallPrefix(), "Resources", self.getApplicationName(), "plugins")) # Locally installed plugins local_path = os.path.join(Resources.getStoragePath(Resources.Resources), "plugins") # Ensure the local plugins directory exists try: os.makedirs(local_path) except OSError: pass self._plugin_registry.addPluginLocation(local_path) if not hasattr(sys, "frozen"): self._plugin_registry.addPluginLocation(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "plugins")) self._plugin_registry.setApplication(self) ContainerRegistry.setApplication(self) UM.Settings.InstanceContainer.setContainerRegistry(self.getContainerRegistry()) UM.Settings.ContainerStack.setContainerRegistry(self.getContainerRegistry()) self._command_line_parser = parser #type: argparse.ArgumentParser self._parsed_command_line = parsed_command_line #type: Dict[str, Any] self.parseCommandLine() self._visible_messages = [] #type: List[Message] self._message_lock = threading.Lock() #type: threading.Lock self.showMessageSignal.connect(self.showMessage) self.hideMessageSignal.connect(self.hideMessage) self._global_container_stack = None #type: ContainerStack
def __init__(self, name: str, version: str, build_type: str = "", **kwargs): if Application._instance != None: raise ValueError("Duplicate singleton creation") # If the constructor is called and there is no instance, set the instance to self. # This is done because we can't make constructor private Application._instance = self self._application_name = name self._version = version self._build_type = build_type os.putenv("UBUNTU_MENUPROXY", "0") # For Ubuntu Unity this makes Qt use its own menu bar rather than pass it on to Unity. Signal._app = self Signal._signalQueue = self Resources.ApplicationIdentifier = name Resources.ApplicationVersion = version Resources.addSearchPath(os.path.join(os.path.dirname(sys.executable), "resources")) Resources.addSearchPath(os.path.join(Application.getInstallPrefix(), "share", "uranium", "resources")) Resources.addSearchPath(os.path.join(Application.getInstallPrefix(), "Resources", "uranium", "resources")) Resources.addSearchPath(os.path.join(Application.getInstallPrefix(), "Resources", self.getApplicationName(), "resources")) #Fixme:CuraApplication will add the path again, so comment this # if not hasattr(sys, "frozen"): # Resources.addSearchPath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "resources")) self._main_thread = threading.current_thread() super().__init__() # Call super to make multiple inheritance work. i18nCatalog.setApplication(self) self._renderer = None PluginRegistry.addType("backend", self.setBackend) PluginRegistry.addType("logger", Logger.addLogger) PluginRegistry.addType("extension", self.addExtension) preferences = Preferences.getInstance() preferences.addPreference("general/language", "en") preferences.addPreference("general/visible_settings", "") try: preferences.readFromFile(Resources.getPath(Resources.Preferences, self._application_name + ".cfg")) except FileNotFoundError: pass self._controller = Controller(self) self._mesh_file_handler = MeshFileHandler.getInstance() self._mesh_file_handler.setApplication(self) self._workspace_file_handler = WorkspaceFileHandler.getInstance() self._workspace_file_handler.setApplication(self) self._extensions = [] self._backend = None self._output_device_manager = OutputDeviceManager() self._required_plugins = [] self._operation_stack = OperationStack(self.getController()) self._plugin_registry = PluginRegistry.getInstance() self._plugin_registry.addPluginLocation(os.path.join(Application.getInstallPrefix(), "lib", "uranium")) self._plugin_registry.addPluginLocation(os.path.join(os.path.dirname(sys.executable), "plugins")) self._plugin_registry.addPluginLocation(os.path.join(Application.getInstallPrefix(), "Resources", "uranium", "plugins")) self._plugin_registry.addPluginLocation(os.path.join(Application.getInstallPrefix(), "Resources", self.getApplicationName(), "plugins")) # Locally installed plugins local_path = os.path.join(Resources.getStoragePath(Resources.Resources), "plugins") # Ensure the local plugins directory exists try: os.makedirs(local_path) except OSError: pass self._plugin_registry.addPluginLocation(local_path) # Fixme:CuraApplication will add the path again, so comment this # if not hasattr(sys, "frozen"): # self._plugin_registry.addPluginLocation(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "plugins")) self._plugin_registry.setApplication(self) ContainerRegistry.setApplication(self) UM.Settings.InstanceContainer.setContainerRegistry(self.getContainerRegistry()) UM.Settings.ContainerStack.setContainerRegistry(self.getContainerRegistry()) self._parsed_command_line = None self.parseCommandLine() self._visible_messages = [] self._message_lock = threading.Lock() self.showMessageSignal.connect(self.showMessage) self.hideMessageSignal.connect(self.hideMessage) self._global_container_stack = None