def changeToRunMode(self): self.preRunSuccessful = 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.GtkSessionMonitor() self.theSession.setMessageMethod(self.message) self.theSession.registerUpdateCallback(self.updateWindows) #load model into GtkSessionMonitor try: self.__preRun() except: 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 = '\n'.join( traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)) 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 __step_activated(self, *args): text = self['entry4'].get_text() if text == '': dialog = ConfirmWindow(0, "Please enter a value as stepsize.") return try: aNum = float(text) except: dialog = ConfirmWindow( 0, "Please enter a numeric value as step size") return if aNum <= 0: dialog = ConfirmWindow( 0, "Please enter a positive value as step size") return if self['radiobuttonSec'].get_active() == True: if self.theRuntimeObject.checkState(ME_RUN_MODE) == True: self.theRuntimeObject.run(aNum) elif self['radiobuttonStep'].get_active() == True: if self.theRuntimeObject.checkState(ME_RUN_MODE) == True: self.theRuntimeObject.step(aNum)
def __canRun(self): if not self.preRunSuccessful: dialog = ConfirmWindow( 1, "Your model is not stable for running! 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
def generateAutoLayout( self, primarySelection, layoutName ): # get secondary selection self.__getSecondarySelection( primarySelection ) self.__getVariableReferenceList( ) # parse into dot text = self.__parseEntities( ME_ROOTID) # write to file outputFileName =os.getcwd() + os.sep + "dotout"+str(os.getpid() ) inputFileName = os.getcwd() + os.sep + "dotin" + str( os.getpid() ) fd = open(outputFileName,'w') fd.write(text) fd.close() # process file os.system('neato -Tdot "' + outputFileName + '" -o"' + inputFileName + '"') #load input file try: fd = open( inputFileName, 'r') except: ConfirmWindow( 0, "Auto visualization function needs Graphviz installed.\n Please download and install this free software from http://www.graphviz.org/Download.php.\n Both windows and linux binaries are available.", "") return intext = " ".join(fd.readlines() ) fd.close() intext = re.sub(r'[\\\n\t]','',intext) intext = re.sub('{','{\n',intext) intext = re.sub('}','}\n',intext) intext = re.sub(';',';\n',intext) self.theText = intext.split('\n') del intext keyWord, parentID = self.theText[0].strip().split(' ')[0:2] if keyWord != "digraph" and parentID!= self.translationList[ME_ROOTID]: ConfirmWindow(0, "There was an error processing dot file.\n No layout is created") return self.__parseGraph( parentID, 1 ) # create systems self.__createBB ( ME_ROOTID ) self.__createSystems( ME_ROOTID ) self.__createConnections() os.unlink ( inputFileName ) os.unlink( outputFileName ) # create varrefs #layoutBuffer = self.theLayoutBufferFactory.createLayoutBuffer(self.theLayoutName) #self.theLayoutManager.deleteLayout(self.theLayoutName) #aCommand = PasteLayout( self.theLayoutManager, layoutBuffer , self.theLayoutName, True ) #self.theModelEditor.doCommandList( [ aCommand ] ) self.theLayoutManager.showLayout( self.theLayoutName )
def changeToRunMode( self ): self.preRunSuccessful= 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.GtkSessionMonitor() self.theSession.setMessageMethod( self.message ) self.theSession.registerUpdateCallback( self.updateWindows ) #load model into GtkSessionMonitor try: self.__preRun() except: 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 = '\n'.join( traceback.format_exception( sys.exc_type,sys.exc_value,sys.exc_traceback ) ) 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 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 running! 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