59 lines
1.2 KiB
Python
59 lines
1.2 KiB
Python
from PyQt6.QtGui import QIcon, QAction
|
|
from PyQt6.QtWidgets import QApplication, QMenu, QSystemTrayIcon
|
|
import os
|
|
|
|
# enable
|
|
# xset s on +dpms;xscreensaver --nosplash
|
|
# disable
|
|
# xset s off -dpms;xscreensaver-command -exit
|
|
|
|
# saber si se está ejecutando
|
|
|
|
|
|
pid = os.popen('pidof xscreensaver').read()
|
|
print(pid)
|
|
matado = os.popen('kill {int(pid)}').read()
|
|
print(matado)
|
|
|
|
|
|
# Al iniciar se activa xscreensaver
|
|
salida = os.popen(
|
|
'xset s on +dpms;/usr/bin/xscreensaver --nosplash;echo ENABLE xscreensaver').read()
|
|
print(salida)
|
|
|
|
app = QApplication([])
|
|
app.setQuitOnLastWindowClosed(False)
|
|
|
|
# Adding an icon
|
|
icon = QIcon("work.png")
|
|
|
|
# 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():
|
|
salida = os.popen(
|
|
'xset s off -dpms;xscreensaver-command -exit').read()
|
|
print(salida)
|
|
|
|
|
|
optionDesactivo = QAction("Desactivar salvapantallas")
|
|
optionDesactivo.triggered.connect(lambda: desactivar())
|
|
menu.addAction(optionDesactivo)
|
|
|
|
# To quit the app
|
|
quit = QAction("Quit")
|
|
quit.triggered.connect(app.quit)
|
|
menu.addAction(quit)
|
|
|
|
# Adding options to the System Tray
|
|
tray.setContextMenu(menu)
|
|
|
|
app.exec()
|