def __init__(self, typedesc, notesdb): self.type = typedesc self.notesdb = notesdb self.stream_properties = {} nn = notesdb.getTypeRefinedNotesLang(self.type, ascpy.SymChar("inline")) for n in nn: self.stream_properties[n.getId()] = []
def listnotes(self): """ make a list of NOTES for the present model """ self = ascpy.Registry().getInstance('context') db = browser.library.getAnnotationDatabase() notes = db.getNotes(self.getType(),ascpy.SymChar("solver")) for i in range(1,len(notes)): mm = notes[i].getMethod() ll = notes[i].getLanguage() ii = notes[i].getId() tt = notes[i].getText() s = "type = %s, method = %s, lang = %s, id = %s, text = %s" % (notes[i].getType(), mm, ll, ii, tt) print "NOTES:",s browser.reporter.reportNote(s)
def reattach_ascend(self,library, notesdb): self.type = library.findType(self.type) nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("inline")) self.inputs = [] self.outputs = [] self.params = [] for n in nn: t = n.getText() if t[0:min(len(t),3)]=="in:": self.inputs += [[n.getId(),self.type.findMember(n.getId()),str(t)]] elif t[0:min(len(t),4)]=="out:": self.outputs += [[n.getId(),self.type.findMember(n.getId()),str(t)]] elif t[0:min(len(t),6)]=="param:": self.params += [[n.getId(),self.type.findMember(n.getId()),str(t)]] print "Reattached type '%s', with %d inputs, %d outputs" % (self.type.getName(), len(self.inputs), len(self.outputs))
def on_treeview_event(self, widget, event): _path = None _contextmenu = False if event.type == gtk.gdk.KEY_RELEASE: _keyval = gtk.gdk.keyval_name(event.keyval) _path, _col = self.modelview.get_cursor() if _keyval == 'Menu': _contextmenu = True _button = 3 elif _keyval == 'F2': print "F2 pressed" self.modelview.set_cursor(_path, self.tvcolumns[2], 1) return elif event.type == gtk.gdk.BUTTON_PRESS: _x = int(event.x) _y = int(event.y) _button = event.button _pthinfo = self.modelview.get_path_at_pos(_x, _y) if _pthinfo is not None: _path, _col, _cellx, _celly = _pthinfo if event.button == 3: _contextmenu = True if _path: _name, _instance = self.otank[_path] # set the statusbar nn = self.notes.getNotes(self.sim.getModel().getType(), ascpy.SymChar("inline"), _name) for n in nn: print "%s: (%s) %s" % (n.getId(), str( n.getLanguage()), n.getText()) self.builder.get_object("free_variable").set_sensitive(False) self.builder.get_object("fix_variable").set_sensitive(False) self.builder.get_object("propsmenuitem").set_sensitive(False) if _instance.isReal(): self.builder.get_object("units").set_sensitive(True) if _instance.getType().isRefinedSolverVar(): self.builder.get_object("propsmenuitem").set_sensitive(True) if _instance.isFixed(): self.builder.get_object("free_variable").set_sensitive( True) else: self.builder.get_object("fix_variable").set_sensitive(True) elif _instance.isRelation(): self.builder.get_object("propsmenuitem").set_sensitive(True) if not _contextmenu: #print "NOT DOING ANYTHING ABOUT %s" % gtk.gdk.keyval_name(event.keyval) return _canpop = False # self.browser.reporter.reportError("Right click on %s" % self.otank[_path][0]) self.unitsmenuitem.set_sensitive(False) self.fixmenuitem.set_sensitive(False) self.freemenuitem.set_sensitive(False) self.observemenuitem.set_sensitive(False) self.studymenuitem.set_sensitive(False) self.propsmenuitem.set_sensitive(False) if _instance.isReal(): print "CAN POP: real atom" _canpop = True self.unitsmenuitem.set_sensitive(True) if _instance.getType().isRefinedSolverVar(): _canpop = True self.propsmenuitem.set_sensitive(True) self.observemenuitem.set_sensitive(True) if _instance.isFixed(): self.freemenuitem.set_sensitive(True) if len(self.browser.observers) > 0: self.studymenuitem.set_sensitive(True) else: self.fixmenuitem.set_sensitive(True) elif _instance.isRelation(): _canpop = True self.propsmenuitem.set_sensitive(True) elif _instance.isModel(): # MODEL instances have a special context menu: _menu = self.get_model_context_menu(_instance) self.modelview.grab_focus() self.modelview.set_cursor(_path, _col, 0) print "RUNNING POPUP MENU" _menu.popup(None, None, None, _button, event.time) return if not _canpop: return self.modelview.grab_focus() self.modelview.set_cursor(_path, _col, 0) self.treecontext.popup(None, None, None, _button, event.time) return 1
elif _instance.isInt(): _val = int(newtext) if _val == _instance.getValue(): self.browser.reporter.reportNote( "Integer atom '%s' was not altered" % _instance.getName()) return _instance.setIntValue(_val) elif _instance.isSymbol(): _val = str(newtext) if _val == _instance.getValue(): self.browser.reporter.reportNote( "Symbol atom '%s' was not altered" % _instance.getName()) return _instance.setSymbolValue(ascpy.SymChar(_val)) else: self.browser.reporter.reportError( "Attempt to set a non-real, non-boolean, non-integer value!" ) return # now that the variable is set, update the GUI and re-solve if desired _iter = self.modelstore.get_iter(path) self.modelstore.set_value(_iter, 2, _instance.getValue()) if _instance.getType().isRefinedSolverVar(): self.modelstore.set_value( _iter, 3, BROWSER_FIXED_COLOR) # set the row green as fixed
def parse_streams(self, t): x = self.annodb.getNotes(t, ascpy.SymChar("stream"), ascpy.SymChar("SELF")) if x: self.streamtypes.add(t)
def parse_types(self, t): x = self.annodb.getNotes(t, ascpy.SymChar("block"), ascpy.SymChar("SELF")) if x: self.blocktypes.add(t)
def solvernotes(self): """ use the NOTES DB to set parameters applicable to the current active solver """ print "SETUP_SOLVER..." sim = ascpy.Registry().getSimulation('sim') browser = extpy.getbrowser() if browser: reporter = browser.reporter else: print "Using console solver reporter" reporter = ascpy.getReporter() if browser: print "Using browser.solver" solver = browser.solver else: print "Using hardwired default solver, QRSlv" solver = ascpy.Solver("QRSlv") db = ascpy.Library().getAnnotationDatabase() print "GOT SIM..." if not sim: reporter.reportError("No simulation present yet") return if not solver: reporter.reportError("No solver yet") return # the simulation needs to be built at this point, else solver could not # be selected, and hence solver params could not be assigned. sim.build() # use the solver selected in the browser sim.setSolver(solver) solvername = solver.getName() reporter.reportNote("Active solver is '%s'" % solvername) notes = db.getNotes(self.getType(),ascpy.SymChar(solvername)) print "GETTING SOLVER PARAMS..." params = sim.getParameters() print "DONE SOLVER PARAMS" print params paramnames = [p.getName() for p in params] print "DONE PARAMS" for i in range(0,len(notes)): note = notes[i] if note.getId()==None: browser.reporter.reportNote("Empty note ID...") continue n = note.getId() param = None for p in params: if p.getName()==n: param = p if param: if param.isInt(): v = int( note.getText() ) param.setIntValue(v) elif param.isReal(): v = float( note.getText() ) param.setRealValue(v) elif param.isStr(): v = note.getText() param.setStrValue(v) elif param.isBool(): v = bool( note.getText() ) param.setBoolValue(v) else: raise Exception("unknown parameter type") reporter.reportNote("Set %s = %s" % (param.getName(),v)) else: reporter.reportWarning("Ignoring unrecognised parameter '%s' for solver '%s' (from solver notes)\n%s:%d" % (n,solvername,note.getFilename(),note.getLineNumber()))
def __init__(self, typedesc, notesdb): self.type = typedesc self.notesdb = notesdb self.arrays = [] self.gr = [] # this data structure is for Graphical Representation for custom icons self.port_in = {} # this list is for location of input ports in custom icons self.port_out = {} # this list is for location of output ports in custom icons self.arrays = [] # FIXME BlockType should know what .a4c file to load in order to access # its type definition, for use in unpickling. self.sourcefile = None nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("inline")) self.inputs = [] self.outputs = [] self.params = [] for n in nn: t = n.getText() if t[0:min(len(t),3)]=="in:": self.inputs += [[n.getId(),self.type.findMember(n.getId()),str(t)]] elif t[0:min(len(t),4)]=="out:": self.outputs += [[n.getId(),self.type.findMember(n.getId()),str(t)]] elif t[0:min(len(t),6)]=="param:": self.params += [[n.getId(),self.type.findMember(n.getId()),str(t)]] self.iconfile = None nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("icon")) if nn: n = nn[0].getText() if os.path.exists(n): self.iconfile = n self.name = None nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("block")) if nn: self.name = nn[0].getText() #fetching the graphic string from model file, string manipulating it and storing it in #list of list nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("graphic")) if nn: t = nn[0].getText().split("\n") for n in t: temp = n.split("-") ll = [] for k in temp: tt = k.split(",") pp = [] for q in tt: q = q.strip("\t") pp.append(q) ll.append(pp) self.gr.append(ll) self.iconfile = self.create_icon(48,48) nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("port_in")) if nn: n = nn[0].getText().split(" ") for m in n: tt = m.split("-") for k in tt: tpp = k.split(":") loc = tpp[1].split(",") xy = [] xy.append(loc[0]) xy.append(loc[1]) self.port_in[str(tpp[0])] = xy nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("port_out")) if nn: n = nn[0].getText().split(" ") for m in n: tt = m.split("-") for k in tt: tpp = k.split(":") loc = tpp[1].split(",") xy = [] xy.append(loc[0]) xy.append(loc[1]) self.port_out[str(tpp[0])] = xy nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("array")) for n in nn: if n: t = n.getText() self.arrays.append([n.getText(),self.type.findMember(n.getText())])