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