Blame view

telemetry/code/monitor/graph_plotter_rewrite.py 1.73 KB
001c428d   Christopher Stone   Beginnings of a c...
1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/env python

import pyglet
#import math
#import time
#import serial

from colours import *

class Plot:
    def __init__(self, title="Unknown", size=(640, 480)):
01bfd701   Christopher Stone   Added docstrings
12
        """Setup a the details of a plot, and create a corresponding window"""
948da001   Christopher Stone   More progress on ...
13
14
15
16
17
18
19
20
        self.title = title
        self.size = size
        self.font = 'Arkhip'
        self.window = pyglet.window.Window(self.size[0], self.size[1], resizable=True)
        self.window.set_caption(title)
        self.window.on_resize = self.resize
        self.window.on_draw = self.draw
    
4d80e306   Christopher Stone   inadvertently fix...
21
    def resize(self, width, height):
01bfd701   Christopher Stone   Added docstrings
22
        """Handle a pyglet resize event, then give control back to the event loop"""
948da001   Christopher Stone   More progress on ...
23
        self.size = (width, height)
44da1d6d   Christopher Stone   Fixed drawing bug...
24
        super(pyglet.window.Window, self.window).on_resize(width, height)
948da001   Christopher Stone   More progress on ...
25
        
001c428d   Christopher Stone   Beginnings of a c...
26
    def draw(self):
01bfd701   Christopher Stone   Added docstrings
27
        """Draw all the components of the graph"""
948da001   Christopher Stone   More progress on ...
28
29
30
        self.drawBackground()
        self.drawHeading()
        
001c428d   Christopher Stone   Beginnings of a c...
31
    def drawBackground(self):
01bfd701   Christopher Stone   Added docstrings
32
        """Draw the graph background, currently a plain colour"""
001c428d   Christopher Stone   Beginnings of a c...
33
34
35
        pyglet.image.SolidColorImagePattern(WHITE).create_image(self.size[0], self.size[1]).blit(0, 0)
        
    def drawHeading(self):
01bfd701   Christopher Stone   Added docstrings
36
        """Draw a title for the graph (duplicated in the window titlebar, if present"""
001c428d   Christopher Stone   Beginnings of a c...
37
38
39
40
41
        heading = pyglet.text.Label(self.title, color=BLACK,
                            font_name=self.font, font_size=self.size[0]/50, x=self.size[0]/2, y=self.size[1],
                            anchor_x='center', anchor_y='top')
        heading.draw()
        
001c428d   Christopher Stone   Beginnings of a c...
42
43
44
plots = []         
plots.append(Plot("This is a test plot"))

4d80e306   Christopher Stone   inadvertently fix...
45
def pollSerial(foo):
01bfd701   Christopher Stone   Added docstrings
46
    """Dummy, will check serial port for incoming data"""
21ddadaa   Christopher Stone   Added a comment a...
47
    # Note, foo seems to be a float
948da001   Christopher Stone   More progress on ...
48
49
    pass

948da001   Christopher Stone   More progress on ...
50
pyglet.clock.schedule_interval(pollSerial, 0.1)
001c428d   Christopher Stone   Beginnings of a c...
51
52

pyglet.app.run()