"""Miscellaneous GUI elements for FancyPlots.This module defines the :class:`FooterSection` class which contains various:class:`.ttk.Button` instances for saving and displaying the graph, resettingparameters, and showing documentation."""fromcontextlibimportsuppressimportloggingimporttkinterastkfromtkinterimportmessageboxfromtkinterimportttkfromtypingimportTYPE_CHECKINGfromccu.fancyplotsimportplottingfromccu.fancyplots._gui.fedimportFreeEnergyDiagramfromccu.fancyplots._gui.framesimportUpdatableFramefromccu.fancyplots._gui.instructionsimportInstructionsWindowfromccu.fancyplots._gui.paletteimportPaletteWindowifTYPE_CHECKING:fromccu.fancyplots._gui.rootimportFancyPlotsGUIlogger=logging.getLogger(__name__)
[docs]classFooterSection(ttk.Frame,UpdatableFrame):"""A collection of utility buttons for settings, instructions, and graphs. Attributes: parent: A :class:`FancyPlotsGUI`. reset_button: A ``ttk.Button`` for resetting formatting parameters. show_button: A ``ttk.Button`` for showing the free energy diagram. save_button: A ``ttk.Button`` for saveing the free energy diagram. palette_button: A ``ttk.Button`` for showing the matplotlib palette. instructions_button: A ``ttk.Button`` for showing the instructions of how to use FancyPlots. """def__init__(self,parent:"FancyPlotsGUI",*args,**kwargs,)->None:"""Create a section with miscellaneous GUI elements. Args: parent: The running :class:`.root.FancyPlotsGUI` instance. *args: Positional arguments for :class:`tkinter.Toplevel`. **kwargs: Keyword arguments fo :class:`tkinter.Toplevel`. """super().__init__(parent._frame,*args,**kwargs)self.parent=parentself.reset_button=ttk.Button(self,text="Reset Formatting Settings",command=self.reset_defaults,)self.show_button=ttk.Button(self,text="Show Graph",command=self.show_graph,)self.save_button=ttk.Button(self,text="Save Graph",command=self.save_figure,)self.palette_button=ttk.Button(self,text="Color Palettes",command=self.show_palette,)self.instructions_button=ttk.Button(self,text="Instructions",command=self.show_instructions,)self._organize()
[docs]defreset_defaults(self)->None:"""Reset the formatting parameters to their default values."""logger.debug("Resetting formatting parameters to default")ifself.parent.sectionsandself.parent.sections["formatting"]:self.parent.sections["formatting"].reset_defaults()logger.info("Succesfully reset defaults")else:logger.info("Unable to reset defaults")
[docs]defshow_graph(self)->None:"""Show the free energy diagram."""windows=self.parent.windowsifwindows["graph_window"]:self.parent._quit_window("graph_window",windows["graph_window"])()logger.debug("Showing free energy diagram")window=FreeEnergyDiagram(self.parent)withsuppress(tk.TclError):_=window.winfo_viewable()windows["graph_window"]=window
[docs]defsave_figure(self)->None:"""Save the free energy diagram."""logger.debug("Saving figure")_=plotting.generate_figure(diagram_data=self.parent.cache.diagram_data,parameters=self.parent.cache.style_parameters,annotations=self.parent.cache.annotations,visual=False,)msg="Succesfully saved figure"logger.info(msg)messagebox.showinfo(message=msg)
[docs]defshow_palette(self)->None:"""Show the matplotlib colour palette."""logger.debug("Launching the colour palette window")windows=self.parent.windowsifwindows["matplotlib_palette"]:self.parent._quit_window(windows,"matplotlib_palette")()logger.debug("Showing colour palette")window=PaletteWindow(self.parent)withsuppress(tk.TclError):_=window.winfo_viewable()windows["matplotlib_palette"]=window
[docs]defshow_instructions(self)->None:"""Show the FancyPlots walkthrough."""logger.debug("Launching the instructions window")windows=self.parent.windowsifwindows["instructions_window"]:self.parent._quit_window("instructions_window",self)()logger.debug("Showing instructions")window=InstructionsWindow(self.parent)withsuppress(tk.TclError):_=window.winfo_viewable()windows["instructions_window"]=window
[docs]defupdate_frames(self)->None:"""Empty function."""logger.debug("Updating frames in %s.%s",__package__,__class__.__name__)