From 8b1049f8f3cb723c0cda4a895e36f07696e295cd Mon Sep 17 00:00:00 2001 From: Kobsel <123456789+kobar13@gmx.de> Date: Fri, 10 Jan 2025 20:57:23 +0100 Subject: [PATCH] created class 'Toolbar' --- napytau/gui/app.py | 15 ++++----------- napytau/gui/components/Toolbar.py | 16 ++++++++++++++++ napytau/gui/components/graph.py | 4 ++-- 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 napytau/gui/components/Toolbar.py diff --git a/napytau/gui/app.py b/napytau/gui/app.py index 7d92783..e6b9e1c 100644 --- a/napytau/gui/app.py +++ b/napytau/gui/app.py @@ -13,10 +13,11 @@ from napytau.gui.components.graph import Graph from napytau.gui.components.logger import Logger from napytau.gui.components.menu_bar import MenuBar +from napytau.gui.components.Toolbar import Toolbar + from napytau.import_export.model.datapoint import Datapoint from napytau.util.model.value_error_pair import ValueErrorPair -from matplotlib.backends.backend_tkagg import NavigationToolbar2Tk # Modes: "System" (standard), "Dark", "Light" customtkinter.set_appearance_mode("System") @@ -120,9 +121,7 @@ def __init__(self) -> None: # Initialize the graph self.graph = Graph(self) - self.create_toolbar() - - + self.toolbar = Toolbar(self) # Initialize the control panel self.control_panel = ControlPanel(self) @@ -212,13 +211,7 @@ def update_data_checkboxes(self, new_datapoints: List[Datapoint]) -> None: self.checkbox_panel.update_data_checkboxes_fitting() self.checkbox_panel.update_data_checkboxes_calculation() - def create_toolbar(self) -> None: - toolbar_frame = tk.Frame(self) - toolbar_frame.config(bg="white") - toolbar_frame.grid(row=0, column=0, sticky="new") # Use grid for the frame - toolbar = NavigationToolbar2Tk(self.graph.canvas, toolbar_frame) - #toolbar.config(bg="white")# Pack inside the frame - toolbar.update() + """ Function for testing purposes only! diff --git a/napytau/gui/components/Toolbar.py b/napytau/gui/components/Toolbar.py new file mode 100644 index 0000000..2463743 --- /dev/null +++ b/napytau/gui/components/Toolbar.py @@ -0,0 +1,16 @@ +from tkinter import Canvas +import tkinter as tk +from matplotlib.backends.backend_tkagg import NavigationToolbar2Tk + + +class Toolbar(): + def __init__(self, parent,): + self.parent = parent + + + toolbar_frame = tk.Frame(parent) + toolbar_frame.config(bg="white") + toolbar_frame.grid(row=0, column=0, sticky="new") # Use grid for the frame + toolbar = NavigationToolbar2Tk(self.parent.graph.canvas, toolbar_frame) + #toolbar.config(bg="white")# Pack inside the frame + toolbar.update() \ No newline at end of file diff --git a/napytau/gui/components/graph.py b/napytau/gui/components/graph.py index f5324c3..a28ccd9 100644 --- a/napytau/gui/components/graph.py +++ b/napytau/gui/components/graph.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING import numpy as np - +from napytau.gui.components.Toolbar import Toolbar from napytau.gui.model.color import Color from napytau.gui.model.marker_factory import generate_marker from napytau.gui.model.marker_factory import generate_error_marker_path @@ -46,7 +46,7 @@ def update_plot(self) -> None: row=0, column=0, rowspan=2, padx=10, pady=10, sticky="nsew" ) self.graph_frame.grid_propagate(False) - self.parent.create_toolbar() + self.parent.toolbar = Toolbar(self.parent) def plot(self, appearance: str) -> Canvas: