Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a right click context menu to the systray applet (to "quit/exit" it and run arch-update) #165

Merged
merged 13 commits into from
May 19, 2024
8 changes: 8 additions & 0 deletions po/arch-update.pot
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,11 @@ msgstr ""
#, sh-format
msgid "The '${config_file}' configuration file has been generated"
msgstr ""

#: src/script/arch-update-tray.py:117
msgid "Run Arch-Update"
msgstr ""

#: src/script/arch-update-tray.py:118
msgid "Exit"
msgstr ""
8 changes: 8 additions & 0 deletions po/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,11 @@ msgstr ""
#, sh-format
msgid "The '${config_file}' configuration file has been generated"
msgstr "Le fichier de configuration '${config_file}' a été généré"

#: src/script/arch-update-tray.py:117
msgid "Run Arch-Update"
msgstr "Lancer Arch-Update"

#: src/script/arch-update-tray.py:118
msgid "Exit"
msgstr "Quitter"
49 changes: 45 additions & 4 deletions src/script/arch-update-tray.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python3
"""Arch-Update System Tray."""
import gettext
import logging
import os
import sys
import subprocess
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QApplication, QSystemTrayIcon
from PyQt6.QtGui import QIcon, QAction
from PyQt6.QtWidgets import QApplication, QSystemTrayIcon, QMenu
from PyQt6.QtCore import QFileSystemWatcher

# Create logger
Expand All @@ -22,6 +23,30 @@
log.error("Statefile does not exist: %s", STATE_FILE)
sys.exit(1)

# Find translations
paths = []
if 'XDG_DATA_DIRS' in os.environ:
Antiz96 marked this conversation as resolved.
Show resolved Hide resolved
paths.extend(os.environ['XDG_DATA_DIRS'].split(":"))
if 'XDG_DATA_HOME' in os.environ:
paths.extend(os.environ['XDG_DATA_HOME'].split(":"))
if 'HOME' in os.environ:
paths.append(os.path.join(
os.environ['HOME'], '.local', 'share'))
paths.extend(['/usr/share', '/usr/local/share'])
_ = None
for path in paths:
french_translation_file = os.path.join(
path, "locale", "fr", "LC_MESSAGES", "Arch-Update.mo")
if os.path.isfile(french_translation_file):
path = os.path.join(path, 'locale')
t = gettext.translation('Arch-Update', localedir=path, fallback=True)
_ = t.gettext
break
if not _:
t = gettext.translation('Arch-Update', fallback=True)
_ = t.gettext
log.error("No translations found")


def arch_update():
""" Launch with desktop file """
Expand Down Expand Up @@ -63,10 +88,14 @@ def file_changed(self):
icon = QIcon.fromTheme(contents)
self.tray.setIcon(icon)

def update(self):
def run(self):
""" Start arch-update """
arch_update()

def exit(self):
""" Close systray process """
sys.exit(0)

def __init__(self, statefile):
""" Start Qt6 System Tray """

Expand All @@ -81,7 +110,19 @@ def __init__(self, statefile):
self.tray = QSystemTrayIcon()
self.file_changed()
self.tray.setVisible(True)
self.tray.activated.connect(self.update)
self.tray.activated.connect(self.run)

# Menu
menu = QMenu()
menu_launch = QAction(_("Run Arch-Update"))
menu_exit = QAction(_("Exit"))
menu.addAction(menu_launch)
menu.addAction(menu_exit)

menu_launch.triggered.connect(self.run)
menu_exit.triggered.connect(self.exit)

self.tray.setContextMenu(menu)

# File Watcher
self.watcher = QFileSystemWatcher([self.statefile])
Expand Down