Add not cheated pause #37

Merged
Shikiryu merged 2 commits from pause into main 2024-06-17 20:29:59 +02:00
2 changed files with 21 additions and 12 deletions
Showing only changes of commit 5941da9ae5 - Show all commits

View File

@ -8,7 +8,6 @@ from PIL import ImageTk, Image, ImageOps
class ImagePlaceholder: class ImagePlaceholder:
def __init__(self, image_window, images): def __init__(self, image_window, images):
self.is_break = False self.is_break = False
self.is_pause = False
self.current_image = None self.current_image = None
self.current_original_image = None self.current_original_image = None
self.paused_original_image = None self.paused_original_image = None
@ -64,15 +63,15 @@ class ImagePlaceholder:
self.image_label.configure(image=image_to_display) self.image_label.configure(image=image_to_display)
self.image_label.image = image_to_display self.image_label.image = image_to_display
def pause(self): def pause(self, pause=True, cheat=False):
if self.is_pause: if pause:
self.is_pause = False
self.current_original_image = self.paused_original_image
self.paused_original_image = None
else:
self.is_pause = True
self.paused_original_image = self.current_original_image self.paused_original_image = self.current_original_image
if not cheat:
image_path = 'assets/images/break.jpg' image_path = 'assets/images/break.jpg'
self.current_original_image = Image.open(image_path) self.current_original_image = Image.open(image_path)
else:
self.current_original_image = self.paused_original_image
self.paused_original_image = None
self.current_image = copy.deepcopy(self.current_original_image) self.current_image = copy.deepcopy(self.current_original_image)
self.apply_options() self.apply_options()

View File

@ -3,6 +3,7 @@ import subprocess
import sys import sys
from tkinter import * from tkinter import *
from tkinter.ttk import Progressbar, Style from tkinter.ttk import Progressbar, Style
from tkinter.messagebox import *
import customtkinter import customtkinter
from CTkToolTip import * from CTkToolTip import *
@ -14,6 +15,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.timers = []
self.is_paused = False
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
@ -154,13 +156,21 @@ class Toolbar:
self.image_window.window.attributes("-fullscreen", self.image_window.option["fullscreen"]) self.image_window.window.attributes("-fullscreen", self.image_window.option["fullscreen"])
def pause(self): def pause(self):
cheating = False
if not self.is_paused:
cheating = askyesno("Pause", "Laisser l'image affichée ?")
self.is_paused = True
else:
self.is_paused = False
# timer is paused whatever happened
if self.timer_check is not None: if self.timer_check is not None:
self.image_window.window.after_cancel(self.timer_check) self.image_window.window.after_cancel(self.timer_check)
self.timer_check = None self.timer_check = None
else: else:
print(self.timer)
print(100-self.progressbar['value'])
self.timer_check = self.image_window.window.after( self.timer_check = self.image_window.window.after(
1000, self.update_timer, int((100-self.progressbar['value'])*self.timer/100) 1000, self.update_timer, int((100-self.progressbar['value'])*self.timer/100)
) )
self.image_window.image.pause()
self.image_window.image.pause(pause=self.is_paused, cheat=cheating)