Pi66

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

← back to log

fix some error handling

author: pixel2175
date: 2024-12-23 17:21
hash: d1ac7a3acbee23e7e78b9c315547cf96c378bc1a

Diffstat:

M

src/pino.py
62 ++++++++++++++++--------------
 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
diff --git a/src/pino.py b/src/pino.py
index 000faaf..bcb994c 100644
--- a/src/pino.py
+++ b/src/pino.py
@@ -14,11 +14,9 @@ HOW TO USE IT:
   the app can handle 3 arguments:
     [1] --title   | will be set the string that u enter it to a title in the notification
     [2] --message | will be set the string that u enter it to a message in the notification
-    [3] --config  | this is a optional its use if you want to set a special config file for the first run

   command:
-    pino --title "enter you title" --message "enter your message" --config "enter a path for the config file that u want "
-
+    pino --title "enter you title" --message "enter your message"


 FUTURE:
@@ -85,8 +83,8 @@ else:
     with open(expanduser(args.config), "r") as file:
         conf = load(file)

-if not exists(f"{config_folder}notification.mp3"):
-    system(f"cp /etc/pino/notification.mp3 {config_folder} > /dev/null 2>&1")
+if not exists(f"{config_folder}notification.wav"):
+    system(f"cp /etc/pino/notification.wav {config_folder} > /dev/null 2>&1")


 sx = get_monitors()[conf["screen"]["monitor"]].x
@@ -108,13 +106,16 @@ title_color = ""
 message_color = ""


-if conf["optional"]["pywal"]:
-    with open(f"/home/{getlogin()}/.cache/wal/colors.json", "r") as file:
-        pywal_conf = load(file)
-    border_color = pywal_conf["colors"]["color1"]
-    frame_fg = pywal_conf["colors"]["color0"]
-    title_color = pywal_conf["special"]["cursor"]
-    message_color = pywal_conf["colors"]["color8"]
+if conf["optional"]["pywal"]  :
+    if exists(f"/home/{getlogin()}/.cache/wal/colors.json"):
+       with open(f"/home/{getlogin()}/.cache/wal/colors.json", "r") as file:
+           pywal_conf = load(file)
+       border_color = pywal_conf["colors"]["color1"]
+       frame_fg = pywal_conf["colors"]["color0"]
+       title_color = pywal_conf["special"]["cursor"]
+       message_color = pywal_conf["colors"]["color8"]
+    else:
+        print("[*]- Pywal is not installed !!")

 else:
     border_color = conf["frame"]["border"]["color"]
@@ -215,23 +216,28 @@ if __name__ == "__main__":
         root.quit,
     )

-    if conf["optional"]["sound"]:
-        from threading import Thread
-        from playsound import playsound
-
-        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")
-        )
+    if conf["optional"]["sound"] :
+        def start_sound():
+            from threading import Thread
+            from os import environ
+            environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
+            from pygame.mixer import init,Sound
+            init()
+     
+            thread = Thread(target=lambda: Sound(str(args.sound) if args.sound else f"{config_folder}notification.wav").play())
+            try:
+                thread.start()
+            except KeyboardInterrupt:
+                exit()
+  
+        if exists(f"{config_folder}notification.wav"):
+            start_sound()
+            pass
+        else:
+            print("[*]- sound file doasn't exist !!")
+            system(f"cp /etc/pino/notification.wav {config_folder}")
+            start_sound()

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