Add sessions

This commit is contained in:
Clement Desmidt 2023-06-02 12:21:12 +02:00
parent e2546c7bfb
commit a149ab71bb
5 changed files with 30 additions and 5 deletions

View File

@ -8,6 +8,7 @@ from src.util import Util
class Toolbar: class Toolbar:
def __init__(self, image_window, timer): def __init__(self, image_window, timer):
self.timers = []
self.current_image = None self.current_image = None
self.current_original_image = None self.current_original_image = None
self.image_window = image_window self.image_window = image_window
@ -47,6 +48,7 @@ class Toolbar:
self.timer_label.pack(side=RIGHT, ipadx=20) self.timer_label.pack(side=RIGHT, ipadx=20)
def display_new_timer(self): def display_new_timer(self):
self.timer = self.timers.pop(0)
self.timer_label.configure(text=Util.format_seconds(self.timer)) self.timer_label.configure(text=Util.format_seconds(self.timer))
self.timer_check = self.image_window.window.after(1000, self.update_timer, self.timer) self.timer_check = self.image_window.window.after(1000, self.update_timer, self.timer)
@ -59,7 +61,7 @@ class Toolbar:
self.timer_check = self.image_window.window.after(1000, self.update_timer, current) self.timer_check = self.image_window.window.after(1000, self.update_timer, current)
else: else:
self.image_window.window.after_cancel(self.timer_check) self.image_window.window.after_cancel(self.timer_check)
if len(self.image_window.images) == 0: if len(self.image_window.image.images) == 0 or len(self.timers) == 0:
self.image_window.window.destroy() self.image_window.window.destroy()
self.image_window.window.update() self.image_window.window.update()
return return

View File

@ -1,6 +1,10 @@
class DrawingElement: class DrawingElement:
def __init__(self): def __init__(self, data=None):
if data is not None:
for key, value in data.items():
setattr(self, key, value)
else:
self.timer = 0 self.timer = 0
self.number_of_drawings = 0 self.number_of_drawings = 0

View File

@ -12,6 +12,7 @@ from src.window.session import SessionWindow
class App: class App:
def __init__(self, root): def __init__(self, root):
super().__init__() super().__init__()
self.list_in_session = None
self.custom = False self.custom = False
self.config = Config() self.config = Config()
self.session = None self.session = None
@ -79,6 +80,7 @@ class App:
self.launch_button.config(state="disabled") self.launch_button.config(state="disabled")
def set_timer_in_seconds(self, user_data): def set_timer_in_seconds(self, user_data):
self.custom = False
self.timer = user_data self.timer = user_data
for button in self.buttons: for button in self.buttons:
if button['text'] == Util.format_seconds(self.timer): if button['text'] == Util.format_seconds(self.timer):
@ -90,3 +92,7 @@ class App:
def set_custom(self, list_in_session): def set_custom(self, list_in_session):
self.custom = True self.custom = True
self.list_in_session = list_in_session self.list_in_session = list_in_session
self.check_lets_draw()
for button in self.buttons:
button.config(bg="gray85")
self.buttons[-1].config(bg="blue")

View File

@ -47,8 +47,17 @@ class ImageWindow:
def lets_draw(self, images, timer): def lets_draw(self, images, timer):
random.shuffle(images) random.shuffle(images)
timers = []
if self.app.custom:
for element in self.app.list_in_session:
for number in range(int(element.number_of_drawings)):
timers.append(int(element.timer))
else:
for i in images:
timers.append(timer)
self.image.images = images self.image.images = images
self.toolbar.timer = timer self.toolbar.timers = timers
self.next_image() self.next_image()
def play_countdown(self): def play_countdown(self):

View File

@ -32,6 +32,9 @@ class SessionWindow:
self.list_in_session = [] self.list_in_session = []
def open(self): def open(self):
list = Config._CONFIG['session']
if list:
self.list_in_session = [DrawingElement(e) for e in list]
self.update_session_list() self.update_session_list()
def update_session_list(self): def update_session_list(self):
@ -155,6 +158,7 @@ class SessionWindow:
self.window.destroy() self.window.destroy()
def save_session(self): def save_session(self):
Config._CONFIG['session'] = []
for element in self.list_in_session: for element in self.list_in_session:
Config._CONFIG['session'].append(element.__dict__) Config._CONFIG['session'].append(element.__dict__)
Config.save() Config.save()