Syncing widgets with MRML scene

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Syncing widgets with MRML scene

Ali Uneri
Hello,

This mail-list has been very helpful in the past, and I'm in need of help once again.

I'm having a problem with my Slicer Interactive module in Python. I've created a vtkSlicerNodeSelectorWidget and I want the nodes to be in sync with my MRMLScene, i.e. if the nodes are of type vtkMRMLFiducialListNode, I would like to see them in my widget just as in the Fiducials Module. Below is how I currently instantiate my widget:

from Slicer import slicer

class MyModule(ScriptedModuleGUI):
   ...

   self.my_selector = slicer.vtkSlicerNodeSelectorWidget()
   self.my_selector.SetParent(parent_frame)
   self.my_selector.SetNodeClass('vtkMRMLFiducialListNode', 0, 0, 0)
   self.my_selector.Create()
   self.my_selector.SetMRMLScene(slicer.MRMLScene)
   self.my_selector.UpdateMenu()
   self.my_selector.SetLabelText('My Fiducials')
   slicer.TkCall('pack %s -side top -fill x -padx 5 -pady 5' % self.my_selector.GetWidgetName())


In the C++ version, .SetMRMLScene() was enough to establish a link between the widget and the scene, however this is not the case in Python. Do I need to handle an event, or update something periodically to ensure that my selector widget displays the correct nodes in the current scene.

I also noticed there are multiple ways to obtain a scene, i.e. slicer.MRMLScene, self.GetApplicationGUI().GetMRMLScene(), self.GetLogic().GetMRMLScene(), what is the preferred way of getting the current scene?

Thank you,
Ali


_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: Syncing widgets with MRML scene

pieper
Administrator
Hi Ali -

Good bug!  I had to really dig to understand this one.  The issue is the
extra arguments to the SetNodeClass need to be strings, like so:

 >     self.my_selector.SetNodeClass('vtkMRMLFiducialListNode', "", "", "")

This is probably due to a subtle difference between 'slicerpython' and
'vktpython' in the way it coerces datatypes - this method expects
strings so it turned the 0s into "0"s
.  Hopefully there aren't too many of those gotcha's hiding.  I'll add a
pointer to this email in the bug tracker.  We'll be reworking all the
python stuff in the not too distant future so I hope this issue will
disappear.

I checked in a standalone example that works for me in case you neede it
for anything:

Base/GUI/Testing/NodeSelector.py

-Steve


On M/19/10 2:40 PM, Ali Uneri wrote:

> Hello,
>
> This mail-list has been very helpful in the past, and I'm in need of
> help once again.
>
> I'm having a problem with my Slicer Interactive module in Python. I've
> created a vtkSlicerNodeSelectorWidget and I want the nodes to be in sync
> with my MRMLScene, i.e. if the nodes are of type
> vtkMRMLFiducialListNode, I would like to see them in my widget just as
> in the Fiducials Module. Below is how I currently instantiate my widget:
>
> from Slicer import slicer
>
> class MyModule(ScriptedModuleGUI):
>     ...
>
>     self.my_selector = slicer.vtkSlicerNodeSelectorWidget()
>     self.my_selector.SetParent(parent_frame)
>     self.my_selector.SetNodeClass('vtkMRMLFiducialListNode', 0, 0, 0)
>     self.my_selector.Create()
>     self.my_selector.SetMRMLScene(slicer.MRMLScene)
>     self.my_selector.UpdateMenu()
>     self.my_selector.SetLabelText('My Fiducials')
>     slicer.TkCall('pack %s -side top -fill x -padx 5 -pady 5' %
> self.my_selector.GetWidgetName())
>
> In the C++ version, .SetMRMLScene() was enough to establish a link
> between the widget and the scene, however this is not the case in
> Python. Do I need to handle an event, or update something periodically
> to ensure that my selector widget displays the correct nodes in the
> current scene.
>
> I also noticed there are multiple ways to obtain a scene, i.e.
> slicer.MRMLScene, self.GetApplicationGUI().GetMRMLScene(),
> self.GetLogic().GetMRMLScene(), what is the preferred way of getting the
> current scene?
>
> Thank you,
> Ali
>
>
>
> _______________________________________________
> slicer-users mailing list
> [hidden email]
> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject