Skip to content

Commit

Permalink
Add tray and hide
Browse files Browse the repository at this point in the history
  • Loading branch information
shotwn committed Apr 3, 2020
1 parent f1e48ba commit 23585f8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
48 changes: 47 additions & 1 deletion gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys

from PySide2.QtWidgets import QApplication
from PySide2.QtWidgets import QApplication, QSystemTrayIcon, QMenu
from PySide2.QtGui import QIcon

from gui.mainwindow import MainWindow
Expand Down Expand Up @@ -35,9 +35,55 @@ def __init__(self, root):
self.main_window.ui.right_status_2
]

menu = QMenu('FS Time Sync')
menu.setStyleSheet("""
QMenu {
background-color: #151515;
color: #ffffff;
}
QMenu::item {
padding: 5px 10px 5px 10px;
}
QMenu::item:selected {
background-color: #ffffff;
color: #151515;
}
""")
self.tray_actions = {}
self.tray_actions["hide_show"] = menu.addAction("Hide")
self.tray_actions["hide_show"].triggered.connect(self.hide)
self.tray_actions["exit"] = menu.addAction("Exit")
self.tray_actions["exit"].triggered.connect(self.exit)

self.tray = QSystemTrayIcon()
self.tray.setIcon(self.icons['logo'])
self.tray.setToolTip("FS Time Sync")
self.tray.setContextMenu(menu)
self.tray.activated.connect(self.trayActivated)
self.tray.show()

def main_window_act(self, func, *args, **kwargs):
self.main_window.act.emit([func, args, kwargs])

def hide(self):
self.tray_actions["hide_show"].setText("Show")
self.tray_actions["hide_show"].triggered.connect(self.show)
if self.offset_window:
self.offset_window.close()
self.main_window.hide()

def trayActivated(self, reason):
if reason == self.tray.ActivationReason.Trigger:
self.show()

def show(self):
self.tray_actions["hide_show"].setText("Hide")
self.tray_actions["hide_show"].triggered.connect(self.hide)
self.main_window.show()

def exit(self):
self.app.quit()

def start(self):
self.main_window.show()
self.app.exec_()
Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ def show_offset_window(self):

def closeEvent(self, event):
event.accept()
self.gui_root.app.quit()
self.gui_root.exit()

0 comments on commit 23585f8

Please sign in to comment.