Beispiel #1
0
    def _data_changed(self, old, new):
        if has_attributes(self.data):
            aa = self._assign_attribute
            aa.input = new
            self._update_data()
            self.outputs = [aa.output]
        else:
            self.outputs = [self.data]
        self.data_changed = True

        self.output_info.datasets = \
                [get_tvtk_dataset_name(self.outputs[0])]

        # Add an observer to the VTK dataset after removing the one
        # for the old dataset.  We use the messenger to avoid an
        # uncollectable reference cycle.  See the
        # enthought.tvtk.messenger module documentation for details.
        if old is not None:
            old.remove_observer(self._observer_id)
        self._observer_id = new.add_observer('ModifiedEvent',
                                             messenger.send)
        new_vtk = tvtk.to_vtk(new)
        messenger.connect(new_vtk, 'ModifiedEvent',
                          self._fire_data_changed)
        
        # Change our name so that our label on the tree is updated.
        self.name = self._get_name()
Beispiel #2
0
    def _data_changed(self, old, new):
        if has_attributes(self.data):
            aa = self._assign_attribute
            aa.input = new
            self._update_data()
            self.outputs = [aa.output]
        else:
            self.outputs = [self.data]
        self.data_changed = True

        self.output_info.datasets = \
                [get_tvtk_dataset_name(self.outputs[0])]

        # Add an observer to the VTK dataset after removing the one
        # for the old dataset.  We use the messenger to avoid an
        # uncollectable reference cycle.  See the
        # enthought.tvtk.messenger module documentation for details.
        if old is not None:
            old.remove_observer(self._observer_id)
        self._observer_id = new.add_observer('ModifiedEvent', messenger.send)
        new_vtk = tvtk.to_vtk(new)
        messenger.connect(new_vtk, 'ModifiedEvent', self._fire_data_changed)

        # Change our name so that our label on the tree is updated.
        self.name = self._get_name()
Beispiel #3
0
    def test_send_on_dead_ref(self):
        """Test if sending to a gc'd callback works gracefully."""
        class C:
            def foo(self, o, e):
                pass

        c = C()
        c1 = C()
        messenger.connect(c1, 'foo', c.foo)
        messenger.send(c1, 'foo')

        # Test if things behave sanely if a message was sent and one
        # of the callbacks has been gc'd.
        m = messenger.Messenger()
        l1 = len(m._signals[hash(c1)]['foo'])
        #
        del c
        messenger.send(c1, 'foo')
        #
        l2 = len(m._signals[hash(c1)]['foo'])
        # Since 'c' is gc'd this callback should have been cleared
        # out.
        self.assertEqual(l2, l1 - 1)

        # Clean up.
        messenger.disconnect(c1)
Beispiel #4
0
    def OnPaint(self, event):
        """This method is overridden temporarily in order to create
        the light manager.  This is necessary because it makes sense
        to create the light manager only when the widget is realized.
        Only when the widget is realized is the VTK render window
        created and only then are the default lights all setup
        correctly.  This handler is removed on the first Paint event
        and the default paint handler of the
        wxVTKRenderWindowInteractor is used instead."""

        # Call the original handler (this will Show the widget)
        self._vtk_control.OnPaint(event)
        if len(self.renderer.lights) == 0:
            # The renderer is not ready yet, we do not do anything, and
            # we do not remove this callback, so that it will be called
            # later.
            return
        # Now create the light manager.
        self.light_manager = light_manager.LightManager(self)

        renwin = self._renwin
        renwin.update_traits()

        vtk_rw = tvtk.to_vtk(renwin)
        renwin.add_observer('StartEvent', messenger.send)
        messenger.connect(vtk_rw, 'StartEvent', self._start_event_callback)
        renwin.add_observer('EndEvent', messenger.send)
        messenger.connect(vtk_rw, 'EndEvent', self._end_event_callback)

        # Reset the event handler to the default since our job is done.
        wx.EVT_PAINT(self._vtk_control, None)  # Remove the default handler.
        wx.EVT_PAINT(self._vtk_control, self._vtk_control.OnPaint)
Beispiel #5
0
    def test_send_on_dead_ref(self):
        """Test if sending to a gc'd callback works gracefully."""
        class C:
            def foo(self, o, e):
                pass
        c = C()
        c1 = C()
        messenger.connect(c1, 'foo', c.foo)
        messenger.send(c1, 'foo')

        # Test if things behave sanely if a message was sent and one
        # of the callbacks has been gc'd.
        m = messenger.Messenger()
        l1 = len(m._signals[hash(c1)]['foo'])
        #
        del c
        messenger.send(c1, 'foo')
        #
        l2 = len(m._signals[hash(c1)]['foo'])
        # Since 'c' is gc'd this callback should have been cleared
        # out.
        self.assertEqual(l2, l1 - 1)

        # Clean up.
        messenger.disconnect(c1)
