|
| 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() |
0 commit comments