#!/usr/bin/env python3 # -*- coding: UTF-8 -*- # # generated by wxGlade 1.0.2 on Sun Jun 20 19:31:43 2021 # import wx from model import Model # begin wxGlade: dependencies # end wxGlade # begin wxGlade: extracode # end wxGlade import matplotlib.cm as cm import matplotlib.cbook as cbook from matplotlib.backends.backend_wxagg import ( FigureCanvasWxAgg as FigureCanvas, NavigationToolbar2WxAgg as NavigationToolbar, ) from matplotlib.figure import Figure import numpy as np class PlotPanel(wx.Panel): def __init__(self, parent, model): super().__init__(parent, -1) self.model = model self.fig = Figure((3, 3), 75) self.canvas = FigureCanvas(self, -1, self.fig) self.toolbar = NavigationToolbar(self.canvas) # matplotlib toolbar self.toolbar.Realize() # Now put all into a sizer sizer = wx.BoxSizer(wx.VERTICAL) # This way of adding to sizer allows resizing sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) # Best to allow the toolbar to resize! sizer.Add(self.toolbar, 0, wx.GROW) self.SetSizer(sizer) self.Fit() self.Bind(wx.EVT_PAINT, self.OnPaint, self) self.init_plot_data() def init_plot_data(self): self.ax = self.fig.add_subplot() self.x, self.y = self.model.getData (self.im,) = self.ax.plot(self.x, self.y, "-.") self.toolbar.update() # Not sure why this is needed - ADS def GetToolBar(self): # You will need to override GetToolBar if you are using an # unmanaged toolbar in your frame return self.toolbar def OnPaint(self, event): print("Paint") self.x, self.y = self.model.getData # print(self.x) self.im.set_data(self.x, self.y) self.ax.relim() self.ax.autoscale_view() self.canvas.draw() event.Skip() class MyFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ self.model = Model() kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.SetSize((400, 300)) self.SetTitle("frame") self.panel_1 = wx.Panel(self, wx.ID_ANY) grid_sizer_1 = wx.GridBagSizer(0, 0) self.b_start = wx.Button(self.panel_1, wx.ID_ANY, "Start") grid_sizer_1.Add(self.b_start, (0, 0), (1, 1), 0, 0) self.b_stop = wx.Button(self.panel_1, wx.ID_ANY, "Stop") grid_sizer_1.Add(self.b_stop, (0, 1), (1, 1), 0, 0) self.b_clear = wx.Button(self.panel_1, wx.ID_ANY, "Clear") grid_sizer_1.Add(self.b_clear, (0, 2), (1, 1), 0, 0) self.b_save = wx.Button(self.panel_1, wx.ID_ANY, "Speichern") grid_sizer_1.Add(self.b_save, (0, 3), (1, 1), 0, 0) self.plot = PlotPanel(self.panel_1, self.model) self.plot.SetMinSize((300, 300)) grid_sizer_1.Add(self.plot, (1, 0), (1, 3), wx.EXPAND, 0) label_1 = wx.StaticText(self.panel_1, wx.ID_ANY, "Test") grid_sizer_1.Add(label_1, (2, 0), (1, 3), 0, 0) self.panel_1.SetSizer(grid_sizer_1) self.timer = wx.Timer(self, wx.ID_ANY) self.Layout() self.Bind(wx.EVT_BUTTON, self.onBstart, self.b_start) self.Bind(wx.EVT_BUTTON, self.offBstop, self.b_stop) self.Bind(wx.EVT_BUTTON, self.delBclear, self.b_clear) self.Bind(wx.EVT_BUTTON, self.onBsave, self.b_save) self.Bind(wx.EVT_TIMER, self.update, self.timer) self.timer.Start(100, False) # end wxGlade def update(self, event): self.plot.Refresh() def onBstart(self, event): # wxGlade: MyFrame. print("Event handler 'onBstart'") self.model.startMeasureing() event.Skip() def onBsave(self, event): # wxGlade: MyFrame. print("Event handler 'onBsave'") with wx.FileDialog( self, "Save csv file", wildcard="CSV files (*.csv)|*.csv", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, ) as fileDialog: if fileDialog.ShowModal() == wx.ID_CANCEL: return # the user changed their mind # save the current contents in the file pathname = fileDialog.GetPath() self.model.saveMeasureing(path=pathname) event.Skip() def offBstop(self, event): # wxGlade: MyFrame. self.model.stopMeasureing() print("Event handler 'offBstop'") event.Skip() def delBclear(self, event): # wxGlade: MyFrame. self.model.clear() print("Event handler 'delBclear'") event.Skip() # end of class MyFrame class MeinErsterMessApp(wx.App): def OnInit(self): self.frame = MyFrame(None, wx.ID_ANY, "") self.SetTopWindow(self.frame) self.frame.Show() return True # end of class MeinErsterMessApp if __name__ == "__main__": app = MeinErsterMessApp(0) app.MainLoop()