-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowergrid.pyw
61 lines (47 loc) · 1.87 KB
/
powergrid.pyw
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
import Tkinter as tk
import subprocess
import im_dat
class PowerGrid:
def __init__(self, root):
self.root = root
# have to keep references to the images else they get garbage collected
self.swapuser = tk.PhotoImage(data=im_dat.swapuser)
self.logoff = tk.PhotoImage(data=im_dat.logoff)
self.hibernate = tk.PhotoImage(data=im_dat.hibernate)
self.shutdown = tk.PhotoImage(data=im_dat.shutdown)
self.b1 = tk.Button(root, background="black", image=self.swapuser,
command=self._swapuser)
self.b2 = tk.Button(root, background="black", activebackground="white", image=self.logoff,
command=self._logoff)
self.b3 = tk.Button(root, background="black", image=self.hibernate,
command=self._hibernate)
self.b4 = tk.Button(root, background="black", image=self.shutdown,
command=self._shutdown)
self.b1.grid(row=0, column=0)
self.b2.grid(row=0, column=1)
self.b3.grid(row=1, column=0)
self.b4.grid(row=1, column=1)
# http://www.blog.pythonlibrary.org/2010/03/27/restarting-pcs-with-python/
def _swapuser(self):
import win32ts
win32ts.WTSDisconnectSession(0, -1, False)
self.root.quit()
def _hibernate(self):
#subprocess.Popen("rundll32 powrprof.dll,SetSuspendState Hibernate")
try:
subprocess.Popen("shutdown /h")
finally:
self.root.quit()
def _logoff(self):
try:
subprocess.Popen("shutdown /l")
finally:
self.root.quit()
def _shutdown(self):
try:
subprocess.Popen("shutdown /p")
finally:
self.root.quit()
root = tk.Tk()
pg = PowerGrid(root)
root.mainloop()