def create_plot(self): if self.plot is not None: self.plot.close() self.toolbar.set_auto(True) if self.settings.display == Display.PLOT: self.plot = Plotter(self.notify, self.figure, self.settings) elif self.settings.display == Display.SPECT: self.plot = Spectrogram(self.notify, self.figure, self.settings) elif self.settings.display == Display.SURFACE: self.plot = Plotter3d(self.notify, self.figure, self.settings) elif self.settings.display == Display.STATUS: self.plot = PlotterStatus(self.notify, self.figure, self.settings) elif self.settings.display == Display.TIMELINE: self.plot = PlotterTime(self.notify, self.figure, self.settings) self.__set_fonts() self.toolbar.set_plot(self.plot) self.toolbar.set_type(self.settings.display) self.measureTable.set_type(self.settings.display) self.set_plot_title() self.figure.subplots_adjust(top=0.85) self.redraw_plot() self.plot.scale_plot(True) self.mouseZoom = MouseZoom(self.toolbar, plot=self.plot, callbackHide=self.__hide_overlay) self.mouseSelect = MouseSelect(self.plot, self.on_select, self.on_selected) self.measureTable.show(self.settings.showMeasure) self.panel.SetFocus()
def __init__(self, parent, spectrum, settings): self.spectrum = spectrum self.settings = settings self.sweeps = None self.isExporting = False wx.Dialog.__init__(self, parent=parent, title='Export Plot Sequence') self.queue = Queue() self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.__on_timer, self.timer) self.timer.Start(self.POLL) self.figure = Figure(facecolor='white') self.canvas = FigureCanvas(self, -1, self.figure) self.plot = Plotter(self.queue, self.figure, settings) textPlot = wx.StaticText(self, label='Plot') self.checkAxes = wx.CheckBox(self, label='Axes') self.checkAxes.SetValue(True) self.Bind(wx.EVT_CHECKBOX, self.__on_axes, self.checkAxes) self.checkGrid = wx.CheckBox(self, label='Grid') self.checkGrid.SetValue(True) self.Bind(wx.EVT_CHECKBOX, self.__on_grid, self.checkGrid) self.checkBar = wx.CheckBox(self, label='Bar') self.checkBar.SetValue(True) self.Bind(wx.EVT_CHECKBOX, self.__on_bar, self.checkBar) sizerCheck = wx.BoxSizer(wx.HORIZONTAL) sizerCheck.Add(self.checkAxes, flag=wx.ALL, border=5) sizerCheck.Add(self.checkGrid, flag=wx.ALL, border=5) sizerCheck.Add(self.checkBar, flag=wx.ALL, border=5) textRange = wx.StaticText(self, label='Range') self.sweepTimeStamps = sorted( [timeStamp for timeStamp in spectrum.keys()]) sweepChoices = [ format_time(timeStamp, True) for timeStamp in self.sweepTimeStamps ] textStart = wx.StaticText(self, label="Start") self.choiceStart = wx.Choice(self, choices=sweepChoices) self.choiceStart.SetSelection(0) self.Bind(wx.EVT_CHOICE, self.__on_choice, self.choiceStart) textEnd = wx.StaticText(self, label="End") self.choiceEnd = wx.Choice(self, choices=sweepChoices) self.choiceEnd.SetSelection(len(self.sweepTimeStamps) - 1) self.Bind(wx.EVT_CHOICE, self.__on_choice, self.choiceEnd) textSweeps = wx.StaticText(self, label='Sweeps') self.textSweeps = wx.StaticText(self, label="") textOutput = wx.StaticText(self, label='Output') self.textSize = wx.StaticText(self) buttonSize = wx.Button(self, label='Change...') buttonSize.SetToolTip('Change exported image size') self.Bind(wx.EVT_BUTTON, self.__on_imagesize, buttonSize) self.__show_image_size() buttonBrowse = wx.Button(self, label='Browse...') self.Bind(wx.EVT_BUTTON, self.__on_browse, buttonBrowse) self.editDir = wx.TextCtrl(self) self.editDir.SetValue(settings.dirExport) font = textPlot.GetFont() fontSize = font.GetPointSize() font.SetPointSize(fontSize + 4) textPlot.SetFont(font) textRange.SetFont(font) textOutput.SetFont(font) sizerButtons = wx.StdDialogButtonSizer() buttonOk = wx.Button(self, wx.ID_OK) buttonCancel = wx.Button(self, wx.ID_CANCEL) sizerButtons.AddButton(buttonOk) sizerButtons.AddButton(buttonCancel) sizerButtons.Realize() self.Bind(wx.EVT_BUTTON, self.__on_ok, buttonOk) sizerGrid = wx.GridBagSizer(5, 5) sizerGrid.Add(self.canvas, pos=(0, 0), span=(10, 6), flag=wx.EXPAND | wx.ALL, border=5) sizerGrid.Add(textPlot, pos=(0, 7), flag=wx.TOP | wx.BOTTOM, border=5) sizerGrid.Add(sizerCheck, pos=(1, 7), span=(1, 2), flag=wx.ALL, border=5) sizerGrid.Add(textRange, pos=(2, 7), flag=wx.TOP | wx.BOTTOM, border=5) sizerGrid.Add(textStart, pos=(3, 7), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALL, border=5) sizerGrid.Add(self.choiceStart, pos=(3, 8), flag=wx.ALL, border=5) sizerGrid.Add(textEnd, pos=(4, 7), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALL, border=5) sizerGrid.Add(self.choiceEnd, pos=(4, 8), flag=wx.ALL, border=5) sizerGrid.Add(textSweeps, pos=(5, 7), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALL, border=5) sizerGrid.Add(self.textSweeps, pos=(5, 8), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALL, border=5) sizerGrid.Add(textOutput, pos=(6, 7), flag=wx.TOP | wx.BOTTOM, border=5) sizerGrid.Add(self.textSize, pos=(7, 7), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALL, border=5) sizerGrid.Add(buttonSize, pos=(7, 8), flag=wx.ALL, border=5) sizerGrid.Add(self.editDir, pos=(8, 7), span=(1, 2), flag=wx.ALL | wx.EXPAND, border=5) sizerGrid.Add(buttonBrowse, pos=(9, 7), flag=wx.ALL, border=5) sizerGrid.Add(sizerButtons, pos=(10, 7), span=(1, 2), flag=wx.ALIGN_RIGHT | wx.ALL, border=5) self.SetSizerAndFit(sizerGrid) self.__draw_plot()
class DialogExportSeq(wx.Dialog): POLL = 250 def __init__(self, parent, spectrum, settings): self.spectrum = spectrum self.settings = settings self.sweeps = None self.isExporting = False wx.Dialog.__init__(self, parent=parent, title='Export Plot Sequence') self.queue = Queue() self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.__on_timer, self.timer) self.timer.Start(self.POLL) self.figure = Figure(facecolor='white') self.canvas = FigureCanvas(self, -1, self.figure) self.plot = Plotter(self.queue, self.figure, settings) textPlot = wx.StaticText(self, label='Plot') self.checkAxes = wx.CheckBox(self, label='Axes') self.checkAxes.SetValue(True) self.Bind(wx.EVT_CHECKBOX, self.__on_axes, self.checkAxes) self.checkGrid = wx.CheckBox(self, label='Grid') self.checkGrid.SetValue(True) self.Bind(wx.EVT_CHECKBOX, self.__on_grid, self.checkGrid) self.checkBar = wx.CheckBox(self, label='Bar') self.checkBar.SetValue(True) self.Bind(wx.EVT_CHECKBOX, self.__on_bar, self.checkBar) sizerCheck = wx.BoxSizer(wx.HORIZONTAL) sizerCheck.Add(self.checkAxes, flag=wx.ALL, border=5) sizerCheck.Add(self.checkGrid, flag=wx.ALL, border=5) sizerCheck.Add(self.checkBar, flag=wx.ALL, border=5) textRange = wx.StaticText(self, label='Range') self.sweepTimeStamps = sorted( [timeStamp for timeStamp in spectrum.keys()]) sweepChoices = [ format_time(timeStamp, True) for timeStamp in self.sweepTimeStamps ] textStart = wx.StaticText(self, label="Start") self.choiceStart = wx.Choice(self, choices=sweepChoices) self.choiceStart.SetSelection(0) self.Bind(wx.EVT_CHOICE, self.__on_choice, self.choiceStart) textEnd = wx.StaticText(self, label="End") self.choiceEnd = wx.Choice(self, choices=sweepChoices) self.choiceEnd.SetSelection(len(self.sweepTimeStamps) - 1) self.Bind(wx.EVT_CHOICE, self.__on_choice, self.choiceEnd) textSweeps = wx.StaticText(self, label='Sweeps') self.textSweeps = wx.StaticText(self, label="") textOutput = wx.StaticText(self, label='Output') self.textSize = wx.StaticText(self) buttonSize = wx.Button(self, label='Change...') buttonSize.SetToolTip('Change exported image size') self.Bind(wx.EVT_BUTTON, self.__on_imagesize, buttonSize) self.__show_image_size() buttonBrowse = wx.Button(self, label='Browse...') self.Bind(wx.EVT_BUTTON, self.__on_browse, buttonBrowse) self.editDir = wx.TextCtrl(self) self.editDir.SetValue(settings.dirExport) font = textPlot.GetFont() fontSize = font.GetPointSize() font.SetPointSize(fontSize + 4) textPlot.SetFont(font) textRange.SetFont(font) textOutput.SetFont(font) sizerButtons = wx.StdDialogButtonSizer() buttonOk = wx.Button(self, wx.ID_OK) buttonCancel = wx.Button(self, wx.ID_CANCEL) sizerButtons.AddButton(buttonOk) sizerButtons.AddButton(buttonCancel) sizerButtons.Realize() self.Bind(wx.EVT_BUTTON, self.__on_ok, buttonOk) sizerGrid = wx.GridBagSizer(5, 5) sizerGrid.Add(self.canvas, pos=(0, 0), span=(10, 6), flag=wx.EXPAND | wx.ALL, border=5) sizerGrid.Add(textPlot, pos=(0, 7), flag=wx.TOP | wx.BOTTOM, border=5) sizerGrid.Add(sizerCheck, pos=(1, 7), span=(1, 2), flag=wx.ALL, border=5) sizerGrid.Add(textRange, pos=(2, 7), flag=wx.TOP | wx.BOTTOM, border=5) sizerGrid.Add(textStart, pos=(3, 7), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALL, border=5) sizerGrid.Add(self.choiceStart, pos=(3, 8), flag=wx.ALL, border=5) sizerGrid.Add(textEnd, pos=(4, 7), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALL, border=5) sizerGrid.Add(self.choiceEnd, pos=(4, 8), flag=wx.ALL, border=5) sizerGrid.Add(textSweeps, pos=(5, 7), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALL, border=5) sizerGrid.Add(self.textSweeps, pos=(5, 8), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALL, border=5) sizerGrid.Add(textOutput, pos=(6, 7), flag=wx.TOP | wx.BOTTOM, border=5) sizerGrid.Add(self.textSize, pos=(7, 7), flag=wx.ALIGN_CENTRE_VERTICAL | wx.ALL, border=5) sizerGrid.Add(buttonSize, pos=(7, 8), flag=wx.ALL, border=5) sizerGrid.Add(self.editDir, pos=(8, 7), span=(1, 2), flag=wx.ALL | wx.EXPAND, border=5) sizerGrid.Add(buttonBrowse, pos=(9, 7), flag=wx.ALL, border=5) sizerGrid.Add(sizerButtons, pos=(10, 7), span=(1, 2), flag=wx.ALIGN_RIGHT | wx.ALL, border=5) self.SetSizerAndFit(sizerGrid) self.__draw_plot() def __on_choice(self, event): start = self.choiceStart.GetSelection() end = self.choiceEnd.GetSelection() control = event.GetEventObject() if start > end: if control == self.choiceStart: self.choiceStart.SetSelection(end) else: self.choiceEnd.SetSelection(start) self.__draw_plot() def __on_axes(self, _event): self.plot.set_axes(self.checkAxes.GetValue()) self.__draw_plot() def __on_grid(self, _event): self.plot.set_grid(self.checkGrid.GetValue()) self.__draw_plot() def __on_bar(self, _event): self.plot.set_bar(self.checkBar.GetValue()) self.__draw_plot() def __on_imagesize(self, _event): dlg = DialogImageSize(self, self.settings) dlg.ShowModal() self.__show_image_size() def __on_browse(self, _event): directory = self.editDir.GetValue() dlg = wx.DirDialog(self, 'Output directory', directory) if dlg.ShowModal() == wx.ID_OK: directory = dlg.GetPath() self.editDir.SetValue(directory) def __on_timer(self, _event): self.timer.Stop() if not self.isExporting: while not self.queue.empty(): event = self.queue.get() status = event.data.get_status() if status == Event.DRAW: self.canvas.draw() self.timer.Start(self.POLL) def __on_ok(self, _event): self.isExporting = True extent = Extent(self.spectrum) dlgProgress = wx.ProgressDialog('Exporting', '', len(self.sweeps), style=wx.PD_AUTO_HIDE | wx.PD_CAN_ABORT | wx.PD_REMAINING_TIME) try: count = 1 for timeStamp, sweep in self.sweeps.items(): name = '{0:.0f}.png'.format(timeStamp) directory = self.editDir.GetValue() # filename = os.path.join(directory, name) thread = self.plot.set_plot({timeStamp: sweep}, extent, False) thread.join() filename = os.path.join(directory, '{}.png'.format(timeStamp)) export_image(filename, File.ImageType.PNG, self.figure, self.settings) cont, _skip = dlgProgress.Update(count, name) if not cont: break count += 1 except IOError as error: wx.MessageBox(error.strerror, 'Error', wx.OK | wx.ICON_WARNING) finally: dlgProgress.Destroy() self.EndModal(wx.ID_OK) def __spectrum_range(self, start, end): sweeps = {} for timeStamp, sweep in self.spectrum.items(): if start <= timeStamp <= end: sweeps[timeStamp] = sweep self.sweeps = sweeps def __draw_plot(self): start, end = self.__get_range() self.__spectrum_range(start, end) self.textSweeps.SetLabel(str(len(self.sweeps))) if len(self.sweeps) > 0: total = count_points(self.sweeps) if total > 0: extent = Extent(self.spectrum) self.plot.set_plot(self.sweeps, extent, False) else: self.plot.clear_plots() def __show_image_size(self): self.textSize.SetLabel('{}" x {}" @ {}dpi'.format( self.settings.exportWidth, self.settings.exportHeight, self.settings.exportDpi)) def __get_range(self): start = self.sweepTimeStamps[self.choiceStart.GetSelection()] end = self.sweepTimeStamps[self.choiceEnd.GetSelection()] return start, end
def __init__(self, parent, spectrum, settings): self.spectrum = spectrum self.settings = settings self.smoothed = None wx.Dialog.__init__(self, parent=parent, title='Smooth Spectrum', style=wx.RESIZE_BORDER | wx.CAPTION | wx.SYSTEM_MENU | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX | wx.CLOSE_BOX) self.queue = Queue() self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.__on_timer, self.timer) self.timer.Start(self.POLL) self.figure = Figure(facecolor='white') self.canvas = FigureCanvas(self, -1, self.figure) settings = copy.copy(settings) settings.plotFunc = PlotFunc.NONE self.plot = Plotter(self.queue, self.figure, settings) textFunc = wx.StaticText(self, label='Window function') self.choiceFunc = wx.Choice(self, choices=WINFUNC[::2]) self.choiceFunc.SetSelection(WINFUNC[::2].index(settings.smoothFunc)) textRatio = wx.StaticText(self, label='Smoothing') self.slideRatio = wx.Slider(self, value=settings.smoothRatio, minValue=2, maxValue=100, style=wx.SL_INVERSE) buttonSmooth = wx.Button(self, label='Smooth') self.Bind(wx.EVT_BUTTON, self.__on_smooth, buttonSmooth) sizerButtons = wx.StdDialogButtonSizer() self.buttonOk = wx.Button(self, wx.ID_OK) self.buttonOk.Disable() buttonCancel = wx.Button(self, wx.ID_CANCEL) sizerButtons.AddButton(self.buttonOk) sizerButtons.AddButton(buttonCancel) sizerButtons.Realize() self.Bind(wx.EVT_BUTTON, self.__on_ok, self.buttonOk) sizerGrid = wx.GridBagSizer(5, 5) sizerGrid.Add(self.canvas, pos=(0, 0), span=(10, 6), flag=wx.EXPAND | wx.ALL, border=5) sizerGrid.Add(textFunc, pos=(1, 6), border=5) sizerGrid.Add(self.choiceFunc, pos=(2, 6), span=(1, 2), flag=wx.ALL, border=5) sizerGrid.Add(textRatio, pos=(3, 6), flag=wx.ALL, border=5) sizerGrid.Add(self.slideRatio, pos=(4, 6), span=(1, 2), flag=wx.ALL, border=5) sizerGrid.Add(buttonSmooth, pos=(5, 6), span=(1, 2), flag=wx.ALL, border=5) sizerGrid.Add(sizerButtons, pos=(11, 6), span=(1, 2), flag=wx.ALIGN_RIGHT | wx.ALL, border=5) sizerGrid.AddGrowableCol(0) sizerGrid.AddGrowableRow(0) self.SetSizerAndFit(sizerGrid) self.__draw_plot(self.spectrum)
class DialogSmooth(wx.Dialog): POLL = 250 def __init__(self, parent, spectrum, settings): self.spectrum = spectrum self.settings = settings self.smoothed = None wx.Dialog.__init__(self, parent=parent, title='Smooth Spectrum', style=wx.RESIZE_BORDER | wx.CAPTION | wx.SYSTEM_MENU | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX | wx.CLOSE_BOX) self.queue = Queue() self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.__on_timer, self.timer) self.timer.Start(self.POLL) self.figure = Figure(facecolor='white') self.canvas = FigureCanvas(self, -1, self.figure) settings = copy.copy(settings) settings.plotFunc = PlotFunc.NONE self.plot = Plotter(self.queue, self.figure, settings) textFunc = wx.StaticText(self, label='Window function') self.choiceFunc = wx.Choice(self, choices=WINFUNC[::2]) self.choiceFunc.SetSelection(WINFUNC[::2].index(settings.smoothFunc)) textRatio = wx.StaticText(self, label='Smoothing') self.slideRatio = wx.Slider(self, value=settings.smoothRatio, minValue=2, maxValue=100, style=wx.SL_INVERSE) buttonSmooth = wx.Button(self, label='Smooth') self.Bind(wx.EVT_BUTTON, self.__on_smooth, buttonSmooth) sizerButtons = wx.StdDialogButtonSizer() self.buttonOk = wx.Button(self, wx.ID_OK) self.buttonOk.Disable() buttonCancel = wx.Button(self, wx.ID_CANCEL) sizerButtons.AddButton(self.buttonOk) sizerButtons.AddButton(buttonCancel) sizerButtons.Realize() self.Bind(wx.EVT_BUTTON, self.__on_ok, self.buttonOk) sizerGrid = wx.GridBagSizer(5, 5) sizerGrid.Add(self.canvas, pos=(0, 0), span=(10, 6), flag=wx.EXPAND | wx.ALL, border=5) sizerGrid.Add(textFunc, pos=(1, 6), border=5) sizerGrid.Add(self.choiceFunc, pos=(2, 6), span=(1, 2), flag=wx.ALL, border=5) sizerGrid.Add(textRatio, pos=(3, 6), flag=wx.ALL, border=5) sizerGrid.Add(self.slideRatio, pos=(4, 6), span=(1, 2), flag=wx.ALL, border=5) sizerGrid.Add(buttonSmooth, pos=(5, 6), span=(1, 2), flag=wx.ALL, border=5) sizerGrid.Add(sizerButtons, pos=(11, 6), span=(1, 2), flag=wx.ALIGN_RIGHT | wx.ALL, border=5) sizerGrid.AddGrowableCol(0) sizerGrid.AddGrowableRow(0) self.SetSizerAndFit(sizerGrid) self.__draw_plot(self.spectrum) def __on_timer(self, _event): self.timer.Stop() while not self.queue.empty(): event = self.queue.get() status = event.data.get_status() if status == Event.DRAW: self.canvas.draw() self.timer.Start(self.POLL) def __on_smooth(self, _event): with wx.BusyInfo('Please wait...'): func = self.choiceFunc.GetStringSelection() ratio = self.slideRatio.GetValue() self.smoothed = smooth_spectrum(self.spectrum, func, ratio) self.__draw_plot(self.smoothed) self.buttonOk.Enable() # dlg.Destroy() def __on_ok(self, _event): self.EndModal(wx.ID_OK) def __draw_plot(self, spectrum): extent = Extent(spectrum) self.plot.set_plot(spectrum, extent, False) def get_spectrum(self): return self.smoothed