I'm in Part design-sketcher, from macro how to click the close button

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

I'm in Part design-sketcher, from macro how to click the close button

Post by freedman »

While in part design-sketcher I want to add a close button to a macro, this would be the close button in sketcher-comboview-tasks. Is there a way to signal the close button is pressed?
Thanks
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: I'm in Part design-sketcher, from macro how to click the close button

Post by openBrain »

This is a bit vague without any context, but generally you can register a FilterEvent to an existing widget. ;)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: I'm in Part design-sketcher, from macro how to click the close button

Post by DeepSOIC »

Part-o-magic Leave command can do it. see https://github.com/DeepSOIC/Part-o-magi ... ter.py#L64
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: I'm in Part design-sketcher, from macro how to click the close button

Post by freedman »

DeepSOIC, thank you, that worked great.
I added this to set focus on the tree when returning to part design (in case anyone is looking) :

Code: Select all

mw = FreeCADGui.getMainWindow()
dw= mw.findChildren(QtGui.QDockWidget)
for i in dw:
	if i.objectName() == "Combo View":
		tab = i.findChild(QtGui.QTabWidget)
		tab.setCurrentIndex(0)
Thanks all
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: I'm in Part design-sketcher, from macro how to click the close button

Post by openBrain »

freedman wrote: Tue Nov 12, 2019 4:46 pm DeepSOIC, thank you, that worked great.
I added this to set focus on the tree when returning to part design (in case anyone is looking) :
Thanks all
You can greatly simplify :

Code: Select all

FreeCADGui.getMainWindow().findChild(QtGui.QDockWidget, "Combo View").findChild(QtGui.QTabWidget).setCurrentIndex(0)
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: I'm in Part design-sketcher, from macro how to click the close button

Post by freedman »

@openBrain, thanks, I was thinking about that. I didn't have the findChild in my mental toolbox, got it now.
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: I'm in Part design-sketcher, from macro how to click the close button

Post by freedman »

@openBrain, I tried that line of code and it does not want to work. I researched the functions and I can't see why. It's no big deal cause I have code that works but there is something not right.
If I run from the console:

Code: Select all

>>> FreeCADGui.getMainWindow().findChild(QtGui.QDockWidget, "Combo View").findChild(QtGui.QTabWidget).setCurrentIndex(0)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'QtGui' is not defined
I have this in my macro:

Code: Select all

import FreeCAD
import FreeCADGui
import time
from pivy import coin
import FreeCAD as App, FreeCADGui 
from PySide import QtGui,QtCore
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: I'm in Part design-sketcher, from macro how to click the close button

Post by openBrain »

Before running the line in the console, you have to enter :

Code: Select all

from PySide import QtGui
Honestly I didn't check the line and post it directly. :oops:
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: I'm in Part design-sketcher, from macro how to click the close button

Post by openBrain »

The line correctly ends here (no error) but I don't see any effect... :?
chrisb
Veteran
Posts: 53945
Joined: Tue Mar 17, 2015 9:14 am

Re: I'm in Part design-sketcher, from macro how to click the close button

Post by chrisb »

openBrain wrote: Tue Nov 12, 2019 6:03 pm

Code: Select all

FreeCADGui.getMainWindow().findChild(QtGui.QDockWidget, "Combo View").findChild(QtGui.QTabWidget).setCurrentIndex(0)
Using the list of imports and executing this line I get no error and FreeCAD switches the tab in ComboView from Tasks to Model. The Sketch stays in edit mode in Sketcher.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply