def make_new_figure(self): chname = self.fv.get_channel_name(self.fitsimage) wd, ht = 400, 300 self._plot_idx += 1 self._plot = plots.Plot(logger=self.logger, width=wd, height=ht) name = "%s: Fig %d" % (chname, self._plot_idx) group = 10 pw = Plot.PlotWidget(self._plot) vbox = Widgets.VBox() vbox.add_widget(pw, stretch=1) hbox = Widgets.HBox() hbox.add_widget(Widgets.Label(''), stretch=1) btn = Widgets.Button('Close Plot') btn.add_callback('activated', lambda w: self.close_plot(name, vbox)) hbox.add_widget(btn, stretch=0) vbox.add_widget(hbox, stretch=0) #vbox.resize(wd, ht) self._plot_w = vbox if self._plots_in_ws: ws = self.fv.get_current_workspace() tab = self.fv.ds.add_tab(ws.name, vbox, group, name, name, data=dict(plot=self._plot)) else: self.nb.add_widget(vbox, name) # imexam should get a clean figure fig = self._plot.get_figure() fig.clf()
def build_gui(self, container): if not have_mpl: raise ImportError('Install matplotlib to use this plugin') top = Widgets.VBox() top.set_border_width(4) # Make the cuts plot box, sw, orientation = Widgets.get_oriented_box(container) box.set_border_width(4) box.set_spacing(2) paned = Widgets.Splitter(orientation=orientation) self.w.splitter = paned self.plot = plots.Plot(logger=self.logger, width=400, height=400) ax = self.plot.add_axis() ax.grid(True) w = Plot.PlotWidget(self.plot) w.resize(400, 400) paned.add_widget(Widgets.hadjust(w, orientation)) captions = (('Cut Low:', 'label', 'Cut Low', 'entry'), ('Cut High:', 'label', 'Cut High', 'entry', 'Cut Levels', 'button'), ('Auto Levels', 'button'), ('Log Histogram', 'checkbutton', 'Plot By Cuts', 'checkbutton'), ('NumBins:', 'label', 'NumBins', 'entry'), ('Full Image', 'button'), ) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) b.cut_levels.set_tooltip("Set cut levels manually") b.auto_levels.set_tooltip("Set cut levels by algorithm") b.cut_low.set_tooltip("Set low cut level (press Enter)") b.cut_high.set_tooltip("Set high cut level (press Enter)") b.log_histogram.set_tooltip("Use the log of the pixel values for the " "histogram (empty bins map to 10^-1)") b.plot_by_cuts.set_tooltip("Only show the part of the histogram " "between the cuts") b.numbins.set_tooltip("Number of bins for the histogram") b.full_image.set_tooltip("Use the full image for calculating the " "histogram") b.numbins.set_text(str(self.numbins)) b.cut_low.add_callback('activated', lambda w: self.cut_levels()) b.cut_high.add_callback('activated', lambda w: self.cut_levels()) b.cut_levels.add_callback('activated', lambda w: self.cut_levels()) b.auto_levels.add_callback('activated', lambda w: self.auto_levels()) b.log_histogram.set_state(self.plot.logy) b.log_histogram.add_callback('activated', self.log_histogram_cb) b.plot_by_cuts.set_state(self.xlimbycuts) b.plot_by_cuts.add_callback('activated', self.plot_by_cuts_cb) b.numbins.add_callback('activated', lambda w: self.set_numbins_cb()) b.full_image.add_callback('activated', lambda w: self.full_image_cb()) fr = Widgets.Frame("Histogram") fr.set_widget(w) box.add_widget(fr, stretch=0) paned.add_widget(sw) paned.set_sizes(self._split_sizes) mode = self.canvas.get_draw_mode() hbox = Widgets.HBox() btn1 = Widgets.RadioButton("Move") btn1.set_state(mode == 'move') btn1.add_callback('activated', lambda w, val: self.set_mode_cb('move', val)) btn1.set_tooltip("Choose this to position box") self.w.btn_move = btn1 hbox.add_widget(btn1) btn2 = Widgets.RadioButton("Draw", group=btn1) btn2.set_state(mode == 'draw') btn2.add_callback('activated', lambda w, val: self.set_mode_cb('draw', val)) btn2.set_tooltip("Choose this to draw a replacement box") self.w.btn_draw = btn2 hbox.add_widget(btn2) btn3 = Widgets.RadioButton("Edit", group=btn1) btn3.set_state(mode == 'edit') btn3.add_callback('activated', lambda w, val: self.set_mode_cb('edit', val)) btn3.set_tooltip("Choose this to edit a box") self.w.btn_edit = btn3 hbox.add_widget(btn3) if self.histtag is None: self.w.btn_move.set_enabled(False) self.w.btn_edit.set_enabled(False) hbox.add_widget(Widgets.Label(''), stretch=1) top.add_widget(paned, stretch=5) top.add_widget(hbox, stretch=0) btns = Widgets.HBox() btns.set_border_width(4) btns.set_spacing(3) btn = Widgets.Button("Close") btn.add_callback('activated', lambda w: self.close()) btns.add_widget(btn, stretch=0) btn = Widgets.Button("Help") btn.add_callback('activated', lambda w: self.help()) btns.add_widget(btn, stretch=0) btns.add_widget(Widgets.Label(''), stretch=1) top.add_widget(btns, stretch=0) container.add_widget(top, stretch=1) self.gui_up = True
def build_gui(self, container): top = Widgets.VBox() top.set_border_width(4) # Make the cuts plot vbox, sw, orientation = Widgets.get_oriented_box(container) vbox.set_margins(4, 4, 4, 4) vbox.set_spacing(2) msgFont = self.fv.getFont("sansFont", 12) tw = Widgets.TextArea(wrap=True, editable=False) tw.set_font(msgFont) self.tw = tw fr = Widgets.Expander("Instructions") fr.set_widget(tw) vbox.add_widget(fr, stretch=0) # Add Tab Widget nb = Widgets.TabWidget(tabpos='top') vbox.add_widget(nb, stretch=1) self.cuts_plot = plots.CutsPlot(logger=self.logger, width=400, height=400) self.plot = Plot.PlotWidget(self.cuts_plot) self.plot.resize(400, 400) ax = self.cuts_plot.add_axis() ax.grid(True) self.slit_plot = plots.Plot(logger=self.logger, width=400, height=400) self.slit_plot.add_axis(axisbg='black') self.plot2 = Plot.PlotWidget(self.slit_plot) self.plot2.resize(400, 400) captions = (('Cut:', 'label', 'Cut', 'combobox', 'New Cut Type:', 'label', 'Cut Type', 'combobox'), ('Delete Cut', 'button', 'Delete All', 'button'), ('Save', 'button'), ) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) # control for selecting a cut combobox = b.cut for tag in self.tags: combobox.append_text(tag) combobox.show_text(self.cutstag) combobox.add_callback('activated', self.cut_select_cb) self.w.cuts = combobox combobox.set_tooltip("Select a cut to redraw or delete") # control for selecting cut type combobox = b.cut_type for cuttype in self.cuttypes: combobox.append_text(cuttype) self.w.cuts_type = combobox index = self.cuttypes.index(self.cuttype) combobox.set_index(index) combobox.add_callback('activated', self.set_cutsdrawtype_cb) combobox.set_tooltip("Choose the cut type to draw") self.save_cuts = b.save self.save_cuts.set_tooltip("Save cuts plot and data") self.save_cuts.add_callback('activated', lambda w: self.save_cb(mode='cuts')) self.save_cuts.set_enabled(self.save_enabled) btn = b.delete_cut btn.add_callback('activated', self.delete_cut_cb) btn.set_tooltip("Delete selected cut") btn = b.delete_all btn.add_callback('activated', self.delete_all_cb) btn.set_tooltip("Clear all cuts") vbox2 = Widgets.VBox() vbox2.add_widget(w, stretch=0) exp = Widgets.Expander("Cut Width") captions = (('Width Type:', 'label', 'Width Type', 'combobox', 'Width radius:', 'label', 'Width radius', 'spinbutton'), ) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) # control for selecting width cut type combobox = b.width_type for atype in self.widthtypes: combobox.append_text(atype) index = self.widthtypes.index(self.widthtype) combobox.set_index(index) combobox.add_callback('activated', self.set_width_type_cb) combobox.set_tooltip("Direction of summation orthogonal to cut") sb = b.width_radius sb.add_callback('value-changed', self.width_radius_changed_cb) sb.set_tooltip("Radius of cut width") sb.set_limits(1, 100) sb.set_value(self.width_radius) fr = Widgets.Frame() fr.set_widget(w) exp.set_widget(fr) vbox2.add_widget(exp, stretch=0) mode = self.canvas.get_draw_mode() hbox = Widgets.HBox() btn1 = Widgets.RadioButton("Move") btn1.set_state(mode == 'move') btn1.add_callback('activated', lambda w, val: self.set_mode_cb('move', val)) btn1.set_tooltip("Choose this to position cuts") self.w.btn_move = btn1 hbox.add_widget(btn1) btn2 = Widgets.RadioButton("Draw", group=btn1) btn2.set_state(mode == 'draw') btn2.add_callback('activated', lambda w, val: self.set_mode_cb('draw', val)) btn2.set_tooltip("Choose this to draw a new or replacement cut") self.w.btn_draw = btn2 hbox.add_widget(btn2) btn3 = Widgets.RadioButton("Edit", group=btn1) btn3.set_state(mode == 'edit') btn3.add_callback('activated', lambda w, val: self.set_mode_cb('edit', val)) btn3.set_tooltip("Choose this to edit a cut") self.w.btn_edit = btn3 hbox.add_widget(btn3) hbox.add_widget(Widgets.Label(''), stretch=1) vbox2.add_widget(hbox, stretch=0) vbox2.add_widget(Widgets.Label(''), stretch=1) vbox.add_widget(vbox2, stretch=0) # Add Cuts plot to its tab vbox_cuts = Widgets.VBox() vbox_cuts.add_widget(self.plot, stretch=1) nb.add_widget(vbox_cuts, title="Cuts") if self.use_slit: captions = (("Transpose Plot", 'checkbutton', "Save", 'button'), ) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) self.t_btn = b.transpose_plot self.t_btn.set_tooltip("Flip the plot") self.t_btn.set_state(self.transpose_enabled) self.t_btn.add_callback('activated', self.transpose_plot) self.save_slit = b.save self.save_slit.set_tooltip("Save slit plot and data") self.save_slit.add_callback('activated', lambda w: self.save_cb(mode='slit')) self.save_slit.set_enabled(self.save_enabled) # Add frame to hold the slit controls fr = Widgets.Frame("Axes controls") self.hbox_axes = Widgets.HBox() self.hbox_axes.set_border_width(4) self.hbox_axes.set_spacing(1) fr.set_widget(self.hbox_axes) # Add Slit plot and controls to its tab vbox_slit = Widgets.VBox() vbox_slit.add_widget(self.plot2, stretch=1) vbox_slit.add_widget(w) vbox_slit.add_widget(fr) nb.add_widget(vbox_slit, title="Slit") top.add_widget(sw, stretch=1) btns = Widgets.HBox() btns.set_border_width(4) btns.set_spacing(3) btn = Widgets.Button("Close") btn.add_callback('activated', lambda w: self.close()) btns.add_widget(btn, stretch=0) btns.add_widget(Widgets.Label(''), stretch=1) top.add_widget(btns, stretch=0) container.add_widget(top, stretch=1) self.select_cut(self.cutstag) self.gui_up = True if self.use_slit: self.build_axes()
def build_gui(self, container): if not have_mpl: raise ImportError('Install matplotlib to use this plugin') top = Widgets.VBox() top.set_border_width(4) # Make the cuts plot box, sw, orientation = Widgets.get_oriented_box(container) box.set_margins(4, 4, 4, 4) box.set_spacing(2) paned = Widgets.Splitter(orientation=orientation) # Add Tab Widget nb = Widgets.TabWidget(tabpos='top') paned.add_widget(Widgets.hadjust(nb, orientation)) self.cuts_plot = plots.CutsPlot(logger=self.logger, width=400, height=400) self.plot = Plot.PlotWidget(self.cuts_plot) self.plot.resize(400, 400) ax = self.cuts_plot.add_axis() ax.grid(True) self.slit_plot = plots.Plot(logger=self.logger, width=400, height=400) if plots.MPL_GE_2_0: kwargs = {'facecolor': 'black'} else: kwargs = {'axisbg': 'black'} self.slit_plot.add_axis(**kwargs) self.plot2 = Plot.PlotWidget(self.slit_plot) self.plot2.resize(400, 400) captions = ( ('Cut:', 'label', 'Cut', 'combobox', 'New Cut Type:', 'label', 'Cut Type', 'combobox'), ('Delete Cut', 'button', 'Delete All', 'button'), ('Save', 'button'), ) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) # control for selecting a cut combobox = b.cut for tag in self.tags: combobox.append_text(tag) combobox.show_text(self.cutstag) combobox.add_callback('activated', self.cut_select_cb) self.w.cuts = combobox combobox.set_tooltip("Select a cut to redraw or delete") # control for selecting cut type combobox = b.cut_type for cuttype in self.cuttypes: combobox.append_text(cuttype) self.w.cuts_type = combobox index = self.cuttypes.index(self.cuttype) combobox.set_index(index) combobox.add_callback('activated', self.set_cutsdrawtype_cb) combobox.set_tooltip("Choose the cut type to draw") self.save_cuts = b.save self.save_cuts.set_tooltip("Save cuts plot and data") self.save_cuts.add_callback('activated', lambda w: self.save_cb(mode='cuts')) self.save_cuts.set_enabled(self.save_enabled) btn = b.delete_cut btn.add_callback('activated', self.delete_cut_cb) btn.set_tooltip("Delete selected cut") btn = b.delete_all btn.add_callback('activated', self.delete_all_cb) btn.set_tooltip("Clear all cuts") fr = Widgets.Frame("Cuts") fr.set_widget(w) box.add_widget(fr, stretch=0) exp = Widgets.Expander("Cut Width") captions = (('Width Type:', 'label', 'Width Type', 'combobox', 'Width radius:', 'label', 'Width radius', 'spinbutton'), ) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) # control for selecting width cut type combobox = b.width_type for atype in self.widthtypes: combobox.append_text(atype) index = self.widthtypes.index(self.widthtype) combobox.set_index(index) combobox.add_callback('activated', self.set_width_type_cb) combobox.set_tooltip("Direction of summation orthogonal to cut") sb = b.width_radius sb.add_callback('value-changed', self.width_radius_changed_cb) sb.set_tooltip("Radius of cut width") sb.set_limits(1, 100) sb.set_value(self.width_radius) fr = Widgets.Frame() fr.set_widget(w) exp.set_widget(fr) box.add_widget(exp, stretch=0) box.add_widget(Widgets.Label(''), stretch=1) paned.add_widget(sw) # hack to set a reasonable starting position for the splitter paned.set_sizes([400, 500]) top.add_widget(paned, stretch=5) mode = self.canvas.get_draw_mode() hbox = Widgets.HBox() btn1 = Widgets.RadioButton("Move") btn1.set_state(mode == 'move') btn1.add_callback('activated', lambda w, val: self.set_mode_cb('move', val)) btn1.set_tooltip("Choose this to position cuts") self.w.btn_move = btn1 hbox.add_widget(btn1) btn2 = Widgets.RadioButton("Draw", group=btn1) btn2.set_state(mode == 'draw') btn2.add_callback('activated', lambda w, val: self.set_mode_cb('draw', val)) btn2.set_tooltip("Choose this to draw a new or replacement cut") self.w.btn_draw = btn2 hbox.add_widget(btn2) btn3 = Widgets.RadioButton("Edit", group=btn1) btn3.set_state(mode == 'edit') btn3.add_callback('activated', lambda w, val: self.set_mode_cb('edit', val)) btn3.set_tooltip("Choose this to edit a cut") self.w.btn_edit = btn3 hbox.add_widget(btn3) hbox.add_widget(Widgets.Label(''), stretch=1) top.add_widget(hbox, stretch=0) # Add Cuts plot to its tab vbox_cuts = Widgets.VBox() vbox_cuts.add_widget(self.plot, stretch=1) nb.add_widget(vbox_cuts, title="Cuts") captions = (("Enable Slit", 'checkbutton', "Transpose Plot", 'checkbutton', "Save", 'button'), ) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) def chg_enable_slit(w, val): self.use_slit = val if val: self.build_axes() return True b.enable_slit.set_state(self.use_slit) b.enable_slit.set_tooltip("Enable the slit function") b.enable_slit.add_callback('activated', chg_enable_slit) self.t_btn = b.transpose_plot self.t_btn.set_tooltip("Flip the plot") self.t_btn.set_state(self.transpose_enabled) self.t_btn.add_callback('activated', self.transpose_plot) self.save_slit = b.save self.save_slit.set_tooltip("Save slit plot and data") self.save_slit.add_callback('activated', lambda w: self.save_cb(mode='slit')) self.save_slit.set_enabled(self.save_enabled) # Add frame to hold the slit controls fr = Widgets.Frame("Axes controls") self.hbox_axes = Widgets.HBox() self.hbox_axes.set_border_width(4) self.hbox_axes.set_spacing(1) fr.set_widget(self.hbox_axes) # Add Slit plot and controls to its tab vbox_slit = Widgets.VBox() vbox_slit.add_widget(self.plot2, stretch=1) vbox_slit.add_widget(w) vbox_slit.add_widget(fr) nb.add_widget(vbox_slit, title="Slit") btns = Widgets.HBox() btns.set_border_width(4) btns.set_spacing(3) btn = Widgets.Button("Close") btn.add_callback('activated', lambda w: self.close()) btns.add_widget(btn, stretch=0) btn = Widgets.Button("Help") btn.add_callback('activated', lambda w: self.help()) btns.add_widget(btn, stretch=0) btns.add_widget(Widgets.Label(''), stretch=1) top.add_widget(btns, stretch=0) container.add_widget(top, stretch=1) self.select_cut(self.cutstag) self.gui_up = True if self.use_slit: self.build_axes()
def build_gui(self, container): if not have_mpl: raise ImportError('Install matplotlib to use this plugin') top = Widgets.VBox() top.set_border_width(4) box, sw, orientation = Widgets.get_oriented_box(container) box.set_border_width(4) box.set_spacing(2) paned = Widgets.Splitter(orientation=orientation) self.plot = plots.Plot(logger=self.logger, width=400, height=400) ax = self.plot.add_axis() ax.grid(True) self._ax2 = self.plot.ax.twiny() w = Plot.PlotWidget(self.plot) w.resize(400, 400) paned.add_widget(Widgets.hadjust(w, orientation)) captions = (('Plot All', 'checkbutton'), ) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) b.plot_all.set_state(False) b.plot_all.add_callback('activated', lambda *args: self.redraw_mark()) b.plot_all.set_tooltip("Plot all marks") box.add_widget(w, stretch=0) fr = Widgets.Frame("Axes controls") self.hbox_axes = Widgets.HBox() self.hbox_axes.set_border_width(4) self.hbox_axes.set_spacing(1) fr.set_widget(self.hbox_axes) box.add_widget(fr, stretch=0) captions = (('marks', 'combobox', 'New Mark Type:', 'label', 'Mark Type', 'combobox'), ('Pan to mark', 'button'), ('Delete', 'button', 'Delete All', 'button')) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) # control for selecting a mark cbox2 = b.marks for tag in self.marks: cbox2.append_text(tag) cbox2.show_text(self.mark_selected) cbox2.add_callback('activated', self.mark_select_cb) self.w.marks = cbox2 cbox2.set_tooltip("Select a mark") # control for selecting mark type cbox2 = b.mark_type for tag in self.mark_types: cbox2.append_text(tag) self.w.marks_type = cbox2 cbox2.set_index(self.mark_types.index(self.mark_type)) cbox2.add_callback('activated', self.set_marksdrawtype_cb) cbox2.set_tooltip("Choose the mark type to draw") b.pan_to_mark.add_callback('activated', self.pan2mark_cb) b.pan_to_mark.set_tooltip("Pan follows selected mark") b.delete.add_callback('activated', self.clear_mark_cb) b.delete.set_tooltip("Delete selected mark") b.delete_all.add_callback('activated', self.clear_all_cb) b.delete_all.set_tooltip("Clear all marks") vbox2 = Widgets.VBox() vbox2.add_widget(w, stretch=0) mode = self.canvas.get_draw_mode() captions = (('Move', 'radiobutton', 'Draw', 'radiobutton', 'Edit', 'radiobutton'), ) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) b.move.set_state(mode == 'move') b.move.add_callback('activated', lambda w, val: self.set_mode_cb('move', val)) b.move.set_tooltip("Choose this to position marks") self.w.btn_move = b.move b.draw.set_state(mode == 'draw') b.draw.add_callback('activated', lambda w, val: self.set_mode_cb('draw', val)) b.draw.set_tooltip("Choose this to draw a new mark") self.w.btn_draw = b.draw b.edit.set_state(mode == 'edit') b.edit.add_callback('activated', lambda w, val: self.set_mode_cb('edit', val)) b.edit.set_tooltip("Choose this to edit a mark") self.w.btn_edit = b.edit vbox2.add_widget(w, stretch=0) fr = Widgets.Frame("Mark controls") fr.set_widget(vbox2) box.add_widget(fr, stretch=0) box.add_widget(Widgets.Label(''), stretch=1) paned.add_widget(sw) # hack to set a reasonable starting position for the splitter paned.set_sizes([400, 500]) top.add_widget(paned, stretch=5) # A button box that is always visible at the bottom btns = Widgets.HBox() btns.set_border_width(4) btns.set_spacing(3) # Add a close button for the convenience of the user btn = Widgets.Button("Close") btn.add_callback('activated', lambda w: self.close()) btns.add_widget(btn, stretch=0) btn = Widgets.Button("Help") btn.add_callback('activated', lambda w: self.help()) btns.add_widget(btn, stretch=0) btns.add_widget(Widgets.Label(''), stretch=1) top.add_widget(btns, stretch=0) # Add our GUI to the container container.add_widget(top, stretch=1) self.gui_up = True self.select_mark(self._new_mark) self.build_axes()
def build_gui(self, container): top = Widgets.VBox() top.set_border_width(4) # Make the cuts plot vbox, sw, orientation = Widgets.get_oriented_box(container) vbox.set_margins(4, 4, 4, 4) vbox.set_spacing(2) # Add Tab Widget nb = Widgets.TabWidget(tabpos='top') vbox.add_widget(nb, stretch=1) self.tab_plot = plots.Plot(logger=self.logger, width=400, height=400) self.plot = Plot.PlotWidget(self.tab_plot) self.plot.resize(400, 400) ax = self.tab_plot.add_axis() ax.grid(True) # Add plot to its tab vbox_plot = Widgets.VBox() vbox_plot.add_widget(self.plot, stretch=1) nb.add_widget(vbox_plot, title='Plot') captions = (('X:', 'label', 'x_combo', 'combobox'), ('Y:', 'label', 'y_combo', 'combobox'), ('Log X', 'checkbutton', 'Log Y', 'checkbutton', 'Show Marker', 'checkbutton'), ('X Low:', 'label', 'x_lo', 'entry'), ('X High:', 'label', 'x_hi', 'entry'), ('Y Low:', 'label', 'y_lo', 'entry'), ('Y High:', 'label', 'y_hi', 'entry'), ('Save', 'button')) w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) # Controls for X-axis column listing combobox = b.x_combo combobox.add_callback('activated', self.x_select_cb) self.w.xcombo = combobox combobox.set_tooltip('Select a column to plot on X-axis') # Controls for Y-axis column listing combobox = b.y_combo combobox.add_callback('activated', self.y_select_cb) self.w.ycombo = combobox combobox.set_tooltip('Select a column to plot on Y-axis') b.log_x.set_state(self.tab_plot.logx) b.log_x.add_callback('activated', self.log_x_cb) b.log_x.set_tooltip('Plot X-axis in log scale') b.log_y.set_state(self.tab_plot.logy) b.log_y.add_callback('activated', self.log_y_cb) b.log_y.set_tooltip('Plot Y-axis in log scale') b.x_lo.add_callback('activated', lambda w: self.set_xlim_cb()) b.x_lo.set_tooltip('Set X lower limit') b.x_hi.add_callback('activated', lambda w: self.set_xlim_cb()) b.x_hi.set_tooltip('Set X upper limit') b.y_lo.add_callback('activated', lambda w: self.set_ylim_cb()) b.y_lo.set_tooltip('Set Y lower limit') b.y_hi.add_callback('activated', lambda w: self.set_ylim_cb()) b.y_hi.set_tooltip('Set Y upper limit') b.show_marker.set_state(self.settings.get('show_marker', True)) b.show_marker.add_callback('activated', self.set_marker_cb) b.show_marker.set_tooltip('Mark data points') # Button to save plot self.save_plot = b.save self.save_plot.set_tooltip('Save table plot') self.save_plot.add_callback('activated', lambda w: self.save_cb()) self.save_plot.set_enabled(False) vbox2 = Widgets.VBox() vbox2.add_widget(w, stretch=0) vbox.add_widget(vbox2, stretch=0) top.add_widget(sw, stretch=1) btns = Widgets.HBox() btns.set_border_width(4) btns.set_spacing(3) btn = Widgets.Button('Close') btn.add_callback('activated', lambda w: self.close()) btns.add_widget(btn, stretch=0) btn = Widgets.Button('Help') btn.add_callback('activated', lambda w: self.help()) btns.add_widget(btn, stretch=0) btns.add_widget(Widgets.Label(''), stretch=1) top.add_widget(btns, stretch=0) container.add_widget(top, stretch=1) self.gui_up = True
def build_gui(self, container): top = Widgets.VBox() top.set_border_width(4) vbox, sw, orientation = Widgets.get_oriented_box(container) vbox.set_margins(4, 4, 4, 4) vbox.set_spacing(2) self.plot = plots.Plot(logger=self.logger, width=400, height=300) ax = self.plot.add_axis() ax.grid(False) w = Plot.PlotWidget(self.plot) w.resize(400, 300) vbox.add_widget(w, stretch=0) fr = Widgets.Frame("Axes controls") self.hbox_axes = Widgets.HBox() self.hbox_axes.set_border_width(4) self.hbox_axes.set_spacing(1) fr.set_widget(self.hbox_axes) vbox.add_widget(fr, stretch=0) btns = Widgets.HBox() btns.set_border_width(4) btns.set_spacing(4) # control for selecting a mark cbox2 = Widgets.ComboBox() for tag in self.marks: cbox2.append_text(tag) if self.mark_selected is None: cbox2.set_index(0) else: cbox2.show_text(self.mark_selected) cbox2.add_callback('activated', self.mark_select_cb) self.w.marks = cbox2 cbox2.set_tooltip("Select a mark") btns.add_widget(cbox2, stretch=0) btn1 = Widgets.CheckBox("Pan to mark") btn1.set_state(self.pan2mark) btn1.add_callback('activated', self.pan2mark_cb) btn1.set_tooltip("Pan follows selected mark") btns.add_widget(btn1) btns.add_widget(Widgets.Label(''), stretch=1) btn2 = Widgets.Button("Delete") self.del_btn = btn2 btn2.add_callback('activated', lambda w: self.clear_mark_cb()) btn2.set_tooltip("Delete selected mark") btn2.set_enabled(False) btns.add_widget(btn2, stretch=0) btn3 = Widgets.Button("Delete All") self.del_all_btn = btn3 btn3.add_callback('activated', lambda w: self.clear_all()) btn3.set_tooltip("Clear all marks") btn3.set_enabled(False) btns.add_widget(btn3, stretch=0) vbox2 = Widgets.VBox() vbox2.add_widget(btns, stretch=0) vbox2.add_widget(Widgets.Label(''), stretch=1) fr = Widgets.Frame("Mark controls") fr.set_widget(vbox2) vbox.add_widget(fr, stretch=1) # scroll bars will allow lots of content to be accessed top.add_widget(sw, stretch=1) # A button box that is always visible at the bottom btns = Widgets.HBox() btns.set_spacing(3) # Add a close button for the convenience of the user btn = Widgets.Button("Close") btn.add_callback('activated', lambda w: self.close()) btns.add_widget(btn, stretch=0) btn = Widgets.Button("Help") btn.add_callback('activated', lambda w: self.help()) btns.add_widget(btn, stretch=0) btns.add_widget(Widgets.Label(''), stretch=1) top.add_widget(btns, stretch=0) # Add our GUI to the container container.add_widget(top, stretch=1) self.gui_up = True self.build_axes()
def initialize_plot(self): self._plot = plots.Plot(logger=self.logger, width=600, height=600) self.gv.initialize_plot_gui(self._plot, width=600, height=600)
def __init__(self, logger=None, settings=None): Callback.Callbacks.__init__(self) if logger is not None: self.logger = logger else: self.logger = logging.Logger('PlotView') # Create settings and set defaults if settings is None: settings = Settings.SettingGroup(logger=self.logger) self.settings = settings self.settings.add_defaults(plot_bg='white', show_marker=False, linewidth=1, linestyle='-', linecolor='blue', markersize=6, markerwidth=0.5, markercolor='red', markerstyle='o', file_suffix='.png') # for debugging self.name = str(self) if not have_mpl: raise ImportError('Install matplotlib to use this plugin') top = Widgets.VBox() top.set_border_width(4) self.line_plot = plots.Plot(logger=self.logger, width=400, height=400) bg = self.settings.get('plot_bg', 'white') if plots.MPL_GE_2_0: kwargs = {'facecolor': bg} else: kwargs = {'axisbg': bg} self.line_plot.add_axis(**kwargs) self.plot_w = Plot.PlotWidget(self.line_plot) self.plot_w.resize(400, 400) # enable interactivity in the plot self.line_plot.connect_ui() self.line_plot.enable(zoom=True, pan=True) self.line_plot.add_callback('limits-set', self.limits_cb) ax = self.line_plot.ax ax.grid(True) top.add_widget(self.plot_w, stretch=1) captions = (('Log X', 'checkbutton', 'Log Y', 'checkbutton', 'Show Marker', 'checkbutton'), ('X Low:', 'label', 'x_lo', 'entry', 'X High:', 'label', 'x_hi', 'entry', 'Reset X', 'button'), ('Y Low:', 'label', 'y_lo', 'entry', 'Y High:', 'label', 'y_hi', 'entry', 'Reset Y', 'button'), ('Save', 'button')) # for now... orientation = 'vertical' w, b = Widgets.build_info(captions, orientation=orientation) self.w = b top.add_widget(w, stretch=0) b.log_x.set_state(self.line_plot.logx) b.log_x.add_callback('activated', self.log_x_cb) b.log_x.set_tooltip('Plot X-axis in log scale') b.log_y.set_state(self.line_plot.logy) b.log_y.add_callback('activated', self.log_y_cb) b.log_y.set_tooltip('Plot Y-axis in log scale') b.x_lo.add_callback('activated', lambda w: self.set_xlim_cb()) b.x_lo.set_tooltip('Set X lower limit') b.x_hi.add_callback('activated', lambda w: self.set_xlim_cb()) b.x_hi.set_tooltip('Set X upper limit') b.y_lo.add_callback('activated', lambda w: self.set_ylim_cb()) b.y_lo.set_tooltip('Set Y lower limit') b.y_hi.add_callback('activated', lambda w: self.set_ylim_cb()) b.y_hi.set_tooltip('Set Y upper limit') b.reset_x.add_callback('activated', lambda w: self.reset_xlim_cb()) b.reset_x.set_tooltip('Autoscale X limits') b.reset_y.add_callback('activated', lambda w: self.reset_ylim_cb()) b.reset_y.set_tooltip('Autoscale Y limits') b.show_marker.set_state(self.settings.get('show_marker', False)) b.show_marker.add_callback('activated', self.set_marker_cb) b.show_marker.set_tooltip('Mark data points') # Button to save plot self.save_plot = b.save self.save_plot.set_tooltip('Save table plot') self.save_plot.add_callback('activated', lambda w: self.save_cb()) self.save_plot.set_enabled(False) self.widget = top # For callbacks for name in ['image-set']: self.enable_callback(name)