Exemplo n.º 1
0
    def Activated(self):
        """Execute when the command is called."""
        super(SelectGroup, self).Activated()

        sel = Gui.Selection.getSelection()
        subs = []
        for obj in sel:
            if groups.is_group(obj):
                for sub in obj.Group:
                    subs.append(sub)
            else:
                for parent in obj.InList:
                    if groups.is_group(parent):
                        for sub in parent.Group:
                            subs.append(sub)

        # Always clear the selection:
        Gui.Selection.clearSelection()

        # Create a new selection from the sub objects:
        for sub in subs:
            Gui.Selection.addSelection(sub)

        # Inform the user if there is no new selection:
        if not Gui.Selection.hasSelection():
            msg = translate(
                "draft",
                "No new selection. You must select non-empty groups or objects inside groups."
            )
            App.Console.PrintMessage(msg + "\n")
Exemplo n.º 2
0
    def Activated(self):
        """Execute when the command is called.

        It calls the `setAutogroup` method of the `DraftToolBar` class
        installed inside the global `Gui` namespace.
        """
        super(SetAutoGroup, self).Activated()

        if not hasattr(Gui, "draftToolBar"):
            return

        # It uses the `DraftToolBar` class defined in the `DraftGui` module
        # and globally initialized in the `Gui` namespace to run
        # some actions.
        # If there is only a group selected, it runs the `AutoGroup` method.
        params = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
        self.ui = Gui.draftToolBar
        s = Gui.Selection.getSelection()
        if len(s) == 1:
            if (utils.get_type(s[0]) == "Layer"
                    or (params.GetBool("AutogroupAddGroups", False)
                        and groups.is_group(s[0]))):
                self.ui.setAutoGroup(s[0].Name)
                return

        # Otherwise it builds a list of layers, with names and icons,
        # including the options "None" and "Add new layer".
        self.groups = ["None"]
        gn = [o.Name for o in self.doc.Objects if utils.get_type(o) == "Layer"]
        if params.GetBool("AutogroupAddGroups", False):
            gn.extend(groups.get_group_names())
        self.groups.extend(gn)
        self.labels = [translate("draft", "None")]
        self.icons = [self.ui.getIcon(":/icons/button_invalid.svg")]
        for g in gn:
            o = self.doc.getObject(g)
            if o:
                self.labels.append(o.Label)
                self.icons.append(o.ViewObject.Icon)
        self.labels.append(translate("draft", "Add new Layer"))
        self.icons.append(self.ui.getIcon(":/icons/document-new.svg"))

        # With the lists created is uses the interface
        # to pop up a menu with layer options.
        # Once the desired option is chosen
        # it launches the `proceed` method.
        self.ui.sourceCmd = self
        pos = self.ui.autoGroupButton.mapToGlobal(
            QtCore.QPoint(0,
                          self.ui.autoGroupButton.geometry().height()))
        self.ui.popupMenu(self.labels, self.icons, pos)