-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrayIcon.py
36 lines (25 loc) · 1.04 KB
/
trayIcon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from os import path, system
from sysTrayIcon import SysTrayIcon
from keyboardEvent import Keyboard
from threading import Thread
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = system._MEIPASS
except Exception:
base_path = path.abspath(".")
return path.join(base_path, relative_path)
class TrayIcon:
_hoverText = "Keep Screen On"
_mainIcon = resource_path('eye.ico')
def __init__(self):
SysTrayIcon(self._mainIcon, self._hoverText, self.menu_options, default_menu_index=0, window_class_name='Keep Screen On')
def pauseApp(sysTrayIcon):
Thread(target=lambda: input("Paused\n")).start()
def resume(sysTrayIcon):
keyboard = Keyboard()
print('Resumed')
Thread(target=lambda: keyboard.press()).start()
menu_options = (('Pause App', None, pauseApp),
('Resume', None, resume))