This commit is contained in:
2023-08-04 11:31:43 +02:00
parent 567542ec4d
commit 4f33273935
3 changed files with 163 additions and 23 deletions

View File

@@ -2,40 +2,98 @@ from PyQt6.QtGui import QIcon, QAction
from PyQt6.QtWidgets import QApplication, QMenu, QSystemTrayIcon
import os
import signal
import subprocess
path = os.path.dirname(os.path.abspath(__file__))
# enable
# xset s on +dpms;xscreensaver --nosplash
# disable
# xset s off -dpms;xscreensaver-command -exit
app = QApplication([])
app.setQuitOnLastWindowClosed(False)
# Adding an icon
icon = QIcon("work.png")
# PID procesos
pidx = os.popen('pidof xscreensaver').read()
pid4 = os.popen('pidof xfce4-screensaver').read()
# Creating the options
menu = QMenu()
# Menú activar
optionActivo = QAction("Activar salvapantallas")
optionActivo.triggered.connect(lambda: activar())
# Menú desactivar
optionDesactivo = QAction("Desactivar salvapantallas")
optionDesactivo.triggered.connect(lambda: desactivar())
# Saber si está funcionando y cambiar el icono
if pidx == "" and pid4 == "":
icon = QIcon(path+"/cinema.png")
menu.addAction(optionActivo)
os.popen('xset -dpms').read()
result = subprocess.run(
["/usr/bin/bash", "-c", "xfce4-power-manager -q"])
print(result)
else:
icon = QIcon(path+"/work.png")
menu.addAction(optionDesactivo)
os.popen('xset +dpms').read()
result = subprocess.run(
["/usr/bin/bash", "-c", "nohup xfce4-power-manager & 2>&1 >/dev/null"])
print(result)
# opción desactivar
def desactivar():
global icon
os.popen('xset +dpms').read()
result = subprocess.run(
["/usr/bin/bash", "-c", "xfce4-power-manager -q"])
print(result)
icon = QIcon(path+"/cinema.png")
tray.setIcon(icon)
menu.removeAction(optionDesactivo)
menu.removeAction(quit)
menu.addAction(optionActivo)
menu.addAction(quit)
pidx = os.popen('pidof xscreensaver').read()
pid4 = os.popen('pidof xfce4-screensaver').read()
if pidx != "":
os.kill(int(pidx), signal.SIGKILL)
if pid4 != "":
os.kill(int(pid4), signal.SIGKILL)
# opción activar
def activar():
global icon
os.popen('xset -dpms').read()
result = subprocess.run(
["/usr/bin/bash", "-c", "nohup xfce4-power-manager & 2>&1 >/dev/null"])
print(result)
icon = QIcon(path+"/work.png")
tray.setIcon(icon)
menu.removeAction(optionActivo)
menu.removeAction(quit)
menu.addAction(optionDesactivo)
menu.addAction(quit)
if os.path.isfile('/usr/bin/xfce4-screensaver'):
result = subprocess.run(
["/usr/bin/bash", "-c", "xfce4-screensaver &"])
print(result)
elif os.path.isfile('/usr/bin/xscreensaver'):
result = subprocess.run(
["/usr/bin/bash", "-c", "xscreensaver &"])
print(result)
# Adding item on the menu bar
tray = QSystemTrayIcon()
tray.setIcon(icon)
tray.setVisible(True)
# Creating the options
menu = QMenu()
# opción desactivar screensaver
def desactivar():
pidx = os.popen('pidof xscreensaver').read()
if pidx != "":
os.killpg(int(pidx), signal.SIGTERM)
pid4 = os.popen('pidof xfce4-screensaver').read()
if pid4 != "":
os.killpg(os.getpid(int(pid4)), signal.SIGTERM)
optionDesactivo = QAction("Desactivar salvapantallas")
optionDesactivo.triggered.connect(lambda: desactivar())
menu.addAction(optionDesactivo)
# To quit the app
quit = QAction("Quit")