-
Notifications
You must be signed in to change notification settings - Fork 1
/
win32Tray.py
59 lines (47 loc) · 1.27 KB
/
win32Tray.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
# coding:utf8
from pystray import MenuItem as item
import pystray
from PIL import Image
import sudawifi
import win32api
import win10toast
toast = win10toast.ToastNotifier()
def LoginAction():
"""
Handle Login
:return:None. Popup a notification bubble, indicating login status
"""
try:
res = sudawifi.ScanAndLogin()
except:
res = "ERROR Please check your connection"
# global toast
toast.show_toast("Login", res, threaded=True, icon_path="Office.ico")
def LogoutAction():
"""
Handle Logout
:return:None. Popup a notification bubble, indicating logout status
"""
res = sudawifi.logout()
global toast
# Generate an image
toast.show_toast("Logout", "Success" if res else "Failed", threaded=True, icon_path="Office.ico")
def Close():
"""
Call windows api to shutdown the app
:return:None
"""
win32api.PostQuitMessage(0)
def setup(iconObject):
"""
do as documents says to fit OS-X
:param iconObject:
:return:None
"""
iconObject.visible = True
image = Image.open("Office.ico")
menu = (item('auto login', LoginAction),
item('logout', LogoutAction),
item('Exit', Close))
icon = pystray.Icon("name", image, "SUDA_WIFI Loginer", menu)
icon.run(setup=setup)