Skip to content

Commit

Permalink
Add a right click context menu to the systray applet (to "quit/exit" …
Browse files Browse the repository at this point in the history
…it and run arch-update) (#165)

* - Add gettext translation to systray
- Add right-click-menu with two options
- - Update
- - Exit
- Added blank translation keys

---------

Co-authored-by: Robin Candau <[email protected]>
  • Loading branch information
trigg and Antiz96 authored May 19, 2024
1 parent 907d7f2 commit 8a850eb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
8 changes: 8 additions & 0 deletions po/arch-update.pot
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,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 @@ -493,3 +493,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:
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

0 comments on commit 8a850eb

Please sign in to comment.