def __init__(self, parent, ignored_samples, sz=None): self._canvas_options = options.PlotCanvasOptions() self.ignored_samples = ignored_samples matplotlib.rc('font', **self.canvas_options.fontdict) super(PlotCanvas, self).__init__(parent, wx.ID_ANY, style=wx.RAISED_BORDER) if not sz: self.delegate = wxagg.FigureCanvasWxAgg( self, wx.ID_ANY, plt.Figure(facecolor=(0.9, 0.9, 0.9))) else: self.delegate = wxagg.FigureCanvasWxAgg( self, wx.ID_ANY, plt.Figure(facecolor=(0.9, 0.9, 0.9), figsize=sz)) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.delegate, 1, wx.EXPAND) self.plot = self.delegate.figure.add_axes([0.1, 0.1, 0.8, 0.8]) self.pointsets = [] self.delegate.figure.canvas.mpl_connect('pick_event', self.on_pick) self.delegate.figure.canvas.mpl_connect('motion_notify_event', self.on_motion) # self.figure.canvas.mpl_connect('motion_notify_event',self.on_motion) self.annotations = {} # used to index into when there is a pick event self.picking_table = {} self.dist_point = None self.SetSizerAndFit(sizer)
def __init__(self): wx.Frame.__init__(self, None) self.panel = backend_wxagg.FigureCanvasWxAgg(self, -1, Figure()) axes = self.panel.figure.gca() axes.cla() axes.plot([1,2,3],[1,2,3])
def __init__(self): wx.Frame.__init__(self, win, title='电机转速', size=(400, 400)) self.x = [0] self.y = [0] self.sympol = 0 self.panel = backend_wxagg.FigureCanvasWxAgg(self, -1, Figure()) self.axes = self.panel.figure.gca() self.axes.cla()
def __init__(self, parent, **kwargs): wx.Panel.__init__(self, parent, **kwargs) self.parent = parent self.figure = matplotlib.figure.Figure() self.canvas = wxaggb.FigureCanvasWxAgg(self, -1, self.figure) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.Bind(wx.EVT_SIZE, self.sizeHandler) self.cmap = matplotlib.cm.RdYlBu_r
def photoSetup(self): self.figure = Figure() self.figure.subplots_adjust(bottom=0.01, top=0.99, left=0.01, right=0.99) self.histogram = wxagg.FigureCanvasWxAgg(self, -1, self.figure) self.histogram.SetMinSize((1, 150)) self.figure.set_facecolor('#282828') self.panel_sizer.Add(self.histogram, 0, wx.ALL | wx.EXPAND, 5) self.info_panel = InfoPanel(self) self.panel_sizer.Add(self.info_panel, 0, wx.ALL | wx.EXPAND, 5) self.line0 = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL) self.line0.SetBackgroundColour((255, 255, 255)) self.panel_sizer.Add(self.line0, 0, wx.ALL | wx.EXPAND, 10) self.exposure = SettingSlider(self, tools.S_EXPOSURE, self.image_processor) self.panel_sizer.Add(self.exposure, 0, wx.ALL | wx.EXPAND, 5) self.contrast = SettingSlider(self, tools.S_CONTRAST, self.image_processor) self.panel_sizer.Add(self.contrast, 0, wx.ALL | wx.EXPAND, 5) self.saturation = SettingSlider(self, tools.S_SATURATION, self.image_processor) self.panel_sizer.Add(self.saturation, 0, wx.ALL | wx.EXPAND, 5) self.line1 = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL) self.line1.SetBackgroundColour((255, 255, 255)) self.panel_sizer.Add(self.line1, 0, wx.ALL | wx.EXPAND, 10) self.label_sharpen = wx.StaticText(self, label="Sharpening") self.label_sharpen.SetFont(self.font) self.label_sharpen.SetForegroundColour((255, 255, 255)) self.panel_sizer.Add(self.label_sharpen, 0, wx.ALL | wx.EXPAND, 5) self.sharpen_amount = SettingSlider(self, tools.S_SHARPEN_AMOUNT, self.image_processor, 0, 150) self.panel_sizer.Add(self.sharpen_amount, 0, wx.ALL | wx.EXPAND, 5) self.sharpen_radius = SettingSlider(self, tools.S_SHARPEN_RADIUS, self.image_processor, 5, 30, 10, 0.1) self.panel_sizer.Add(self.sharpen_radius, 0, wx.ALL | wx.EXPAND, 5) self.sharpen_masking = SettingSlider(self, tools.S_SHARPEN_MASKING, self.image_processor, 0) self.panel_sizer.Add(self.sharpen_masking, 0, wx.ALL | wx.EXPAND, 5) self.denoise = SettingSlider(self, tools.S_DENOISE, self.image_processor, 0) self.panel_sizer.Add(self.denoise, 0, wx.ALL | wx.EXPAND, 5) self.line2 = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL) self.line2.SetBackgroundColour((255, 255, 255)) self.panel_sizer.Add(self.line2, 0, wx.ALL | wx.EXPAND, 10) self.vignette = SettingSlider(self, tools.S_VIGNETTE, self.image_processor) self.panel_sizer.Add(self.vignette, 0, wx.ALL | wx.EXPAND, 5) self.distort = SettingSlider(self, tools.S_DISTORT, self.image_processor) self.panel_sizer.Add(self.distort, 0, wx.ALL | wx.EXPAND, 5)
def __init__(self, parent): wx.Panel.__init__(self, parent) """self.matplotlibPanel完全继承自wx.Panel类,可以与Panel类一样的使用""" self.matplotlibPanel = backend_wxagg.FigureCanvasWxAgg( self, -1, Figure()) self.drawGraph() sizer = wx.BoxSizer() sizer.AddStretchSpacer(1) sizer.Add(self.matplotlibPanel, flag=wx.EXPAND) sizer.AddStretchSpacer(1) self.SetSizer(sizer)
def create_main_panel(self): self.panel = wx.Panel(self) self.dpi = 100 self.fig = fg.Figure((5.0, 4.0), dpi=self.dpi) self.canvas = wxagg.FigureCanvasWxAgg(self.panel, -1, self.fig) self.axes = self.fig.add_subplot(111) self.toolbar = wxagg.NavigationToolbar2WxAgg(self.canvas) self.vbox = wx.BoxSizer(wx.VERTICAL) self.vbox.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.vbox.AddSpacer(25) self.vbox.Add(self.toolbar, 0, wx.EXPAND) self.panel.SetSizer(self.vbox) self.vbox.Fit(self) self.fig.canvas.mpl_connect('pick_event', self.on_pick) self.fig.canvas.mpl_connect('key_press_event', self.on_key)
def __init__(self, parent=None): super().__init__(parent, title='PCA', size=(800, 800)) self.panel = wx.Panel(self) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.AddSpacer(5) self.panel.SetSizer(self.sizer) top_sizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(top_sizer, 0) ctl_sizer = wx.BoxSizer(wx.VERTICAL) top_sizer.Add(ctl_sizer, 0) ctl_sizer.Add(wx.StaticText(self.panel, -1, 'Variables:'), flag=wx.TOP | wx.LEFT | wx.RIGHT, border=20) self.data = Project.get().all_data data_choices = [n.data.data_name for n in self.data] self.chooser = wx.ListBox(self.panel, choices=data_choices, style=wx.LB_EXTENDED) ctl_sizer.Add(self.chooser, 0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=20) ctl_sizer.Add(wx.StaticText(self.panel, -1, 'Plot type:'), flag=wx.TOP | wx.LEFT | wx.RIGHT, border=12) self.plot_type = wx.RadioBox(self.panel, choices=['scatterplot', 'heatmap']) ctl_sizer.Add(self.plot_type, flag=wx.LEFT | wx.RIGHT, border=10) ctl_sizer.Add(wx.StaticText(self.panel, -1, 'Axis type:'), flag=wx.TOP | wx.LEFT | wx.RIGHT, border=12) self.axis_type = wx.RadioBox(self.panel, choices=['fixed', 'adaptive']) ctl_sizer.Add(self.axis_type, flag=wx.LEFT | wx.RIGHT, border=10) self.Bind(wx.EVT_RADIOBOX, self.doPlot) self.fig = mpl.figure.Figure() self.canvas = wxagg.FigureCanvasWxAgg(self.panel, -1, self.fig) top_sizer.Add(self.canvas, 1, wx.EXPAND) self.Bind(wx.EVT_LISTBOX, self.doPlot) self.Bind(wx.EVT_CLOSE, self.onClose) get_main_window().Bind(EVT_TIMELINE_CHANGED, self.doPlot) self.CenterOnParent() self.panel.Layout() self.Show()
def __init__(self): global filename, words1, words2, contents, dateStart, dateEnd wx.Frame.__init__(self, None, -1, title=u"话题热度预测", size=(1100, 600)) wx.StaticText(self, label=u'语料文件:', pos=(15, 13)) filename = wx.TextCtrl(self, pos=(80, 10), size=(210, 25)) openButton = wx.Button(self, label=u'打开', pos=(305, 10), size=(80, 25)) wx.StaticText(self, label=u'起止日期:', pos=(470, 13)) dateStart = wx.TextCtrl(self, pos=(550, 10), size=(100, 25)) wx.StaticText(self, label=u'至', pos=(665, 13)) dateEnd = wx.TextCtrl(self, pos=(700, 10), size=(100, 25)) submitButton = wx.Button(self, label=u'提交', pos=(820, 10), size=(80, 25)) wx.StaticText(self, label=u'话题关键字:', pos=(15, 55)) words1 = wx.TextCtrl(self, pos=(90, 50), size=(90, 25)) words2 = wx.TextCtrl(self, pos=(200, 50), size=(90, 25)) sureButton = wx.Button(self, label=u'确定', pos=(305, 50), size=(80, 25)) contents = wx.TextCtrl(self, pos=(15, 90), size=(370, 450), style=wx.TE_MULTILINE | wx.HSCROLL) panel = wx.Panel(self, pos=(420, 55), size=(640, 480)) self.fg = Figure() self.panel = backend_wxagg.FigureCanvasWxAgg(panel, -1, self.fg) self.axes = self.panel.figure.gca() self.axes.cla() openButton.Bind(wx.EVT_BUTTON, self.openFile) sureButton.Bind(wx.EVT_BUTTON, self.sureWords) submitButton.Bind(wx.EVT_BUTTON, self.submit)
def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, size=(800, 600)) self.panel = wx.Panel(self) self.fig = mplfig.Figure(figsize=(5, 4), dpi=100) self.ax = self.fig.add_subplot(111) self.vbox = wx.BoxSizer(wx.VERTICAL) self.canvas = mwx.FigureCanvasWxAgg(self.panel, wx.ID_ANY, self.fig) self.toolbar = mwx.NavigationToolbar2WxAgg(self.canvas) self.button = wx.Button(self.panel, wx.ID_ANY, "Quit") self.vbox.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.vbox.Add(self.toolbar, 0, wx.EXPAND) self.vbox.Add(self.button, 0, border=3, flag=wx.ALIGN_LEFT | wx.ALL | wx.ALIGN_CENTER_VERTICAL) self.panel.SetSizer(self.vbox) self.vbox.Fit(self) self.toolbar.update() self.update = self.animate().next self.timer = wx.Timer(self) self.timer.Start(1) self.Bind(wx.EVT_BUTTON, self.OnCloseWindow, self.button) self.Bind(wx.EVT_TIMER, lambda event: self.update()) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def run_mouse(self, background_image, image_set_number): """Define a grid by running the UI Returns a CPGridInfo object """ import matplotlib import matplotlib.backends.backend_wxagg as backend import wx from wx.lib.intctrl import IntCtrl # # Make up a dialog box. It has the following structure: # # Dialog: # top_sizer: # Canvas # Figure # Axis # control_sizer # first_sizer # first_row # first_col # second_sizer # second_row # second_col # button_sizer # Redisplay # OK # cancel # status bar # figure = matplotlib.figure.Figure() frame = wx.Dialog(wx.GetApp().TopWindow, title="Select grid cells, image cycle #%d:" % (image_set_number)) top_sizer = wx.BoxSizer(wx.VERTICAL) frame.SetSizer(top_sizer) canvas = backend.FigureCanvasWxAgg(frame, -1, figure) top_sizer.Add(canvas, 1, wx.EXPAND) top_sizer.Add( wx.StaticText( frame, -1, "Select the center of a grid cell with the left mouse button.\n", ), 0, wx.EXPAND | wx.ALL, 5, ) control_sizer = wx.BoxSizer(wx.HORIZONTAL) top_sizer.Add(control_sizer, 0, wx.EXPAND | wx.ALL, 5) FIRST_CELL = "First cell" SECOND_CELL = "Second cell" cell_choice = wx.RadioBox( frame, label="Choose current cell", choices=[FIRST_CELL, SECOND_CELL], style=wx.RA_VERTICAL, ) control_sizer.Add(cell_choice) # # Text boxes for the first cell's row and column # first_sizer = wx.GridBagSizer(2, 2) control_sizer.Add(first_sizer, 1, wx.EXPAND | wx.ALL, 5) first_sizer.Add( wx.StaticText(frame, -1, "First cell column:"), wx.GBPosition(0, 0), flag=wx.EXPAND, ) first_column = IntCtrl(frame, -1, 1, min=1, max=self.grid_columns.value) first_sizer.Add(first_column, wx.GBPosition(0, 1), flag=wx.EXPAND) first_sizer.Add( wx.StaticText(frame, -1, "First cell row:"), wx.GBPosition(1, 0), flag=wx.EXPAND, ) first_row = IntCtrl(frame, -1, 1, min=1, max=self.grid_rows.value) first_sizer.Add(first_row, wx.GBPosition(1, 1), flag=wx.EXPAND) first_sizer.Add(wx.StaticText(frame, -1, "X:"), wx.GBPosition(0, 2)) first_x = IntCtrl(frame, -1, 100, min=1) first_sizer.Add(first_x, wx.GBPosition(0, 3)) first_sizer.Add(wx.StaticText(frame, -1, "Y:"), wx.GBPosition(1, 2)) first_y = IntCtrl(frame, -1, 100, min=1) first_sizer.Add(first_y, wx.GBPosition(1, 3)) # # Text boxes for the second cell's row and column # second_sizer = wx.GridBagSizer(2, 2) control_sizer.Add(second_sizer, 1, wx.EXPAND | wx.ALL, 5) second_sizer.Add( wx.StaticText(frame, -1, "Second cell column:"), wx.GBPosition(0, 0), flag=wx.EXPAND, ) second_column = IntCtrl(frame, -1, self.grid_columns.value, min=1, max=self.grid_columns.value) second_sizer.Add(second_column, wx.GBPosition(0, 1), flag=wx.EXPAND) second_sizer.Add( wx.StaticText(frame, -1, "Second cell row:"), wx.GBPosition(1, 0), flag=wx.EXPAND, ) second_row = IntCtrl(frame, -1, self.grid_rows.value, min=1, max=self.grid_rows.value) second_sizer.Add(second_row, wx.GBPosition(1, 1), flag=wx.EXPAND) second_sizer.Add(wx.StaticText(frame, -1, "X:"), wx.GBPosition(0, 2)) second_x = IntCtrl(frame, -1, 200, min=1) second_sizer.Add(second_x, wx.GBPosition(0, 3)) second_sizer.Add(wx.StaticText(frame, -1, "Y:"), wx.GBPosition(1, 2)) second_y = IntCtrl(frame, -1, 200, min=1) second_sizer.Add(second_y, wx.GBPosition(1, 3)) # # Buttons # button_sizer = wx.BoxSizer(wx.VERTICAL) control_sizer.Add(button_sizer, 0, wx.EXPAND | wx.ALL, 5) redisplay_button = wx.Button(frame, -1, "Redisplay") button_sizer.Add(redisplay_button) button_sizer.Add(wx.Button(frame, wx.OK, "OK")) button_sizer.Add(wx.Button(frame, wx.CANCEL, "Cancel")) # # Status bar # status_bar = wx.StatusBar(frame, style=0) top_sizer.Add(status_bar, 0, wx.EXPAND) status_bar.SetFieldsCount(1) SELECT_FIRST_CELL = "Select the center of the first cell" SELECT_SECOND_CELL = "Select the center of the second cell" status_bar.SetStatusText(SELECT_FIRST_CELL) status = [wx.OK] gridding = [None] if self.display_image_name == "Leave blank": image_shape = None else: image_shape = background_image.shape[:2] def redisplay(event): figure.clf() axes = figure.add_subplot(1, 1, 1) if (event is not None) or (gridding[0] is None): do_gridding(first_x.Value, first_y.Value, second_x.Value, second_y.Value) self.display_grid(background_image, gridding[0], image_set_number, axes) canvas.draw() def cancel(event): status[0] = wx.CANCEL frame.SetReturnCode(wx.CANCEL) frame.Close(True) def ok(event): status[0] = wx.OK frame.SetReturnCode(wx.OK) frame.Close(True) def on_cell_selection(event): if cell_choice.Selection == 0: status_bar.SetStatusText(SELECT_FIRST_CELL) else: status_bar.SetStatusText(SELECT_SECOND_CELL) def do_gridding(x1, y1, x2, y2): try: gridding[0] = self.build_grid_info( int(x1), int(y1), int(first_row.Value), int(first_column.Value), int(x2), int(y2), int(second_row.Value), int(second_column.Value), image_shape, ) except Exception as e: logger.error(e.message, exc_info=True) status_bar.SetStatusText(e.message) return False return True def button_release(event): if event.inaxes == figure.axes[0]: if cell_choice.Selection == 0: new_first_x = str(int(event.xdata)) new_first_y = str(int(event.ydata)) if do_gridding(new_first_x, new_first_y, second_x.Value, second_y.Value): first_x.Value = new_first_x first_y.Value = new_first_y cell_choice.Selection = 1 status_bar.SetStatusText(SELECT_SECOND_CELL) else: new_second_x = str(int(event.xdata)) new_second_y = str(int(event.ydata)) if do_gridding(first_x.Value, first_y.Value, new_second_x, new_second_y): second_x.Value = new_second_x second_y.Value = new_second_y cell_choice.Selection = 0 status_bar.SetStatusText(SELECT_FIRST_CELL) redisplay(None) redisplay(None) frame.Fit() frame.Bind(wx.EVT_BUTTON, redisplay, redisplay_button) frame.Bind(wx.EVT_BUTTON, cancel, id=wx.CANCEL) frame.Bind(wx.EVT_BUTTON, ok, id=wx.OK) frame.Bind(wx.EVT_RADIOBOX, on_cell_selection, cell_choice) canvas.mpl_connect("button_release_event", button_release) frame.ShowModal() do_gridding(first_x.Value, first_y.Value, second_x.Value, second_y.Value) frame.Destroy() if status[0] != wx.OK: raise RuntimeError("Pipeline aborted during grid editing") return gridding[0]
def run_mouse(self, background_image, image_set_number): '''Define a grid by running the UI Returns a CPGridInfo object ''' import matplotlib import matplotlib.backends.backend_wxagg as backend import wx from wx.lib.intctrl import IntCtrl # # Make up a dialog box. It has the following structure: # # Dialog: # top_sizer: # Canvas # Figure # Axis # control_sizer # first_sizer # first_row # first_col # second_sizer # second_row # second_col # button_sizer # Redisplay # OK # cancel # status bar # figure = matplotlib.figure.Figure() frame = wx.Dialog(wx.GetApp().TopWindow, title="Select grid cells") top_sizer = wx.BoxSizer(wx.VERTICAL) frame.SetSizer(top_sizer) canvas = backend.FigureCanvasWxAgg(frame, -1, figure) top_sizer.Add(canvas, 1, wx.EXPAND) top_sizer.Add( wx.StaticText( frame, -1, "Select the center of a grid cell with the left mouse button.\n" ), 0, wx.EXPAND | wx.ALL, 5) control_sizer = wx.BoxSizer(wx.HORIZONTAL) top_sizer.Add(control_sizer, 0, wx.EXPAND | wx.ALL, 5) FIRST_CELL = "First cell" SECOND_CELL = "Second cell" cell_choice = wx.RadioBox(frame, label="Choose current cell", choices=[FIRST_CELL, SECOND_CELL], style=wx.RA_VERTICAL) control_sizer.Add(cell_choice) # # Text boxes for the first cell's row and column # first_sizer = wx.GridBagSizer(2, 2) control_sizer.Add(first_sizer, 1, wx.EXPAND | wx.ALL, 5) first_sizer.Add(wx.StaticText(frame, -1, "First cell column:"), wx.GBPosition(0, 0), flag=wx.EXPAND) first_column = IntCtrl(frame, -1, 1, min=1, max=self.grid_columns.value) first_sizer.Add(first_column, wx.GBPosition(0, 1), flag=wx.EXPAND) first_sizer.Add(wx.StaticText(frame, -1, "First cell row:"), wx.GBPosition(1, 0), flag=wx.EXPAND) first_row = IntCtrl(frame, -1, 1, min=1, max=self.grid_rows.value) first_sizer.Add(first_row, wx.GBPosition(1, 1), flag=wx.EXPAND) first_sizer.Add(wx.StaticText(frame, -1, "X:"), wx.GBPosition(0, 2)) first_x = IntCtrl(frame, -1, 100, min=1) first_sizer.Add(first_x, wx.GBPosition(0, 3)) first_sizer.Add(wx.StaticText(frame, -1, "Y:"), wx.GBPosition(1, 2)) first_y = IntCtrl(frame, -1, 100, min=1) first_sizer.Add(first_y, wx.GBPosition(1, 3)) # # Text boxes for the second cell's row and column # second_sizer = wx.GridBagSizer(2, 2) control_sizer.Add(second_sizer, 1, wx.EXPAND | wx.ALL, 5) second_sizer.Add(wx.StaticText(frame, -1, "Second cell column:"), wx.GBPosition(0, 0), flag=wx.EXPAND) second_column = IntCtrl(frame, -1, self.grid_columns.value, min=1, max=self.grid_columns.value) second_sizer.Add(second_column, wx.GBPosition(0, 1), flag=wx.EXPAND) second_sizer.Add(wx.StaticText(frame, -1, "Second cell row:"), wx.GBPosition(1, 0), flag=wx.EXPAND) second_row = IntCtrl(frame, -1, self.grid_rows.value, min=1, max=self.grid_rows.value) second_sizer.Add(second_row, wx.GBPosition(1, 1), flag=wx.EXPAND) second_sizer.Add(wx.StaticText(frame, -1, "X:"), wx.GBPosition(0, 2)) second_x = IntCtrl(frame, -1, 200, min=1) second_sizer.Add(second_x, wx.GBPosition(0, 3)) second_sizer.Add(wx.StaticText(frame, -1, "Y:"), wx.GBPosition(1, 2)) second_y = IntCtrl(frame, -1, 200, min=1) second_sizer.Add(second_y, wx.GBPosition(1, 3)) # # Buttons # button_sizer = wx.BoxSizer(wx.VERTICAL) control_sizer.Add(button_sizer, 0, wx.EXPAND | wx.ALL, 5) redisplay_button = wx.Button(frame, -1, "Redisplay") button_sizer.Add(redisplay_button) button_sizer.Add(wx.Button(frame, wx.OK, "OK")) button_sizer.Add(wx.Button(frame, wx.CANCEL, "Cancel")) # # Status bar # status_bar = wx.StatusBar(frame, style=0) top_sizer.Add(status_bar, 0, wx.EXPAND) status_bar.SetFieldsCount(1) SELECT_FIRST_CELL = "Select the center of the first cell" SELECT_SECOND_CELL = "Select the center of the second cell" status_bar.SetStatusText(SELECT_FIRST_CELL) status = [wx.OK] gridding = [None] if self.display_image_name == cps.LEAVE_BLANK: image_shape = None else: image_shape = background_image.shape[:2] def redisplay(event): figure.clf() axes = figure.add_subplot(1, 1, 1) if (event is not None) or (gridding[0] is None): do_gridding(first_x.Value, first_y.Value, second_x.Value, second_y.Value) self.display_grid(background_image, gridding[0], image_set_number, axes) canvas.draw() def cancel(event): status[0] = wx.CANCEL frame.SetReturnCode(wx.CANCEL) frame.Close(True) def ok(event): status[0] = wx.OK frame.SetReturnCode(wx.OK) frame.Close(True) def on_cell_selection(event): if cell_choice.Selection == 0: status_bar.SetStatusText(SELECT_FIRST_CELL) else: status_bar.SetStatusText(SELECT_SECOND_CELL) def do_gridding(x1, y1, x2, y2): try: gridding[0] = self.build_grid_info(int(x1), int(y1), int(first_row.Value), int(first_column.Value), int(x2), int(y2), int(second_row.Value), int(second_column.Value), image_shape) except Exception, e: logger.error(e.message, exc_info=True) status_bar.SetStatusText(e.message) return False return True
def __init__(self, parent=None): super().__init__(parent, title='Linear Regression', size=(800, 800)) self.zoom = zoom.Zoom() # Global variables self.reset_bounds = True # True if bounds have been reset by changing variables self.update_graph = True # True if graph needs to be updated self.update_table = True # True if data tables need to be updated self.user_bounds = False # True if the user bounds should be used self.user_update = False # True if the user bounds have been updated self.box_dirty = False # True if textboxes have been modified # Sizers self.panel = wx.Panel(self) self.sizer = wx.BoxSizer(wx.VERTICAL) # Main sizer self.panel.SetSizer(self.sizer) top_sizer = wx.BoxSizer( wx.HORIZONTAL) # Sizer to divide screen into left and right halves self.sizer.Add(top_sizer, 0) ctl_sizer = wx.BoxSizer( wx.VERTICAL) # Sizer for the controls on left size of the screen top_sizer.Add(ctl_sizer, 0) zoom_sizer = wx.BoxSizer(wx.HORIZONTAL) # Sizer for the zoom controls self.right_sizer = wx.BoxSizer( wx.VERTICAL) # Sizer for the right half of the window # Variables title ctl_sizer.Add(wx.StaticText(self.panel, -1, 'Variables:'), flag=wx.TOP | wx.LEFT | wx.RIGHT, border=20) # Get choices for independent and dependent variables self.data = Project.get().all_data data_choices = [n.data.data_name for n in self.data] # Independent variable ctl_sizer.Add(wx.StaticText(self.panel, -1, 'Independent variable(s):'), flag=wx.TOP | wx.LEFT | wx.RIGHT, border=12) self.iv_chooser = wx.ListBox(self.panel, choices=data_choices, style=wx.LB_EXTENDED) ctl_sizer.Add(self.iv_chooser, flag=wx.LEFT | wx.RIGHT, border=12) # Dependent variable ctl_sizer.Add(wx.StaticText(self.panel, -1, 'Dependent variable:'), flag=wx.TOP | wx.LEFT | wx.RIGHT, border=12) self.dv_chooser = wx.Choice(self.panel, choices=['-'] + data_choices) ctl_sizer.Add(self.dv_chooser, flag=wx.LEFT | wx.RIGHT, border=12) # Plot type ctl_sizer.Add(wx.StaticText(self.panel, -1, 'Plot type:'), flag=wx.TOP | wx.LEFT | wx.RIGHT, border=12) self.plot_type = wx.RadioBox(self.panel, choices=['Scatterplot', 'Heatmap']) ctl_sizer.Add(self.plot_type, flag=wx.LEFT | wx.RIGHT, border=10) # Axis type ctl_sizer.Add(wx.StaticText(self.panel, -1, 'Axis type:'), flag=wx.TOP | wx.LEFT | wx.RIGHT, border=12) self.axis_type = wx.RadioBox(self.panel, choices=['Fit All', 'Adaptive', 'Zoom']) ctl_sizer.Add(self.axis_type, flag=wx.LEFT | wx.RIGHT, border=10) self.Bind(wx.EVT_RADIOBOX, self.on_axis_change) # User Bounds x_full_sizer = wx.BoxSizer(wx.VERTICAL) x_full_sizer.Add(wx.StaticText(self.panel, -1, 'X-axis:'), flag=wx.TOP, border=15) self.bound_box_max_length = 6 x_sizer = wx.BoxSizer(wx.HORIZONTAL) self.box_x_min = wx.TextCtrl(self.panel, -1, size=(50, 20), value="", style=wx.TE_PROCESS_ENTER) self.box_x_min.SetMaxLength(self.bound_box_max_length) x_sizer.Add(self.box_x_min, flag=wx.LEFT, border=10) self.box_x_max = wx.TextCtrl(self.panel, -1, size=(50, 20), value="", style=wx.TE_PROCESS_ENTER) self.box_x_max.SetMaxLength(self.bound_box_max_length) x_sizer.Add(self.box_x_max, flag=wx.LEFT, border=5) x_full_sizer.Add(x_sizer, flag=wx.LEFT | wx.TOP, border=0) y_full_sizer = wx.BoxSizer(wx.VERTICAL) y_full_sizer.Add(wx.StaticText(self.panel, -1, 'Y-axis:'), flag=wx.TOP, border=15) y_sizer = wx.BoxSizer(wx.HORIZONTAL) self.box_y_min = wx.TextCtrl(self.panel, -1, size=(50, 20), value="", style=wx.TE_PROCESS_ENTER) self.box_y_min.SetMaxLength(self.bound_box_max_length) y_sizer.Add(self.box_y_min, flag=wx.LEFT, border=10) self.box_y_max = wx.TextCtrl(self.panel, -1, size=(50, 20), value="", style=wx.TE_PROCESS_ENTER) self.box_y_max.SetMaxLength(self.bound_box_max_length) y_sizer.Add(self.box_y_max, flag=wx.LEFT, border=5) y_full_sizer.Add(y_sizer) text_box_sizer = wx.BoxSizer(wx.HORIZONTAL) text_box_sizer.Add(x_full_sizer, flag=wx.LEFT, border=15) text_box_sizer.Add(y_full_sizer, flag=wx.LEFT, border=15) ctl_sizer.Add(text_box_sizer) self.Bind(wx.EVT_TEXT, self.on_text) self.Bind(wx.EVT_TEXT_ENTER, self.on_enter) self.default_box = wx.Button(self.panel, label="Default") ctl_sizer.Add(self.default_box, flag=wx.LEFT | wx.TOP, border=15) self.default_box.Bind(wx.EVT_BUTTON, self.on_default_box_button) # Blank spacer ctl_sizer.AddSpacer(130) # Zoom controls # Zoom button for dragging a box self.zoom_box = wx.Button(self.panel, label="Box Zoom") zoom_sizer.Add(self.zoom_box) self.zoom_box.Bind(wx.EVT_BUTTON, self.on_zoom_box_button) # Zoom slider self.zoom_slider = wx.Slider(self.panel, value=0, minValue=0, maxValue=49 * self.zoom.zoom_multiple, size=(600, -1), style=wx.SL_HORIZONTAL) zoom_sizer.Add(self.zoom_slider, flag=wx.LEFT, border=10) self.zoom_slider.Bind(wx.EVT_SCROLL, self.on_zoom_scroll) # Graph canvas self.fig = mpl.figure.Figure() self.canvas = wxagg.FigureCanvasWxAgg(self.panel, -1, self.fig) self.right_sizer.Add(self.canvas, 1, wx.EXPAND) self.right_sizer.Add(zoom_sizer, flag=wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, border=10) top_sizer.Add(self.right_sizer) # Events self.Bind(wx.EVT_LISTBOX, self.on_var_change) self.Bind(wx.EVT_CHOICE, self.on_var_change) self.Bind(wx.EVT_CLOSE, self.on_close) # Move along with timeline get_main_window().Bind(EVT_TIMELINE_CHANGED, self.on_timeline_change) # Mouse events on graph (Matplotlib events) self.fig.canvas.mpl_connect('button_press_event', self.on_mouse_press) self.fig.canvas.mpl_connect('button_release_event', self.on_mouse_release) self.fig.canvas.mpl_connect('motion_notify_event', self.on_mouse_move) # Open in the center of VISTAS main window self.CenterOnParent() self.panel.Layout() self.Show()