Here's a Python 2.7 question form a n00b:
I am running an App that reads data from a serial port and makes a live graph using a Tkinter-Canvas. I am not using matplotlib, since this lib is not available on the A20 plattform I want to run the program on. (some dependencies of mpl are not at the necessary version yet on the A20)
I know this is not the most elegant way to draw a live graph, but to me it seemed to be the most compatible, since its just relying on Tkinter as lib, which is available on really every plattform. I am basically deleting the canvas and redrawing it with one postion offset every time new data comes in. It flickers a bit, but as I said... i am a n00b. :)
here's my code for drawing the graph:
class TeleGraph(Canvas):
def __init__(self, master, FrameTitle, Col, Row, Height):
Canvas.__init__(self, master)
self.FrameTitle = FrameTitle
self.Value1 = range(60)
self.Value2 = range(60)
self.Value3 = range(60)
self.configure(height = Height, width = 750, bg = 'grey', bd = 3,relief = GROOVE)
self.grid()
self.grid_propagate(0)
self.Col = Col
self.Row = Row
self.place(y = Col, x = Row)
def NewEntry(self, NewValue1, NewValue2, NewValue3 = 0, Centerline = False, ThirdLine = False):
self.delete("all")
self.create_text( 380,20,text = self.FrameTitle, fill = 'black')
if Centerline == True:
self.create_line(0,90,760,90, fill = 'dark grey')
for x in range(1,59):
self.Value1[x] = self.Value1[x+1]
self.Value2[x] = self.Value2[x+1]
self.Value3[x] = self.Value3[x+1]
self.Value1[59] = NewValue1
self.Value2[59] = NewValue2
self.Value3[59] = NewValue3
for x in range(0,59):
self.create_line(-13+(x*13),self.Value1[x],0+(x*13),self.Value1[x+1], fill='blue' )
self.create_line(-13+(x*13),self.Value2[x],0+(x*13),self.Value2[x+1], fill='red' )
if ThirdLine == True:
self.create_line(-13+(x*13),self.Value3[x],0+(x*13),self.Value3[x+1], fill='yellow' )
It is working fine so far, but I noticed an odd error:
After half a minute or so the Canvas stops updating, even thou the programm itself is still running perfectly. When i move the mouse over the app, the Canvas updates again. I call the NewEntry Function every 0.5 seconds. I thought of generating a mouse event every now and then, but that would be a nasty work around... Any help is highly appreciated!
Thanks,
deck
First I thought a new Code solved the issue, but it turns out, it just happens less often. Also it seems it doesn't happen on Debian on A20ARM.
Here is the code: