Commits

iorodeo committed 9798ac8

Improved plugin system.

  • Participants
  • Parent commits 394deef

Comments (0)

Files changed (2)

File software/gui/nodes/gui_constants.py

 FEEDBACK_POSITIONING_VELOCITY = 0.2
 FEEDBACK_POSITIONING_ACCELERATION = 0.05
 
-PLUGIN_DIRECTORY = os.path.join(os.environ['HOME'],'ros','water_channel_plugins')
+PLUGIN_DIRECTORY = os.path.join(
+        os.environ['HOME'],
+        'ros',
+        'water_channel_plugins',
+        'src',
+        'water_channel_plugins',
+        )
 
 # Default log file
 DEFAULT_LOG_FILE = os.path.join(os.environ['HOME'],'default_log.hdf5')

File software/gui/nodes/sled_control.py

     def pluginStart_Callback(self):
         currentItem = self.pluginListWidget.currentItem()
         if currentItem is not None:
+            pluginName = str(currentItem.text())
+            pluginModule = self.pluginDict[pluginName]
+            try:
+                self.pluginObj = pluginModule.SledControlPlugin(
+                        self.robotControl, 
+                        self.startupMode,
+                        self.logFileName,
+                        self.pluginSetOutscanInProgress,
+                        self.pluginSetRunStateDone,
+                        self.pluginWriteStatusMessage,
+                        )
+            except Exception, e:
+                msg = 'unable to start plugin: %s'%(str(e),)
+                msgBoxTitle = 'Plugin Error'
+                QtGui.QMessageBox.critical(self,msgBoxTitle,msg)
+                return
             self.pluginStartPushButton.setEnabled(False)
             self.pluginStopPushButton.setEnabled(True)
-            pluginName = str(currentItem.text())
-            pluginModule = self.pluginDict[pluginName]
-            self.pluginObj = pluginModule.SledControlPlugin(
-                    self.robotControl, 
-                    self.pluginSetOutscanInProgress,
-                    self.pluginSetRunStateDone,
-                    self.writeStatusMessage,
-                    )
             self.runInProgress = True
             self.pluginRunning = True
             self.runState = 'plugin running'
             self.statusbar.showMessage('System Enabled - Plugin Running')
 
     def pluginStop_Callback(self):
+        self.outscanStopActions()
         self.pluginStartPushButton.setEnabled(True)
         self.pluginStopPushButton.setEnabled(False)
 
             self.runState = 'done'
 
     def pluginWriteStatusMessage(self,msg):
-        self.writeStatusMessage(msg)
-        self.statusWindowTextEdit.repaint()
+        """
+        Thread safe status messages for plugins
+        """
+        self.statusMessageQueue.put(msg)
 
     def logTreeItemClicked_Callback(self):
         currentItem = self.logTreeWidget.currentItem()
             self.robotControl.disableControllerMode()
             self.writeStatusMessage('feedback positioning stopped')
             self.progressBar.setVisible(False)
-        elif self.controlMode == 'startupMode':
+        #elif self.controlMode == 'startupMode':
+        else:
             self.robotControl.stopSetptOutscan()
             self.robotControl.stopActuatorOutscan()
             self.robotControl.disableControllerMode()
                 try:
                     f = h5py.File(self.logFileName)
                 except h5py.h5e.LowLevelIOError, e:
-                    msg = 'unable to delete log item: %s'%(str(e),)
+                    msg = 'unable to open log file: %s'%(str(e),)
                     QtGui.QMessageBox.critical(self,msgBoxtitle,msg)
                     return
                 itemName = str(currentItem.text(0))
                 except Exception, e:
                     errorMsg = 'unable to import plugin {0}: {1}'.format(f,str(e))
                     QtGui.QMessageBox.critical(self,'Plugin Import Error', errorMsg) 
+
+            # Remove plugins whose specified modes is not the startup mode.
+            for name, module in pluginDict.items():
+                try: 
+                    if not (module.PLUGIN_MODE == self.startupMode or module.PLUGIN_MODE=='any'):
+                        del pluginDict[name]
+                except KeyError:
+                    pass
         return pluginDict
 
     def main(self):