[SOLVED] Taskpanel open .ui panel after object 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
karim.achaibou
Posts: 62
Joined: Tue Oct 26, 2021 5:39 pm

[SOLVED] Taskpanel open .ui panel after object creation

Post by karim.achaibou »

Hello,

I have made .ui interface with QT designer and a featurepart object which gets his parameters from the interface. Everything is working fine but after creation when I double click the feature in the tree the translation panel opens in the task panel.
How can I open my .ui interface? I want the same behavior as when you edit a sketch.

Thanks,
Karim
Last edited by karim.achaibou on Sat Dec 25, 2021 4:43 pm, edited 2 times in total.
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Taskpanel

Post by ebrahim raeyat »

you must implement doubleClicked() method, look at my punch object:

https://github.com/ebrahimraeyat/Civil/ ... ch.py#L301
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: Taskpanel

Post by edi »

A simple example:
DialogUsingUiFile03.FCMacro
(2.19 KiB) Downloaded 50 times
TaskSelectLineAttributes.ui
(9.13 KiB) Downloaded 52 times
Just copy both files into the same directory and start the macro.
karim.achaibou
Posts: 62
Joined: Tue Oct 26, 2021 5:39 pm

Re: Taskpanel

Post by karim.achaibou »

ebrahim raeyat wrote: Wed Oct 27, 2021 10:22 am you must implement doubleClicked() method, look at my punch object:

https://github.com/ebrahimraeyat/Civil/ ... ch.py#L301
I got it to work after looking at your .py file but now all values are set to zero in the taskpanel. How do you set the values in the taskpanel to the values of the featurepython object? Code below doesn't update the taskpanel.

Code: Select all

class BoxTaskPanel():
    def __init__(self, obj):
        self.form = Gui.PySideUic.loadUi(path_to_ui)
        self.fp = obj
        self.form.BoxLength = obj.Length
        self.form.BoxWidth = obj.Width
        self.form.BoxHeight = obj.Height
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Taskpanel

Post by TheMarkster »

If you look at the source code for part workbench attachment there is a good example of gui.expressionbinding. Make your ui spinboxes Gui::QuantitySpinBox class types.

https://github.com/FreeCAD/FreeCAD/tree ... mentEditor
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Taskpanel

Post by ebrahim raeyat »

karim.achaibou wrote: Wed Oct 27, 2021 6:53 pm

Code: Select all

class BoxTaskPanel():
    def __init__(self, obj):
        self.form = Gui.PySideUic.loadUi(path_to_ui)
        self.fp = obj
        self.form.BoxWidth = obj.Width
        self.form.BoxHeight = obj.Height
I think you must give the Value of width and height like:

Code: Select all

self.form.BoxWidth = obj.Width.Value
self.form.BoxHeight = obj.Height.Value
Edit:
what are the type of BoxWidth, BoxHeight Gui? if those are spinBox, then you must set the value like this:

Code: Select all

self.form.BoxWidth.setValue = obj.Width.Value
self.form.BoxHeight.setValue = obj.Height.Value
karim.achaibou
Posts: 62
Joined: Tue Oct 26, 2021 5:39 pm

Re: Taskpanel

Post by karim.achaibou »

Code: Select all

self.form.BoxWidth.setValue = obj.Width.Value
self.form.BoxHeight.setValue = obj.Height.Value
It is indeed a spinbox and the above code got me in the wright direction but didn't work for me
The following code updates the taskpanel with the object properties:

Code: Select all

self.form.BoxLength.setValue(obj.Length)
Only a new problem occurs...
After creating the object through the panel the object is displayed and can be edited and recomputes automatically when the dimensions are edited in the data panel of the combo view.
When I double click the object, the taskpanel opens as accepted and parameters can be updated and part also updates automatically.
When I now want to change the parameters in the data panel the object doesn't update automatically and the object is "touched" and now I need to recompute the object manually.
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: Taskpanel

Post by ebrahim raeyat »

karim.achaibou wrote: Thu Oct 28, 2021 6:46 pm

Code: Select all

self.form.BoxWidth.setValue = obj.Width.Value
self.form.BoxHeight.setValue = obj.Height.Value
It is indeed a spinbox and the above code got me in the wright direction but didn't work for me
The following code updates the taskpanel with the object properties:

Code: Select all

self.form.BoxLength.setValue(obj.Length)
Only a new problem occurs...
After creating the object through the panel the object is displayed and can be edited and recomputes automatically when the dimensions are edited in the data panel of the combo view.
When I double click the object, the taskpanel opens as accepted and parameters can be updated and part also updates automatically.
When I now want to change the parameters in the data panel the object doesn't update automatically and the object is "touched" and now I need to recompute the object manually.
oops, thanks for your hint.
for your question:
you must do it manually with qt signal & slot.
karim.achaibou
Posts: 62
Joined: Tue Oct 26, 2021 5:39 pm

Re: Taskpanel

Post by karim.achaibou »

Thanks, I will look for more info about QT signals and slots.
karim.achaibou
Posts: 62
Joined: Tue Oct 26, 2021 5:39 pm

Re: Solved: Taskpanel open .ui panel after object creation

Post by karim.achaibou »

small addition:

when implementing the doubleClicked function in the viewprovider class you can access the setEdit(vobj) function. But if you do that, you can not longer right click and use the transform function because you have overwritten it. Therefore create new functions as below:

Code: Select all

    def doubleClicked(self, vobj):
        self.setEditPanel(vobj)

    def setEditPanel(self, vobj, mode=0):
        obj = vobj.Object
        panel = BoxTaskPanel(obj.Name, ... relevant parameters ...)
        Gui.Control.showDialog(panel)
        return True
result in my case:
  • doubleclinking opens the panel to edit my properties
  • rightclicking + selecting transform in pop-up menu opens the transform function
Post Reply