connect self.a.createWindow() to doubleClick

Questions about Anatomist manipulation

Moderators: riviere, denghien

pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

connect self.a.createWindow() to doubleClick

Postby pdeman » Wed Feb 01, 2017 1:43 pm

Hi,

I generate an anatomist window using self.a.createWindow.
I'ld like to connect it to "doubleClicked()" to a function.

I tried :
self.firstWindow = self.a.createWindow('Axial')
self.firstWindow.doubleClicked.connect(self.IwantIbilliondollars) and it's not working.
I have tried as well:
self.connect(self.firstWindow,QtCore.SIGNAL('doubleClicked()'),self.IwantIbilliondollars) as well without success.

any Idea ?

(the goal is that when I doubleClick on a marsatlas parcels on the "left window", on the "right window" it opens the mesh texture of the f-tract results for the stimulation in the "double clicked parcel").

User avatar
riviere
Site Admin
Posts: 1358
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: connect self.a.createWindow() to doubleClick

Postby riviere » Thu Feb 02, 2017 1:50 am

Hi,
The window is made of several widgets who behave differently to clicks, so it's not the right place to connect a callback. It should rather be set on the 3D widget (the display zone in the window). However Anatomist has its own callbacks system for windows, using Control and Action classes, which manage both contol buttons and callbacks.
See http://brainvisa.info/pyanatomist/sphinx/pyanatomist_examples.html#custom-controls-example for an example, and you may use the Control mouseDoubleClickEventSubscribe() method to connect an action to a double click event.
Denis

pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

Re: connect self.a.createWindow() to doubleClick

Postby pdeman » Thu Feb 02, 2017 11:57 am

thanks for the quick answer as usual !

the link doesn't work :( I'll try anyway but if you have the valid link I am interested ;)


User avatar
riviere
Site Admin
Posts: 1358
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: connect self.a.createWindow() to doubleClick

Postby riviere » Thu Feb 02, 2017 12:34 pm

The link works now (there was a missing symlink on the web server).

pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

Re: connect self.a.createWindow() to doubleClick

Postby pdeman » Mon Feb 13, 2017 3:22 pm

Hi,

I haven't understand how to add the control.

In IntrAnat codes I do:

Code: Select all

import anatomist.direct.api as testanatomist
cd = anatomist.cpp.ControlDictionary.instance()

now I have the object with existing controls, I want to add one:

Code: Select all

cd.addControl('leftMouseDoubleClick',lambda:self.leftmousedoubleclickeventsubscribe,25)
#it needs a number but I didn't get what this number is
now I have connected the event "leftMouseDoubleClick" to a function in my software, but I still have to define the event right ?

and I don't understand how. something to do with the ControlManager ?

Code: Select all

cm.anatomist.copp.ControlManager.instance()
cm.addControl( 'QAGLWidget3D', '', '??' )

User avatar
riviere
Site Admin
Posts: 1358
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: connect self.a.createWindow() to doubleClick

Postby riviere » Tue Feb 28, 2017 12:16 pm

Hi,
A Control corresponds to a complete keyboard/mouse interaction mode, it overrides entirely all events from keyboard and mouse. It is materialized by an icon on the left side of the window. In a Control, you can (and should) plug Actions, which define callback functions which are bound to events in the control.
So you have to define a Control subclass, one or several Action subclasses, and plug actions methods to events in the Control eventAutoSubscription() method.
Then actions and controls classes have to be registered in ActionDictionary and ControlDictionary so that Anatomist knows which controls are available for its windows.
Last, the ControlManager should register the control too, which specifies for which kind of window, and in presence of which type of object (which may be "": any) the control can be activated.
Thus, "cd.addControl" should take as argument a control name, a control creation function (the lambda in the example could be replaced by just the class actually), and the number is a priority number used to sort icons in the toolbar.
Is it clearer ?
Denis

pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

Re: connect self.a.createWindow() to doubleClick

Postby pdeman » Tue Feb 28, 2017 2:51 pm

thanks for the details.

