isActive Method in Python Commands

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

isActive Method in Python Commands

Post 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
User avatar
jonasb
Posts: 162
Joined: Tue Dec 22, 2020 7:57 pm

Re: isActive Method in Python Commands

Post 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.
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: isActive Method in Python Commands

Post 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.
Post Reply