Add System Tray Icon + settings
This commit is contained in:
parent
a9e02ae1a5
commit
65f08007c1
|
@ -1,3 +1,4 @@
|
|||
from PyQt5.QtCore import QSettings
|
||||
from PyQt5.QtGui import QCloseEvent
|
||||
from PyQt5.QtWidgets import QMainWindow, QMessageBox
|
||||
|
||||
|
@ -14,9 +15,10 @@ class MainWindow(QMainWindow):
|
|||
self.show()
|
||||
|
||||
def closeEvent(self, e: QCloseEvent):
|
||||
if self.tab_widget.downloadTab.active_game is None:
|
||||
e.accept()
|
||||
elif QMessageBox.question(self, "Close", self.tr("There is a download active. Do you really want to exit app?"), QMessageBox.Yes, QMessageBox.No) == QMessageBox.Yes:
|
||||
if QSettings().value("sys_tray", True, bool):
|
||||
self.hide()
|
||||
e.ignore()
|
||||
elif self.tab_widget.downloadTab.active_game is not None and QMessageBox.question(self, "Close", self.tr("There is a download active. Do you really want to exit app?"), QMessageBox.Yes, QMessageBox.No) == QMessageBox.Yes:
|
||||
e.accept()
|
||||
else:
|
||||
e.ignore()
|
||||
e.accept()
|
||||
|
|
|
@ -31,7 +31,6 @@ class TabWidget(QTabWidget):
|
|||
|
||||
self.tabBarClicked.connect(lambda x: self.game_list.layout.setCurrentIndex(0) if x == 0 else None)
|
||||
|
||||
# Commented, because it is not finished
|
||||
self.cloud_saves = SyncSaves(core)
|
||||
self.addTab(self.cloud_saves, "Cloud Saves")
|
||||
|
||||
|
|
|
@ -19,14 +19,9 @@ class RareSettings(QGroupBox):
|
|||
self.setObjectName("group")
|
||||
self.layout = QVBoxLayout()
|
||||
settings = QSettings()
|
||||
img_dir = settings.value("img_dir", type=str)
|
||||
language = settings.value("language", type=str)
|
||||
# default settings
|
||||
if not img_dir:
|
||||
settings.setValue("img_dir", os.path.expanduser("~/.cache/rare/images/"))
|
||||
if not language:
|
||||
settings.setValue("language", get_lang())
|
||||
del settings
|
||||
img_dir = settings.value("img_dir",os.path.expanduser("~/.cache/rare/images/"), type=str)
|
||||
language = settings.value("language", get_lang(), type=str)
|
||||
|
||||
# select Image dir
|
||||
self.select_path = PathEdit(img_dir, type_of_file=QFileDialog.DirectoryOnly)
|
||||
self.select_path.text_edit.textChanged.connect(lambda t: self.save_path_button.setDisabled(False))
|
||||
|
@ -50,6 +45,12 @@ class RareSettings(QGroupBox):
|
|||
self.select_lang.currentIndexChanged.connect(self.update_lang)
|
||||
self.layout.addWidget(self.lang_widget)
|
||||
|
||||
self.exit_to_sys_tray = QCheckBox("Hide to System Tray Icon")
|
||||
self.exit_to_sys_tray.setChecked(settings.value("sys_tray", True, bool))
|
||||
self.exit_to_sys_tray.stateChanged.connect(self.update_sys_tray)
|
||||
self.sys_tray_widget = SettingsWidget(self.tr("Exit to System Tray Icon"), self.exit_to_sys_tray)
|
||||
self.layout.addWidget(self.sys_tray_widget)
|
||||
|
||||
self.game_start_accept = QCheckBox(self.tr("Confirm launch of game"))
|
||||
self.game_start_accept.stateChanged.connect(self.update_start_confirm)
|
||||
self.game_start_accept_widget = SettingsWidget(self.tr("Confirm launch of game"), self.game_start_accept)
|
||||
|
@ -59,6 +60,10 @@ class RareSettings(QGroupBox):
|
|||
|
||||
self.setLayout(self.layout)
|
||||
|
||||
def update_sys_tray(self):
|
||||
settings = QSettings()
|
||||
settings.setValue("sys_tray", self.exit_to_sys_tray.isChecked())
|
||||
|
||||
def update_start_confirm(self):
|
||||
settings = QSettings()
|
||||
settings.setValue("confirm_start", self.game_start_accept.isChecked())
|
||||
|
|
22
Rare/Components/TrayIcon.py
Normal file
22
Rare/Components/TrayIcon.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from PyQt5.QtCore import QCoreApplication
|
||||
from PyQt5.QtWidgets import QSystemTrayIcon, QMenu, QAction
|
||||
from qtawesome import icon
|
||||
|
||||
|
||||
class TrayIcon(QSystemTrayIcon):
|
||||
def __init__(self, parent):
|
||||
super(TrayIcon, self).__init__(parent)
|
||||
self.setIcon(icon("ei.cogs", color="white"))
|
||||
self.setVisible(True)
|
||||
self.setToolTip("Rare")
|
||||
|
||||
self.menu = QMenu()
|
||||
|
||||
self.start_rare = QAction("Rare")
|
||||
self.menu.addAction(self.start_rare)
|
||||
|
||||
self.exit_action = QAction(self.tr("Exit"))
|
||||
self.menu.addSeparator()
|
||||
self.menu.addAction(self.exit_action)
|
||||
|
||||
self.setContextMenu(self.menu)
|
18
Rare/Main.py
18
Rare/Main.py
|
@ -6,11 +6,12 @@ import time
|
|||
|
||||
from PyQt5.QtCore import QSettings, QTranslator
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon
|
||||
|
||||
from Rare import lang_path, style_path
|
||||
from Rare.Components.Launch.LaunchDialog import LaunchDialog
|
||||
from Rare.Components.MainWindow import MainWindow
|
||||
from Rare.Components.TrayIcon import TrayIcon
|
||||
from Rare.utils.utils import get_lang
|
||||
from custom_legendary.core import LegendaryCore
|
||||
|
||||
|
@ -67,6 +68,8 @@ class App(QApplication):
|
|||
self.setStyleSheet(open(style_path + "RareStyle.qss").read())
|
||||
self.setWindowIcon(QIcon(style_path + "Logo.png"))
|
||||
|
||||
# tray icon
|
||||
|
||||
# launch app
|
||||
self.launch_dialog = LaunchDialog(self.core)
|
||||
self.launch_dialog.start_app.connect(self.start_app)
|
||||
|
@ -74,9 +77,20 @@ class App(QApplication):
|
|||
|
||||
def start_app(self):
|
||||
self.mainwindow = MainWindow(self.core)
|
||||
# close launch dialog after app widgets were created
|
||||
self.tray_icon = TrayIcon(self)
|
||||
self.tray_icon.exit_action.triggered.connect(lambda: exit(0))
|
||||
self.tray_icon.start_rare.triggered.connect(self.mainwindow.show)
|
||||
self.tray_icon.activated.connect(self.tray)
|
||||
self.mainwindow.tab_widget.downloadTab.finished.connect(lambda: self.tray_icon.showMessage(
|
||||
self.tr("Download finished"), self.tr("Download finished. Game is playable now"),
|
||||
QSystemTrayIcon.Information, 4000))
|
||||
self.launch_dialog.close()
|
||||
|
||||
def tray(self, reason):
|
||||
if reason == QSystemTrayIcon.DoubleClick:
|
||||
self.mainwindow.show()
|
||||
logger.info("Show App")
|
||||
|
||||
|
||||
def start():
|
||||
while True:
|
||||
|
|
|
@ -14,20 +14,3 @@ def main():
|
|||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
"""
|
||||
tray = QSystemTrayIcon()
|
||||
tray.setIcon(icon("fa.gamepad", color="white"))
|
||||
tray.setVisible(True)
|
||||
menu = QMenu()
|
||||
option1 = QAction("Geeks for Geeks")
|
||||
option1.triggered.connect(lambda: app.exec_())
|
||||
option2 = QAction("GFG")
|
||||
menu.addAction(option1)
|
||||
menu.addAction(option2)
|
||||
# To quit the app
|
||||
quit = QAction("Quit")
|
||||
quit.triggered.connect(app.quit)
|
||||
menu.addAction(quit)
|
||||
# Adding options to the System Tray
|
||||
tray.setContextMenu(menu)"""
|
||||
|
|
Loading…
Reference in a new issue