connect self.a.createWindow() to doubleClick

Questions about Anatomist manipulation

Moderators: denghien, riviere

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

connect self.a.createWindow() to doubleClick

Post by pdeman »

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: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

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

Post by riviere »

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/sphin ... ls-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

Post by pdeman »

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
Yann Cointepas
Posts: 316
Joined: Tue Jan 20, 2004 2:56 pm
Location: Neurospin, Saint Aubin, France
Contact:

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

Post by Yann Cointepas »

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

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

Post by riviere »

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

Post by pdeman »

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: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

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

Post by riviere »

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

Post by pdeman »

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 20820 times
pdeman
Posts: 39
Joined: Thu Sep 17, 2015 4:09 pm
Location: moving sometimes

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

Post by pdeman »

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 20814 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: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

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

Post by riviere »

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 :) )
Post Reply