Пример #1
0
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
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
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")
Пример #5
0
    def aboutInfo(self):

        try:
            aboutText = open("./ABOUT", "r")
            contents = aboutText.read()
            plot.msgOut(contents, self)
        except:
            plot.msgOut("Error opening ABOUT file", self)
Пример #6
0
    def aboutInfo(self) :

        try :
            aboutText = open("./ABOUT","r")
            contents = aboutText.read()
            plot.msgOut(contents,self)
        except :
            plot.msgOut("Error opening ABOUT file",self)
Пример #7
0
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")
Пример #8
0
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
Пример #9
0
    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)
Пример #10
0
    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)
Пример #11
0
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()
Пример #12
0
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()
Пример #13
0
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
Пример #14
0
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
Пример #15
0
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()
Пример #16
0
def printHelp() :
    plot.msgOut("Usage: plot.py [selection] filename\n selection takes form x-y or x,y,z...") 
Пример #17
0
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()
Пример #18
0
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)
Пример #19
0
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)
Пример #20
0
def printHelp():
    plot.msgOut(
        "Usage: plot.py [selection] filename\n selection takes form x-y or x,y,z..."
    )
Пример #21
0
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)
Пример #22
0
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)