77 lines
1.9 KiB
Python
77 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import signal
|
|
import subprocess
|
|
from gi.repository import Gtk, AppIndicator3
|
|
import gi
|
|
gi.require_version('Gtk', '4.0') # Usamos GTK 3
|
|
gi.require_version('AppIndicator3', '0.1')
|
|
|
|
|
|
class Indicador:
|
|
|
|
def __init__(self):
|
|
self.app = 'menu_comandos_systray'
|
|
# Reemplaza con la ruta a tu icono
|
|
icono = os.path.abspath('/ruta/a/tu/icono.png')
|
|
|
|
self.indicador = AppIndicator3.Indicator.new(
|
|
self.app,
|
|
icono,
|
|
AppIndicator3.IndicatorCategory.APPLICATION_STATUS
|
|
)
|
|
self.indicador.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
|
|
|
|
# Crear el menú
|
|
self.menu = Gtk.Menu()
|
|
|
|
# Opción 1
|
|
opcion1 = Gtk.MenuItem(label='Comando 1')
|
|
opcion1.connect('activate', self.ejecutar_comando1)
|
|
self.menu.append(opcion1)
|
|
|
|
# Opción 2
|
|
opcion2 = Gtk.MenuItem(label='Comando 2')
|
|
opcion2.connect('activate', self.ejecutar_comando2)
|
|
self.menu.append(opcion2)
|
|
|
|
# Opción 3
|
|
opcion3 = Gtk.MenuItem(label='Comando 3')
|
|
opcion3.connect('activate', self.ejecutar_comando3)
|
|
self.menu.append(opcion3)
|
|
|
|
# Separador
|
|
separador = Gtk.SeparatorMenuItem()
|
|
self.menu.append(separador)
|
|
|
|
# Opción Salir
|
|
salir = Gtk.MenuItem(label='Salir')
|
|
salir.connect('activate', self.salir)
|
|
self.menu.append(salir)
|
|
|
|
self.menu.show_all()
|
|
self.indicador.set_menu(self.menu)
|
|
|
|
def ejecutar_comando1(self, widget):
|
|
subprocess.run(['comando1'])
|
|
|
|
def ejecutar_comando2(self, widget):
|
|
subprocess.run(['comando2'])
|
|
|
|
def ejecutar_comando3(self, widget):
|
|
subprocess.run(['comando3'])
|
|
|
|
def salir(self, widget):
|
|
Gtk.main_quit()
|
|
|
|
|
|
def main():
|
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
Indicador()
|
|
Gtk.main()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|