class PlotterWidget(Graph): # 7 # 7 SPplot = ObjectProperty(None) # Set Point, will either be 105 or 140 PVplot = ObjectProperty(None) # Process Value, will be temperature # 8 index = ObjectProperty(0) # Time startTime = ObjectProperty(0) currentTemp = ObjectProperty(23) currentSignal = ObjectProperty(105) def __init__(self, **kwargs): # 8 self.startTime = self.getCurrentTime() # 7 kwargs = dict( label_options=dict(color=(1,1,1,1), bold=False), background_color=(0,0,0,1), tick_color=(1,1,1,1), border_color=(1,1,1,1), padding=2, xlabel='On Time (Seconds):', ylabel='Temperature', x_ticks_minor=2, x_ticks_major=10, y_ticks_minor=2, y_ticks_major=10, y_grid_label=False, x_grid_label=False, xlog=False, ylog=False, x_grid=False, y_grid=False, ymin=0, ymax=170, # 8 xmin= int(self.getCurrentTime()*TIME_DECIMALS)/TIME_DECIMALS, xmax= int((self.getCurrentTime() + START_SIZE_WINDOW)*TIME_DECIMALS)/TIME_DECIMALS ) # 7 super(PlotterWidget, self).__init__(**kwargs) # 8 self.SPplot = LinePlot(color=(1,0,0,1)) self.add_plot(self.SPplot) self.PVplot = LinePlot(color=(0,1,0,1)) self.add_plot(self.PVplot) # 8; At dt update the plot def update(self, dt): self.addPlott() if self.startScrolling() == True: self.scrollXaxis() # Commence scrolling axis. self.cutLinesNotInWindow() # Remove data not seen from array. Smoothes the graphics # 8; Get current run time by subtracting start time def getCurrentTime(self): # Obtains time stamp as an float from epoch (1/1/1970) ts = time.time() # Take start time away from the epoch time to min the label size. ts = ts - self.startTime return ts # 8; Add plots to the graph at current run time def addPlott(self): self.index = self.getCurrentTime() self.SPplot.points.append([self.index, self.currentSignal]) self.SPplot.draw() self.PVplot.points.append([self.index, self.currentTemp]) self.PVplot.draw() # 8; Returns a true value if the plot has reached the START_SCROLLING point on the window. def startScrolling(self): if self.index >= self.xmax - START_SCROLLING: return True else: return False # 8; Commences Scroll of xAxis def scrollXaxis(self): # Round time stamp to 2DP self.xmax=float((self.index+START_SCROLLING)*TIME_DECIMALS)/TIME_DECIMALS self.xmin=float((self.xmax-START_SIZE_WINDOW)*TIME_DECIMALS)/TIME_DECIMALS # 8; Remove lines that are no longer on the graph def cutLinesNotInWindow(self): del self.SPplot.points[0] del self.PVplot.points[0]