parent
693c596224
commit
5a83727c39
BIN
assets/images/break.gif
Normal file
BIN
assets/images/break.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 280 KiB |
6
src/element/breakPlaceholder.py
Normal file
6
src/element/breakPlaceholder.py
Normal file
@ -0,0 +1,6 @@
|
||||
from customtkinter import CTkLabel
|
||||
|
||||
|
||||
class BreakPlaceholder:
|
||||
def __init__(self, image_window, images):
|
||||
self.loading_label = CTkLabel(image_window.window, text="Loading…")
|
@ -17,6 +17,8 @@ class ImagePlaceholder:
|
||||
def display_new_image(self):
|
||||
image_path = self.images[0]
|
||||
self.images.pop(0)
|
||||
if image_path == "break":
|
||||
image_path = 'assets/images/break.gif'
|
||||
self.current_original_image = Image.open(image_path)
|
||||
self.current_image = copy.deepcopy(self.current_original_image)
|
||||
self.apply_options()
|
||||
@ -45,6 +47,11 @@ class ImagePlaceholder:
|
||||
self.resize_image(True)
|
||||
|
||||
def load_widget(self):
|
||||
print(self.current_image.format)
|
||||
if self.current_image.format == "GIF":
|
||||
print("is gif !")
|
||||
image_to_display = ImageTk.PhotoImage(self.current_image, format = "gif -index 2")
|
||||
else:
|
||||
image_to_display = ImageTk.PhotoImage(self.current_image)
|
||||
self.image_label.configure(image=image_to_display)
|
||||
self.image_label.image = image_to_display
|
||||
|
11
src/entity/session/breakEntity.py
Normal file
11
src/entity/session/breakEntity.py
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
class BreakElement:
|
||||
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.type = "Break"
|
@ -8,3 +8,5 @@ class DrawingElement:
|
||||
else:
|
||||
self.timer = 0
|
||||
self.number_of_drawings = 0
|
||||
|
||||
self.type = "Drawing"
|
||||
|
@ -49,16 +49,23 @@ class ImageWindow:
|
||||
|
||||
def lets_draw(self, images, timer):
|
||||
random.shuffle(images)
|
||||
final_images = []
|
||||
timers = []
|
||||
if self.app.custom:
|
||||
for element in self.app.list_in_session:
|
||||
if element.type == "Drawing":
|
||||
for number in range(int(element.number_of_drawings)):
|
||||
timers.append(int(element.timer))
|
||||
final_images.append(images.pop(0))
|
||||
else:
|
||||
timers.append(int(element.timer))
|
||||
final_images.append("break")
|
||||
self.image.images = final_images
|
||||
else:
|
||||
for i in images:
|
||||
timers.append(timer)
|
||||
|
||||
self.image.images = images
|
||||
|
||||
self.toolbar.timers = timers
|
||||
self.next_image()
|
||||
|
||||
|
@ -2,6 +2,7 @@ from functools import partial
|
||||
from customtkinter import *
|
||||
from src.entity.config import Config
|
||||
from src.entity.session.drawing import DrawingElement
|
||||
from src.entity.session.breakEntity import BreakElement
|
||||
from src.util import Util
|
||||
|
||||
|
||||
@ -33,21 +34,33 @@ class SessionWindow:
|
||||
def open(self):
|
||||
list = Config._CONFIG['session']
|
||||
if list:
|
||||
self.list_in_session = [DrawingElement(e) for e in list]
|
||||
self.list_in_session = [DrawingElement(e) if e["type"] == "Drawing" else BreakElement(e) for e in list]
|
||||
self.update_session_list()
|
||||
|
||||
def update_session_list(self):
|
||||
self.reset_list()
|
||||
for i, session in enumerate(self.list_in_session):
|
||||
if isinstance(session, DrawingElement):
|
||||
new_session = CTkButton(self.left_column,
|
||||
text=session.number_of_drawings + " drawings of " + session.timer + "s each",
|
||||
text=session.number_of_drawings + " drawings of " + Util.format_seconds(int(session.timer)) + " each",
|
||||
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())
|
||||
fg_color=(
|
||||
Util.get_default_button_color() if i == self.selected_element_index else Util.get_default_active_button_color())
|
||||
)
|
||||
elif isinstance(session, BreakElement):
|
||||
new_session = CTkButton(self.left_column,
|
||||
text="Break of " + Util.format_seconds(int(session.timer)) + " each",
|
||||
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())
|
||||
)
|
||||
else:
|
||||
raise Exception("unknown type.")
|
||||
|
||||
new_session.grid(row=i, column=0)
|
||||
|
||||
buttons = CTkSegmentedButton(
|
||||
self.left_column, values=["+", "-", "^", "v", "save"],
|
||||
self.left_column, values=["+", "-", "☕", "^", "v", "save"],
|
||||
command=self.button_command
|
||||
)
|
||||
buttons.grid()
|
||||
@ -63,6 +76,8 @@ class SessionWindow:
|
||||
self.down_element()
|
||||
elif command == "save":
|
||||
self.save_session()
|
||||
elif command == "☕":
|
||||
self.add_break()
|
||||
else:
|
||||
print("unknown command")
|
||||
|
||||
@ -83,6 +98,12 @@ class SessionWindow:
|
||||
else:
|
||||
element = DrawingElement()
|
||||
|
||||
if isinstance(element, DrawingElement):
|
||||
self.print_drawing_form(element)
|
||||
elif isinstance(element, BreakElement):
|
||||
self.print_break_form(self.selected_element_index)
|
||||
|
||||
def print_drawing_form(self, element):
|
||||
number_of_drawings_label = CTkLabel(self.right_column, text="Number of drawings")
|
||||
number_of_drawings_label.pack()
|
||||
|
||||
@ -139,11 +160,18 @@ class SessionWindow:
|
||||
self.selected_element_index += 1
|
||||
self.update_session_list()
|
||||
|
||||
def save(self):
|
||||
def save(self, element_type="Drawing"):
|
||||
if element_type == "Drawing":
|
||||
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()
|
||||
elif element_type == "Break":
|
||||
element = BreakElement() if self.selected_element_index < 0 \
|
||||
else self.list_in_session[self.selected_element_index]
|
||||
element.timer = self.timer_input.get()
|
||||
else:
|
||||
raise Exception("unknown type.")
|
||||
|
||||
if self.selected_element_index < 0:
|
||||
self.list_in_session.append(element)
|
||||
@ -165,3 +193,27 @@ class SessionWindow:
|
||||
Config.save()
|
||||
self.app.set_custom(self.list_in_session)
|
||||
self.window.destroy()
|
||||
|
||||
def add_break(self):
|
||||
self.selected_element_index = -1
|
||||
self.update_session_list()
|
||||
self.print_break_form()
|
||||
|
||||
def print_break_form(self, index=None):
|
||||
self.reset_element()
|
||||
if index is not None:
|
||||
self.selected_element_index = index
|
||||
element = self.list_in_session[self.selected_element_index]
|
||||
self.update_session_list()
|
||||
else:
|
||||
element = BreakElement()
|
||||
|
||||
timer_label = CTkLabel(self.right_column, text="Time for this break in seconds")
|
||||
timer_label.pack()
|
||||
|
||||
self.timer_input = CTkEntry(self.right_column)
|
||||
self.timer_input.insert(INSERT, element.timer)
|
||||
self.timer_input.pack()
|
||||
|
||||
save_button = CTkButton(self.right_column, text="Save", command=partial(self.save, "Break"))
|
||||
save_button.pack()
|
||||
|
Loading…
Reference in New Issue
Block a user