Intuitive variable management

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
mag
Posts: 20
Joined: Mon Nov 09, 2020 12:55 pm

Intuitive variable management

Post by mag »

I am thinking about creating a set of macros which would help with the variables we normally store in a spreadsheet.
For some of the features I need to figure out how to do it using the Freecad api. I understand that my questions are basic, just pointing to RTFM or code already doing such things would help.
And of course if there is already a mod for those features, I would just use and possibly modify it.
The features I am thinking about:

- Assigning variables to objects. For this I guess I need to create an object holding the assignments (thinking about a hash indexed by model object, with a list of variable names), which is visible in the model tree. Possibly making the spreadsheet object a child of it.
- A task which shows the variables assigned to the selected object, with a numeric entry and a vertical slider assigned for each of them, so one can easily manipulate those variables. For this I need to figure out how to create a task in the task view, how to show a slider in it, how to get notified if an object is deleted.
User avatar
ppemawm
Veteran
Posts: 1199
Joined: Fri May 17, 2013 3:54 pm
Location: New York NY USA

Re: Intuitive variable management

Post by ppemawm »

mag wrote: Sun Feb 11, 2024 1:38 pm ...code already doing such things would help.
Please see the following workbenches or macros available via the AddOn Manager:

1. Assembly4 > Variables & Animator (single slider)
2. DynamicData > Variables & Configurator (no sliders)
3. Mnesarco Utils > 'Timers' (multiple sliders)

Each is an excellent alternative to a spreadsheet.
"It is a poor workman who blames his tools..." ;)
mag
Posts: 20
Joined: Mon Nov 09, 2020 12:55 pm

Re: Intuitive variable management

Post by mag »

ppemawm wrote: Sun Feb 11, 2024 10:22 pm
mag wrote: Sun Feb 11, 2024 1:38 pm ...code already doing such things would help.
Please see the following workbenches or macros available via the AddOn Manager:
[...]
Each is an excellent alternative to a spreadsheet.
Thank you. These are good code examples. I am more interested on being able to adjust variables relevant to a specific object through sliders than alternatives to the spreadsheet method, as it is more or less standard usage.

I am now able to put sliders on the task panel through Gui.Control.showDialog
In the TemplatePyMod I see however a TaskWatcher having some ui, although commented out. As I understand the difference is that the dialog is closed and opened, while the taskwatcher is mostly there. I want to achieve that. But I could not.

Based on the code example it seems the widgets in the widgets property of the TaskWatcher are displayed. However I do not see my widget.
What do I missing?

My current code:

Code: Select all

class TaskPanelWatcher:
    def __init__(self):
        ui_file = QtCore.QFile(UIFILE)
        if not ui_file.open(QtCore.QIODevice.ReadOnly):
            print("Cannot open {}: {}".format(UIFILE, ui_file.errorString()))
            return
        loader = QUiLoader()
        widget = loader.load(ui_file, None)
        ui_file.close()
        panel = TaskPanel()
        panel.setupForm(widget)
        self.widgets = [widget]
        self.commands = ["Draft_Move","Draft_Rotate"]
        self.title = "move"

    def shouldShow(self):
        return (FreeCAD.ActiveDocument != None) and (FreeCADGui.Selection.getSelection() != [])

Gui.Control.addTaskWatcher([TaskPanelWatcher()])
pieterhijma
Posts: 27
Joined: Thu Dec 16, 2021 9:25 am

Re: Intuitive variable management

Post by pieterhijma »

mag wrote: Mon Feb 12, 2024 8:25 am
ppemawm wrote: Sun Feb 11, 2024 10:22 pm Please see the following workbenches or macros available via the AddOn Manager:
[...]
Each is an excellent alternative to a spreadsheet.
Thank you. These are good code examples. I am more interested on being able to adjust variables relevant to a specific object through sliders than alternatives to the spreadsheet method, as it is more or less standard usage.
I'm currently working on improving managing variables. Sliders are not part of that though. See this forum topic, this issue, and this introduction to a possible solution.
Post Reply