Skip to content

Commit d634eed

Browse files
authored
fix(bug97): modify setAlwaysOnTop() to somehow allow theme switches (#98)
* fix(bug97): modify setAlwaysOnTop() to somehow allow theme switches How is it connected? * style: code formatting
1 parent 399e0f5 commit d634eed

File tree

3 files changed

+61
-29
lines changed

3 files changed

+61
-29
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
rev: 21.12b0
1111
hooks:
1212
- id: black
13-
language_version: python3.8
13+
language_version: python3
1414
- repo: https://github.com/asottile/seed-isort-config
1515
rev: v2.2.0
1616
hooks:

main.py

+52-27
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
from platform import system
1010
from threading import Thread
1111
from tkinter import Frame, PhotoImage, Tk, ttk
12-
from tkinter.constants import DISABLED, LEFT, END
12+
from tkinter.constants import DISABLED, END, LEFT
1313
from tkinter.filedialog import askopenfile
1414

1515
import darkdetect
1616
import sv_ttk
1717
from playsound import playsound
18+
1819
if system() == "Windows":
1920
from win10toast_click import ToastNotifier
2021

@@ -57,15 +58,17 @@ def seticon(win):
5758
except tkinter.TclError:
5859
pass
5960

60-
def fullredraw(e):
61+
62+
def fullredraw(e):
6163
global prev_state
62-
if prev_state == "zoomed":
63-
app._dwm_set_window_attribute(app.DWMWA_TRANSITIONS_FORCEDISABLED, 1)
64-
app.minimize()
65-
app.restore()
66-
app._dwm_set_window_attribute(app.DWMWA_TRANSITIONS_FORCEDISABLED, 0)
64+
if prev_state == "zoomed":
65+
app._dwm_set_window_attribute(app.DWMWA_TRANSITIONS_FORCEDISABLED, 1)
66+
app.minimize()
67+
app.restore()
68+
app._dwm_set_window_attribute(app.DWMWA_TRANSITIONS_FORCEDISABLED, 0)
6769
prev_state = app.state()
6870

71+
6972
seticon(app)
7073

7174
# VARIABLES
@@ -244,7 +247,10 @@ def createManagerWindow(saveTimer, current_mins, current_secs, current_hrs):
244247
manager_window,
245248
text="Ok!",
246249
command=lambda: saveTimer(
247-
timer_sec_input.get(), timer_min_input.get(), timer_hr_input.get(), manager_app_window
250+
timer_sec_input.get(),
251+
timer_min_input.get(),
252+
timer_hr_input.get(),
253+
manager_app_window,
248254
),
249255
style="Accent.TButton",
250256
)
@@ -293,10 +299,7 @@ def createSettingsWindow():
293299
transparency_label.place(x=23, y=73)
294300

295301
pin_label = ttk.Label(
296-
tab_1,
297-
text=" Keep app always on top",
298-
image=pin_dark,
299-
compound=LEFT
302+
tab_1, text=" Keep app always on top", image=pin_dark, compound=LEFT
300303
)
301304
pin_label.place(x=23, y=123)
302305

@@ -322,8 +325,12 @@ def createSettingsWindow():
322325
default_hours_label = ttk.Label(tab_3, text=" Default Hours:").place(x=23, y=163)
323326

324327
logo_label = ttk.Label(tab_4, image=logo).place(x=50, y=30)
325-
TimerX_Label = ttk.Label(tab_4, text="TimerX", font=("Arial Rounded MT Bold", 50)).place(x=210, y=40)
326-
version_Label = ttk.Label(tab_4, text=f"Version: {ver}", font=("Segoe UI", "20")).place(x=220, y=120)
328+
TimerX_Label = ttk.Label(
329+
tab_4, text="TimerX", font=("Arial Rounded MT Bold", 50)
330+
).place(x=210, y=40)
331+
version_Label = ttk.Label(
332+
tab_4, text=f"Version: {ver}", font=("Segoe UI", "20")
333+
).place(x=220, y=120)
327334

