Add button to leave image always on top #22

Merged
Shikiryu merged 1 commits from feature/always_on_top into main 2023-05-23 22:00:08 +02:00

View File

@ -13,7 +13,8 @@ class ImageWindow:
self.window.geometry("1280x1024") self.window.geometry("1280x1024")
self.option = { self.option = {
"bw": False, "bw": False,
"mirror": False "mirror": False,
"always_on_top": False,
} }
self.images = [] self.images = []
self.current_image = None self.current_image = None
@ -23,6 +24,7 @@ class ImageWindow:
self.timer = 0 self.timer = 0
self.timer_label = None self.timer_label = None
self.timer_check = None self.timer_check = None
self.timer_check = None
next_button = Button(toolbar, relief=FLAT, compound=LEFT, text="next ➡️", command=self.next_image) next_button = Button(toolbar, relief=FLAT, compound=LEFT, text="next ➡️", command=self.next_image)
next_button.pack(side=LEFT, padx=0, pady=0) next_button.pack(side=LEFT, padx=0, pady=0)
@ -38,6 +40,11 @@ class ImageWindow:
, text="open folder") , text="open folder")
self.open_folder_button.pack(side=LEFT, padx=0, pady=0) self.open_folder_button.pack(side=LEFT, padx=0, pady=0)
self.always_on_top_button = Button(toolbar, relief=FLAT, compound=LEFT, command=self.toggle_always_on_top
, text="always on top")
self.always_on_top_button.pack(side=LEFT, padx=0, pady=0)
self.always_on_top_check = None
self.timer_button = Button(toolbar, relief=FLAT, compound=LEFT, command=self.toggle_timer, text="timer") self.timer_button = Button(toolbar, relief=FLAT, compound=LEFT, command=self.toggle_timer, text="timer")
self.timer_button.pack(side=LEFT, padx=0, pady=0) self.timer_button.pack(side=LEFT, padx=0, pady=0)
@ -84,14 +91,24 @@ class ImageWindow:
def open_folder(self): def open_folder(self):
os.startfile(self.app.selected_folder) os.startfile(self.app.selected_folder)
def toggle_always_on_top(self):
self.option["always_on_top"] = not self.option["always_on_top"]
if self.option["always_on_top"]:
self.always_on_top_button.config(bg="blue")
self.stay_on_top()
else:
self.always_on_top_button.config(bg="grey85")
self.window.after_cancel(self.always_on_top_check)
def stay_on_top(self):
# self.window.lift()
self.window.attributes('-topmost', True)
self.always_on_top_check = self.window.after(2000, self.stay_on_top)
def lets_draw(self, images, timer): def lets_draw(self, images, timer):
random.shuffle(images) random.shuffle(images)
self.images = images self.images = images
self.timer = timer self.timer = timer
# canvas = Canvas(self.window)
# canvas.pack(fill=BOTH, expand=1)
self.next_image() self.next_image()
def display_new_timer(self): def display_new_timer(self):