Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: Always on top
  • Loading branch information
sumeshir26 committed Nov 26, 2021
commit fa55afd9b11f2112d81e24e083bd3ada7806b68e
54 changes: 40 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# IMPORTS
from time import sleep
from tkinter import TclError, ttk, Tk, PhotoImage, Frame
from tkinter.constants import SE, SW
from tkinter.constants import LEFT, RIGHT, SE, SW
from playsound import playsound
from threading import Thread
import configurator
Expand All @@ -14,7 +14,7 @@
app.title('TimerX')
app.geometry('300x210')
app.resizable(False, False)
# app.attributes('-topmost', False)
# app.attributes('-topmost', True)
# app.update()
# app.attributes('-alpha', 0.75)

Expand All @@ -27,6 +27,7 @@
app.iconphoto(r'assets/logo.ico')
elif system() == "win":
app.iconphoto(r'assets/logo.ico')
app.overrideredirect(True)
else:
logo_img = PhotoImage(file = 'assets/images/logo.png')
app.iconphoto(False, logo_img)
Expand All @@ -36,15 +37,15 @@
# VARIABLES
app_on = True

default_font = './assets/fonts/font.ttf'

timer_on = False
timer_paused = True

timer_seconds = 5
timer_minutes = 0
timer_hours = 0

ontop = False

# FUNCTIONS
def playBuzzer():
playsound('./assets/sounds/sound1.wav')
Expand Down Expand Up @@ -112,6 +113,28 @@ def runTimer():
play_button.config(text = "Play")
playBuzzer()

def toggleAlwaysOnTop(app):
global ontop, pin_button, theme
if ontop == False:
app.attributes('-topmost', True)
ontop = True
if theme == 'dark':
global unpin_image_dark
pin_button.configure(image=unpin_image_dark)
else:
global unpin_image_light
pin_button.configure(image=unpin_image_light)
return
else:
app.attributes('-topmost', False)
if theme == 'dark':
global pin_image_dark
pin_button.configure(image=pin_image_dark)
else:
global pin_image_light
pin_button.configure(image=pin_image_light)
ontop = False

# APP THEME

app.tk.call("source", "sun-valley.tcl")
Expand All @@ -124,25 +147,28 @@ def runTimer():
app.tk.call("set_theme", "light")

def switchTheme():
global theme, app, info_button, switch_theme_button
global theme, app, pin_button, switch_theme_button
if theme == 'light':
theme = 'dark'
app.tk.call("set_theme", "dark")
switch_theme_button.configure(image=switch_theme_image_dark)
info_button.configure(image=info_image_dark)
pin_button.configure(image=pin_image_dark)
else:
theme = 'light'
app.tk.call("set_theme", "light")
info_button.configure(image=info_image_light)
pin_button.configure(image=pin_image_light)
switch_theme_button.configure(image=switch_theme_image_light)

# IMAGES

switch_theme_image_light = PhotoImage(file=f"./assets/images/light/dark_theme.png")
switch_theme_image_dark = PhotoImage(file=f"./assets/images/dark/dark_theme.png")

info_image_light = PhotoImage(file=f"./assets/images/light/info.png")
info_image_dark = PhotoImage(file=f"./assets/images/dark/info.png")
pin_image_light = PhotoImage(file=f"./assets/images/light/pin.png")
pin_image_dark = PhotoImage(file=f"./assets/images/dark/pin.png")

unpin_image_light = PhotoImage(file=f"./assets/images/light/unpin.png")
unpin_image_dark = PhotoImage(file=f"./assets/images/dark/unpin.png")

# WINDOW FRAME
window = Frame(app)
Expand All @@ -161,16 +187,16 @@ def switchTheme():
manager_button = ttk.Button(master =window, text = 'Edit Timer', command = lambda: configurator.createManagerWindow(saveTimer, timer_minutes, timer_seconds, timer_hours), width = 25)
manager_button.pack(pady = 5)

switch_theme_button = ttk.Button(master=window, image=switch_theme_image_light, command=switchTheme)
switch_theme_button.pack(anchor=SW, padx=5, pady=(5, 5))
switch_theme_button = ttk.Button(master=window, image=switch_theme_image_light, command=switchTheme, style="Toolbutton")
switch_theme_button.pack(side=LEFT, padx=5, pady=(5, 5))

info_button = ttk.Button(master=window, image=switch_theme_image_light, command = configurator.createAboutWindow)
#info_button.pack(anchor=SE, padx=50)
pin_button = ttk.Button(master=window, image=switch_theme_image_light, command = lambda:toggleAlwaysOnTop(app), style="Toolbutton")
pin_button.pack(side=RIGHT, padx=(0, 5), pady=(5, 5))

# THEMED IMAGES
if darkdetect.theme() == "Dark":
switch_theme_button.configure(image=switch_theme_image_dark)
info_button.configure(image=info_image_dark)
pin_button.configure(image=pin_image_dark)

# TKINTER MAINLOOP
window.mainloop()