I have succeed to add an icon with the ftract logo for the control. which do nothing for now but I'll try to understand how to do.
how should I do to have the explanation of the control when the mouse goes over the logo ? as for other controls. for now it just says "ftract_control"

if I do:

Code: Select all

import anatomist.direct.api as anatomist
cd = anatomist.cpp.ControlDictionary.instance()


is there a way to know which "control" I am currently using ? "white arrow" or "paper plane" for example ?
Attachments
ftract_control_logo.png
ftract_control_logo.png (12.32 KiB) Viewed 7990 times

pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

Re: connect self.a.createWindow() to doubleClick

Postby pdeman » Wed Mar 01, 2017 10:16 am

is it possible to add the icon to a anatomist windows already created ?
My gui is already generated, with two anatomist windows on it.
gui_ftract_results.png
gui_ftract_results.png (35.36 KiB) Viewed 7984 times


once the user generate the meshes (ftract results) it would add the icon for the specific controls to navigate on these results:
so at the end of the function generating the results, I do:

Code: Select all

import control_ftract
pix = QtGui.QPixmap('/home/b67-belledone/Desktop/epilepsie-manik/Logo-F-TRACT.xpm' )
anatomist.anatomist.cpp.IconDictionary.instance().addIcon('ftract_control', pix)
ad = anatomist.anatomist.cpp.ActionDictionary.instance()
ad.addAction( 'fTract_Action', lambda: control_ftract.fTract_Action() )
cd = anatomist.anatomist.cpp.ControlDictionary.instance()
cd.addControl( 'ftract_control', lambda: control_ftract.ftract_control(), 25 )
cm = anatomist.anatomist.cpp.ControlManager.instance()


no error for now.
and now I'ld like to specify in which anatomist windows the control has to be added.
the two windows are :

Code: Select all

self.sagWindow = self.a.createWindow( 'Sagittal' )
self.axialWindow = self.a.createWindow( 'Axial' )


I tried this, without success:

Code: Select all

cm.addControl( self.sagWindow, '', 'ftract_control' )
*** TypeError: ControlManager.addControl(): arguments did not match any overloaded call:
  overload 1: argument 1 has unexpected type 'AWindow'
  overload 2: argument 1 has unexpected type 'AWindow'

User avatar
riviere
Site Admin
Posts: 1358
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: connect self.a.createWindow() to doubleClick

Postby riviere » Wed Mar 01, 2017 11:15 am

how should I do to have the explanation of the control when the mouse goes over the logo ?

We are using the string translation system of Qt/PyQt for this, using pylupdate / lrelease and linguist tools. It's integrated in our build system so I don't do it by hand. Actually we use a string translation on the control name, which was probably not a good idea because this needs a "translation" even in english to get an explanation string, but this is how it works up to now. pylupdate parses python sources for strings to be translated and generates/updates a .ts file (here, pyanatomist.ts which is in share/anatomist-<ver>/po/<lang>/), then we can edit it using linguist, then "compile" the translated strings using lrelease to build the pyanatomist.qm file which is used in runtime.

is there a way to know which "control" I am currently using ?

Code: Select all

win.view().controlSwitch().activeControl()

You can also set a control:

Code: Select all

win.setControl('SelectionControl')


is it possible to add the icon to a anatomist windows already created ?

I don't remember actually. We generally define controls when initializing a plugin or a custom application, not after a window is open. Available controls in a window may then change according to the objects it contains.

Code: Select all

I'ld like to specify in which anatomist windows the control has to be added

If 2 windows are the same type and contain the same objects, then they should allow the same controls: the controls system is precisely meant for this, not to specialize a specific window. However what is possible is to activate a given control in a given window (using the above setControl() method).

I tried this, without success:
cm.addControl( self.sagWindow, '', 'ftract_control' )

As said just before, ControlManager manages controls available for a type of window, not a specific one: its purpose is to provide a (new) window controls compatible with it. So the 1st argument of addControl is a string identifying a window type - technically, more a "view" type, which happens to have this cool name "QAGLWidget3D" in 3D windows :) )


Return to “Anatomist”

Who is online

Users browsing this forum: No registered users and 8 guests