Skip to content

Commit

Permalink
Replaced List[Datapoint] objects with DatapointCollections
Browse files Browse the repository at this point in the history
Toolbar background color now changes with appearance mode
  • Loading branch information
Kobsel committed Jan 10, 2025
1 parent 8b1049f commit 94b2deb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 51 deletions.
13 changes: 7 additions & 6 deletions napytau/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from napytau.gui.components.Toolbar import Toolbar

from napytau.import_export.model.datapoint import Datapoint
from napytau.import_export.model.datapoint_collection import DatapointCollection
from napytau.util.model.value_error_pair import ValueErrorPair


Expand All @@ -34,9 +35,9 @@ def __init__(self) -> None:
super().__init__()

# Datapoints
self.datapoints: List[Datapoint] = []
self.datapoints_for_fitting: List[Datapoint] = []
self.datapoints_for_calculation: List[Datapoint] = []
self.datapoints: DatapointCollection = DatapointCollection([])
self.datapoints_for_fitting: DatapointCollection = DatapointCollection([])
self.datapoints_for_calculation: DatapointCollection = DatapointCollection([])

# values
self.tau = tk.IntVar()
Expand Down Expand Up @@ -202,11 +203,11 @@ def update_data_checkboxes(self, new_datapoints: List[Datapoint]) -> None:
Call this method if there are new datapoints.
:param new_datapoints: The new list of datapoints.
"""
self.datapoints = new_datapoints.copy()
self.datapoints = DatapointCollection(new_datapoints)

for point in new_datapoints:
self.datapoints_for_fitting.append(point)
self.datapoints_for_calculation.append(point)
self.datapoints_for_fitting.add_datapoint(point)
self.datapoints_for_calculation.add_datapoint(point)

self.checkbox_panel.update_data_checkboxes_fitting()
self.checkbox_panel.update_data_checkboxes_calculation()
Expand Down
19 changes: 15 additions & 4 deletions napytau/gui/components/Toolbar.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
from tkinter import Canvas
import tkinter as tk

from matplotlib.backends.backend_tkagg import NavigationToolbar2Tk


class Toolbar():
def __init__(self, parent,):
self.parent = parent

#Create frame to hold Toolbar

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_frame.grid(row=0,
column=0,
padx=10,
pady=10,
sticky="new"
)

#Create Toolbar

toolbar = NavigationToolbar2Tk(self.parent.graph.canvas,
toolbar_frame)
#Adjust background color
toolbar.config(bg=self.parent.graph.main_color)
toolbar.update()
4 changes: 2 additions & 2 deletions napytau/gui/components/control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ def calc(self) -> None:
"""
Starts the main calculation.
"""
#entry_value = self.parent.tau.get()
entry_value = self.parent.tau.get()

#self.label.configure(text=f"Result: {logic(entry_value)}")
self.label.configure(text=f"Result: {entry_value}")
32 changes: 20 additions & 12 deletions napytau/gui/components/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
from napytau.gui.model.marker_factory import generate_error_marker_path

from napytau.import_export.model.datapoint import Datapoint
from napytau.import_export.model.datapoint import (get_checked_datapoints,
get_distances,
get_shifted_intensities)
from napytau.import_export.model.datapoint_collection import DatapointCollection


if TYPE_CHECKING:
Expand Down Expand Up @@ -85,7 +83,7 @@ def plot(self, appearance: str) -> Canvas:

# draw the fitting curve on the axes
self.plot_fitting_curve(
self.parent.datapoints_for_fitting,
DatapointCollection(self.parent.datapoints_for_fitting),
axes_1)


Expand Down Expand Up @@ -161,7 +159,8 @@ def plot_markers(self,
)
index = index + 1

def plot_fitting_curve(self, datapoints: list[Datapoint],
def plot_fitting_curve(self,
datapoints: DatapointCollection,
axes: Axes)-> None:

"""
Expand All @@ -173,15 +172,24 @@ def plot_fitting_curve(self, datapoints: list[Datapoint],
"""

#Extracting distance values / intensities of checked datapoints
checked_datapoints: list[Datapoint] = get_checked_datapoints(datapoints)

checked_distances: list[float] = (
get_distances(checked_datapoints)
)
checked_shifted_intensities: list[float] = (
get_shifted_intensities(checked_datapoints)
checked_datapoints: DatapointCollection = (
datapoints.get_active_datapoints()
)



checked_distances: list[float] = [
valueErrorPair.value
for valueErrorPair in checked_datapoints.get_distances()
]


checked_shifted_intensities: list[float] = [
valueErrorPair.value
for valueErrorPair in checked_datapoints.get_shifted_intensities()
]


# Calculating coefficients
coeffs = np.polyfit(checked_distances,
checked_shifted_intensities,
Expand Down
27 changes: 0 additions & 27 deletions napytau/import_export/model/datapoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,3 @@ def set_active(self, active: bool) -> None:
self.active = active


def get_checked_datapoints( datapoints: list[Datapoint]) -> list[Datapoint]:

checked_datapoints: list[Datapoint] = []
for datapoint in datapoints:
if datapoint.active:
checked_datapoints.append(datapoint)

return checked_datapoints



def get_distances( datapoints: list[Datapoint]) -> list[float]:

distances = []
for datapoint in datapoints:
distances.append(datapoint.get_distance().value)

return distances

def get_shifted_intensities( datapoints: list[Datapoint]) -> list[float]:

intensities = []
for datapoint in datapoints:
intensities.append(datapoint.get_intensity()[0].value)

return intensities

0 comments on commit 94b2deb

Please sign in to comment.