feature/session #27

Merged
Shikiryu merged 7 commits from feature/session into main 2023-06-02 12:24:15 +02:00
2 changed files with 77 additions and 22 deletions
Showing only changes of commit 0cca0b05ed - Show all commits

View File

@ -0,0 +1,6 @@
class DrawingElement:
def __init__(self):
self.timer = 0
self.number_of_drawings = 0

View File

@ -1,10 +1,14 @@
from functools import partial
from tkinter import *
from src.entity.session.drawing import DrawingElement
class SessionWindow:
def __init__(self, app):
self.selected_element_index = 0
self.timer_input = None
self.number_of_drawings_input = None
self.selected_element_index = -1
self.delete_button = None
self.add_button = None
self.app = app
@ -25,39 +29,84 @@ class SessionWindow:
def open(self):
self.update_session_list()
def update_session_list(self):
self.reset_list()
for i, session in enumerate(self.list_in_session):
new_session = Button(self.left_column,
text=session.number_of_drawings + " drawings of "+session.timer+"s each",
command=partial(self.edit_element, i)
)
new_session.grid(row=i, column=0)
self.add_button = Button(self.left_column, text="+", command=self.add_element)
self.add_button.pack()
self.add_button.grid()
self.delete_button = Button(self.left_column, text="-", command=self.remove_element)
self.delete_button.pack()
self.delete_button.grid()
def update_session_list(self):
for i, session in enumerate(self.list_in_session):
new_session = Button(self.left_column, text="element " + str(i), command=partial(self.edit_element, i))
new_session.grid(row=i, column=0)
def reset_element(self):
for widget in self.right_column.winfo_children():
widget.destroy()
def reset_list(self):
for widget in self.left_column.winfo_children():
widget.destroy()
def update_element(self, index=None):
if index is not None:
self.selected_element_index = index
element = self.list_in_session[self.selected_element_index]
else:
element = DrawingElement()
number_of_drawings_label = Label(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.insert(INSERT, element.number_of_drawings)
self.number_of_drawings_input.pack()
timer_label = Label(self.right_column, text="Time per drawing in seconds")
timer_label.pack()
self.timer_input = Entry(self.right_column)
self.timer_input.insert(INSERT, element.timer)
self.timer_input.pack()
row_time = IntVar()
total_row_time_label = Label(self.right_column, text="Total row time")
total_row_time_label.pack()
total_row_time_value_label = Label(self.right_column, textvariable=row_time)
total_row_time_value_label.pack()
save_button = Button(self.right_column, text="Save", command=self.save)
save_button.pack()
def remove_element(self):
self.list_in_session.pop(self.selected_element_index)
self.selected_element_index = -1
self.update_session_list()
def edit_element(self, i):
self.selected_element_index = i
element = self.list_in_session[self.selected_element_index]
number_of_drawings_label = Text(self.right_column)
number_of_drawings_label.insert(INSERT, "Nombre de dessins :")
number_of_drawings_label.pack()
number_of_drawings_input = Entry(self.right_column)
number_of_drawings_input.insert(INSERT, element.number_of_drawings)
number_of_drawings_input.pack()
self.update_element(i)
def add_element(self):
number_of_drawings_label = Text(self.right_column)
number_of_drawings_label.insert(INSERT, "Nombre de dessins :")
number_of_drawings_label.pack()
self.update_element()
number_of_drawings_input = Entry(self.right_column)
number_of_drawings_input.pack()
def save(self):
element = DrawingElement() if self.selected_element_index < 0 \
else self.list_in_session[self.selected_element_index]
element.timer = self.timer_input.get()
element.number_of_drawings = self.number_of_drawings_input.get()
if self.selected_element_index < 0:
self.list_in_session.append(element)
else:
self.list_in_session[self.selected_element_index] = element
self.update_session_list()
self.selected_element_index = -1
self.reset_element()
def save_on_closing(self):
# TODO save