How do we simulate a double-click in the tree view?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
ceremcem
Posts: 226
Joined: Sun Jan 07, 2018 11:10 am

How do we simulate a double-click in the tree view?

Post by ceremcem »

I want to programmatically double click on an object in the tree view with Python API. It seems it's not ".recompute()" method (or I might be doing something in a wrong way).

Code: Select all

x = App.ActiveDocument.getObjectsByLabel('foo')[0]
x.recompute() # <- this doesn't seem to work 
How can I send a "double click signal" to an object?
mario52
Veteran
Posts: 4701
Joined: Wed May 16, 2012 2:13 pm

Re: How do we simulate a double-click in the tree view?

Post by mario52 »

hi

maybe with Gui.Selection.addSelection(obj)

Code: Select all

FreeCADGui.Selection.addSelection(App.ActiveDocument.getObjectsByLabel("Cube")[0])
Selection_API

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: How do we simulate a double-click in the tree view?

Post by DeepSOIC »

I'm afraid there is no universal way to simulate a double-click, other than digging out the tree widget, and sending the event to appropriate item.

Is there a specific double-click action that you would like to trigger? For example, for many objects, Gui.ActiveDocument.setEdit('put_your_object_name_here')
is equivalent. For python-powered objects, you can dig out viewprovider proxy and call the corresponding method...
User avatar
ceremcem
Posts: 226
Joined: Sun Jan 07, 2018 11:10 am

Re: How do we simulate a double-click in the tree view?

Post by ceremcem »

As I'm both new to FreeCAD and using LinkStage3 branch, it becomes very confusing to me if something is directly related with LinkStage3 branch or Asm3 WB or FreeCAD (upstream) itself. This was one of those issues.

First I asked that in Asm3 issues, then I thought that there might be a universal way to simulate the double-click, so I asked it here. According to @realthunder's answer, it won't be "that easy" in my case but still possible.
Is there a specific double-click action that you would like to trigger?
Yes, but this is actually a dirty workaround in my case. I'm extensively using LinkStage3's Sub-shape Binder to get external geometry into sketches and they (currently) need to be updated by double-clicking on them in some circumstances. I thought I could write a macro that would run on Refresh which would simply double-click on the Sub-shape Binder.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: How do we simulate a double-click in the tree view?

Post by DeepSOIC »

I am not into asm3 unfortunately (my FreeCAD work doesn't really need them). But to me, it looks like there is some not-so-great design going on.

Realthunder's answer to simulate a double-click with App.ActiveDocument.Binder.ViewObject.doubleClicked() is as close as it gets to simulating a double-click, that's for sure.


Part-o-magic Ghost may be a little bit better for your needs, except I can't be sure because I don't know what exactly you are after. Ghost doesn't need a double-click, it updates itself automatically, at a cost of not being able to live in an assembly container.
User avatar
ebrahim raeyat
Posts: 625
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: How do we simulate a double-click in the tree view?

Post by ebrahim raeyat »

DeepSOIC wrote: Thu Sep 13, 2018 8:51 pm I'm afraid there is no universal way to simulate a double-click, other than digging out the tree widget, and sending the event to appropriate item.

Is there a specific double-click action that you would like to trigger? For example, for many objects, Gui.ActiveDocument.setEdit('put_your_object_name_here')
is equivalent. For python-powered objects, you can dig out viewprovider proxy and call the corresponding method...
Hello @DeepSOIC. I have a python object with setEdit method in ViewProvider of object. When I click the object name in Tree View, the appropriate UI opens, but my question is:

How can I open the same UI, with double-clicking the object in 3D view scene? If I implement DoubleClick method and refer it to setEdit:

Code: Select all

def setEdit(self, vobj, mode=0):
		obj = vobj.Object
		ui = Ui(obj)
		ui.setupUi()
		Gui.Control.showDialog(ui)
		return True
	
	def unsetEdit(self, vobj, mode):
		Gui.Control.closeDialog()
		return
		
	def doubleClicked(self,vobj):
		self.setEdit(vobj)
Thanks.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: How do we simulate a double-click in the tree view?

Post by DeepSOIC »

yes, except i don't know how to capture the double-click in 3d view. In your code, the doubleClicked method refers to a double-clicking it in model tree.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How do we simulate a double-click in the tree view?

Post by openBrain »

ebrahim raeyat wrote: Sat Apr 17, 2021 2:50 pm How can I open the same UI, with double-clicking the object in 3D view scene?
IMO you should not do that as this isn't how FC works and creating inconsistency is rarely a good thing.
User avatar
ebrahim raeyat
Posts: 625
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: How do we simulate a double-click in the tree view?

Post by ebrahim raeyat »

DeepSOIC wrote: Sat Apr 17, 2021 3:01 pm yes, except i don't know how to capture the double-click in 3d view. In your code, the doubleClicked method refers to a double-clicking it in model tree.
Thanks. I am a little confused. The DoubleClick method doesn't execute when double-clicking an object in a 3D scene? Thus, how can I execute it? Thanks.
User avatar
ebrahim raeyat
Posts: 625
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: How do we simulate a double-click in the tree view?

Post by ebrahim raeyat »

openBrain wrote: Sat Apr 17, 2021 4:13 pm
ebrahim raeyat wrote: Sat Apr 17, 2021 2:50 pm How can I open the same UI, with double-clicking the object in 3D view scene?
IMO you should not do that as this isn't how FC works and creating inconsistency is rarely a good thing.
Thanks, But why I should not do that? I don't know. In most cased the user wants to click on an object in 3D, but with double-clicking in tree view, the user first must click on the object in 3D and then double-click on it in the tree. Because the user doesn't know the name of the object, most of the time.
Post Reply