python_utilities/system_tray.py
2020-12-24 16:00:54 -05:00

44 lines
1.2 KiB
Python

import os
import sys
from PySide2 import QtWidgets, QtGui
class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
"""
Create the system Tray
"""
def __init__(self, icon, parent=None):
QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)
self.setToolTip(f'Alex And His Backup Utility')
menu = QtWidgets.QMenu(parent)
backup_files = menu.addAction("Backup Bookmarks")
backup_files.triggered.connect(self.copy_files)
backup_files.setIcon(QtGui.QIcon("icon.png"))
menu.addSeparator()
exit_ = menu.addAction("Exit")
exit_.triggered.connect(lambda: sys.exit())
self.setContextMenu(menu)
self.activated.connect(self.onTrayIconActivated)
def onTrayIconActivated(self, reason):
if reason == self.DoubleClick:
pass
else:
pass
def copy_files(self):
os.system('notepad')
def main():
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
tray_icon = SystemTrayIcon(QtGui.QIcon("icon.png"), w)
tray_icon.show()
tray_icon.showMessage('Bookmarks Backup Utility', 'Hi!')
sys.exit(app.exec_())
if __name__ == '__main__':
main()