Skip to content

Commit 870cab5

Browse files
authored
Add files via upload
1 parent 8a5fbc4 commit 870cab5

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

core/icon0.ico

37.2 KB
Binary file not shown.

core/notification.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
core module for showing a windows 10 action center toaster showing that you need to take a break.
3+
"""
4+
from win10toast import ToastNotifier
5+
6+
# initializing toaster service
7+
toasterService = ToastNotifier()
8+
9+
# declaring a function for showing toaster messages.
10+
def showWinToast(title: str, content: str, toastDuration: int=2,
11+
iconPath=None, isThreaded: bool=True):
12+
"""
13+
Shows a message in Windows 10's Action Center.
14+
15+
This function takes 6 parameters (2 required, 4 optional)
16+
17+
Parameters are: title: str, content: str, toastDuration: int, iconPath, isThreaded: bool
18+
"""
19+
toasterService.show_toast(title, content, duration=toastDuration, icon_path=iconPath, threaded=isThreaded)
20+
return None
21+
22+
23+
if __name__ == '__main__':
24+
# showWinToast("test", "hello world", toastDuration=40)
25+
# raise SystemExit(0) # for testing only
26+
pass

core/windows.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""
2+
core module for spawning a notification window indicating that user has been looking at screen for so long
3+
"""
4+
# imports
5+
from tkinter import *
6+
from tkinter import scrolledtext, messagebox
7+
from customtkinter import *
8+
from awesometkinter import DEFAULT_COLOR
9+
# imports necessary to get the path where the files are extracted in
10+
import os
11+
import sys
12+
13+
# initializing a variable containing the path where application files are stored.
14+
application_path = ''
15+
16+
# attempting to get where the program files are stored
17+
if getattr(sys, 'frozen', False):
18+
# if program was frozen (compiled) using pyinstaller, the pyinstaller bootloader creates a sys attribute
19+
# frozen=True to indicate that the script file was compiled using pyinstaller, then it creates a
20+
# constant in sys that points to the directory where program executable is (where program files are extracted in).
21+
application_path = sys._MEIPASS
22+
else:
23+
# if program is not frozen (compiled) using pyinstaller and is running normally like a Python 3.x.x file.
24+
application_path = os.path.dirname(os.path.abspath(__file__))
25+
26+
# changing the current working directory to the path where one-file mode source files are extracted in.
27+
os.chdir(application_path)
28+
29+
30+
class RestWindow(Tk):
31+
def __init__(self, sessionMinutes):
32+
self.sessionMinutes = sessionMinutes
33+
super().__init__()
34+
# customtkinter related configuration.
35+
deactivate_automatic_dpi_awareness() # for hidpi displays
36+
set_appearance_mode("dark")
37+
set_default_color_theme("blue")
38+
# ------------------------------------
39+
40+
self.title("ScreenBreak")
41+
# declaring the geometry of the windows in separate variables.
42+
wWidth = 638
43+
wHeight = 300
44+
self.geometry(f'{wWidth}x{wHeight}')
45+
self.minsize(wWidth, wHeight)
46+
self.maxsize(wWidth, wHeight)
47+
self.resizable(False, False)
48+
self.configure(bg=DEFAULT_COLOR)
49+
try:
50+
self.iconbitmap(f"{application_path}\\core\\icon0.ico")
51+
except Exception as errorLoadingIconBitmap:
52+
messagebox.showerror("Error in mainloop", f"Couldn't load iconbitmap for this window due to this error\n{errorLoadingIconBitmap}\n\nPress OK to continue")
53+
pass
54+
55+
# defining a function to insert text into the scrolledtext widget.
56+
def insertInformation():
57+
"""
58+
A function for inserting text into the scrolledtext widget that will show information to the user.
59+
"""
60+
self.moreinfo_widget.configure(state='normal')
61+
self.moreinfo_widget.delete(1.0, END)
62+
self.moreinfo_widget.insert(END, f"""You have been looking at the computer's screen for {self.sessionMinutes} minute(s)
63+
continuously, it is strongly recommended that you take a break for 5
64+
minutes or more to save your eyesight and help you get better sleep at night.
65+
66+
Please take a break for 5 minutes or more then press the 'OK' button
67+
below to close this window and notify you again after {self.sessionMinutes} minute(s) from the
68+
pressing time.
69+
""")
70+
self.moreinfo_widget.configure(state='disabled')
71+
return None
72+
73+
74+
# defining the function for the OK button
75+
def okBtn_Function():
76+
"""
77+
OK btn function
78+
"""
79+
self.destroy()
80+
return None
81+
# declaring widgets in this window.
82+
self.lbl0 = Label(self, bg=DEFAULT_COLOR, foreground='white', font=("Arial Bold",14), text="You need to take a break.")
83+
self.lbl0.place(x=15, y=7)
84+
self.moreinfo_widget = scrolledtext.ScrolledText(self, cursor='arrow', font=("Consolas", 11), background=DEFAULT_COLOR, foreground='white', state='disabled')
85+
self.moreinfo_widget.place(x=15, y=40, relwidth=0.96, relheight=0.73)
86+
self.ok_btn = CTkButton(self, text="OK", command=okBtn_Function)
87+
self.ok_btn.place(x=250, y=265)
88+
# let's display information to the user.
89+
insertInformation()
90+
91+
92+
93+
94+
95+
if __name__ == '__main__':
96+
pass

0 commit comments

Comments
 (0)