[Ticket #5975] Get reference to active task dialog

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

[Ticket #5975] Get reference to active task dialog

Post by Joel_graff »

Is it possible to get a reference to the active task dialog in Python?

Gui.Control.activeDialog() only returns a boolean indicating whether or not it exists.
Last edited by Kunda1 on Sun Aug 28, 2022 2:34 pm, edited 2 times in total.
Reason: Added GH ticket number to thread title
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Get reference to active task dialog

Post by TheMarkster »

This is code from the wiki on adding a new tab to the combo view. Perhaps it will help.

Code: Select all

# create new Tab in ComboView
from PySide import QtGui,QtCore
#from PySide import uic

def getMainWindow():
   "returns the main window"
   # using QtGui.qApp.activeWindow() isn't very reliable because if another
   # widget than the mainwindow is active (e.g. a dialog) the wrong widget is
   # returned
   toplevel = QtGui.qApp.topLevelWidgets()
   for i in toplevel:
       if i.metaObject().className() == "Gui::MainWindow":
           return i
   raise Exception("No main window found")

def getComboView(mw):
   dw=mw.findChildren(QtGui.QDockWidget)
   for i in dw:
       if str(i.objectName()) == "Combo View":
           return i.findChild(QtGui.QTabWidget)
       elif str(i.objectName()) == "Python Console":
           return i.findChild(QtGui.QTabWidget)
   raise Exception ("No tab widget found")

mw = getMainWindow()
tab = getComboView(getMainWindow())
tab2=QtGui.QDialog()
tab.addTab(tab2,"A Special Tab")

#uic.loadUi("/myTaskPanelforTabs.ui",tab2)
tab2.show()
#tab.removeTab(2)
You might need to change qApp to QApplication.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Get reference to active task dialog

Post by Joel_graff »

TheMarkster wrote: Fri Aug 09, 2019 6:25 pm This is code from the wiki on adding a new tab to the combo view. Perhaps it will help.
Yeah, I've got that code. I was just hoping there was a way to directly get a reference to the active task dialog. That's what Control.activeDialog() returns on the C++, side, but it's reduced to a boolean for the Python call.

I have a workaround figured out already, so it's not an issue - but it sure seems like a valuable feature to add to Gui::ControlPy :)
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Get reference to active task dialog

Post by wmayer »

Feel free to open a ticket for a feature request.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: Get reference to active task dialog

Post by Joel_graff »

FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Get reference to active task dialog

Post by Kunda1 »

@Joel_graff care to add this forum thread link to the ticket (didn't see it there) and also modifying/prepending the thread title with the ticket number associated ? 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
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: [Ticket #4090] Get reference to active task dialog

Post by Joel_graff »

Kunda1 wrote: Mon Aug 12, 2019 10:20 pm @Joel_graff care to add this forum thread link to the ticket (didn't see it there) and also modifying/prepending the thread title with the ticket number associated ? Thanks!
Done!
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
User avatar
rockn
Veteran
Posts: 1791
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: [Ticket #4090] Get reference to active task dialog

Post by rockn »

+1 for this feature request :)

In the meantime, do you know a workaround to get the name of the active dialog ?
Formations - Assistance - Développement : https://freecad-france.com
walpa
Posts: 65
Joined: Wed Nov 09, 2016 5:22 pm
Location: Brazil

Re: Get reference to active task dialog

Post by walpa »

+1 for this :)

Joel_graff wrote: Fri Aug 09, 2019 7:05 pm
I have a workaround figured out already, so it's not an issue...
@Joel_graff can you show how you did it?
Thanks.
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: [Ticket #4090] Get reference to active task dialog

Post by Joel_graff »

I have no idea how I did it. Or where that code resides anymore. lol

I'll dig around and see if I can figure it out.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
Post Reply