pino
Useless X11 Python notification daemon
git clone https://git.pi66.xyz/pino
About | Files | Commits | Refs | License
root
Author: pixel2175
Date: 2024-12-18 10:32
commit: 67935064
Stat
| A | install.py | 105 | +105 | -0 |
| A | plugs/src/battry.c | 106 | +106 | -0 |
| A | src/config.json | 42 | +42 | -0 |
| A | src/pino.py | 190 | +190 | -0 |
| A | src/pino_start.c | 81 | +81 | -0 |
| A | uninstall.py | 61 | +61 | -0 |
Diff
diff --git a/install.py b/install.py
new file mode 100644
index 0000000..532a4a4
--- /dev/null
+++ b/install.py
@@ -0,0 +1,105 @@
+import os
+
+
+def get_distro():
+ if os.path.isfile("/etc/os-release"):
+ with open("/etc/os-release") as f:
+ for line in f:
+ if line.startswith("ID="):
+ return line.strip().split("=")[1].strip('"')
+ elif os.system("command -v lsb_release > /dev/null 2>&1") == 0:
+ stream = os.popen("lsb_release -i")
+ result = stream.read().strip()
+ if result:
+ return result.split(":")[1].strip()
...
Show all
Show less
diff --git a/install.py b/install.py
new file mode 100644
index 0000000..532a4a4
--- /dev/null
+++ b/install.py
@@ -0,0 +1,105 @@
+import os
+
+
+def get_distro():
+ if os.path.isfile("/etc/os-release"):
+ with open("/etc/os-release") as f:
+ for line in f:
+ if line.startswith("ID="):
+ return line.strip().split("=")[1].strip('"')
+ elif os.system("command -v lsb_release > /dev/null 2>&1") == 0:
+ stream = os.popen("lsb_release -i")
+ result = stream.read().strip()
+ if result:
+ return result.split(":")[1].strip()
...
diff --git a/install.py b/install.py
new file mode 100644
index 0000000..532a4a4
--- /dev/null
+++ b/install.py
@@ -0,0 +1,105 @@
+import os
+
+
+def get_distro():
+ if os.path.isfile("/etc/os-release"):
+ with open("/etc/os-release") as f:
+ for line in f:
+ if line.startswith("ID="):
+ return line.strip().split("=")[1].strip('"')
+ elif os.system("command -v lsb_release > /dev/null 2>&1") == 0:
+ stream = os.popen("lsb_release -i")
+ result = stream.read().strip()
+ if result:
+ return result.split(":")[1].strip()
+ return "unknown"
+
+
+distro = get_distro()
+
+
+def install_pip():
+ exit_code = os.system("pip3 --version > /dev/null 2>&1")
+ if exit_code == 0:
+ print("Pip: Done")
+ else:
+ print("pip not found. Installing pip...")
+ if distro in ["ubuntu", "debian"]:
+ os.system("sudo apt-get update")
+ os.system("sudo apt-get install -y python3-pip > /dev/null 2>&1")
+ os.system("clear")
+ print("Pip: Done")
+ elif distro == "fedora":
+ os.system("sudo dnf install -y python3-pip > /dev/null 2>&1")
+ os.system("clear")
+ print("Pip: Done")
+ elif distro in ["centos", "rhel"]:
+ os.system("sudo yum install -y python3-pip > /dev/null 2>&1")
+ os.system("clear")
+ print("Pip: Done")
+ elif distro == "arch":
+ os.system("sudo pacman -S --noconfirm python-pip > /dev/null 2>&1")
+ os.system("clear")
+ print("Pip: Done")
+ elif distro == "void":
+ os.system("sudo xbps-install -y python3-pip > /dev/null 2>&1")
+ os.system("clear")
+ print("Pip: Done")
+ else:
+ print("Unsupported distribution. Please install pip manually.")
+ exit(1)
+
+
+def install_system_deps():
+ if distro in ["ubuntu", "debian"]:
+ os.system("sudo apt-get update > /dev/null 2>&1")
+ os.system("sudo apt-get install -y tk > /dev/null 2>&1")
+ print("Dependencies: Done")
+ elif distro == "fedora":
+ os.system("sudo dnf install -y tk > /dev/null 2>&1")
+ print("Dependencies: Done")
+
+ elif distro in ["centos", "rhel"]:
+ os.system("sudo yum install -y tk > /dev/null 2>&1")
+ print("Dependencies: Done")
+ elif distro == "arch":
+ os.system("sudo pacman -S --noconfirm tk > /dev/null 2>&1")
+ print("Dependencies: Done")
+ elif distro == "void":
+ os.system("sudo xbps-install -y tk > /dev/null 2>&1")
+ print("Dependencies: Done")
+ else:
+ print("Unsupported distribution. Please install system dependencies manually.")
+
+
+def install_libs():
+ os.system(
+ "pip install customtkinter screeninfo playsound --break-system-packages > /dev/null 2>&1"
+ )
+ print("Libs: Done")
+
+
+def copy_file():
+ try:
+ os.system("cp ./src/pino.py pino > /dev/null 2>&1")
+ os.system(
+ 'echo "#!/usr/bin/env python3" | cat - pino > temp.txt && mv temp.txt pino > /dev/null 2>&1'
+ )
+ os.system("chmod +x pino > /dev/null 2>&1")
+ os.system("sudo cp pino ./src/pino_start /usr/bin/ > /dev/null 2>&1")
+ os.system("rm pino > /dev/null 2>&1")
+ os.system("sudo mkdir /etc/pino/ > /dev/null 2>&1")
+ os.system("mkdir ~/.config/pino/ ~/.config/pino/plugs/ > /dev/null 2>&1")
+ os.system("cp ./plugs/* ~/.config/pino/plugs > /dev/null 2>&1")
+ os.system(
+ "sudo cp ./src/config.json ./src/notification.mp3 /etc/pino/ > /dev/null 2>&1"
+ )
+ print("\nAll Done")
+ except:
+ print("The file has not moved")
+
+
+install_pip()
+install_libs()
+install_system_deps()
+copy_file()
diff --git a/plugs/battry b/plugs/battry
new file mode 100755
index 0000000..048461f
Binary files /dev/null and b/plugs/battry differ
diff --git a/plugs/src/battry.c b/plugs/src/battry.c
new file mode 100644
index 0000000..5429fe6
--- /dev/null
+++ b/plugs/src/battry.c
@@ -0,0 +1,106 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define BATTERY_PATH "/sys/class/power_supply/BAT1"
+#define MAX_BUFFER 100
+
+void pino(const char *title, const char *message) {
+ char command[MAX_BUFFER * 2];
+ snprintf(command, sizeof(command), "pino --title \"%s\" --massage \"%s\"",
+ title, message);
+ system(command);
+}
+
+int battery_capacity() {
+ char path[MAX_BUFFER];
+ snprintf(path, sizeof(path), "%s/capacity", BATTERY_PATH);
+
+ FILE *file = fopen(path, "r");
+ if (!file) {
+ perror("Error opening capacity file");
+ return -1;
+ }
+
+ int capacity;
+ if (fscanf(file, "%d", &capacity) != 1) {
+ perror("Error reading capacity");
+ fclose(file);
+ return -1;
+ }
+
+ fclose(file);
+ return capacity;
+}
+
+char *battery_status() {
+ char path[MAX_BUFFER];
+ snprintf(path, sizeof(path), "%s/status", BATTERY_PATH);
+
+ FILE *file = fopen(path, "r");
+ if (!file) {
+ perror("Error opening status file");
+ return NULL;
+ }
+
+ static char status[MAX_BUFFER];
+ if (fgets(status, sizeof(status), file) == NULL) {
+ perror("Error reading status");
+ fclose(file);
+ return NULL;
+ }
+
+ status[strcspn(status, "\n")] = 0;
+
+ fclose(file);
+ return status;
+}
+
+int main() {
+ int low_battery_warning = 0;
+ int charging_warning = 0;
+ int discharging_warning = 0;
+ int full = 0;
+
+ while (1) {
+ int capacity = battery_capacity();
+ char *status = battery_status();
+
+ if (capacity <= 20 && strcmp(status, "Discharging") == 0 &&
+ !low_battery_warning) {
+ pino("Low Battery", "Plug Your Charger in");
+ low_battery_warning = 1;
+ charging_warning = 0;
+ }
+
+ if (strcmp(status, "Charging") == 0) {
+ low_battery_warning = 0;
+ discharging_warning = 0;
+ full = 0;
+ if (!charging_warning) {
+ pino("Battery Charging", "The battery is charging now");
+ charging_warning = 1;
+ }
+ }
+
+ if (strcmp(status, "Discharging") == 0) {
+ low_battery_warning = 0;
+ charging_warning = 0;
+ full = 0;
+ if (!discharging_warning) {
+ pino("Battery Discharging", "The battery is discharging now ");
+ discharging_warning = 1;
+ }
+ }
+
+ if (capacity == 100 && strcmp(status, "Not charging") == 0 && !full) {
+ pino(" Battery Fully Charged", "You can unplug the charger now");
+ full = 1;
+ }
+
+ usleep(50000);
+ }
+
+ return 0;
+}
diff --git a/src/config.json b/src/config.json
new file mode 100644
index 0000000..0d09298
--- /dev/null
+++ b/src/config.json
@@ -0,0 +1,42 @@
+{
+ "screen": {
+ "monitor": 0,
+ "vertical": "right",
+ "horizontal": "top",
+ "x": 20,
+ "y": 20,
+ "width": 300,
+ "height": 100,
+ "opacity": 100,
+ "show": 3
+ },
+ "frame": {
+ "fg_color": "#1a1e24",
+ "font_family": "Fira Code",
+ "border": {
+ "width": 3,
+ "color": "#566D8d",
+ "border_radius": 10
+ }
+ },
+ "title": {
+ "color": "#c5c6c8",
+ "font_size": 19,
+ "x": 10,
+ "y": 10,
+ "weigth": "bold",
+ "wrap_length": "auto"
+ },
+ "massage": {
+ "color": "#626977",
+ "font_size": 15,
+ "x": 15,
+ "y": 45,
+ "weigth": "normal",
+ "wrap_length": "auto"
+ },
+ "optional": {
+ "pywal": false,
+ "sound": false
+ }
+}
diff --git a/src/notification.mp3 b/src/notification.mp3
new file mode 100644
index 0000000..3860589
Binary files /dev/null and b/src/notification.mp3 differ
diff --git a/src/pino.py b/src/pino.py
new file mode 100644
index 0000000..e7ebd31
--- /dev/null
+++ b/src/pino.py
@@ -0,0 +1,190 @@
+"""
+PINO Tool:
+ - Pino its a high customazabel app with low hardware usage and support pywal its a single file
+ and its work in x11 and wayland normally without problems
+
+ - to create a new notification u can use my Plugs or just create a scripts with any lang that u want
+ that when your script run this app to show what u want thats all
+
+REPORT:
+ if u get some glitchs or something and u want to report it,
+ just sent it to me in my DISCORD:pi66 and i will fix it
+
+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] --massage | will be set the string that u enter it to a massage 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" --massage "enter your massage" --config "enter a path for the config file that u want "
+
+
+
+FUTURE:
+- possiblity to add icon
+
+"""
+
+from customtkinter import CTk, CTkFont, CTkFrame, CTkLabel
+from screeninfo import get_monitors
+from json import load
+from os.path import exists, expanduser
+from os import getlogin, system
+from argparse import ArgumentParser
+# from threading import Thread
+# 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.add_argument(
+ "--config", metavar="", help="to use a special config file 'optional'"
+)
+args = parsers.parse_args()
+
+
+pywal_conf = None
+conf = None
+config_folder = f"/home/{getlogin()}/.config/pino/"
+
+if not args.config:
+ if exists(f"{config_folder}config.json"):
+ with open(f"{config_folder}config.json", "r") as file:
+ conf = load(file)
+ else:
+ system(f"mkdir {config_folder} > /dev/null 2>&1")
+ system(f"cp /etc/pino/config.json {config_folder} > /dev/null 2>&1")
+ with open(f"{config_folder}config.json", "r") as file:
+ conf = load(file)
+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")
+
+sx = get_monitors()[conf["screen"]["monitor"]].x
+sy = get_monitors()[conf["screen"]["monitor"]].y
+sw = get_monitors()[conf["screen"]["monitor"]].width
+sh = get_monitors()[conf["screen"]["monitor"]].height
+
+ax = conf["screen"]["x"]
+ay = conf["screen"]["y"]
+aw = conf["screen"]["width"]
+ah = conf["screen"]["height"]
+
+V = conf["screen"]["vertical"]
+H = conf["screen"]["horizontal"]
+
+frame_fg = ""
+border_color = ""
+title_color = ""
+massage_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"]
+ massage_color = pywal_conf["colors"]["color8"]
+
+else:
+ border_color = conf["frame"]["border"]["color"]
+ frame_fg = conf["frame"]["fg_color"]
+ title_color = conf["title"]["color"]
+ massage_color = conf["massage"]["color"]
+
+
+def place():
+ if V == "left".lower():
+ if H == "top".lower():
+ return f"{aw}x{ah}+{ax + sx}+{ay + sy}"
+ elif H == "bottom".lower():
+ return f"{aw}x{ah}+{sx + ax}+{sy + sh - ah - ay}"
+ if V == "right".lower():
+ if H == "top".lower():
+ return f"{aw}x{ah}+{sx + sw - aw - ax }+{ay + sy}"
+ elif H == "bottom".lower():
+ return f"{aw}x{ah}+{sx + sw - aw - ax }+{sy + sh - ah - ay}"
+
+
+class Main(CTk):
+ def __init__(self):
+ super().__init__()
+ self.geometry(str(place()))
+ self.resizable(False, False)
+ self.overrideredirect(True)
+
+ self.main = CTkFrame(
+ width=aw,
+ height=ah,
+ master=self,
+ border_width=conf["frame"]["border"]["width"],
+ border_color=border_color,
+ fg_color=frame_fg,
+ corner_radius=conf["frame"]["border"]["border_radius"],
+ )
+ self.main.place(x=0, y=0)
+
+ self.title = CTkLabel(
+ self,
+ text=f"{args.title} ",
+ anchor="w",
+ fg_color=frame_fg,
+ text_color=title_color,
+ width=aw
+ - int(conf["frame"]["border"]["width"])
+ - int(conf["title"]["x"] + 1),
+ wraplength=(int(aw - conf["title"]["x"]) - 20)
+ if (conf["title"]["wrap_length"] == "auto")
+ else (int(conf["title"]["wrap_length"]) - 20),
+ font=CTkFont(
+ conf["frame"]["font_family"],
+ conf["title"]["font_size"],
+ conf["title"]["weigth"],
+ ),
+ )
+ self.title.place(x=conf["title"]["x"], y=conf["title"]["y"])
+
+ self.massage = CTkLabel(
+ self,
+ text=f"{args.massage} ",
+ anchor="w",
+ fg_color=frame_fg,
+ text_color=massage_color,
+ width=aw
+ - int(conf["frame"]["border"]["width"])
+ - int(conf["massage"]["x"] + 2),
+ wraplength=(int(aw - conf["massage"]["x"]) - 20)
+ if (conf["massage"]["wrap_length"] == "auto")
+ else (int(conf["massage"]["wrap_length"]) - 20),
+ font=CTkFont(
+ conf["frame"]["font_family"],
+ conf["massage"]["font_size"],
+ conf["massage"]["weigth"],
+ ),
+ )
+ self.massage.place(x=conf["massage"]["x"], y=conf["massage"]["y"])
+
+
+if __name__ == "__main__":
+ if args.massage == None or args.title == None:
+ parsers.print_help()
+ exit()
+
+ root = Main()
+ root.after(30, lambda: root.attributes("-alpha", conf["screen"]["opacity"] / 100))
+ root.after(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()
+
+ root.mainloop()
diff --git a/src/pino_start b/src/pino_start
new file mode 100755
index 0000000..5561600
Binary files /dev/null and b/src/pino_start differ
diff --git a/src/pino_start.c b/src/pino_start.c
new file mode 100644
index 0000000..eb4737f
--- /dev/null
+++ b/src/pino_start.c
@@ -0,0 +1,81 @@
+#include <dirent.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#define MAX_PATH_LENGTH 1024
+
+int is_executable(const char *path) {
+ struct stat st;
+
+ // Check if file exists and is a regular file
+ if (stat(path, &st) != 0) {
+ return 0;
+ }
+
+ // Check if file is executable
+ return (st.st_mode & S_IXUSR) || (st.st_mode & S_IXGRP) ||
+ (st.st_mode & S_IXOTH);
+}
+
+int main() {
+ const char *home_dir = getenv("HOME");
+ if (home_dir == NULL) {
+ fprintf(stderr, "Could not get HOME directory\n");
+ return 1;
+ }
+
+ char plugs_dir[MAX_PATH_LENGTH];
+ snprintf(plugs_dir, sizeof(plugs_dir), "%s/.config/pino/plugs/", home_dir);
+
+ DIR *dir;
+ struct dirent *entry;
+
+ // Open directory
+ dir = opendir(plugs_dir);
+ if (dir == NULL) {
+ fprintf(stderr, "Unable to open directory %s: %s\n", plugs_dir,
+ strerror(errno));
+ return 1;
+ }
+
+ // Read directory entries
+ while ((entry = readdir(dir)) != NULL) {
+ // Skip current and parent directory entries
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
+ continue;
+ }
+
+ // Construct full path
+ char full_path[MAX_PATH_LENGTH];
+ snprintf(full_path, sizeof(full_path), "%s%s", plugs_dir, entry->d_name);
+
+ // Check if file is executable
+ if (is_executable(full_path)) {
+ printf("Starting: %s\n", full_path);
+
+ // Fork and execute
+ pid_t pid = fork();
+
+ if (pid == 0) {
+ // Child process
+ execl(full_path, full_path, NULL);
+
+ // If execl fails
+ fprintf(stderr, "Failed to execute %s\n", strerror(errno));
+ exit(1);
+ }
+ // Parent process continues to next file
+ }
+ }
+
+ // Close directory
+ closedir(dir);
+
+ printf("Finished.\n");
+
+ return 0;
+}
diff --git a/uninstall.py b/uninstall.py
new file mode 100644
index 0000000..e79138b
--- /dev/null
+++ b/uninstall.py
@@ -0,0 +1,61 @@
+import os
+
+
+def get_distro():
+ if os.path.isfile("/etc/os-release"):
+ with open("/etc/os-release") as f:
+ for line in f:
+ if line.startswith("ID="):
+ return line.strip().split("=")[1].strip('"')
+ elif os.system("command -v lsb_release > /dev/null 2>&1") == 0:
+ stream = os.popen("lsb_release -i")
+ result = stream.read().strip()
+ if result:
+ return result.split(":")[1].strip()
+ return "unknown"
+
+
+distro = get_distro()
+
+
+def remove_system_deps():
+ if distro in ["ubuntu", "debian"]:
+ os.system("sudo apt-get remove -y tk > /dev/null 2>&1")
+ print("Remove System Dep: Done")
+ elif distro == "fedora":
+ os.system("sudo dnf remove -y tk > /dev/null 2>&1")
+ print("Remove System Dep: Done")
+ elif distro in ["centos", "rhel"]:
+ os.system("sudo yum remove -y tk > /dev/null 2>&1")
+ print("Remove System Dep: Done")
+ elif distro == "arch":
+ os.system("sudo pacman -Rns --noconfirm tk > /dev/null 2>&1")
+ print("Remove System Dep: Done")
+ elif distro == "void":
+ os.system("sudo xbps-remove -R tk > /dev/null 2>&1")
+ print("Remove System Dep: Done")
+ else:
+ print("Unsupported distribution. Please install system dependencies manually.")
+
+
+def uninstall_libs():
+ os.system(
+ "pip uninstall --yes customtkinter playsound screeninfo --break-system-packages > /dev/null 2>&1"
+ )
+ print("Remove Libs: Done")
+
+
+def remove_files():
+ try:
+ os.system(
+ "sudo rm -r /usr/bin/pino /usr/bin/pino_start /etc/pino/ > /dev/null 2>&1"
+ )
+ os.system("rm -r ~/.config/pino/ ~/.config/pino/plugs/ > /dev/null 2>&1")
+ print("App Remove: Done")
+ except:
+ print("Faild remove")
+
+
+remove_system_deps()
+uninstall_libs()
+remove_files()