Commit bee52a20 authored by David Gobbi's avatar David Gobbi
Browse files

BUG: Re-enable python wrapping of vtkCommand event ids.

Commit 1993b941 made the event enum constants invisible to the
wrappers.  This change makes it possible for the wrappers to
expand the macros used to define the constants, and hence allows
the constants to be wrapped again.

Change-Id: Ib36d00f80caf7d87cdfcd479c15e6ebc176e240e
parent 75745365
...@@ -5,6 +5,7 @@ IF (VTK_PYTHON_EXE) ...@@ -5,6 +5,7 @@ IF (VTK_PYTHON_EXE)
FOREACH ( tfile FOREACH ( tfile
PythonSmoke PythonSmoke
TestArrayArguments TestArrayArguments
TestCommand
TestGhost TestGhost
TestMutable TestMutable
TestSubClass TestSubClass
......
"""Test the wrapping of vtkCommand
The following vtkCommmand functionality must be tested
- Event enum constants
- Event names
- Adding/removing observers
Created on Mar 22, 2012 by David Gobbi
"""
import sys
import exceptions
import vtk
from vtk.test import Testing
class callback:
def __init__(self):
self.caller = None
self.event = None
def __call__(self, o, e):
self.caller = o
self.event = e
class TestCommand(Testing.vtkTest):
def testEnumConstants(self):
"""Make sure the event id constants are wrapped
"""
self.assertEqual(vtk.vtkCommand.ErrorEvent, 39)
def testCommandWithArgs(self):
"""Test binding a command that has arguments.
"""
cb = callback()
o = vtk.vtkObject()
o.AddObserver(vtk.vtkCommand.ModifiedEvent, cb)
o.Modified()
self.assertEqual(cb.caller, o)
self.assertEqual(cb.event, "ModifiedEvent")
def testUseEventNameString(self):
"""Test binding with a string event name.
"""
cb = callback()
o = vtk.vtkObject()
o.AddObserver("ModifiedEvent", cb)
o.Modified()
self.assertEqual(cb.caller, o)
self.assertEqual(cb.event, "ModifiedEvent")
def testPriorityArg(self):
"""Test the optional priority argument
"""
cb = callback()
o = vtk.vtkObject()
o.AddObserver(vtk.vtkCommand.ModifiedEvent, cb, 0.5)
o.Modified()
self.assertEqual(cb.caller, o)
def testRemoveCommand(self):
"""Test the removal of an observer.
"""
cb = callback()
o = vtk.vtkObject()
o.AddObserver(vtk.vtkCommand.ModifiedEvent, cb)
o.Modified()
self.assertEqual(cb.caller, o)
o.RemoveObservers(vtk.vtkCommand.ModifiedEvent)
cb.caller = None
cb.event = None
o.Modified()
self.assertEqual(cb.caller, None)
def testGetCommand(self):
"""Test getting the vtkCommand object
"""
cb = callback()
o = vtk.vtkObject()
n = o.AddObserver(vtk.vtkCommand.ModifiedEvent, cb)
o.Modified()
self.assertEqual(cb.caller, o)
c = o.GetCommand(n)
self.assertEqual((c.IsA("vtkCommand") != 0), True)
# in the future, o.RemoveObserver(c) should also be made to work
o.RemoveObserver(n)
cb.caller = None
cb.event = None
o.Modified()
self.assertEqual(cb.caller, None)
if __name__ == "__main__":
Testing.main([(TestCommand, 'test')])
...@@ -45,7 +45,7 @@ const char *vtkCommand::GetStringFromEventId(unsigned long event) ...@@ -45,7 +45,7 @@ const char *vtkCommand::GetStringFromEventId(unsigned long event)
#define _vtk_add_event(Enum)\ #define _vtk_add_event(Enum)\
case Enum: return #Enum; case Enum: return #Enum;
VTK_EVENT_TYPES vtkAllEventsMacro()
#undef _vtk_add_event #undef _vtk_add_event
...@@ -68,7 +68,7 @@ unsigned long vtkCommand::GetEventIdFromString(const char *event) ...@@ -68,7 +68,7 @@ unsigned long vtkCommand::GetEventIdFromString(const char *event)
{ {
#define _vtk_add_event(Enum)\ #define _vtk_add_event(Enum)\
if (strcmp(event, #Enum) == 0) {return Enum;} if (strcmp(event, #Enum) == 0) {return Enum;}
VTK_EVENT_TYPES vtkAllEventsMacro()
#undef _vtk_add_event #undef _vtk_add_event
if (strcmp("UserEvent",event) == 0) if (strcmp("UserEvent",event) == 0)
......
...@@ -208,7 +208,7 @@ ...@@ -208,7 +208,7 @@
// Define all types of events here. // Define all types of events here.
// Using this macro makes it possible to avoid mismatches between the event // Using this macro makes it possible to avoid mismatches between the event
// enums and their string counterparts. // enums and their string counterparts.
#define VTK_EVENT_TYPES \ #define vtkAllEventsMacro() \
_vtk_add_event(AnyEvent)\ _vtk_add_event(AnyEvent)\
_vtk_add_event(DeleteEvent)\ _vtk_add_event(DeleteEvent)\
_vtk_add_event(StartEvent)\ _vtk_add_event(StartEvent)\
...@@ -309,10 +309,10 @@ ...@@ -309,10 +309,10 @@
_vtk_add_event(WindowIsDirectEvent)\ _vtk_add_event(WindowIsDirectEvent)\
_vtk_add_event(UncheckedPropertyModifiedEvent) _vtk_add_event(UncheckedPropertyModifiedEvent)
#define VTK_DECLARE_EVENTIDS(_enum_name)\ #define vtkEventDeclarationMacro(_enum_name)\
enum _enum_name{\ enum _enum_name{\
NoEvent = 0,\ NoEvent = 0,\
VTK_EVENT_TYPES \ vtkAllEventsMacro() \
UserEvent = 1000\ UserEvent = 1000\
}; };
...@@ -382,9 +382,9 @@ public: ...@@ -382,9 +382,9 @@ public:
// All the currently defined events are listed here. Developers can // All the currently defined events are listed here. Developers can
// use -- vtkCommand::UserEvent + int to specify their own event // use -- vtkCommand::UserEvent + int to specify their own event
// ids. // ids.
// Add new events by updating VTK_EVENT_TYPES macro. // Add new events by updating vtkAllEventsMacro.
#define _vtk_add_event(Enum) Enum, #define _vtk_add_event(Enum) Enum,
VTK_DECLARE_EVENTIDS(EventIds); vtkEventDeclarationMacro(EventIds);
#undef _vtk_add_event #undef _vtk_add_event
//ETX //ETX
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment