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 system tray #68

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/nexus/GUI.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import argparse
import os
from threading import Thread
from pathlib import Path
from typing import Literal

from PySide6.QtCore import Qt, QTranslator, QLocale
from PySide6.QtWidgets import QApplication, QPushButton, QStatusBar, QTableWidget, QTableWidgetItem, QMainWindow, \
QDialog, QFileDialog, QDialogButtonBox, QVBoxLayout, QLabel, QMenu
QDialog, QFileDialog, QDialogButtonBox, QVBoxLayout, QLabel, QMenu, QSystemTrayIcon
from PySide6.QtGui import QIcon, QAction

from nexus.Freqlog import Freqlog
from nexus.ui.BanlistDialog import Ui_BanlistDialog
Expand Down Expand Up @@ -74,12 +76,31 @@ def __init__(self, args: argparse.Namespace):
self.app = QApplication([])
self.window = MainWindow()

script_parent_path = str(Path(__file__).resolve().parent)

# Translation
self.translator = Translator(self.app)
if self.translator.load(QLocale.system(), 'i18n', '_', str(Path(__file__).resolve().parent) + '/translations'):
if self.translator.load(QLocale.system(), 'i18n', '_', os.path.join(script_parent_path, 'translations')):
self.app.installTranslator(self.translator)
self.tr = self.translator.translate

# System tray
self.tray_icon = QIcon(os.path.join(script_parent_path, 'assets', 'images', 'icon.ico'))
self.tray = QSystemTrayIcon()
self.tray.activated.connect(self.show_hide)
self.tray.setIcon(self.tray_icon)
self.tray.setVisible(True)

# System tray menu
self.tray_menu = QMenu()
self.start_stop_tray_menu_action = QAction(self.tr("GUI", "Start/stop logging"))
self.quit_tray_menu_action = QAction(self.tr("GUI", "Quit"))
self.start_stop_tray_menu_action.triggered.connect(self.start_stop)
self.quit_tray_menu_action.triggered.connect(self.app.quit)
self.tray_menu.addAction(self.start_stop_tray_menu_action)
self.tray_menu.addAction(self.quit_tray_menu_action)
self.tray.setContextMenu(self.tray_menu)

# Components
self.start_stop_button: QPushButton = self.window.startStopButton
self.chentry_table: QTableWidget = self.window.chentryTable
Expand Down Expand Up @@ -165,6 +186,13 @@ def __init__(self, args: argparse.Namespace):
self.window.entries_input.valueChanged.connect(self.refresh)
self.window.search_input.textChanged.connect(self.refresh)

def show_hide(self, reason):
if reason == QSystemTrayIcon.ActivationReason.Trigger:
if not self.window.isVisible():
self.window.show()
else:
self.window.hide()

def set_style(self, style: Literal['Nexus_Dark', 'Fusion', 'Default']):
self.app.setStyleSheet('')
if style == 'Default':
Expand Down
Binary file added src/nexus/assets/images/icon.ico
Binary file not shown.
54 changes: 54 additions & 0 deletions src/nexus/assets/images/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 37 additions & 25 deletions translations/i18n_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,140 +70,152 @@
<context>
<name>GUI</name>
<message>
<location filename="../src/nexus/GUI.py" line="225"/>
<location filename="../src/nexus/GUI.py" line="253"/>
<source>GUI</source>
<comment>Start logging</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="194"/>
<location filename="../src/nexus/GUI.py" line="222"/>
<source>GUI</source>
<comment>Starting...</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="109"/>
<location filename="../src/nexus/GUI.py" line="96"/>
<source>GUI</source>
<comment>Start/stop logging</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="117"/>
<location filename="../src/nexus/GUI.py" line="97"/>
<source>GUI</source>
<comment>Quit</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="130"/>
<source>GUI</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="138"/>
<source>GUI</source>
<comment>Ban and delete</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="205"/>
<location filename="../src/nexus/GUI.py" line="233"/>
<source>GUI</source>
<comment>Stop logging</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="210"/>
<location filename="../src/nexus/GUI.py" line="238"/>
<source>GUI</source>
<comment>Logging started</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="230"/>
<location filename="../src/nexus/GUI.py" line="258"/>
<source>GUI</source>
<comment>Logging stopped</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="277"/>
<location filename="../src/nexus/GUI.py" line="305"/>
<source>GUI</source>
<comment>Loaded {}/{} freqlogged words</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="316"/>
<location filename="../src/nexus/GUI.py" line="392"/>
<location filename="../src/nexus/GUI.py" line="344"/>
<location filename="../src/nexus/GUI.py" line="420"/>
<source>GUI</source>
<comment>Banned &apos;{}&apos;</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="317"/>
<location filename="../src/nexus/GUI.py" line="393"/>
<location filename="../src/nexus/GUI.py" line="345"/>
<location filename="../src/nexus/GUI.py" line="421"/>
<source>GUI</source>
<comment>&apos;{}&apos; already banned</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="339"/>
<location filename="../src/nexus/GUI.py" line="367"/>
<source>GUI</source>
<comment>Unban {} words?</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="341"/>
<location filename="../src/nexus/GUI.py" line="369"/>
<source>GUI</source>
<comment>Unban &apos;{}&apos;?</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="348"/>
<location filename="../src/nexus/GUI.py" line="376"/>
<source>GUI</source>
<comment>Unbanned &apos;{}&apos;</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="349"/>
<location filename="../src/nexus/GUI.py" line="377"/>
<source>GUI</source>
<comment>&apos;{}&apos; not banned</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="351"/>
<location filename="../src/nexus/GUI.py" line="379"/>
<source>GUI</source>
<comment>None of the selected words were banned</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="354"/>
<location filename="../src/nexus/GUI.py" line="382"/>
<source>GUI</source>
<comment>Unbanned {}/{} selected words</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="373"/>
<location filename="../src/nexus/GUI.py" line="401"/>
<source>GUI</source>
<comment>Exported {} entries to {}</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="382"/>
<location filename="../src/nexus/GUI.py" line="410"/>
<source>GUI</source>
<comment>Ban and delete {} words?</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="384"/>
<location filename="../src/nexus/GUI.py" line="412"/>
<source>GUI</source>
<comment>Ban and delete &apos;{}&apos;?</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="395"/>
<location filename="../src/nexus/GUI.py" line="423"/>
<source>GUI</source>
<comment>All of the selected words were already banned</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="398"/>
<location filename="../src/nexus/GUI.py" line="426"/>
<source>GUI</source>
<comment>Banned and deleted {}/{} selected words</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="400"/>
<location filename="../src/nexus/GUI.py" line="428"/>
<source>GUI</source>
<comment>Confirm ban</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/nexus/GUI.py" line="356"/>
<location filename="../src/nexus/GUI.py" line="384"/>
<source>GUI</source>
<comment>Confirm unban</comment>
<translation type="unfinished"></translation>
Expand Down