-
Notifications
You must be signed in to change notification settings - Fork 0
/
tray_app.py
66 lines (56 loc) · 2.03 KB
/
tray_app.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pystray
from PIL import Image
import threading
from window_handler import HotkeyHandler
import logging
import tkinter as tk
from tkinter import messagebox
import base64
import io
# Import the icon data
from icon_data import ICON_BASE64
KILL_HOTKEY = '<ctrl>+<alt>+<f4>'
SUSPEND_HOTKEY = '<ctrl>+<alt>+<f3>'
class TrayIcon:
def __init__(self):
self.icon = None
self.hotkey_handler = HotkeyHandler()
self.hotkey_thread = None
self.icon_base64 = ICON_BASE64 # icon_data.py contains the icon data
def create_image(self):
icon_data = base64.b64decode(self.icon_base64)
return Image.open(io.BytesIO(icon_data))
def about(self):
logging.info("Showing About information")
root = tk.Tk()
root.withdraw()
messagebox.showinfo("About Process Killer/Suspender",
"Process Killer/Suspender\n"
"Version 1.0\n\n"
"Kill Hotkey: Ctrl+Alt+F4\n"
"Suspend/Resume Hotkey: Ctrl+Alt+F3\n\n"
"Created by Yakov")
def exit_app(self):
logging.info("Exiting application")
self.icon.stop()
if self.hotkey_thread:
self.hotkey_handler.stop()
self.hotkey_thread.join()
def setup(self):
self.icon = pystray.Icon("ProcessKillerSuspender", self.create_image(), "Process Killer/Suspender")
self.icon.menu = pystray.Menu(
pystray.MenuItem("About", self.about),
pystray.MenuItem("Exit", self.exit_app)
)
self.hotkey_handler.set_hotkeys(KILL_HOTKEY, SUSPEND_HOTKEY)
def run(self):
self.setup()
self.hotkey_thread = threading.Thread(target=self.hotkey_handler.start)
self.hotkey_thread.start()
self.icon.run()
def run_tray_app():
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
tray_app = TrayIcon()
tray_app.run()
if __name__ == "__main__":
run_tray_app()