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

Need help, or want to share a macro? Post here!
freedman
Posts: 1731
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

Postby freedman » Tue Nov 12, 2019 4:25 am

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
Posts: 5126
Joined: Fri Nov 09, 2018 5:38 pm

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

Postby openBrain » Tue Nov 12, 2019 9:36 am

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

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

Postby DeepSOIC » Tue Nov 12, 2019 11:18 am

Part-o-magic Leave command can do it. see https://github.com/DeepSOIC/Part-o-magi ... ter.py#L64
freedman
Posts: 1731
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

Postby freedman » 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) :

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
Posts: 5126
Joined: Fri Nov 09, 2018 5:38 pm

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

Postby openBrain » Tue Nov 12, 2019 6:03 pm

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
Posts: 1731
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

Postby freedman » Wed Nov 13, 2019 1:12 am

@openBrain, thanks, I was thinking about that. I didn't have the findChild in my mental toolbox, got it now.
freedman
Posts: 1731
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

Postby freedman » Wed Nov 13, 2019 5:00 pm

@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
Posts: 5126
Joined: Fri Nov 09, 2018 5:38 pm

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

Postby openBrain » Wed Nov 13, 2019 6:14 pm

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
Posts: 5126
Joined: Fri Nov 09, 2018 5:38 pm

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

Postby openBrain » Wed Nov 13, 2019 6:20 pm

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

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

Postby chrisb » Wed Nov 13, 2019 6:31 pm

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.
You need at least FreeCAD 0.19.23300 to edit my current sketches.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.