Skip to content

Commit 40c8109

Browse files
authored
Merge pull request #105 from FurkanBaytak/master
Data-Point-Digitizer
2 parents f3e46ca + 1040efa commit 40c8109

File tree

8 files changed

+1830
-0
lines changed

8 files changed

+1830
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import tkinter as tk
2+
from tkinter import colorchooser
3+
4+
5+
class CurveSettingsWindow:
6+
def __init__(self, parent):
7+
"""
8+
Initialize the CurveSettingsWindow class.
9+
10+
Parameters:
11+
parent (tk.Widget): The parent widget that contains the settings.
12+
"""
13+
self.parent = parent
14+
self.settings_window = None
15+
self.line_type = tk.StringVar(value="Smooth")
16+
17+
def open_settings_window(self):
18+
"""
19+
Open a new window for curve settings. If a settings window is already open, it will be destroyed and recreated.
20+
"""
21+
if self.settings_window is not None:
22+
self.settings_window.destroy()
23+
24+
self.settings_window = tk.Toplevel(self.parent.root)
25+
self.settings_window.title("Curve Settings")
26+
27+
# Label for curve color selection
28+
color_label = tk.Label(self.settings_window, text="Select Curve Color:")
29+
color_label.grid(row=0, column=0, padx=5, pady=5)
30+
31+
# Button to open color chooser
32+
color_button = tk.Button(self.settings_window, text="Choose Color", command=self.choose_color)
33+
color_button.grid(row=0, column=1, padx=5, pady=5)
34+
35+
# Label for curve size setting
36+
size_label = tk.Label(self.settings_window, text="Set Curve Size:")
37+
size_label.grid(row=1, column=0, padx=5, pady=5)
38+
39+
# Scale for adjusting curve size
40+
size_scale = tk.Scale(self.settings_window, from_=1, to=3, orient=tk.HORIZONTAL, command=self.change_size)
41+
size_scale.set(self.parent.size)
42+
size_scale.grid(row=1, column=1, padx=5, pady=5)
43+
44+
# Line type selection
45+
line_type_label = tk.Label(self.settings_window, text="Connect As:")
46+
line_type_label.grid(row=2, column=0, padx=5, pady=5)
47+
self.line_type = tk.StringVar(value=self.parent.line_type)
48+
line_type_smooth = tk.Radiobutton(self.settings_window, text="Smooth", variable=self.line_type, value="Smooth")
49+
line_type_smooth.grid(row=2, column=1, padx=5, pady=5)
50+
line_type_straight = tk.Radiobutton(self.settings_window, text="Straight", variable=self.line_type,
51+
value="Straight")
52+
line_type_straight.grid(row=2, column=2, padx=5, pady=5)
53+
54+
# Apply button
55+
apply_button = tk.Button(self.settings_window, text="Apply", command=self.apply_settings)
56+
apply_button.grid(row=3, column=0, columnspan=3, pady=10)
57+
58+
def choose_color(self):
59+
"""
60+
Open a color chooser dialog to select a color. Sets the selected color to the parent's color attribute.
61+
"""
62+
color_code = colorchooser.askcolor(title="Choose color")[1]
63+
if color_code:
64+
self.parent.color = color_code
65+
self.parent.draw_curve_line()
66+
67+
def change_size(self, value):
68+
"""
69+
Change the size of the curve based on the scale value.
70+
71+
Parameters:
72+
value (int): The new size value.
73+
"""
74+
self.parent.size = value
75+
76+
def apply_settings(self):
77+
"""
78+
Apply the selected settings and redraw the curve line. Closes the settings window.
79+
"""
80+
self.parent.line_type = self.line_type.get()
81+
self.parent.draw_curve_line()
82+
self.settings_window.destroy()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import tkinter as tk
2+
3+
4+
class EditCurveList:
5+
def __init__(self, viewer):
6+
"""
7+
Initialize the EditCurveList class.
8+
9+
Parameters:
10+
viewer (Viewer): An instance of a viewer class that provides data.
11+
"""
12+
self.viewer = viewer
13+
self.list_window = None
14+
15+
def open_list_window(self):
16+
"""
17+
Open a new window to display and edit the list of curves.
18+
If a list window is already open, it will be destroyed and recreated.
19+
"""
20+
if self.list_window is not None:
21+
self.list_window.destroy()
22+
23+
self.list_window = tk.Toplevel(self.viewer.root)
24+
self.list_window.title("Curve List")
25+
26+
listbox = tk.Listbox(self.list_window, selectmode=tk.SINGLE)
27+
for curve in self.viewer.curve_IDs:
28+
listbox.insert(tk.END, self.viewer.curve_names[curve - 1])
29+
listbox.pack()
30+
31+
change_button = tk.Button(
32+
self.list_window,
33+
text="Change Curve Name",
34+
command=lambda: self.change_curve_name(listbox.get(listbox.curselection()))
35+
)
36+
change_button.pack()
37+
38+
def change_curve_name(self, curve_name):
39+
"""
40+
Open a window to change the name of the selected curve.
41+
42+
Parameters:
43+
curve_name (str): The name of the curve to be changed.
44+
"""
45+
entry_window = tk.Toplevel(self.list_window)
46+
entry_window.title("Change Curve Name")
47+
48+
tk.Label(entry_window, text="Enter new curve name:").pack()
49+
entry = tk.Entry(entry_window)
50+
entry.pack()
51+
52+
def save_new_name():
53+
new_name = entry.get()
54+
if new_name:
55+
index = self.viewer.curve_names.index(curve_name)
56+
self.viewer.curve_names[index] = new_name
57+
self.open_list_window()
58+
entry_window.destroy()
59+
60+
save_button = tk.Button(entry_window, text="Save", command=save_new_name)
61+
save_button.pack()
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import copy
2+
import tkinter as tk
3+
from tkinter import ttk
4+
import csv
5+
from tkinter import filedialog
6+
7+
8+
class GeometryWindow:
9+
def __init__(self, parent, viewer):
10+
"""
11+
Initialize the GeometryWindow class.
12+
13+
Parameters:
14+
parent (tk.Tk or tk.Widget): The parent widget.
15+
viewer (Viewer): An instance of a viewer class that provides data.
16+
"""
17+
self.viewer = viewer
18+
self.parent = parent
19+
self.frame = tk.Frame(parent, width=320, bg="grey")
20+
self.label = tk.Label(self.frame, text="Geometry Window", bg="grey")
21+
self.label.pack(side=tk.TOP, fill=tk.X)
22+
self.tree = ttk.Treeview(self.frame, columns=("Curves", "Points", "X", "Y"), show="headings")
23+
self._configure_tree()
24+
self.tree.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
25+
26+
self.populate_tree()
27+
28+
def _configure_tree(self):
29+
"""
30+
Configure the treeview widget's headings and columns.
31+
"""
32+
headings = ["Curves", "Points", "X", "Y"]
33+
for heading in headings:
34+
self.tree.heading(heading, text=heading)
35+
self.tree.column(heading, anchor=tk.CENTER, stretch=tk.NO, width=80)
36+
37+
def populate_tree(self):
38+
"""
39+
Populate the treeview with data from the viewer.
40+
"""
41+
# Clear the tree
42+
for item in self.tree.get_children():
43+
self.tree.delete(item)
44+
45+
# Retrieve data
46+
data = self.viewer.data_values
47+
curves = self.viewer.curves
48+
49+
curve_values = self._deep_copy_curves(curves, data)
50+
self._insert_data_into_tree(curve_values)
51+
52+
@staticmethod
53+
def _deep_copy_curves(curves, data):
54+
"""
55+
Deep copy curves and update with data values.
56+
57+
Parameters:
58+
curves (list): List of curves.
59+
data (list): List of data values.
60+
61+
Returns:
62+
list: Updated list of curve values.
63+
"""
64+
curve_values = copy.deepcopy(curves)
65+
for i, curve in enumerate(curves):
66+
if curve: # Check if the sublist is not empty
67+
for j in range(len(curve)):
68+
if j < len(data[0]): # Ensure index does not exceed the data list length
69+
curve_values[i][j] = data[0][j]
70+
return curve_values
71+
72+
def _insert_data_into_tree(self, curve_values):
73+
"""
74+
Insert data into the treeview.
75+
76+
Parameters:
77+
curve_values (list): List of updated curve values.
78+
"""
79+
for i, curve in enumerate(curve_values):
80+
if curve:
81+
for j, value in enumerate(curve):
82+
self.tree.insert("", tk.END, values=(
83+
self.viewer.curve_names[i], j + 1, value[0], value[1]
84+
))
85+
86+
def export_to_csv(self):
87+
"""
88+
Export the data in the treeview to a CSV file.
89+
"""
90+
file_path = filedialog.asksaveasfilename(defaultextension=".csv", filetypes=[("CSV files", "*.csv")])
91+
if file_path:
92+
with open(file_path, mode='w', newline='') as file:
93+
writer = csv.writer(file)
94+
writer.writerow(["Curves", "Points", "X", "Y"]) # Write the headers
95+
96+
# Write the treeview data
97+
for row_id in self.tree.get_children():
98+
row = self.tree.item(row_id)['values']
99+
writer.writerow(row)
100+
print(f"Data exported to {file_path}")
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import tkinter as tk
2+
3+
4+
class GridSettings:
5+
def __init__(self, parent):
6+
"""
7+
Initialize the GridSettings class.
8+
9+
Parameters:
10+
parent (tk.Widget): The parent widget that contains the settings.
11+
"""
12+
self.parent = parent
13+
self.settings_window = None
14+
15+
def open_settings_window(self):
16+
"""
17+
Open a new window for grid settings. If a settings window is already open, it will be destroyed and recreated.
18+
"""
19+
if self.settings_window is not None:
20+
self.settings_window.destroy()
21+
22+
self.settings_window = tk.Toplevel(self.parent.root)
23+
self.settings_window.title("Grid Settings")
24+
25+
# Label and scale for grid size X
26+
size_label_x = tk.Label(self.settings_window, text="Set Grid Size X:")
27+
size_label_x.grid(row=1, column=0, padx=5, pady=5)
28+
size_scale_x = tk.Scale(self.settings_window, from_=1, to=25, orient=tk.HORIZONTAL, command=self.change_size_x)
29+
size_scale_x.set(self.parent.grid_size_x)
30+
size_scale_x.grid(row=1, column=1, padx=5, pady=5)
31+
32+
# Label and scale for grid size Y
33+
size_label_y = tk.Label(self.settings_window, text="Set Grid Size Y:")
34+
size_label_y.grid(row=2, column=0, padx=5, pady=5)
35+
size_scale_y = tk.Scale(self.settings_window, from_=1, to=25, orient=tk.HORIZONTAL, command=self.change_size_y)
36+
size_scale_y.set(self.parent.grid_size_y)
37+
size_scale_y.grid(row=2, column=1, padx=5, pady=5)
38+
39+
# Button to apply settings
40+
apply_button = tk.Button(self.settings_window, text="Apply", command=self.apply_settings)
41+
apply_button.grid(row=3, column=0, columnspan=2, pady=10)
42+
43+
def change_size_x(self, value):
44+
"""
45+
Change the grid size in the X direction.
46+
47+
Parameters:
48+
value (int): The new size value for the X axis.
49+
"""
50+
self.parent.grid_size_x = value
51+
self.parent.draw_grid()
52+
53+
def change_size_y(self, value):
54+
"""
55+
Change the grid size in the Y direction.
56+
57+
Parameters:
58+
value (int): The new size value for the Y axis.
59+
"""
60+
self.parent.grid_size_y = value
61+
self.parent.draw_grid()
62+
63+
def apply_settings(self):
64+
"""
65+
Apply the selected settings and redraw the grid. Closes the settings window.
66+
"""
67+
self.parent.draw_grid()
68+
self.settings_window.destroy()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Furkan Baytak
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)