Forráskód Böngészése

Added test to ctkSimplePythonShell

 1) ctkWidgetsTest: Attempt to construct and show a CTK widget
 2) vtkPythonSmoke: Try to instantiate VTK object, check if downcasting works
 3) DerivedQWidgetTest: Derive a QWidget and set some signal/slot connection
Jean-Christophe Fillion-Robin 14 éve
szülő
commit
6bbac15c54

+ 1 - 1
Applications/ctkSimplePythonShell/CMakeLists.txt

@@ -89,5 +89,5 @@ ADD_SUBDIRECTORY(Python)
 
 # Testing
 IF(BUILD_TESTING)
-#   ADD_SUBDIRECTORY(Testing)
+  ADD_SUBDIRECTORY(Testing)
 ENDIF(BUILD_TESTING)

+ 1 - 0
Applications/ctkSimplePythonShell/Testing/CMakeLists.txt

@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(Python)

+ 24 - 0
Applications/ctkSimplePythonShell/Testing/Python/CMakeLists.txt

@@ -0,0 +1,24 @@
+
+SET(KIT_TESTS ${CPP_TEST_PATH}/ctkSimplePythonShell)
+
+SET(SCRIPTS
+  DerivedQWidgetTest.py
+  )
+
+IF(CTK_LIB_Widgets)
+  LIST(APPEND SCRIPTS ctkWidgetsTest.py)
+ENDIF()
+
+IF(CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
+  LIST(APPEND SCRIPTS vtkPythonSmoke.py)
+ENDIF()
+
+
+MACRO(SIMPLE_TEST_WITH_SCRIPT SCRIPT)
+  GET_FILENAME_COMPONENT(TESTNAME ${SCRIPT} NAME_WE)
+  ADD_TEST(ctkSimplePythonShell_${TESTNAME} ${KIT_TESTS} ${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT})
+ENDMACRO()
+
+FOREACH(s ${SCRIPTS})
+  SIMPLE_TEST_WITH_SCRIPT(${s})
+ENDFOREACH()

+ 41 - 0
Applications/ctkSimplePythonShell/Testing/Python/DerivedQWidgetTest.py

@@ -0,0 +1,41 @@
+
+from ctkqt import *
+
+class ExampleWidget(QWidget):
+  def __init__(self, parent=None):
+    QWidget.__init__(self, parent)
+
+    self.setGeometry(300, 300, 250, 150)
+    self.setWindowTitle('Example Widget')
+    
+    layout = QHBoxLayout(self)
+    
+    checkbox = QCheckBox('Shell Visibility', self)
+    layout.addWidget(checkbox);
+    checkbox.setChecked(True)
+    checkbox.connect('toggled(bool)', _ctkPythonShellInstance, 'setVisible(bool)')
+    
+    self.button = QPushButton('Quit', self)
+    layout.addWidget(self.button);
+    QObject.connect(self.button, SIGNAL('clicked()'), app(), SLOT('quit()'))
+    
+    self.center()
+
+  def center(self):
+    screen = QDesktopWidget().screenGeometry()
+    size =  self.geometry
+    self.move((screen.width() - size.width())/2, (screen.height() - size.height())/2)
+    
+w = ExampleWidget()
+w.show()
+
+if not _ctkPythonShellInstance.isInteractive:
+  #QTimer().singleShot(0, app(), SLOT('quit()'))
+  t = QTimer()
+  t.setInterval(250)
+  t.connect('timeout()', app(), 'quit()')
+  t.start()
+  
+  
+
+

+ 13 - 0
Applications/ctkSimplePythonShell/Testing/Python/ctkWidgetsTest.py

@@ -0,0 +1,13 @@
+
+from ctk import *
+from ctkqt import QTimer
+
+w = ctkMatrixWidget()
+w.show()
+
+if not _ctkPythonShellInstance.isInteractive:
+  #QTimer().singleShot(0, app(), SLOT('quit()'))
+  t = QTimer()
+  t.setInterval(250)
+  t.connect('timeout()', app(), 'quit()')
+  t.start()

+ 52 - 0
Applications/ctkSimplePythonShell/Testing/Python/vtkPythonSmoke.py

@@ -0,0 +1,52 @@
+
+#
+# Copied from VTK/Common/Testing/Python/PythonSmoke.py
+#
+
+import sys
+
+try:
+  import vtk
+
+except:
+  print "Cannot import vtk"
+  sys.exit(1)
+try:
+  print dir(vtk)
+except:
+  print "Cannot print dir(vtk)"
+  sys.exit(1)
+
+try:
+  try:
+    try:
+      o = vtk.vtkLineWidget()
+      print "Using Hybrid"
+    except:
+      o = vtk.vtkActor()
+      print "Using Rendering"
+  except:
+    o = vtk.vtkObject()
+    print "Using Common"
+except:
+  print "Cannot create vtkObject"
+  sys.exit(1)
+
+try:
+  print o
+  print "Reference count: %d" % o.GetReferenceCount()
+  print "Class name: %s" % o.GetClassName()
+except:
+  print "Cannot print object"
+  sys.exit(1)
+
+try:
+  b = vtk.vtkObject()
+  d = b.SafeDownCast(o)
+  print b, d
+except:
+  print "Cannot downcast"
+  sys.exit(1)
+
+sys.exit(0)
+