From d9082b1ea33bfeb31740147795867ee41af8750e Mon Sep 17 00:00:00 2001 From: Christopher Stone Date: Fri, 9 Feb 2018 23:18:43 +0000 Subject: [PATCH] Made plot a subclass of window --- telemetry/code/monitor/.graph_plotter_rewrite.py.kate-swp | Bin 0 -> 167 bytes telemetry/code/monitor/graph_plotter_rewrite.py | 29 +++++++++++++---------------- 2 files changed, 13 insertions(+), 16 deletions(-) create mode 100644 telemetry/code/monitor/.graph_plotter_rewrite.py.kate-swp diff --git a/telemetry/code/monitor/.graph_plotter_rewrite.py.kate-swp b/telemetry/code/monitor/.graph_plotter_rewrite.py.kate-swp new file mode 100644 index 0000000..ac169c0 Binary files /dev/null and b/telemetry/code/monitor/.graph_plotter_rewrite.py.kate-swp differ diff --git a/telemetry/code/monitor/graph_plotter_rewrite.py b/telemetry/code/monitor/graph_plotter_rewrite.py index d6fd81c..41c0ca4 100755 --- a/telemetry/code/monitor/graph_plotter_rewrite.py +++ b/telemetry/code/monitor/graph_plotter_rewrite.py @@ -28,28 +28,25 @@ class Series: if len(self.data) > self.points: del self.points[-1] -class Plot(): - def __init__(self, series, size=(640, 480)): +class Plot(pyglet.window.Window): + def __init__(self, series): """Setup a the details of a plot, and create a corresponding window""" + pyglet.window.Window.__init__(self, resizable=True) self.series = series self.title = self.series.title - self.size = size self.font = 'Arkhip' self.margins = (0.02, 0.02) # Fractions of window size self.lines = (12, 8) - self.window = pyglet.window.Window(self.size[0], self.size[1], resizable=True) - self.window.set_caption(self.title) - self.window.on_resize = self.resize - self.window.on_draw = self.draw - self.bounds = ((int(self.window.width * self.margins[0]), int(self.window.width * (1 - self.margins[0]))), - (int(self.window.height * self.margins[1]), int(self.window.height * (1 - self.margins[1])))) + #self.resizable = True + self.set_caption(self.title) + self.bounds = ((int(self.width * self.margins[0]), int(self.width * (1 - self.margins[0]))), + (int(self.height * self.margins[1]), int(self.height * (1 - self.margins[1])))) - def resize(self, width, height): - """Handle a pyglet resize event, then give control back to the event loop""" - self.size = (width, height) - super(pyglet.window.Window, self.window).on_resize(width, height) + #def on_resize(self, width, height): + """Handle a pyglet resize event""" + # pass - def draw(self): + def on_draw(self): """Draw all the components of the graph""" self.drawBackground() self.drawHeading() @@ -57,12 +54,12 @@ class Plot(): def drawBackground(self): """Draw the graph background, currently a plain colour""" - pyglet.image.SolidColorImagePattern(WHITE).create_image(self.size[0], self.size[1]).blit(0, 0) + pyglet.image.SolidColorImagePattern(WHITE).create_image(self.width, self.height).blit(0, 0) def drawHeading(self): """Draw a title for the graph (duplicated in the window titlebar, if present""" heading = pyglet.text.Label(self.title, color=BLACK, - font_name=self.font, font_size=self.size[0]*self.margins[0], x=self.size[0]/2, y=self.size[1], + font_name=self.font, font_size=self.width*self.margins[0], x=self.width/2, y=self.height, anchor_x='center', anchor_y='top') heading.draw() -- libgit2 0.21.2