Example #1
0
    def loadModelDialogSlot(self):
        """Start a file dialog to choose a model file.

        Once the dialog succeeds, we should hand-over the duty of
        actual model loading to something else. Then refresh the
        views. Things to check from the user:

        1) The file type

        2) Target element

        3) Whether we should update the current window or start a new
        window.

        4) Plugin to use for displaying this model (can be automated
        by looking into the model file for a regular expression)

        """
        if self.popup is not None:
            self.popup.close()
        activeWindow = None # This to be used later to refresh the current widget with newly loaded model
        dialog = LoaderDialog(self,
                              self.tr('Load model from file'))

        if dialog.exec_():
            valid = False
            ret = []
            ret,pluginName = self.checkPlugin(dialog)
            if pluginName == 'kkit':
                compt = moose.wildcardFind(ret['model'].path+'/##[ISA=ChemCompt]')
                if not len(compt):
                    reply = QtGui.QMessageBox.question(self, "Model is empty","Model has no compartment, atleast one compartment should exist to display the widget\n Do you want another file",
                                               QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
                    if reply == QtGui.QMessageBox.Yes:
                        dialog = LoaderDialog(self,self.tr('Load model from file'))
                        if dialog.exec_():
                            ret,pluginName = self.checkPlugin(dialog)
                            ret,valid = self.dialog_check(ret)
                    else:
                        QtGui.QApplication.restoreOverrideCursor()        
                        return
                else:
                    valid = True
            if valid == True:
                modelAnno = moose.Annotator(ret['model'].path+'/info')
                if ret['subtype']:
                    modelAnno.modeltype = ret['subtype']
                else:
                    modelAnno.modeltype = ret['modeltype']
                modelAnno.dirpath = str(dialog.directory().absolutePath())
                self.loadedModelsAction(ret['model'].path,pluginName)
                self.setPlugin(pluginName, ret['model'].path)
                if pluginName == 'kkit':
                    QtCore.QCoreApplication.sendEvent(self.plugin.getEditorView().getCentralWidget().view, QtGui.QKeyEvent(QtCore.QEvent.KeyPress, Qt.Qt.Key_A, Qt.Qt.NoModifier))
Example #2
0
 def dialog_check(self,ret):
     pluginLookup = '%s/%s' % (ret['modeltype'], ret['subtype'])
     try:
         pluginName = subtype_plugin_map['%s/%s' % (ret['modeltype'], ret['subtype'])]
     except KeyError:
         pluginName = 'default'
     if pluginName == 'kkit':
         compt = moose.wildcardFind(ret['model'].path+'/##[ISA=ChemCompt]')
         if not len(compt):
             reply = QtGui.QMessageBox.question(self, "Model is empty","Model has no compartment, atleast one compartment should exist to display the widget\n Do you want another file",
                                        QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
             if reply == QtGui.QMessageBox.Yes:
                 dialog = LoaderDialog(self,self.tr('Load model from file'))
                 if dialog.exec_():
                     ret,pluginName = self.checkPlugin(dialog)
             else:
                 QtGui.QApplication.restoreOverrideCursor()        
                 return
         else:
             return ret,True