Exemplo n.º 1
0
    def __deleted(self, *arg):
        """When delete_event happens or exit menu is selected, 
        this method is called.
        """
        running_flag = False
        if self.theSession.theRunningFlag:
            # stop simulation temporarily
            self.theSession.stop()
            running_flag = True

        if self.theSession.theSession is not None:
            # If there is no logger data, exit this program.
            if len(self.theSession.getLoggerList()) != 0:
                aMessage = 'Are you sure you want to quit?'
                aTitle = 'Question'
                # Popup confirm window, and check user request
                aDialog = ConfirmWindow(1, aMessage, aTitle)

                # ok is pressed

                if aDialog.return_result() != OK_PRESSED:
                    if running_flag:
                        self.theSession.run()
                    return True

        self.setStopState()
        self.close()
        self.theSession.QuitGUI()

        return True
Exemplo n.º 2
0
    def changeSaveDirectory( self, obj ):
        aSaveDirectory = self.theSaveDirectorySelection.get_filename()
        self.theSaveDirectorySelection.hide()
        selectedFullPNList = []
        for anItem in self.getSelected():
            selectedFullPNList.append( anItem[0] )
        # If same directory exists.
        if os.path.isdir(aSaveDirectory):
            aConfirmMessage = "%s directory already exist.\n Would you like to override it?"%aSaveDirectory
            confirmWindow = ConfirmWindow(1,aConfirmMessage)

            if confirmWindow.return_result() == 0:
                pass
            else:
                return None

        # If same directory dose not exists.
        else:
            try:
                os.mkdir(aSaveDirectory)
            except:
                aErrorMessage='couldn\'t create %s!\n'%aSaveDirectory
                aWarningWindow = ConfirmWindow(0,aErrorMessage)
                return None


        try:
            self.theSession.saveLoggerData( selectedFullPNList, aSaveDirectory, -1, -1, -1 )
        except:
            anErrorMessage = "Error : could not save "
            aWarningWindow = ConfirmWindow(0,anErrorMessage)
            return None
Exemplo n.º 3
0
    def __deleted(self, *arg):
        """When delete_event happens or exit menu is selected, 
        this method is called.
        """
        running_flag = False
        if self.theSession.theRunningFlag:
            # stop simulation temporarily
            self.theSession.stop()
            running_flag = True

        if self.theSession.theSession is not None:
            # If there is no logger data, exit this program.
            if len(self.theSession.getLoggerList()) != 0:
                aMessage = "Are you sure you want to quit?"
                aTitle = "Question"
                # Popup confirm window, and check user request
                aDialog = ConfirmWindow(1, aMessage, aTitle)

                # ok is pressed

                if aDialog.return_result() != OK_PRESSED:
                    if running_flag:
                        self.theSession.run()
                    return True

        self.setStopState()
        self.close()
        self.theSession.QuitGUI()

        return True
Exemplo n.º 4
0
	def openConfirmWindow(self,  aMessage, aTitle, isCancel = 1 ):
		""" pops up a modal dialog window
			with aTitle (str) as its title
			and displaying aMessage as its message
			and with an OK and a Cancel button
			returns:
			True if Ok button is pressed
			False if cancel button is pressed
		"""
		aConfirmWindow = ConfirmWindow(isCancel, aMessage, aTitle )
		return aConfirmWindow.return_result() == OK_PRESSED
Exemplo n.º 5
0
    def openConfirmWindow(self, aMessage, aTitle, isCancel=1):
        """ pops up a modal dialog window
			with aTitle (str) as its title
			and displaying aMessage as its message
			and with an OK and a Cancel button
			returns:
			True if Ok button is pressed
			False if cancel button is pressed
		"""
        aConfirmWindow = ConfirmWindow(isCancel, aMessage, aTitle)
        return aConfirmWindow.return_result() == OK_PRESSED
