Added about menu and exit notification
This commit is contained in:
parent
3ab79da4e1
commit
1a8afa7063
|
@ -0,0 +1,2 @@
|
||||||
|
@echo off
|
||||||
|
python "C:\Example\Directory\windows_usbkill\windows_usbkill.py"
|
|
@ -1,4 +1,5 @@
|
||||||
Pillow==10.0.0
|
Pillow==10.0.0
|
||||||
pystray==0.19.4
|
pystray==0.19.4
|
||||||
pywin32==306
|
pywin32==306
|
||||||
|
win11toast==0.32
|
||||||
WMI==1.5.1
|
WMI==1.5.1
|
||||||
|
|
|
@ -12,7 +12,12 @@ import PIL.Image
|
||||||
import ctypes
|
import ctypes
|
||||||
import logging
|
import logging
|
||||||
import pythoncom
|
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
|
from pystray import MenuItem as item
|
||||||
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
|
@ -28,14 +33,44 @@ logging.basicConfig(filename="log.txt",
|
||||||
format='%(asctime)s | %(message)s',
|
format='%(asctime)s | %(message)s',
|
||||||
level=logging.INFO)
|
level=logging.INFO)
|
||||||
|
|
||||||
# Load icon
|
# Load Image 512x512
|
||||||
current_dir_image = os.path.dirname(os.path.abspath(__file__))
|
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:
|
try:
|
||||||
image = PIL.Image.open(image_file)
|
image = PIL.Image.open(image_file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
asset_error = (None, 'Asset folder missing!', 'Fatal Error!', 0x10)
|
asset_error = (None, 'File missing! Try to pull from Git!', 'Windows usbkill | Fatal Error!', 0x10)
|
||||||
logging.info("[ERROR] Asset folder missing!")
|
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)
|
ctypes.windll.user32.MessageBoxW(*asset_error)
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
@ -80,19 +115,88 @@ def toggle_pause():
|
||||||
scan_thread = threading.Thread(target=start_scan)
|
scan_thread = threading.Thread(target=start_scan)
|
||||||
scan_thread.start()
|
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
|
# Exit
|
||||||
def terminate():
|
def terminate():
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
print("[Info] Exited!")
|
print("[Info] Exited!")
|
||||||
icon = pystray.Icon
|
icon = pystray.Icon
|
||||||
icon.visible = False
|
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
|
# Tray
|
||||||
def create_tray_icon():
|
def create_tray_icon():
|
||||||
pythoncom.CoInitialize()
|
pythoncom.CoInitialize()
|
||||||
icon = pystray.Icon("Test", image, 'Windows usbkill', menu=pystray.Menu(
|
icon = pystray.Icon("Test", image, 'Windows usbkill', menu=pystray.Menu(
|
||||||
pystray.MenuItem("Pause", toggle_pause, checked=lambda item: is_paused),
|
pystray.MenuItem("Pause", toggle_pause, checked=lambda item: is_paused),
|
||||||
|
pystray.MenuItem("About", trigger_about_section),
|
||||||
pystray.MenuItem("Exit", terminate)
|
pystray.MenuItem("Exit", terminate)
|
||||||
))
|
))
|
||||||
icon.run()
|
icon.run()
|
||||||
|
|
Loading…
Reference in New Issue