def __init__(self, master, plotgroup, **params): super(TemplatePlotGroupPanel, self).__init__(master, plotgroup, **params) self.pack_param('strength_only', parent=self.control_frame_1, on_set=self.redraw_plots, side='right') # Display any plots that can be done with existing data, but # don't regenerate the SheetViews unless requested if self.plotgroup.plot_immediately: self.refresh_plots() else: self.redraw_plots() self.display_labels( ) # should this be called for any redraw? genuinely needs to be # called here because labels might never have been drawn. #################### RIGHT-CLICK MENU STUFF #################### self._sheet_menu.add_command(label="Save image as PNG", command=self.__save_to_png) self._sheet_menu.add_command(label="Save image as EPS", command=self.__save_to_postscript) self._unit_menu.add_command(label="Print info", command=self.__print_info) # JABALERT: Shouldn't be assuming SHC here; should also work # for RGB (or any other channels). channel_menus = {} for chan in ['Strength', 'Hue', 'Confidence']: newmenu = tk.Menu(self._canvas_menu, tearoff=0) self._canvas_menu.add_cascade(menu=newmenu, label=chan + ' channel', indexname=chan) # The c=chan construction is required so that each lambda has its own copy of the string newmenu.add_command(label="Print matrix", command=lambda c=chan: self.__print_matrix(c)) newmenu.add_command( label="Plot in sheet coords", command=lambda c=chan: self.__plot_sheet_matrix(c)) newmenu.add_command(label="Plot in matrix coords", command=lambda c=chan: self.__plot_matrix(c)) newmenu.add_command(label="Plot as 3D wireframe", command=lambda c=chan: self.__plot_matrix3d(c)) newmenu.add_command(label="Fourier transform", command=lambda c=chan: self.__fft(c)) newmenu.add_command(label="Autocorrelation", command=lambda c=chan: self.__autocorrelate(c)) newmenu.add_command(label="Histogram", command=lambda c=chan: self.__histogram(c)) newmenu.add_command(label="Gradient", command=lambda c=chan: self.__gradient(c)) channel_menus[chan] = newmenu
def __init__(self, master, plotgroup, **params): """ If your parameter should be available in history, add its name to the params_in_history list, otherwise it will be disabled in historical views. """ tk.TkParameterized.__init__(self, master, extraPO=plotgroup, msg_handler=master.status, **params) Frame.__init__(self, master.content) self.parent = master #CEBALERT self.setup_plotgroup() self.canvases = [] self.plot_labels = [] ### JCALERT! Figure out why we need that! self._num_labels = 0 self.plotgroups_history = [] self.history_index = 0 self.params_in_history = [] # parameters valid to adjust in history # Factor for reducing or enlarging the Plots (where 1.2 = 20% change) self.zoom_factor = 1.2 # CEBALERT: rename these frames self.control_frame_1 = Frame(master.noscroll) self.control_frame_1.pack(side=TOP, expand=NO, fill=X) self.control_frame_2 = Frame(master.noscroll) self.control_frame_2.pack(side=TOP, expand=NO, fill=X) self.plot_frame = Tkinter.LabelFrame(self, text=self.plotgroup.name) self.plot_frame.pack(side=TOP, expand=YES, fill=BOTH) #,padx=5,pady=5) # CB: why did I need a new frame after switching to 8.5? # I've forgotten what i changed. self.plot_container = Tkinter.Frame(self.plot_frame) self.plot_container.pack(anchor="center") # Label does have a wraplength option...but it's in screen # units. Surely tk has a function to convert between # text and screen units? no_plot_note_text = """ Press Refresh on the pre-plot hooks to generate the plot, after modifying the hooks below if necessary. Note that Refreshing may take some time. Many hooks accept 'display=True' so that the progress can be viewed in an open Activity window, e.g. for debugging. """ self.no_plot_note = Label(self.plot_container, text=no_plot_note_text, justify="center", wraplength=350) self.no_plot_note_enabled = False self.control_frame_3 = Frame(master.noscroll_bottom) self.control_frame_3.pack(side=TOP, expand=NO, fill=X) self.control_frame_4 = Frame(self) self.control_frame_4.pack(side=TOP, expand=NO, fill=NONE) self.updatecommand_frame = Frame(self.control_frame_3) self.updatecommand_frame.pack(side=TOP, expand=YES, fill=X) self.plotcommand_frame = Frame(self.control_frame_3) self.plotcommand_frame.pack(side=TOP, expand=YES, fill=X) # CEBALERT: replace self.messageBar = self.parent.status self.pack_param('pre_plot_hooks', parent=self.updatecommand_frame, expand='yes', fill='x', side='left') self.pack_param('Refresh', parent=self.updatecommand_frame, on_set=self.refresh, side='right') self.params_in_history.append('Refresh') self.pack_param('plot_hooks', parent=self.plotcommand_frame, expand='yes', fill='x', side='left') # CEBALERT: should disable unless data exists. self.pack_param('Redraw', parent=self.plotcommand_frame, on_set=self.redraw_plots, side='right') self.pack_param('Enlarge', parent=self.control_frame_1, on_set=self.enlarge_plots, side=LEFT) self.params_in_history.append( 'Enlarge') # CEBNOTE: while it's a GUI op self.pack_param('Reduce', parent=self.control_frame_1, on_set=self.reduce_plots, side=LEFT) self.params_in_history.append('Reduce') if topo.tkgui.TK_SUPPORTS_DOCK: self.pack_param("dock", parent=self.control_frame_1, on_set=self.set_dock, side=LEFT) # Don't need to add these two to params_in_history because their # availability is controlled separately (determined by what's # in the history) self.pack_param('Back', parent=self.control_frame_2, on_set=lambda x=-1: self.navigate_pg_history(x), side=LEFT) self.pack_param('Fwd', parent=self.control_frame_2, on_set=lambda x=+1: self.navigate_pg_history(x), side=LEFT) #################### RIGHT-CLICK MENU STUFF #################### ### Right-click menu for canvases; subclasses can add cascades ### or insert commands on the existing cascades. self._canvas_menu = tk.Menu(self, tearoff=0) #self.context_menu self._unit_menu = tk.Menu(self._canvas_menu, tearoff=0) self._canvas_menu.add_cascade(menu=self._unit_menu, state=DISABLED, indexname='unit_menu') self._canvas_menu.add_separator() # CEBALERT: scheme for enabling/disabling menu items ('disable # items hack') needs to be generalized. What we have now is # just a mechanism to disable/enable cfs/rfs plots as # necessary. Hack includes the attribute below as well as # other items marked 'disable items hack'. # (Note that tk 8.5 has better handling of state switching # (using flags for each state, I think), so presumably this # can be cleaned up easily.) self._unit_menu_updaters = {} self._sheet_menu = tk.Menu(self._canvas_menu, tearoff=0) self._canvas_menu.add_cascade(menu=self._sheet_menu, state=DISABLED, indexname='sheet_menu') self._canvas_menu.add_separator() self.update_plot_frame(plots=False)