浏览代码

ctk/__init__.py.in - Decorates ctkWorkflowStep and ctkWorkflowWidgetStep

Decorate these two classes so that python API is simplified.
Jean-Christophe Fillion-Robin 14 年之前
父节点
当前提交
4877ee5687
共有 1 个文件被更改,包括 88 次插入2 次删除
  1. 88 2
      Libs/Scripting/Python/Core/Python/ctk/__init__.py.in

+ 88 - 2
Libs/Scripting/Python/Core/Python/ctk/__init__.py.in

@@ -12,6 +12,92 @@ for kit in __kits_to_load:
   except ImportError as detail:
     if CTK_VERBOSE_IMPORT: 
       print detail
-   
+
+def add_methodclass_to_ctkWorkflowStep_or_ctkWorkflowWidgetStep(workflowstep_class):
+  
+  def validate(self, validationSucceed, desiredBranchId):
+    """Validates the computation performed in this step's processing state."""
+    self.ctkWorkflowStepQObject().validationComplete(validationSucceed, desiredBranchId)
+    
+  def onEntry(self, comingFrom, transitionType):
+    """Reimplement this function for step-specific processing when entering a step."""
+    self.ctkWorkflowStepQObject().onEntryComplete()
+
+  def onExit(self, comingFrom, transitionType):
+    """Reimplement this function for step-specific processing when exiting a step."""
+    self.ctkWorkflowStepQObject().onExitComplete()
+    
+  def initialize(self):
+    workflowstep_class.__init__(self)
+    self.setHasValidateCommand(True)
+    self.setHasOnEntryCommand(True)
+    self.setHasOnExitCommand(True)
+    
+    qobj = self.ctkWorkflowStepQObject()
+    
+    qobj.connect('invokeValidateCommand(const QString&)', self.validate)
+    
+    qobj.connect('invokeOnEntryCommand(const ctkWorkflowStep*, \
+      ctkWorkflowInterstepTransition::InterstepTransitionType)', self.onEntry)
+      
+    qobj.connect('invokeOnExitCommand(const ctkWorkflowStep*, \
+      ctkWorkflowInterstepTransition::InterstepTransitionType)', self.onExit)    
+    
+  workflowstep_class.validate = validate
+  workflowstep_class.onEntry = onEntry
+  workflowstep_class.onExit = onExit
+  workflowstep_class.initialize = initialize
+
+def add_methodclass_to_ctkWorkflowWidgetStep():
+  
+  def createUserInterface(self):
+    self.ctkWorkflowStepQObject().createUserInterfaceComplete()
+    
+  #def showUserInterface(self):
+  #  self.ctkWorkflowStepQObject().showUserInterfaceComplete()
+    
+  ctkWorkflowWidgetStep.createUserInterface = createUserInterface;
+  #ctkWorkflowWidgetStep.showUserInterface = showUserInterface;
+    
+def decorates_ctkWorkflowWidgetStep_initialize_method():
+  """Decorates ctkWorkflowWidgetStep::initialize() method.
+  The properties 'hasCreateUserInterfaceCommand' and 'hasShowUserInterfaceCommand'
+  are set to True.
+  Signals 'invokeCreateUserInterfaceCommand' and 'invokeShowUserInterfaceCommand'
+  are respectively connected to the slots 'createUserInterface' and 'showUserInterface'.
+  """
+  
+  f = ctkWorkflowWidgetStep.initialize
+  
+  from functools import wraps
+  @wraps(f)
+  def decorated(self, *args, **kwargs):
+    f(self, *args, **kwargs)
+    self.setHasCreateUserInterfaceCommand(True)
+    #self.setHasShowUserInterfaceCommand(True)
+    
+    qobj = self.ctkWorkflowStepQObject()
+    
+    qobj.connect('invokeCreateUserInterfaceCommand()', self.createUserInterface)
+    #qobj.connect('invokeShowUserInterfaceCommand()', self.showUserInterface)
+  
+  ctkWorkflowWidgetStep.initialize = decorated
+
+#
+# Decorators
+#
+
+_lib = next((_lib for _lib in __kits_to_load if _lib == 'Core'), None)
+if _lib == 'Core':
+  add_methodclass_to_ctkWorkflowStep_or_ctkWorkflowWidgetStep(ctkWorkflowStep)
+  
+_lib = next((_lib for _lib in __kits_to_load if _lib == 'Widgets'), None)
+if _lib == 'Widgets':
+  add_methodclass_to_ctkWorkflowStep_or_ctkWorkflowWidgetStep(ctkWorkflowWidgetStep)
+  add_methodclass_to_ctkWorkflowWidgetStep()
+  decorates_ctkWorkflowWidgetStep_initialize_method()
+
 # Removing things the user shouldn't have to see.
-del __kits_to_load
+del __kits_to_load, _lib
+del add_methodclass_to_ctkWorkflowStep_or_ctkWorkflowWidgetStep
+del add_methodclass_to_ctkWorkflowWidgetStep, decorates_ctkWorkflowWidgetStep_initialize_method