def preprocess(path, fn, obj=None): var_list = [] sourceFile = open(path, "r") #where to read from contents = sourceFile.readlines() #read in lines from file parsedFile = open("./plot/" + fn, "w") #open file for processed version if re.match('^VRLOG', contents[0]): plot.msgOut("Found villaremote type trend file", obj) if not os.path.exists("./plot/plotsettings_" + fn): plotSettings = open("./plot/plotsettings_" + fn, "w") plotSettings.write("set xdata time\n") plotSettings.write("set timefmt \"%Y-%m-%d-%H:%M:%S\"\n") plotSettings.close() vr_parse(contents, parsedFile, var_list) else: plot.msgOut( "Could not recognize file format. Currently supported types are:\n-VR log files", obj) sourceFile.close() parsedFile.close() return var_list
def onPlot(self): # in listmode, we need to do work to set selection # button mode selection is handled directly by gui if self.listmode: tup_sel = self.Lb.curselection() # print tup_sel self.selected = [IntVar(value=0)] * len(self.var_list) self.scaling = [StringVar(value=0)] * len(self.var_list) #activate selection and scale in plot list for idx in tup_sel: self.selected[int(idx)] = IntVar(value=1) self.scaling[int(idx)] = StringVar(value="1.0") var_arg = [] var_scale = [] for idx, var in enumerate(self.selected): if self.selected[idx].get(): var_arg.append(idx) var_scale.append(self.scaling[idx].get()) if len(var_arg) < 1: plot.msgOut("No signal(s) selected. Plotting all variables found.", self) var_arg = range(len(self.var_list)) for idx, var in enumerate(self.var_list): #get all given scalings var_scale.append(self.scaling[idx].get()) plot.threaded_plot(self.var_list, self.fn, var_arg, var_scale, self)
def onPlot(self) : # in listmode, we need to do work to set selection # button mode selection is handled directly by gui if self.listmode : tup_sel = self.Lb.curselection() # print tup_sel self.selected = [IntVar(value=0)]*len(self.var_list) self.scaling = [StringVar(value=0)]*len(self.var_list) #activate selection and scale in plot list for idx in tup_sel : self.selected[int(idx)] = IntVar(value=1) self.scaling[int(idx)] = StringVar(value="1.0") var_arg = [] var_scale = [] for idx,var in enumerate(self.selected) : if self.selected[idx].get() : var_arg.append(idx) var_scale.append(self.scaling[idx].get()) if len(var_arg) < 1 : plot.msgOut("No signal(s) selected. Plotting all variables found.",self) var_arg = range(len(self.var_list)) for idx,var in enumerate(self.var_list) : #get all given scalings var_scale.append(self.scaling[idx].get()) plot.threaded_plot(self.var_list,self.fn,var_arg, var_scale, self)
def cleanUp(): try: if os.path.exists("./plot"): plot.msgOut("removing temp ./plot directory before quitting.") shutil.rmtree("./plot") except: plot.msgOut("Failed removing ./plot")
def aboutInfo(self): try: aboutText = open("./ABOUT", "r") contents = aboutText.read() plot.msgOut(contents, self) except: plot.msgOut("Error opening ABOUT file", self)
def aboutInfo(self) : try : aboutText = open("./ABOUT","r") contents = aboutText.read() plot.msgOut(contents,self) except : plot.msgOut("Error opening ABOUT file",self)
def cleanUp() : try : if os.path.exists("./plot") : plot.msgOut("removing temp ./plot directory before quitting.") shutil.rmtree("./plot"); except : plot.msgOut("Failed removing ./plot")
def get_varlist(path, obj=None) : try: os.stat("plot") except: os.mkdir("plot") fn = (path.split("/"))[-1] #get filename try: var_list = preprocess(path, fn, obj) if len(var_list) < 1 : plot.msgOut("Warning: No signals found in selected file.", obj) else : plot.msgOut("Stripped nonnumerical values from %s, written to ./plot/" %fn, obj) except Exception as e: plot.msgOut(str(e),obj) plot.msgOut("Error in file or file not found.", obj) plot.msgOut(path, obj) return -1 return var_list
def initialize(self,fn): self.cb = [] #checkbuttons self.selected=[] #button on/off status self.cb_scaling=[] #scaling of signals self.b = Button() self.Lb = Listbox() self.scrollbar = Scrollbar() self.listmode = False #button style or list mode view self.setupMenu() self.txt = Text(self,borderwidth=1, height=6)#, state=DISABLED) self.txt.pack(fill="x", side="top", expand=0) self.frame = Frame(self, relief=RAISED, borderwidth=1) self.frame.pack(fill=BOTH, expand=1) self.pack(fill=BOTH, expand=1) plot.msgOut("Open file to begin plotting.",self) self.idir = 'C:' #default folder for opening file if fn != '' : #open directly if file name given on cmdline self.onOpen(fn)
def initialize(self, fn): self.cb = [] #checkbuttons self.selected = [] #button on/off status self.cb_scaling = [] #scaling of signals self.b = Button() self.Lb = Listbox() self.scrollbar = Scrollbar() self.listmode = False #button style or list mode view self.setupMenu() self.txt = Text(self, borderwidth=1, height=6) #, state=DISABLED) self.txt.pack(fill="x", side="top", expand=0) self.frame = Frame(self, relief=RAISED, borderwidth=1) self.frame.pack(fill=BOTH, expand=1) self.pack(fill=BOTH, expand=1) plot.msgOut("Open file to begin plotting.", self) self.idir = 'C:' #default folder for opening file if fn != '': #open directly if file name given on cmdline self.onOpen(fn)
def gui_main() : atexit.register(plot.cleanUp) root = Tk() #create top level Tk widget ww = 720 #px wh = 500 #px w = root.winfo_screenwidth() #screen h = root.winfo_screenheight() geo = str(ww)+"x"+str(wh)+"+"+str(w/2-ww/2)+"+"+str(h/2-wh/2) root.geometry(geo) #enough to fit 8 signals root.resizable(width=FALSE, height=TRUE) #disable resizing the window path = '' try: path = sys.argv[1] except: plot.msgOut("No input file given.") app = plotapp(root,path) #create file dialog root.title('DPlot file plotter') # img = PhotoImage(file='plot_icon.gif') # root.tk.call('wm', 'iconphoto', root._w, img) root.mainloop()
def gui_main(): atexit.register(plot.cleanUp) root = Tk() #create top level Tk widget ww = 720 #px wh = 500 #px w = root.winfo_screenwidth() #screen h = root.winfo_screenheight() geo = str(ww) + "x" + str(wh) + "+" + str(w / 2 - ww / 2) + "+" + str(h / 2 - wh / 2) root.geometry(geo) #enough to fit 8 signals root.resizable(width=FALSE, height=TRUE) #disable resizing the window path = '' try: path = sys.argv[1] except: plot.msgOut("No input file given.") app = plotapp(root, path) #create file dialog root.title('DPlot file plotter') # img = PhotoImage(file='plot_icon.gif') # root.tk.call('wm', 'iconphoto', root._w, img) root.mainloop()
def get_varlist(path, obj=None): try: os.stat("plot") except: os.mkdir("plot") fn = (path.split("/"))[-1] #get filename try: var_list = preprocess(path, fn, obj) if len(var_list) < 1: plot.msgOut("Warning: No signals found in selected file.", obj) else: plot.msgOut( "Stripped nonnumerical values from %s, written to ./plot/" % fn, obj) except Exception as e: plot.msgOut(str(e), obj) plot.msgOut("Error in file or file not found.", obj) plot.msgOut(path, obj) return -1 return var_list
def preprocess(path,fn,obj=None): var_list=[] sourceFile = open(path, "r") #where to read from contents = sourceFile.readlines() #read in lines from file parsedFile = open("./plot/"+fn,"w") #open file for processed version if re.match('^VRLOG',contents[0]) : plot.msgOut("Found villaremote type trend file", obj) if not os.path.exists("./plot/plotsettings_"+fn) : plotSettings = open("./plot/plotsettings_"+fn, "w") plotSettings.write("set xdata time\n") plotSettings.write("set timefmt \"%Y-%m-%d-%H:%M:%S\"\n") plotSettings.close() vr_parse(contents, parsedFile, var_list) else : plot.msgOut("Could not recognize file format. Currently supported types are:\n-VR log files",obj) sourceFile.close() parsedFile.close() return var_list
def cmd_main_plot(): var_arg = [] try: path = sys.argv[1] except: plot.msgOut("No input file given.") printHelp() return -1 get_varlist(path) fn = (path.split("/"))[-1] #get filename try: var_list = preprocess(path, fn) plot.msgOut( "Stripped nonnumerical values from %s, written to ./plot/" % fn) except: plot.msgOut("Error in file or file not found.") plot.msgOut(path) return -1 try: #process input arguments for how to plot ''' input args accepted in form x-y or x,y,z ... ''' args = sys.argv[2].split("-") # x-y type argument args2 = sys.argv[2].split(",") # a,b,c .. type argument if len(args) > 1: var_arg = range(int(args[0]), int(args[1]) + 1) #+1 to get upper bound correctly elif len(args2) > 1: #add all given arguments for a in range(len(args2)): var_arg.append(int(args2[a])) else: #only one argument to plot var_arg = args[0] except: plot.msgOut( "No vars selected or input error. Plotting all variables found.") var_arg = range(len(var_list)) var_scale = [1.0] * len(var_list) #default scale list needed try: draw_plot(var_list, fn, var_arg, var_scale) plot.msgOut("Showing requested plot.") except: plot.msgOut("Error in using gnuplot or bad plot selection.") printHelp() return -1 cleanUp()
def printHelp() : plot.msgOut("Usage: plot.py [selection] filename\n selection takes form x-y or x,y,z...")
def cmd_main_plot() : var_arg =[] try: path = sys.argv[1] except: plot.msgOut("No input file given.") printHelp() return -1 get_varlist(path) fn = (path.split("/"))[-1] #get filename try: var_list = preprocess(path, fn) plot.msgOut("Stripped nonnumerical values from %s, written to ./plot/" %fn) except: plot.msgOut("Error in file or file not found.") plot.msgOut(path) return -1 try : #process input arguments for how to plot ''' input args accepted in form x-y or x,y,z ... ''' args = sys.argv[2].split("-") # x-y type argument args2 = sys.argv[2].split(",") # a,b,c .. type argument if len(args) > 1 : var_arg = range(int(args[0]),int(args[1])+1) #+1 to get upper bound correctly elif len(args2) > 1 : #add all given arguments for a in range(len(args2)) : var_arg.append(int(args2[a])) else : #only one argument to plot var_arg = args[0] except : plot.msgOut("No vars selected or input error. Plotting all variables found.") var_arg = range(len(var_list)) var_scale = [1.0]*len(var_list) #default scale list needed try : draw_plot(var_list,fn,var_arg,var_scale) plot.msgOut("Showing requested plot.") except : plot.msgOut("Error in using gnuplot or bad plot selection.") printHelp() return -1 cleanUp()
def print_vars(var_list) : plot.msgOut( "found " +str(len(var_list)) + " variables") for idx, v in enumerate(var_list) : s = str(idx)+": "+str(v) plot.msgOut(s)
def print_vars(var_list): plot.msgOut("found " + str(len(var_list)) + " variables") for idx, v in enumerate(var_list): s = str(idx) + ": " + str(v) plot.msgOut(s)
def printHelp(): plot.msgOut( "Usage: plot.py [selection] filename\n selection takes form x-y or x,y,z..." )
def draw_plot(var_list, fn, var_arg, var_scale, obj=None) : try: gpl = subprocess.Popen("gnuplot",bufsize=1,stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) except OSError : msgOut("Error starting gnuplot, do you have it installed?\n\ Also, check that it is in your PATH.",obj) return -1 #cannot go on #specific plotsettings for file type if os.path.exists("./plot/plotsettings_"+fn) : plotSet = open("./plot/plotsettings_"+fn, "r") setting = plotSet.readlines() for l in setting : gpl.stdin.write(l) plotSet.close() if os.path.exists(plot_recipe) : plot.msgOut("Found recipe "+ str(plot_recipe) +" for setting up plot.", obj) f_recipe = open(plot_recipe, "r") recipe = f_recipe.readlines() for ingredient in recipe : gpl.stdin.write(ingredient) f_recipe.close() else : plot.msgOut("No plot recipe found, doing clean plot.", obj) if "darwin" in sys.platform : #use qt on os x for correct persist behaviour title = "set terminal qt title \""+fn+"\" \n" else : title = "set terminal wxt persist title \""+fn+"\" \n" gpl.stdin.write(title) if obj is not None : style = obj.getLineStyle() else : style = "lines" plot.msgOut("plotting selection: " + str(var_arg), obj) #generate a plot cmd that gnuplot understands plot_cmd = "plot " for idx, var in enumerate(var_arg) : plot_cmd += "\'./plot/"+fn+"\'"+" using 1:($"+str(int(var)+2)+"*"+str(var_scale[idx])+") title \'"+\ var_list[int(var)]+"\' with "+style+", " plot_cmd = plot_cmd[:-2] ##ix version gnuplot needs this, removing last "," plot_cmd +=" \n" #Note: add a newline like this to actually generate plot if "win" in sys.platform : plot_cmd +=" pause mouse close \n" #IMPORTANT line for Windows. On Linux, leave out #pipe to gnuplot gpl.stdin.write(plot_cmd) gpl.stdin.flush() gpl.stdin.close() while True: line = gpl.stderr.readline() #thread blocks on stderr if not line: break plot.msgOut(line, obj, False) retcode = gpl.wait() #wait on child msgOut("Plot window closed. " + str(retcode), obj)
def draw_plot(var_list, fn, var_arg, var_scale, obj=None): try: gpl = subprocess.Popen("gnuplot", bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) except OSError: msgOut( "Error starting gnuplot, do you have it installed?\n\ Also, check that it is in your PATH.", obj) return -1 #cannot go on #specific plotsettings for file type if os.path.exists("./plot/plotsettings_" + fn): plotSet = open("./plot/plotsettings_" + fn, "r") setting = plotSet.readlines() for l in setting: gpl.stdin.write(l) plotSet.close() if os.path.exists(plot_recipe): plot.msgOut( "Found recipe " + str(plot_recipe) + " for setting up plot.", obj) f_recipe = open(plot_recipe, "r") recipe = f_recipe.readlines() for ingredient in recipe: gpl.stdin.write(ingredient) f_recipe.close() else: plot.msgOut("No plot recipe found, doing clean plot.", obj) if "darwin" in sys.platform: #use qt on os x for correct persist behaviour title = "set terminal qt title \"" + fn + "\" \n" else: title = "set terminal wxt persist title \"" + fn + "\" \n" gpl.stdin.write(title) if obj is not None: style = obj.getLineStyle() else: style = "lines" plot.msgOut("plotting selection: " + str(var_arg), obj) #generate a plot cmd that gnuplot understands plot_cmd = "plot " for idx, var in enumerate(var_arg): plot_cmd += "\'./plot/"+fn+"\'"+" using 1:($"+str(int(var)+2)+"*"+str(var_scale[idx])+") title \'"+\ var_list[int(var)]+"\' with "+style+", " plot_cmd = plot_cmd[: -2] ##ix version gnuplot needs this, removing last "," plot_cmd += " \n" #Note: add a newline like this to actually generate plot if "win" in sys.platform: plot_cmd += " pause mouse close \n" #IMPORTANT line for Windows. On Linux, leave out #pipe to gnuplot gpl.stdin.write(plot_cmd) gpl.stdin.flush() gpl.stdin.close() while True: line = gpl.stderr.readline() #thread blocks on stderr if not line: break plot.msgOut(line, obj, False) retcode = gpl.wait() #wait on child msgOut("Plot window closed. " + str(retcode), obj)