Beispiel #6
0
    def OnPaint(self, event):
        """This method is overridden temporarily in order to create
        the light manager.  This is necessary because it makes sense
        to create the light manager only when the widget is realized.
        Only when the widget is realized is the VTK render window
        created and only then are the default lights all setup
        correctly.  This handler is removed on the first Paint event
        and the default paint handler of the
        wxVTKRenderWindowInteractor is used instead."""

        # Call the original handler (this will Show the widget)
        self._vtk_control.OnPaint(event)
        if len(self.renderer.lights) == 0:
            # The renderer is not ready yet, we do not do anything, and
            # we do not remove this callback, so that it will be called
            # later.
            return
        # Now create the light manager.
        self.light_manager = light_manager.LightManager(self)

        renwin = self._renwin
        renwin.update_traits()

        vtk_rw = tvtk.to_vtk(renwin)
        renwin.add_observer('StartEvent', messenger.send)
        messenger.connect(vtk_rw, 'StartEvent', self._start_event_callback)
        renwin.add_observer('EndEvent', messenger.send)
        messenger.connect(vtk_rw, 'EndEvent', self._end_event_callback)

        # Reset the event handler to the default since our job is done.
        wx.EVT_PAINT(self._vtk_control, None) # Remove the default handler.
        wx.EVT_PAINT(self._vtk_control, self._vtk_control.OnPaint)
Beispiel #7
0
 def _setup_listners(self):
     object = self.object
     kids = self.children_cache
     for key, val in kids.items():
         if isinstance(val, tvtk.Collection):
             vtk_obj = tvtk.to_vtk(val)
             messenger.connect(vtk_obj, "ModifiedEvent", self._notify_children)
         else:
             object.on_trait_change(self._notify_children, key)
Beispiel #8
0
 def _setup_listners(self):
     object = self.object
     kids = self.children_cache
     for key, val in kids.items():
         if isinstance(val, tvtk.Collection):
             vtk_obj = tvtk.to_vtk(val)
             messenger.connect(vtk_obj, 'ModifiedEvent',
                               self._notify_children)
         else:
             object.on_trait_change(self._notify_children, key)
Beispiel #9
0
 def test_catchall(self):
     """Tests if catch all handlers are called."""
     b = B()
     b.send()
     self.assertEqual(b.a.event, 'method')
     self.assertEqual(b.a.args, ())
     self.assertEqual(b.a.kw, {})
     self.assertEqual(b.a.did_catch_all, 0)
     messenger.connect(b, 'AnyEvent', b.a.catch_all_cb)
     b.send(1, test=1)
     self.assertEqual(b.a.event, 'method')
     self.assertEqual(b.a.args, (1, ))
     self.assertEqual(b.a.kw, {'test': 1})
     self.assertEqual(b.a.did_catch_all, 1)
     b.a.did_catch_all = 0
     messenger.disconnect(b, 'AnyEvent')
     b.send(1, test=1)
     self.assertEqual(b.a.did_catch_all, 0)
Beispiel #10
0
 def test_catchall(self):
     """Tests if catch all handlers are called."""
     b = B()
     b.send()
     self.assertEqual(b.a.event, 'method')
     self.assertEqual(b.a.args, ())
     self.assertEqual(b.a.kw, {})
     self.assertEqual(b.a.did_catch_all, 0)
     messenger.connect(b, 'AnyEvent', b.a.catch_all_cb)
     b.send(1, test=1)
     self.assertEqual(b.a.event, 'method')
     self.assertEqual(b.a.args, (1,))
     self.assertEqual(b.a.kw, {'test':1})
     self.assertEqual(b.a.did_catch_all, 1)
     b.a.did_catch_all = 0
     messenger.disconnect(b, 'AnyEvent')
     b.send(1, test=1)
     self.assertEqual(b.a.did_catch_all, 0)
Beispiel #11
0
 def _recorder_changed(self, r):
     """When the recorder is set we add an event handler so we can
     record the change to the camera position after the interaction.
     """
     iren = self._interactor 
     if r is not None:
         self._script_id = r.get_script_id(self)
         id = iren.add_observer('EndInteractionEvent', 
                                messenger.send)
         self._camera_observer_id = id
         i_vtk = tvtk.to_vtk(iren)
         messenger.connect(i_vtk, 'EndInteractionEvent', 
                           self._record_camera_position)
     else:
         self._script_id = ''
         iren.remove_observer(self._camera_observer_id)
         i_vtk = tvtk.to_vtk(iren)
         messenger.disconnect(i_vtk, 'EndInteractionEvent', 
                              self._record_camera_position)
Beispiel #12
0
    def paintEvent(self, e):
        """ Reimplemented to create the light manager only when needed.  This
        is necessary because it makes sense to create the light manager only
        when the widget is realized.  Only when the widget is realized is the
        VTK render window created and only then are the default lights all
        setup correctly.
        """
        QVTKRenderWindowInteractor.paintEvent(self, e)

        scene = self._scene

        if scene.light_manager is None:
            scene.light_manager = light_manager.LightManager(scene)
            renwin = scene._renwin
            renwin.update_traits()
            vtk_rw = tvtk.to_vtk(renwin)
            renwin.add_observer('StartEvent', messenger.send)
            messenger.connect(vtk_rw, 'StartEvent', self._start_event_callback)
            renwin.add_observer('EndEvent', messenger.send)
            messenger.connect(vtk_rw, 'EndEvent', self._end_event_callback)