Exemplo n.º 6
0
    def __loadData(self, *arg):
        """loads model or script file
        arg[0]    ---   ok button of FileSelection
        arg[1]    ---   'Model'/'Script' (str)
        Return None
        """

        # checks the length of argument, but this is verbose
        if len(arg) < 2:
            return None

        aFileType = arg[1]

        aFileName = self.theFileSelection.get_filename()
        if os.path.isfile(aFileName):
            pass
        else:
            aMessage = ' Error ! No such file. \n[%s]' % aFileName
            self.theSession.message(aMessage)
            aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')
            self.theFileSelection.present()
            return None

        self.__deleteFileSelection()
        self.theSession.message('Loading %s file %s\n' %
                                (aFileType, aFileName))

        try:

            if aFileType == 'Model':
                self.theSession.loadModel(aFileName)
            elif aFileType == 'Script':
                self.theSession.loadScript(aFileName)
            elif aFileType == 'SBML':
                self.theSession.importSBML(aFileName)
            self.theSession.updateWindows()
        except:
            # expants message window, when it is folded.
            if self.exists():
                if not (self['message_togglebutton'].get_child()).get_active():
                    (self['message_togglebutton'].get_child()).set_active(True)

            # displays confirm window
            aMessage = 'Can\'t load [%s]\nSee MessageWindow for details.' % aFileName
            aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')

            # displays message on MessageWindow
            aMessage = 'Can\'t load [%s]' % aFileName
            self.theSession.message(aMessage)
            anErrorMessage = '\n'.join(
                traceback.format_exception(sys.exc_type, sys.exc_value,
                                           sys.exc_traceback))
            self.theSession.message(anErrorMessage)
Exemplo n.º 7
0
    def __exportSBML(self, *arg):

        # gets file name
        aFileName = self.theFileSelection.get_filename()

        # when the file already exists
        if os.path.isfile(aFileName):

            # displays confirm window
            aMessage = 'Would you like to replace the existing file? \n[%s]' % aFileName
            aDialog = ConfirmWindow(OKCANCEL_MODE, aMessage,
                                    'Confirm File Overwrite')

            # when canceled, does nothing
            if aDialog.return_result() != OK_PRESSED:
                # does nothing
                return None

        # when ok is pressed, overwrites it.
        # deletes FileSelection
        self.__deleteFileSelection()

        try:

            # displays save message
            self.theSession.message('Export SBML file %s\n' % aFileName)
            # saves Model
            self.theSession.exportSBML(aFileName)

        except:

            # expants message window, when it is folded.
            if not (self['message_togglebutton'].get_child()).get_active():
                (self['message_togglebutton'].get_child()).set_active(True)

            # displays confirm window
            aMessage = 'Can\'t save [%s]\nSee MessageWindow for details.' % aFileName
            aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')

            # displays error message of MessageWindow
            self.theSession.message('Can\'t export [%s]' % aFileName)
            anErrorMessage = '\n'.join(
                traceback.format_exception(sys.exc_type, sys.exc_value,
                                           sys.exc_traceback))
            self.theSession.message(anErrorMessage)

        # updates
        self.update()
        self.theSession.updateFundamentalWindows()
Exemplo n.º 8
0
    def inputValue(self, *arg):
        # gets text from text field.
        aText = self['value_frame'].get_text().split()
        if type(aText) == type([]):
            if len(aText) > 0:
                aText = aText[0]
            else:
                return None
        else:
            return None

        # Only when the length of text > 0,
        # checks type of text and set it.
        if len(aText) > 0:
            # Only when the value is numeric,
            # the value will be set to value_frame.
            try:
                aValue = float(aText)
                self.theSession.setEntityProperty(self.getFullPN(), aValue)
            except:
                ConfirmWindow.ConfirmWindow(0, 'Input numerical value.')
                aValue = self.theSession.getEntityProperty(self.getFullPN())
                self["value_frame"].set_text(str(aValue))
            return None
        else:
            return None
Exemplo n.º 9
0
    def __setValue( self ):
        #take value from list and redraw
        aVarrefList = []
        anIter = self.theListStore.get_iter_first()
        while anIter != None:
            aVarref = ["","",1, 1]
            aVarref[VARREF_NAME] = self.theListStore.get_value( anIter, NAME_COLUMN )
            aVarref[VARREF_FULLID] = self.theListStore.get_value( anIter, FULLID_COLUMN )
            aVarref[VARREF_COEF] = self.theListStore.get_value( anIter, COEF_COLUMN )
            aVarrefList.append( tuple( aVarref ) )
            anIter = self.theListStore.iter_next( anIter )
        aVarrefListTuple = tuple( aVarrefList )

        try:
            self.theSession.createEntityStub( self.theFullIDString ).setProperty( "VariableReferenceList", aVarrefListTuple )
        except:
            # print out traceback
            import sys
            import traceback
            anErrorMessage = '\n'.join( traceback.format_exception( sys.exc_type,sys.exc_value,sys.exc_traceback ) )
            self.theSession.message("-----An error happens.-----")
            self.theSession.message(anErrorMessage)
            self.theSession.message("---------------------------")
    
            # creates and display error message dialog.
            anErrorMessage = "Couldnot change variablereference"
            anErrorTitle = "Error"
            anErrorWindow = ConfirmWindow(OK_MODE,anErrorMessage,anErrorTitle)
            self.update()
Exemplo n.º 10
0
    def __saveModel( self, *arg ) :

        # gets file name
        aFileName = self.theFileSelection.get_filename()

        # when the file already exists
        if os.path.isfile( aFileName ):

            # displays confirm window
            aMessage = 'Would you like to replace the existing file? \n[%s]' %aFileName
            aDialog = ConfirmWindow(OKCANCEL_MODE,aMessage,'Confirm File Overwrite')

            # when canceled, does nothing 
            if aDialog.return_result() != OK_PRESSED:
                # does nothing
                return None

        # when ok is pressed, overwrites it.
        # deletes FileSelection
        self.__deleteFileSelection()

        try:

            # displays save message
            self.theSession.message('Save model file %s\n' % aFileName)                        
            # saves Model
            self.theSession.saveModel( aFileName )

        except:

            # expants message window, when it is folded.
            if not ( self['message_togglebutton'].get_child() ).get_active():
                ( self['message_togglebutton'].get_child() ).set_active( True )


            # displays confirm window
            aMessage = 'Can\'t save [%s]\nSee MessageWindow for details.' %aFileName
            aDialog = ConfirmWindow(OK_MODE,aMessage,'Error!')

            # displays error message of MessageWindow
            self.theSession.message('Can\'t save [%s]' %aFileName)
            anErrorMessage = '\n'.join( traceback.format_exception( sys.exc_type,sys.exc_value,sys.exc_traceback ) )
            self.theSession.message(anErrorMessage)

        # updates
        self.update()
        self.theSession.updateFundamentalWindows()
Exemplo n.º 11
0
    def __setStepSizeOrSec(self, *arg):

        # gets the inputerd characters from the GtkEntry.
        aNewValue = self['sec_step_entry'].get_text().strip()

        try:
            # converts string to float
            aNewValue = float(aNewValue)

        # when string can't be converted to float
        except ValueError:

            # displays a Confirm Window.
            aMessage = "\"%s\" is not numerical value." % aNewValue
            aMessage += "\nInput numerical character"
            aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')

            # sets the previous value
            self['sec_step_entry'].set_text(str(self.theStepSizeOrSec))

        # when string can be converted to float
        else:

            #check for numerical constraints
            aMessage = ""

            if aNewValue <= 0:
                aMessage += "Input positive number.\n"

            # when 'step' is selected.
            if self['step_radiobutton'].get_active():

                # step must be integer
                if int(aNewValue) != aNewValue:
                    aMessage += "Input integer.\n"

                # convets float to int
                aNewValue = int(aNewValue)

            if len(aMessage) > 0:

                #aDialog = ConfirmWindow(OK_MODE,aMessage,'Error!')
                aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')

            else:

                self.theStepSizeOrSec = aNewValue
Exemplo n.º 12
0
 def checkRun( self ):
     if self.theSession.isRunning():
         # displays a Confirm Window.
         aMessage = "Cannot create new logger, because simulation is running.\n"
         aMessage += "Please stop simulation if you want to create a logger" 
         aDialog = ConfirmWindow(OK_MODE,aMessage,'Warning!')
         return True
     return False
Exemplo n.º 13
0
    def openPreferences(self, *arg):
        """display the preference window
        arg[0]   ---  self['preferences_menu']
        Return None
        """

        # Preference Window is not implemented yet.
        # So, displays Warning Dialog
        aMessage = ' Sorry ! Not implemented... [%s]\n' % '03/April/2003'
        aDialog = ConfirmWindow(OK_MODE, aMessage, 'Sorry!')
Exemplo n.º 14
0
    def __init__(self, aDirName, aData, aPluginManager, aRoot=None):
        # call constructor of superclass
        OsogoPluginWindow.__init__( self, aDirName, aData, \
                                    aPluginManager, aRoot )

        aFullPNString = createFullPNString(self.getFullPN())
        aValue = self.theSession.getEntityProperty(aFullPNString)
        if not operator.isNumberType(aValue):
            aMessage = "Error: (%s) is not numerical data" % aFullPNString
            self.thePluginManager.printMessage(aMessage)
            aDialog = ConfirmWindow.ConfirmWindow(0, aMessage, 'Error!')
            raise TypeError(aMessage)
Exemplo n.º 15
0
 def __cellEdited( self, *args ):
     aNewValue = args[2]
     aPath = args[1]
     anIter = self.theListStore.get_iter_from_string( aPath )
     column = args[3]
     if column == COEF_COLUMN:
         #check whether it is integer
         if not operator.isNumberType( aNewValue):
             anErrorWindow = ConfirmWindow(OK_MODE,"Coefficient should be numeric.","Error")
             return
     self.theListStore.set_value( anIter, column, aNewValue )
     self.__setValue()
Exemplo n.º 16
0
    def changeTitle(self, *arg):

        aNewTitle = self["title_entry"].get_text()
        aNewTitle = aNewTitle.strip()

        if len(aNewTitle) == 0:
            anErrorMessage = '\nError text field is blank.!\n'
            #self.theSession.message( anErrorMessage )
            aWarningWindow = ConfirmWindow(OK_MODE, anErrorMessage, "!")
            return None

        aTitle = self.thePluginMap[str(self.theSelectedPluginFrame)].getTitle()

        self.thePluginManager.editInstanceTitle(aTitle, aNewTitle)
        self.theSession.updateWindows()
Exemplo n.º 17
0
    def __updateProperty(self, renderer, path, aValue, *kwarg):
        """updates property
        Return None
        """

        # --------------------------------------------------
        # creates selected StepperSub
        # --------------------------------------------------
        iter = self['stepper_id_list'].get_selection().get_selected()[1]
        aStepperID = self['stepper_id_list'].get_model().get_value(iter, 0)
        aStepperStub = self.theSession.createStepperStub(aStepperID)

        # gets selected property row
        aPropertyModel = self['property_list'].get_model()
        iter = aPropertyModel.get_iter(path)
        # -----------------------------------------------------------
        # get a property name from property list
        # -----------------------------------------------------------
        aPropertyName = aPropertyModel.get_value(iter, PROPERTY_INDEX)

        # converts value type
        anOldValue = aStepperStub.getProperty(aPropertyName)

        # ---------------------------------------------------
        # checks float and int type of inputted value
        # does not check str. ( not needed )
        # ---------------------------------------------------
        # float
        if type(anOldValue) == float:
            try:
                aValue = float(aValue)
            except:
                # displays confirm window
                anErrorMessage = "Input float value."
                aDialog = ConfirmWindow(
                    OK_MODE, "Can't set property!\n" + anErrorMessage,
                    'Error!')
                return None

        # int
        if type(anOldValue) == int:
            try:
                aValue = int(aValue)
            except:
                # displays confirm window
                anErrorMessage = "Input int value."
                aDialog = ConfirmWindow(
                    OK_MODE, "Can't set property!\n" + anErrorMessage,
                    'Error!')
                return None

        # sets new value
        try:
            aStepperStub.setProperty(aPropertyName, aValue)
            aPropertyModel.set_value(iter, VALUE_INDEX, aValue)
        except:

            # displays error message to MessageWindow
            anErrorMessage = '\n'.join(
                traceback.format_exception(sys.exc_type, sys.exc_value,
                                           sys.exc_traceback))
            self.theSession.message(anErrorMessage)

            # displays confirm window
            anErrorMessage = "See MessageWindow for details."
            aDialog = ConfirmWindow(OK_MODE, aMessage,
                                    "Can't set property!\n" + anErrorMessage)
            return False

        # when to set property is succeeded,
        else:
            # refreshs self['property_list']
            self.update()
            return True