Pi66

pino
Python notification daemon.
git clone https://git.pi66.xyz/pino

← back to log

enhanced Ux and error messages

author: pixel2175
date: 2024-12-21 14:27
hash: 967141dc2adee61f66761d0e6dc92fcd09bf4260

Diffstat:

M

src/pino.py
72 +++++++++++++++++++++++++-----
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
diff --git a/src/pino.py b/src/pino.py
index e7ebd31..27d1bb4 100644
--- a/src/pino.py
+++ b/src/pino.py
@@ -26,8 +26,10 @@ FUTURE:

 """

-from customtkinter import CTk, CTkFont, CTkFrame, CTkLabel
-from screeninfo import get_monitors
+from customtkinter.windows.widgets import CTkFrame, CTkLabel
+from customtkinter.windows.ctk_tk import CTk
+from customtkinter.windows.ctk_input_dialog import CTkFont
+from screeninfo.screeninfo import get_monitors
 from json import load
 from os.path import exists, expanduser
 from os import getlogin, system
@@ -36,15 +38,36 @@ from argparse import ArgumentParser
 # from playsound import playsound


-parsers = ArgumentParser(description="Enter Title and Massage that you want to show")
-parsers.add_argument("--title", metavar="", help="enter a string title")
-parsers.add_argument("--massage", metavar="", help="enter a string massage")
+parsers = ArgumentParser(
+    description="""This tool lets you display notification with  customizable options. 
+you can also use a configuration file to set theme and everything easily (conf path = ~/.config/pino)"""
+)
+
+parsers.add_argument("--title", metavar="", help="set the notification title content")
+
 parsers.add_argument(
-    "--config", metavar="", help="to use a special config file 'optional'"
+    "--massage", metavar="", help="set the notification massage content"
 )
-args = parsers.parse_args()


+parsers.add_argument(
+    "--opacity",
+    metavar="",
+    help="set the opacity level for the window (range: 0 to 100)",
+)
+
+parsers.add_argument(
+    "--delay", metavar="", help="set the delay before program closes with secends"
+)
+parsers.add_argument(
+    "--sound",
+    metavar="",
+    help="set a custom sound file to play with notificaitons ( enable it in config file if its not )",
+)
+parsers.add_argument("--config", metavar="", help="set a custom configuration file ")
+
+
+args = parsers.parse_args()
 pywal_conf = None
 conf = None
 config_folder = f"/home/{getlogin()}/.config/pino/"
@@ -65,6 +88,7 @@ else:
 if not exists(f"{config_folder}notification.mp3"):
     system(f"cp /etc/pino/notification.mp3 {config_folder} > /dev/null 2>&1")

+
 sx = get_monitors()[conf["screen"]["monitor"]].x
 sy = get_monitors()[conf["screen"]["monitor"]].y
 sw = get_monitors()[conf["screen"]["monitor"]].width
@@ -177,14 +201,38 @@ if __name__ == "__main__":
         exit()

     root = Main()
-    root.after(30, lambda: root.attributes("-alpha", conf["screen"]["opacity"] / 100))
-    root.after(conf["screen"]["show"] * 1000, root.quit)
+    root.after(
+        30,
+        lambda: root.attributes(
+            "-alpha",
+            int(args.opacity) / 100
+            if args.opacity
+            else conf["screen"]["opacity"] / 100,
+        ),
+    )
+    root.after(
+        int(args.delay) * 1000 if args.delay else conf["screen"]["show"] * 1000,
+        root.quit,
+    )

     if conf["optional"]["sound"]:
         from threading import Thread
         from playsound import playsound

-        thread = Thread(target=lambda: playsound(f"{config_folder}notification.mp3"))
-        thread.start()
+        def start_sound(file):
+            return Thread(target=lambda: playsound(file))
+
+        thread = (
+            start_sound(str(args.sound))
+            if args.sound
+            else start_sound(f"{config_folder}notification.mp3")
+        )

-    root.mainloop()
+        try:
+            thread.start()
+        except KeyboardInterrupt:
+            exit()
+    try:
+        root.mainloop()
+    except KeyboardInterrupt:
+        exit()