Beispiel #13
0
    def __init__(self, parent=None, wflags=QtCore.Qt.WindowFlags(), **kw):
        # the current button
        self._ActiveButton = QtCore.Qt.NoButton

        # private attributes
        self.__oldFocus = None
        self.__saveX = 0
        self.__saveY = 0
        self.__saveModifiers = QtCore.Qt.NoModifier
        self.__saveButtons = QtCore.Qt.NoButton

        # do special handling of some keywords:
        # stereo, rw

        stereo = 0

        if kw.has_key('stereo'):
            if kw['stereo']:
                stereo = 1

        rw = None

        if kw.has_key('rw'):
            rw = kw['rw']

        # create qt-level widget
        QtGui.QWidget.__init__(self, parent, wflags|QtCore.Qt.MSWindowsOwnDC)

        if rw: # user-supplied render window
            self._RenderWindow = rw
        else:
            self._RenderWindow = vtk.vtkRenderWindow()

        self._RenderWindow.SetWindowInfo(str(int(self.winId())))
        self._should_set_parent_info = (sys.platform == 'win32')

        if stereo: # stereo mode
            self._RenderWindow.StereoCapableWindowOn()
            self._RenderWindow.SetStereoTypeToCrystalEyes()

        self._Iren = vtk.vtkGenericRenderWindowInteractor()
        self._Iren.SetRenderWindow(self._RenderWindow)

        # do all the necessary qt setup
        self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
        self.setAttribute(QtCore.Qt.WA_PaintOnScreen)
        self.setMouseTracking(True) # get all mouse events
        self.setFocusPolicy(QtCore.Qt.WheelFocus)
        self.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))

        self._Timer = QtCore.QTimer(self)
        self.connect(self._Timer, QtCore.SIGNAL('timeout()'), self.TimerEvent)
        
        self._Iren.AddObserver('CreateTimerEvent', messenger.send)
        messenger.connect(self._Iren, 'CreateTimerEvent', self.CreateTimer)
        self._Iren.AddObserver('DestroyTimerEvent', messenger.send)
        messenger.connect(self._Iren, 'DestroyTimerEvent', self.DestroyTimer)
        render_window = self._Iren.GetRenderWindow()
        render_window.AddObserver('CursorChangedEvent', messenger.send)
        messenger.connect(render_window, 'CursorChangedEvent', self.CursorChangedEvent)
    def __init__(self, parent=None, wflags=QtCore.Qt.WindowFlags(), **kw):
        # the current button
        self._ActiveButton = QtCore.Qt.NoButton

        # private attributes
        self.__oldFocus = None
        self.__saveX = 0
        self.__saveY = 0
        self.__saveModifiers = QtCore.Qt.NoModifier
        self.__saveButtons = QtCore.Qt.NoButton

        # do special handling of some keywords:
        # stereo, rw

        stereo = 0

        if kw.has_key('stereo'):
            if kw['stereo']:
                stereo = 1

        rw = None

        if kw.has_key('rw'):
            rw = kw['rw']

        # create qt-level widget
        QtGui.QWidget.__init__(self, parent, wflags | QtCore.Qt.MSWindowsOwnDC)

        if rw:  # user-supplied render window
            self._RenderWindow = rw
        else:
            self._RenderWindow = vtk.vtkRenderWindow()

        self._RenderWindow.SetWindowInfo(str(int(self.winId())))
        self._should_set_parent_info = (sys.platform == 'win32')

        if stereo:  # stereo mode
            self._RenderWindow.StereoCapableWindowOn()
            self._RenderWindow.SetStereoTypeToCrystalEyes()

        self._Iren = vtk.vtkGenericRenderWindowInteractor()
        self._Iren.SetRenderWindow(self._RenderWindow)

        # do all the necessary qt setup
        self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
        self.setAttribute(QtCore.Qt.WA_PaintOnScreen)
        self.setMouseTracking(True)  # get all mouse events
        self.setFocusPolicy(QtCore.Qt.WheelFocus)
        self.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Expanding))

        self._Timer = QtCore.QTimer(self)
        self.connect(self._Timer, QtCore.SIGNAL('timeout()'), self.TimerEvent)

        self._Iren.AddObserver('CreateTimerEvent', messenger.send)
        messenger.connect(self._Iren, 'CreateTimerEvent', self.CreateTimer)
        self._Iren.AddObserver('DestroyTimerEvent', messenger.send)
        messenger.connect(self._Iren, 'DestroyTimerEvent', self.DestroyTimer)
        render_window = self._Iren.GetRenderWindow()
        render_window.AddObserver('CursorChangedEvent', messenger.send)
        messenger.connect(render_window, 'CursorChangedEvent',
                          self.CursorChangedEvent)
Beispiel #15
0
 def __init__(self):
     self.a = A()
     messenger.connect(self, 'method', self.a.callback)
     messenger.connect(self, 'function', callback)
Beispiel #16
0
 def __init__(self):
     self.a = A()
     messenger.connect(self, 'method', self.a.callback)
     messenger.connect(self, 'function', callback)