def query(qname, args=None, rmode="value", echo=False, msg_lvl=2, **kwargs): """ Executes a query and returns result based on 'rmode'. rmode={'value','string',object'} Raises an exception if an error occurs. """ if echo: print("[Query: %s(%s)]" % (qname, str(args))) prev_lvl = visit.SuppressMessages(msg_lvl) if args is None: qres = visit.Query(qname, **kwargs) else: # call w/ args + kwargs cargs = [qname] cargs.extend(args) qres = visit.Query(*cargs, **kwargs) if qres == 0: visit.SuppressMessages(prev_lvl) raise VisItException("Execution of query: '%s' failed." % qname) if rmode == "value": res = visit.GetQueryOutputValue() elif rmode == "string" or rmode == "text" or rmode == "txt": res = visit.GetQueryOutputString() elif rmode == "object": res = visit.GetQueryOutputObject() else: visit.SuppressMessages(prev_lvl) raise VisItException("Unsupported query result mode: %s" % rmode) visit.SuppressMessages(prev_lvl) return res
def python_query(source=None,file=None,vars=None,args=[],rmode="value",echo = False, msg_lvl = 2): """ Executes a Python Query and returns result based on 'rmode'. rmode={'value','string',object'} Rasies an exception if an error occurs. """ if echo: print "[PythonQuery]" prev_lvl = visit.SuppressMessages(msg_lvl) kwargs = {} if not source is None: kwargs["source"] = source if not file is None: kwargs["file"] = file if not vars is None: kwargs["vars"] = vars if len(args) > 0: kwargs["args"] = args qres = visit.PythonQuery(**kwargs) if qres == 0: visit.SuppressMessages(prev_lvl) raise VisItException("Execution of PythonQuery failed.") if rmode == "value": res = visit.GetQueryOutputValue() elif rmode == "string": res = visit.GetQueryOutputString() elif rmode == "object": res = visit.GetQueryOutputObject() else: visit.SuppressMessages(prev_lvl) raise VisItException("Unsupported Python Query result mode: %s" % rmode) visit.SuppressMessages(prev_lvl) return res
def remove_window(cls, win): win.clear_plots() # make sure we don't delete the last window if len(cls.__windows.keys()) > 1: prev_lvl = visit.SuppressMessages(2) visit.DeleteWindow() visit.SuppressMessages(prev_lvl) # remove key from active windows dict del cls.__windows[win.window_id]
def export(self, format, obase, vnames=None, seq_id=None): ts = self.ts if not seq_id is None: ts = seq_id prev_lvl = visit.SuppressMessages(2) if vnames is None: vnames = ("default", ) obase = os.path.abspath(obase) odir, ofile = os.path.split(obase) if not ts is None: ofile = "%s%04d" % (ofile, ts) stargs = (format, str(vnames), odir, ofile) print "[exporting format: %s vars: %s path: %s/%s ]" % stargs eatts = visit.ExportDBAttributes() eatts.db_type = format eatts.filename = ofile eatts.dirname = odir eatts.variables = tuple(vnames) visit.ExportDatabase(eatts) visit.SuppressMessages(prev_lvl)
def __save_window(self, obase, res, ores, screen_cap, ts): prev_lvl = visit.SuppressMessages(2) res = [int(v) for v in res] if ores is None: ores = res obase = os.path.abspath(obase) odir, ofile = os.path.split(obase) if ts is None: print "[rendering %s/%s.png]" % (odir, ofile) tmp_ofile = "%s___.tmp" % ofile else: print "[rendering %s/%s%04d.png]" % (odir, ofile, ts) tmp_ofile = "%s.%04d___.tmp" % (ofile, ts) sa = visit.SaveWindowAttributes() sa.outputToCurrentDirectory = 0 sa.outputDirectory = odir sa.fileName = tmp_ofile sa.format = sa.PNG sa.width, sa.height = res sa.screenCapture = 0 sa.saveTiled = 0 sa.resConstraint = sa.NoConstraint visit.SetSaveWindowAttributes(sa) a = visit.GetAnnotationAttributes() a.userInfoFlag = 0 visit.SetAnnotationAttributes(a) fname = visit.SaveWindow() if fname == "/dev/null/SaveWindow_Error.txt" or not os.path.isfile( fname): raise VisItException("Error saving window.") des = fname[:fname.find("___.tmp")] des += ".png" shutil.move(fname, des) if ores[0] != res[0] or ores[1] != res[1]: stargs = (res[0], res[1], ores[0], ores[1]) print "[resizing output (from %dx%d to %dx%d)]" % stargs sexe("convert -resize %dx%d %s %s" % (ores[0], ores[1], des, des)) visit.SuppressMessages(prev_lvl) return des