107
src/element/toolbar.py
Normal file
107
src/element/toolbar.py
Normal file
@@ -0,0 +1,107 @@
|
||||
import copy
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from tkinter import *
|
||||
from src.util import Util
|
||||
|
||||
|
||||
class Toolbar:
|
||||
def __init__(self, image_window, timer):
|
||||
self.current_image = None
|
||||
self.current_original_image = None
|
||||
self.image_window = image_window
|
||||
|
||||
self.timer = timer
|
||||
self.timer_label = None
|
||||
self.timer_check = None
|
||||
|
||||
toolbar = Frame(self.image_window.window, bd=1, relief=RAISED)
|
||||
toolbar.pack(side=BOTTOM, fill=X)
|
||||
|
||||
next_button = Button(toolbar, relief=FLAT, compound=LEFT, text="next ➡️", command=self.image_window.next_image)
|
||||
next_button.pack(side=LEFT, padx=0, pady=0)
|
||||
|
||||
self.bw_button = Button(toolbar, relief=FLAT, compound=LEFT, text="black&white",
|
||||
command=self.toggle_black_white)
|
||||
self.bw_button.pack(side=LEFT, padx=0, pady=0)
|
||||
|
||||
self.mirror_button = Button(toolbar, relief=FLAT, compound=LEFT, command=self.toggle_mirror,
|
||||
text="mirror")
|
||||
self.mirror_button.pack(side=LEFT, padx=0, pady=0)
|
||||
|
||||
self.open_folder_button = Button(toolbar, relief=FLAT, compound=LEFT, command=self.open_folder
|
||||
, text="open folder")
|
||||
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.pack(side=LEFT, padx=0, pady=0)
|
||||
|
||||
self.timer_label = Label(toolbar, text=self.timer)
|
||||
self.timer_label.pack(side=RIGHT, ipadx=20)
|
||||
|
||||
def display_new_timer(self):
|
||||
self.timer_label.configure(text=Util.format_seconds(self.timer))
|
||||
self.timer_check = self.image_window.window.after(1000, self.update_timer, self.timer)
|
||||
|
||||
def update_timer(self, current):
|
||||
current -= 1
|
||||
if current == 10:
|
||||
self.image_window.play_countdown()
|
||||
if current > 0:
|
||||
self.timer_label.configure(text=Util.format_seconds(current))
|
||||
self.timer_check = self.image_window.window.after(1000, self.update_timer, current)
|
||||
else:
|
||||
self.image_window.window.after_cancel(self.timer_check)
|
||||
if len(self.image_window.images) == 0:
|
||||
self.image_window.window.destroy()
|
||||
self.image_window.window.update()
|
||||
return
|
||||
self.image_window.next_image()
|
||||
|
||||
def toggle_black_white(self):
|
||||
self.image_window.option["bw"] = not self.image_window.option["bw"]
|
||||
self.bw_button.config(bg="blue" if self.image_window.option["bw"] else "grey85")
|
||||
|
||||
self.image_window.image.apply_options()
|
||||
|
||||
def toggle_mirror(self):
|
||||
self.image_window.option["mirror"] = not self.image_window.option["mirror"]
|
||||
self.mirror_button.config(bg="blue" if self.image_window.option["mirror"] else "grey85")
|
||||
|
||||
self.image_window.image.apply_options()
|
||||
|
||||
def toggle_timer(self):
|
||||
try:
|
||||
self.timer_label.pack_info()
|
||||
self.timer_label.pack_forget()
|
||||
except TclError:
|
||||
self.timer_label.pack(side=RIGHT, ipadx=20)
|
||||
|
||||
def open_folder(self):
|
||||
if sys.platform == "win32":
|
||||
os.startfile(self.image_window.app.selected_folder)
|
||||
else:
|
||||
opener = "open" if sys.platform == "darwin" else "xdg-open"
|
||||
subprocess.call([opener, self.image_window.app.selected_folder])
|
||||
|
||||
def toggle_always_on_top(self):
|
||||
self.image_window.option["always_on_top"] = not self.image_window.option["always_on_top"]
|
||||
if self.image_window.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.image_window.window.after_cancel(self.always_on_top_check)
|
||||
|
||||
def stay_on_top(self):
|
||||
# self.window.lift()
|
||||
self.image_window.window.attributes('-topmost', True)
|
||||
self.always_on_top_check = self.image_window.window.after(2000, self.stay_on_top)
|
||||
Reference in New Issue
Block a user