Added about menu and exit notification

This commit is contained in:
Willy 2023-09-13 20:39:04 -04:00
parent 3ab79da4e1
commit 1a8afa7063
3 changed files with 112 additions and 5 deletions

2
python launcher.bat Normal file
View File

@ -0,0 +1,2 @@
@echo off
python "C:\Example\Directory\windows_usbkill\windows_usbkill.py"

View File

@ -1,4 +1,5 @@
Pillow==10.0.0
pystray==0.19.4
pywin32==306
win11toast==0.32
WMI==1.5.1

View File

@ -12,7 +12,12 @@ import PIL.Image
import ctypes
import logging
import pythoncom
import time
import tkinter as tk
from tkinter import ttk
from tkinter.ttk import Label
from win11toast import toast
from pystray import MenuItem as item
if sys.platform != 'win32':
@ -28,14 +33,44 @@ logging.basicConfig(filename="log.txt",
format='%(asctime)s | %(message)s',
level=logging.INFO)
# Load icon
# Load Image 512x512
current_dir_image = os.path.dirname(os.path.abspath(__file__))
image_file = os.path.join(current_dir_image, 'assets', 'icon.png')
image_file = os.path.join(current_dir_image, 'assets', 'icon_512x512.png')
try:
image = PIL.Image.open(image_file)
except FileNotFoundError:
asset_error = (None, 'Asset folder missing!', 'Fatal Error!', 0x10)
logging.info("[ERROR] Asset folder missing!")
asset_error = (None, 'File missing! Try to pull from Git!', 'Windows usbkill | Fatal Error!', 0x10)
logging.info("[ERROR] File missing!")
ctypes.windll.user32.MessageBoxW(*asset_error)
os._exit(0)
# Load Image 128x128
current_dir_image = os.path.dirname(os.path.abspath(__file__))
image_file2 = os.path.join(current_dir_image, 'assets', 'icon_128x128.png')
try:
image2 = PIL.Image.open(image_file2)
except FileNotFoundError:
asset_error = (None, 'File missing! Try to pull from Git!', 'Windows usbkill | Fatal Error!', 0x10)
logging.info("[ERROR] File missing!")
ctypes.windll.user32.MessageBoxW(*asset_error)
os._exit(0)
# Load ico
current_dir_image = os.path.dirname(os.path.abspath(__file__))
image_icon = os.path.join(current_dir_image, 'assets', 'icon.ico')
try:
image3 = PIL.Image.open(image_icon)
except FileNotFoundError:
asset_error = (None, 'File missing! Try to pull from Git!', 'Windows usbkill | Fatal Error!', 0x10)
logging.info("[ERROR] File missing!")
ctypes.windll.user32.MessageBoxW(*asset_error)
os._exit(0)
# load exit-icon
current_dir_image = os.path.dirname(os.path.abspath(__file__))
exit_icon = os.path.join(current_dir_image, 'assets', 'exit-icon_512x512.png')
try:
image4 = PIL.Image.open(exit_icon)
except FileNotFoundError:
asset_error = (None, 'File missing! Try to pull from Git!', 'Windows usbkill | Fatal Error!', 0x10)
logging.info("[ERROR] File missing!")
ctypes.windll.user32.MessageBoxW(*asset_error)
os._exit(0)
@ -80,19 +115,88 @@ def toggle_pause():
scan_thread = threading.Thread(target=start_scan)
scan_thread.start()
# About Page
def about_section():
root = tk.Tk()
root.geometry('600x450')
root.resizable(False, False)
root.title('About | Windows usbkill')
root.iconbitmap(image_icon)
# Declare Exit
def close_window():
root.destroy()
# Image
photo = tk.PhotoImage(file=image_file2)
image_label = ttk.Label(
root,
image=photo,
padding=5
)
image_label.pack()
# Label 1
label = ttk.Label(
root,
text='Windows usbkill',
font=("Helvetica", 14, "bold"))
label.pack(ipadx=10, ipady=10)
label2 = ttk.Label(
root,
text = '''
Author: Willy
Version: 0.2 BETA (9/12/2023)
License: GNU GENERAL PUBLIC LICENSE 3
''',
font=("Helvetica", 10))
# Label 2
label2.pack(ipadx=200, ipady=20)
# Exit Button
button = tk.Button(root, text="Close Window", command=close_window)
button.pack()
# loop
root.mainloop()
# Trigger about section
def trigger_about_section():
about_thread = threading.Thread(target=about_section)
about_thread.start()
# Exit
def terminate():
pythoncom.CoInitialize()
print("[Info] Exited!")
icon = pystray.Icon
icon.visible = False
os._exit(0)
def exit_toast():
toast(app_id="Windows usbkill",
icon=exit_icon,
title='Exited!',
body='Windows usbkill has exited! It will no longer detect changes in the USB ports!'
)
def os_exit():
os._exit(0)
exit_toast_thread = threading.Thread(target=exit_toast)
os_exit_thread = threading.Thread(target=os_exit)
exit_toast_thread.start()
time.sleep(1)
os_exit_thread.start()
# Tray
def create_tray_icon():
pythoncom.CoInitialize()
icon = pystray.Icon("Test", image, 'Windows usbkill', menu=pystray.Menu(
pystray.MenuItem("Pause", toggle_pause, checked=lambda item: is_paused),
pystray.MenuItem("About", trigger_about_section),
pystray.MenuItem("Exit", terminate)
))
icon.run()