Example #1
0
    def setActiveTool(self, tool: Optional[Union["Tool", str]]):
        from UM.Tool import Tool
        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolDeactivateEvent))

        if isinstance(tool, Tool) or tool is None:
            new_tool = cast(Optional[Tool], tool)
        else:
            new_tool = self.getTool(tool)

        tool_changed = False
        if self._active_tool is not new_tool:
            self._active_tool = new_tool
            tool_changed = True

        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

        from UM.Scene.Selection import Selection  # Imported here to prevent a circular dependency.
        if not self._active_tool and Selection.getCount() > 0:  # If something is selected, a tool must always be active.
            if "TranslateTool" in self._tools:
                self._active_tool = self._tools["TranslateTool"]  # Then default to the translation tool.
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))
                tool_changed = True
            else:
                Logger.log("w", "Controller does not have an active tool and could not default to Translate tool.")

        if tool_changed:
            self.activeToolChanged.emit()
Example #2
0
    def setActiveTool(self, name):
        try:
            if self._active_tool:
                self._active_tool.event(
                    ToolEvent(ToolEvent.ToolDeactivateEvent))

            if name:
                self._active_tool = self._tools[name]
            else:
                self._active_tool = None

            if self._active_tool:
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

            self.activeToolChanged.emit()
        except KeyError:
            Logger.log("e", "No tool named %s found.", name)
Example #3
0
    def setActiveTool(self, tool):
        from UM.Tool import Tool
        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolDeactivateEvent))

        if isinstance(tool, Tool) or tool is None:
            self._active_tool = tool
        else:
            self._active_tool = self.getTool(tool)

        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

        from UM.Scene.Selection import Selection  # Imported here to prevent a circular dependency.
        if not self._active_tool and Selection.getCount() > 0:  # If something is selected, a tool must always be active.
            self._active_tool = self._tools["TranslateTool"]  # Then default to the translation tool.
            self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

        self.activeToolChanged.emit()
Example #4
0
    def setActiveTool(self, tool: Optional[Union["Tool", str]]):
        """Set the current active tool.

        The tool can be set by name of the tool or directly passing the tool object.
        :param tool: A tool object or the name of a tool.
        """

        from UM.Tool import Tool
        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolDeactivateEvent))

        if isinstance(tool, Tool) or tool is None:
            new_tool = cast(Optional[Tool], tool)
        else:
            new_tool = self.getTool(tool)

        tool_changed = False
        if self._active_tool is not new_tool:
            self._active_tool = new_tool
            tool_changed = True

        if self._active_tool:
            self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

        from UM.Scene.Selection import Selection  # Imported here to prevent a circular dependency.
        if not self._active_tool and Selection.getCount(
        ) > 0:  # If something is selected, a tool must always be active.
            if self._fallback_tool in self._tools:
                self._active_tool = self._tools[
                    self.
                    _fallback_tool]  # Then default to the translation tool.
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))
                tool_changed = True
            else:
                Logger.log(
                    "w",
                    "Controller does not have an active tool and could not default to the tool, called \"{}\"."
                    .format(self._fallback_tool))

        if tool_changed:
            Selection.setFaceSelectMode(False)
            Selection.clearFace()
            self.activeToolChanged.emit()
Example #5
0
    def setActiveTool(self, name):
        try:
            if self._active_tool:
                self._active_tool.event(
                    ToolEvent(ToolEvent.ToolDeactivateEvent))

            if name:
                self._active_tool = self._tools[name]
            else:
                self._active_tool = None

            if self._active_tool:
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

            from UM.Scene.Selection import Selection  # Imported here to prevent a circular dependency.
            if not self._active_tool and Selection.getCount(
            ) > 0:  # If something is selected, a tool must always be active.
                self._active_tool = self._tools[
                    "TranslateTool"]  # Then default to the translation tool.
                self._active_tool.event(ToolEvent(ToolEvent.ToolActivateEvent))

            self.activeToolChanged.emit()
        except KeyError:
            Logger.log("e", "No tool named %s found.", name)