[SOLVED] Menu 'Checkable' how to unset at creation

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

[SOLVED] Menu 'Checkable' how to unset at creation

Post by onekk »

Hello to all, I'm developing a Plugin, and I've one problem:

I have created a menu item that is checkable:

Code: Select all

class _SetDebugLevel:
    """Set the debug level"""

    def Activated(self, index):
        # what is done when the command is clicked
        if index == 0:
            SetDBLevel(False)
        else:
            SetDBLevel(True)
        

    def GetResources(self):
        # icon and command information
        MenuText = QtCore.QT_TRANSLATE_NOOP(
            'OneCAM_Main',
            'Debug')
        ToolTip = QtCore.QT_TRANSLATE_NOOP(
            'OneCAM_Main',
            'Set Debug Level for OneCAM')
        return {
            'MenuText': MenuText,
            'ToolTip': ToolTip,
            'Checkable': True}
Now I want when I activate the workbench check if a variable "DEBUG" is set and put the toggle mark according to it.

so if debug is True i want the mark checked and if debug is False put the mark as unchecked.

At the menu creation the mark is set (it as the little v on it)

How to achieve that?

Regards

Carlo D.
OS: Devuan GNU/Linux 2.0 (ascii)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13541 (Git)
Build type: None
Branch: releases/FreeCAD-0-17
Hash: 9948ee4f1570df9216862a79705afb367b2c6ffb
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Italian/Italy (it_IT)
Last edited by onekk on Sun Oct 14, 2018 10:00 pm, edited 1 time in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Menu 'Checkable' how to unset at creation

Post by onekk »

No one have some hint, or this thing is not feasible in FreeCAD?
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Menu 'Checkable' how to unset at creation

Post by triplus »

onekk wrote: Wed Oct 10, 2018 8:08 am No one have some hint, or this thing is not feasible in FreeCAD?
If i understand you correctly you already did try to set the index to 0 or 1? And it didn't work?
wmayer wrote: Tue Aug 25, 2015 4:14 pm Note:
1. The changes compared to a normal command is that the 'Activated' has a second parameter of type int which is 0 for off and 1 for on.

https://forum.freecadweb.org/viewtopic. ... 208#p98311
wmayer
Founder
Posts: 20317
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Menu 'Checkable' how to unset at creation

Post by wmayer »

In your workbench class you need to implement the method:

Code: Select all

def Activated(self):
    from PySide import QtGui
    action=mw.findChild(QtGui.QAction,"_SetDebugLevel")
    action.blockSignals(True)
    action.setChecked(DEBUG) # not sure if DEBUG is a boolean
    action.blockSignals(False)
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Menu 'Checkable' how to unset at creation

Post by onekk »

Thank you, wmayer now it is working.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Menu 'Checkable' how to unset at creation

Post by Kunda1 »

onekk wrote: Sat Oct 13, 2018 7:56 am Thank you, wmayer now it is working.
@onekk please mark this topic [SOLVED] by editing the summary of the first post. Thanks.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: [SOLVED] Menu 'Checkable' how to unset at creation

Post by onekk »

Done.

I didn't know that the title was editable, many other forum don't permit editing after some time (usually one or two day).

Good to know

Many thanks and Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply