def changeToRunMode( self ): self.preRunSuccessful= False self.preLoadSuccessful = False # DO VALIDATION first!!! # destroy BoardWindow, save tracerlist if self.theModelEditor.theResultsWindow != None: self.theModelEditor.theResultsWindow.closeBoardWindow() # destroy previous SessionMonitor: if self.theSession != None: # deregister previous callbacks self.theSession = None #save model to temp file if not self.theModelEditor.autoSave(): return fileName = self.theModelEditor.autoSaveName self.theModelEditor.theMainWindow.displayHourglass() #instantiate GtkSessionMonitor self.theSession = GtkSessionMonitor() self.theSession.setMessageMethod( self.message ) self.theSession.registerUpdateCallback( self.updateWindows ) #load model into GtkSessionMonitor self.__preRun() if not self.preLoadSuccessful: dialog = ConfirmWindow(1,"This operation needs loading model into Simulator, but your model is not stable!\nTest load hanged or crashed! Are you sure you want to load model into Simulator?\nIf you choose yes, ModelEditor can hang or crash.\n(Changes are saved)", "CRITICAL" ) if dialog.return_result() != 0: self.theModelEditor.theMainWindow.resetCursor() return False try: self.theSession.loadModel( fileName ) #self.theSession.theSimulator.initialize() except: self.message(' Error while trying to parse model into simulator \n') anErrorMessage = string.join( traceback.format_exception(sys.exc_type,sys.exc_value,sys.exc_traceback), '\n' ) self.message(anErrorMessage) self.theModelEditor.theMainWindow.resetCursor() dialog = ConfirmWindow(0,"Sorry, error in parsing model, see message window for details." ) return False self.theMode = ME_RUN_MODE if self.theModelEditor.theResultsWindow != None: self.theModelEditor.theResultsWindow.openBoardWindow(self.theSession) self.theModelEditor.theMainWindow.resetCursor() self.theModelEditor.theMainWindow.updateRunMode() return True
def changeToDesignMode( self, forced = False ): # check whether simulation is running if self.isRunning(): if not forced: dialog = ConfirmWindow(1, "To perform this operation, simulation must be stopped.\n Can simulation be stopped?") if dialog.return_result() == 0: self.theSession.stop() else: return False else: self.theSession.stop() self.theMode = ME_DESIGN_MODE self.theModelEditor.theMainWindow.updateRunMode() return True
def __canRun( self ): if not self.preRunSuccessful : dialog = ConfirmWindow(1,"Your model is not stable for runnig! Test run hanged or crashed!\nAre you sure you want to run in ModelEditor?\nIf you choose yes, ModelEditor can hang or crash.\n(Changes are saved)", "CRITICAL" ) if dialog.return_result() != 0: return False return True