Commit d9082b1ea33bfeb31740147795867ee41af8750e
1 parent
cad30d6c
Exists in
master
Made plot a subclass of window
Showing
2 changed files
with
13 additions
and
16 deletions
Show diff stats
No preview for this file type
telemetry/code/monitor/graph_plotter_rewrite.py
| ... | ... | @@ -28,28 +28,25 @@ class Series: |
| 28 | 28 | if len(self.data) > self.points: |
| 29 | 29 | del self.points[-1] |
| 30 | 30 | |
| 31 | -class Plot(): | |
| 32 | - def __init__(self, series, size=(640, 480)): | |
| 31 | +class Plot(pyglet.window.Window): | |
| 32 | + def __init__(self, series): | |
| 33 | 33 | """Setup a the details of a plot, and create a corresponding window""" |
| 34 | + pyglet.window.Window.__init__(self, resizable=True) | |
| 34 | 35 | self.series = series |
| 35 | 36 | self.title = self.series.title |
| 36 | - self.size = size | |
| 37 | 37 | self.font = 'Arkhip' |
| 38 | 38 | self.margins = (0.02, 0.02) # Fractions of window size |
| 39 | 39 | self.lines = (12, 8) |
| 40 | - self.window = pyglet.window.Window(self.size[0], self.size[1], resizable=True) | |
| 41 | - self.window.set_caption(self.title) | |
| 42 | - self.window.on_resize = self.resize | |
| 43 | - self.window.on_draw = self.draw | |
| 44 | - self.bounds = ((int(self.window.width * self.margins[0]), int(self.window.width * (1 - self.margins[0]))), | |
| 45 | - (int(self.window.height * self.margins[1]), int(self.window.height * (1 - self.margins[1])))) | |
| 40 | + #self.resizable = True | |
| 41 | + self.set_caption(self.title) | |
| 42 | + self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))), | |
| 43 | + (int(self.height * self.margins[1]), int(self.height * (1 - self.margins[1])))) | |
| 46 | 44 | |
| 47 | - def resize(self, width, height): | |
| 48 | - """Handle a pyglet resize event, then give control back to the event loop""" | |
| 49 | - self.size = (width, height) | |
| 50 | - super(pyglet.window.Window, self.window).on_resize(width, height) | |
| 45 | + #def on_resize(self, width, height): | |
| 46 | + """Handle a pyglet resize event""" | |
| 47 | + # pass | |
| 51 | 48 | |
| 52 | - def draw(self): | |
| 49 | + def on_draw(self): | |
| 53 | 50 | """Draw all the components of the graph""" |
| 54 | 51 | self.drawBackground() |
| 55 | 52 | self.drawHeading() |
| ... | ... | @@ -57,12 +54,12 @@ class Plot(): |
| 57 | 54 | |
| 58 | 55 | def drawBackground(self): |
| 59 | 56 | """Draw the graph background, currently a plain colour""" |
| 60 | - pyglet.image.SolidColorImagePattern(WHITE).create_image(self.size[0], self.size[1]).blit(0, 0) | |
| 57 | + pyglet.image.SolidColorImagePattern(WHITE).create_image(self.width, self.height).blit(0, 0) | |
| 61 | 58 | |
| 62 | 59 | def drawHeading(self): |
| 63 | 60 | """Draw a title for the graph (duplicated in the window titlebar, if present""" |
| 64 | 61 | heading = pyglet.text.Label(self.title, color=BLACK, |
| 65 | - font_name=self.font, font_size=self.size[0]*self.margins[0], x=self.size[0]/2, y=self.size[1], | |
| 62 | + font_name=self.font, font_size=self.width*self.margins[0], x=self.width/2, y=self.height, | |
| 66 | 63 | anchor_x='center', anchor_y='top') |
| 67 | 64 | heading.draw() |
| 68 | 65 | ... | ... |