Page 1 of 1

isActive Method in Python Commands

Posted: Fri Jan 14, 2022 1:55 pm
by wandererfan
In the c++ version of Gui/Command, there is a method isActive that returns true if the command is available for use. Does this method work in Python commands? Mine does not seem to get executed.

Code: Select all

#does isActive work in python commands?
    def isActive(self):
        """Return True when the command should be active or False when it should be disabled (greyed)."""
        print("isActive")
        if App.ActiveDocument:
            print("have ActiveDocument")
            return havePage() and haveView()
        else:
            return False

Re: isActive Method in Python Commands

Posted: Fri Jan 14, 2022 3:07 pm
by jonasb
wandererfan wrote: Fri Jan 14, 2022 1:55 pm In the c++ version of Gui/Command, there is a method isActive that returns true if the command is available for use. Does this method work in Python commands? Mine does not seem to get executed.

Code: Select all

#does isActive work in python commands?
    def isActive(self):
        """Return True when the command should be active or False when it should be disabled (greyed)."""
        print("isActive")
        if App.ActiveDocument:
            print("have ActiveDocument")
            return havePage() and haveView()
        else:
            return False
Try it with an upper case i, see here: https://github.com/FreeCAD/FreeCAD/blob ... ure.py#L68
This does what it's supposed to do; I verified by inverting the condition. A `print` call though seems to end up in the limbo; it's neither redirected to the reports view, nor to the terminal that started freecad.

Re: isActive Method in Python Commands

Posted: Fri Jan 14, 2022 6:31 pm
by wandererfan
jonasb wrote: Fri Jan 14, 2022 3:07 pm Try it with an upper case i, see here: https://github.com/FreeCAD/FreeCAD/blob ... ure.py#L68
I was once told that programming was the art of searching pages of print looking for a misplaced '.'. I guess lower case 'i' could also apply. :oops:

My print statement shows up in the report view.

Thank you.