enhance/ui #28
@ -1,6 +1,5 @@
|
||||
from functools import partial
|
||||
from tkinter import *
|
||||
|
||||
from customtkinter import *
|
||||
from src.entity.config import Config
|
||||
from src.entity.session.drawing import DrawingElement
|
||||
from src.util import Util
|
||||
@ -18,16 +17,16 @@ class SessionWindow:
|
||||
self.add_button = None
|
||||
self.app = app
|
||||
|
||||
self.window = Toplevel(app.root)
|
||||
self.window = CTkToplevel(app.root)
|
||||
self.window.title("Custom session")
|
||||
self.window.geometry("600x600")
|
||||
self.window.protocol("WM_DELETE_WINDOW", self.save_on_closing)
|
||||
|
||||
self.left_column = Frame(self.window, width=300, height=600)
|
||||
self.right_column = Frame(self.window, width=300, height=600)
|
||||
self.left_column = CTkFrame(self.window, width=300, height=60)
|
||||
self.right_column = CTkFrame(self.window, width=300, height=600)
|
||||
|
||||
self.left_column.grid(row=0, column=0, sticky="ns")
|
||||
self.right_column.grid(row=0, column=1, sticky="ns")
|
||||
self.left_column.pack(padx=10, pady=10, side=LEFT, fill=BOTH, expand=True)
|
||||
self.right_column.pack(padx=10, pady=10, side=LEFT, fill=BOTH, expand=True)
|
||||
|
||||
self.list_in_session = []
|
||||
|
||||
@ -40,30 +39,32 @@ class SessionWindow:
|
||||
def update_session_list(self):
|
||||
self.reset_list()
|
||||
for i, session in enumerate(self.list_in_session):
|
||||
bg = "blue" if i == self.selected_element_index else "grey85"
|
||||
new_session = Button(self.left_column,
|
||||
new_session = CTkButton(self.left_column,
|
||||
text=session.number_of_drawings + " drawings of " + session.timer + "s each",
|
||||
command=partial(self.edit_element, i),
|
||||
bg=bg
|
||||
fg_color=(Util.get_default_button_color() if i == self.selected_element_index else Util.get_default_active_button_color())
|
||||
)
|
||||
new_session.grid(row=i, column=0)
|
||||
|
||||
button_frame = Frame(self.left_column)
|
||||
self.add_button = Button(button_frame, text="+", command=self.add_element)
|
||||
self.add_button.pack(side=LEFT, padx=0, pady=0)
|
||||
buttons = CTkSegmentedButton(
|
||||
self.left_column, values=["+", "-", "^", "v", "save"],
|
||||
command=self.button_command
|
||||
)
|
||||
buttons.grid()
|
||||
|
||||
self.delete_button = Button(button_frame, text="-", command=self.remove_element)
|
||||
self.delete_button.pack(side=LEFT, padx=0, pady=0)
|
||||
|
||||
self.up_button = Button(button_frame, text="^", command=self.up_element)
|
||||
self.up_button.pack(side=LEFT, padx=0, pady=0)
|
||||
|
||||
self.down_button = Button(button_frame, text="v", command=self.down_element)
|
||||
self.down_button.pack(side=LEFT, padx=0, pady=0)
|
||||
|
||||
save_session_button = Button(button_frame, text="v", command=self.save_session)
|
||||
save_session_button.pack(side=LEFT, padx=0, pady=0)
|
||||
button_frame.grid()
|
||||
def button_command(self, command):
|
||||
if command == "+":
|
||||
self.add_element()
|
||||
elif command == "-":
|
||||
self.remove_element()
|
||||
elif command == "^":
|
||||
self.up_element()
|
||||
elif command == "v":
|
||||
self.down_element()
|
||||
elif command == "save":
|
||||
self.save_session()
|
||||
else:
|
||||
print("unknown command")
|
||||
|
||||
def reset_element(self):
|
||||
for widget in self.right_column.winfo_children():
|
||||
@ -82,34 +83,34 @@ class SessionWindow:
|
||||
else:
|
||||
element = DrawingElement()
|
||||
|
||||
number_of_drawings_label = Label(self.right_column, text="Number of drawings")
|
||||
number_of_drawings_label = CTkLabel(self.right_column, text="Number of drawings")
|
||||
number_of_drawings_label.pack()
|
||||
|
||||
self.number_of_drawings_input = Entry(self.right_column)
|
||||
self.number_of_drawings_input = CTkEntry(self.right_column)
|
||||
self.number_of_drawings_input.insert(INSERT, element.number_of_drawings)
|
||||
self.number_of_drawings_input.bind("<KeyRelease>", lambda e: self.update_local_timer(e))
|
||||
self.number_of_drawings_input.pack()
|
||||
self.number_of_drawings_input.focus_set()
|
||||
|
||||
timer_label = Label(self.right_column, text="Time per drawing in seconds")
|
||||
timer_label = CTkLabel(self.right_column, text="Time per drawing in seconds")
|
||||
timer_label.pack()
|
||||
|
||||
self.timer_input = Entry(self.right_column)
|
||||
self.timer_input = CTkEntry(self.right_column)
|
||||
self.timer_input.insert(INSERT, element.timer)
|
||||
self.timer_input.bind("<KeyRelease>", lambda e: self.update_local_timer(e))
|
||||
self.timer_input.pack()
|
||||
|
||||
total_row_time_label = Label(self.right_column, text="Total row time")
|
||||
total_row_time_label = CTkLabel(self.right_column, text="Total row time")
|
||||
total_row_time_label.pack()
|
||||
self.total_row_time_value_label = Label(self.right_column, text="")
|
||||
self.total_row_time_value_label = CTkLabel(self.right_column, text="")
|
||||
self.total_row_time_value_label.pack()
|
||||
self.update_local_timer()
|
||||
|
||||
save_button = Button(self.right_column, text="Save", command=self.save)
|
||||
save_button = CTkButton(self.right_column, text="Save", command=self.save)
|
||||
save_button.pack()
|
||||
|
||||
def update_local_timer(self, event=None):
|
||||
self.total_row_time_value_label.config(
|
||||
self.total_row_time_value_label.configure(
|
||||
text=Util.format_seconds(int(self.timer_input.get()) * int(self.number_of_drawings_input.get()))
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user