328335
github_btn = ttk.Button(
329336
tab_4,
@@ -406,7 +413,9 @@ def slider_changed(value):
406413
ontop_button.place(x=360, y=125)
407414

408415
def browse():
409-
filedialog = askopenfile(mode="r", filetypes=[("Audio Files", ["*.mp3", "*.wav"])])
416+
filedialog = askopenfile(
417+
mode="r", filetypes=[("Audio Files", ["*.mp3", "*.wav"])]
418+
)
410419
if not filedialog == None:
411420
sound_path_entry.delete(0, END)
412421
sound_path_entry.insert(1, filedialog.name)
@@ -458,6 +467,14 @@ def ApplyChanges():
458467
config["sound_path"] = sp
459468

460469
setAlwaysOnTop()
470+
471+
saveTimer(
472+
config["default_seconds"],
473+
config["default_minutes"],
474+
config["default_hours"],
475+
None,
476+
)
477+
461478
saveTimer(config["default_seconds"], config["default_minutes"], config["default_hours"], None)
462479

463480
saveConfig(config)
@@ -494,13 +511,13 @@ def Error(reason, entry, label):
494511
label.configure(text="Enter a number above -1")
495512
elif reason == "sound":
496513
entry.state(["invalid"])
497-
label.configure(text="This file doesnt exist.")
514+
label.configure(text="This file doesnt exist.")
498515

499516
validated = True
500517

501518
try:
502519
void = int(default_secs_entry.get())
503-
if not void < 60:
520+
if not void < 60:
504521
validated = False
505522
Error("wv", default_secs_entry, dse_error_lbl)
506523
if not void > 0:
@@ -591,6 +608,7 @@ def reset_spe(e):
591608
sound_path_entry.bind("<FocusIn>", reset_spe)
592609
sound_path_entry.bind("<KeyRelease>", reset_spe)
593610

611+
594612
# KEYBINDS
595613
app.bind("key-space", startstopButtonPressed)
596614

@@ -705,29 +723,38 @@ def sizechanged(e):
705723
play_button.configure(width=int(app.winfo_width() / 12))
706724
manager_button.configure(width=int(app.winfo_width() / 12))
707725

726+
708727
def makeWindowsBlur():
709728
from ctypes import windll
710729
from sys import getwindowsversion
711-
if getwindowsversion().build >= 22000:
712-
from win32mica import ApplyMica, MICAMODE
730+
731+
if getwindowsversion().build >= 22000:
732+
from win32mica import MICAMODE, ApplyMica
733+
713734
app.wm_attributes("-transparent", bg_color)
714735
app.update()
715736
if theme == "Dark":
716-
ApplyMica(HWND=windll.user32.GetParent(app.winfo_id()), ColorMode=MICAMODE.DARK)
737+
ApplyMica(
738+
HWND=windll.user32.GetParent(app.winfo_id()), ColorMode=MICAMODE.DARK
739+
)
717740
else:
718-
ApplyMica(HWND=windll.user32.GetParent(app.winfo_id()), ColorMode=MICAMODE.LIGHT)
741+
ApplyMica(
742+
HWND=windll.user32.GetParent(app.winfo_id()), ColorMode=MICAMODE.LIGHT
743+
)
719744
else:
720745
from BlurWindow.blurWindow import GlobalBlur
746+
721747
if theme == "Dark":
722748
GlobalBlur(
723749
windll.user32.GetParent(app.winfo_id()),
724750
Acrylic=True,
725751
hexColor="#1c1c1c",
726-
Dark=True
752+
Dark=True,
727753
)
728754
else:
729755
pass
730-
756+
757+
731758
# LOAD IMAGES
732759
theme_dark = PhotoImage(file="./assets/images/dark/dark_theme.png")
733760
theme_light = PhotoImage(file="./assets/images/light/dark_theme.png")
@@ -764,15 +791,13 @@ def makeWindowsBlur():
764791

765792
app.bind("<Configure>", sizechanged)
766793

767-
app.bind("<Expose>", fullredraw)
794+
app.bind("<Expose>", fullredraw)
768795

769796
app.wait_visibility()
770797
app.attributes("-alpha", config["transperency"])
771798

772799
# UPDATE
773-
app.after(
774-
500, Thread(target=checkForUpdates, args=(ver,)).start
775-
)
800+
app.after(500, Thread(target=checkForUpdates, args=(ver,)).start)
776801

777802
# TKINTER MAINLOOP
778803
app.mainloop()

setup.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@
6262
build_exe_options = {
6363
"include_msvcr": True,
6464
"include_files": (r"./utils.py", r"./assets"),
65-
"includes": ["tkinter", "platform", "threading", "BlurWindow", "darkdetect", "sv_ttk"],
65+
"includes": [
66+
"tkinter",
67+
"platform",
68+
"threading",
69+
"BlurWindow",
70+
"darkdetect",
71+
"sv_ttk",
72+
],
6673
}
6774

6875
bdist_rpm_options = {"icon": icon}

0 commit comments

Comments
 (0)