-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkleds.py
103 lines (91 loc) · 2.68 KB
/
tkleds.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
# Author: cptx032
# Mail-me: cptx032 arroba gmail dot com
# Also available here: http://pastebin.com/raw.php?i=mpi06NTu
import sys, os
from Tkinter import *
def centralize(_window):
_window.update_idletasks()
width, height = _window.winfo_width(), _window.winfo_height()
sw,sh = _window.winfo_screenwidth(), _window.winfo_screenheight()
_window.geometry("+%d+%d" % (sw/2-width/2, sh/2-height/2))
top = Tk()
top.title("tk-leds")
top.resizable(0,0)
centralize(top)
top.bind("<Escape>", lambda e:top.destroy())
e = Entry(top,bd=5,highlightcolor="white",relief=FLAT)
e.focus_force()
Label(top, text="tty").grid(pady=5,padx=5,row=0,column=0)
e.grid(pady=5,padx=5,row=0,column=1,columnspan=2,sticky=W+E)
if len(sys.argv) > 1:
e.insert(0, sys.argv[1])
numbtn = Button(top,text="+num",width=10)
capsbtn = Button(top,text="+caps",width=10)
scrollbtn = Button(top,text="+scroll",width=10)
clearbtn = Button(top,text="reset")
clearbtn.grid(pady=0,padx=0,columnspan=3,row=2,column=0,sticky=W+E)
def set_status(status=None):
if status == "error":
e["bg"] = "red"
e["fg"] = "white"
else:
e["bg"] = "white"
e["fg"] = "black"
def _reset(*args):
if e.get() == "":
set_status("error")
return
__command = "setleds -num -caps -scroll < %s" % (e.get())
if os.system(__command) != 0:
set_status("error")
else:
set_status("success")
numbtn["text"] = "+num"
capsbtn["text"] = "+caps"
scrollbtn["text"] = "+scroll"
clearbtn.bind("<Button-1>", _reset, "+")
numbtn.grid(row=1,column=0)
capsbtn.grid(row=1,column=1)
scrollbtn.grid(row=1,column=2)
# [fixme] > as tres funcoes seguem a mesma estrutura > refatorar!
def _num(*args):
if e.get() == "":
set_status("error")
return
if numbtn["text"][0] == "+":
if os.system("setleds +num < %s" % (e.get())) != 0:
set_status("error")
numbtn["text"] = "-num"
else:
if os.system("setleds -num < %s" % (e.get())) != 0:
set_status("error")
numbtn["text"] = "+num"
numbtn.bind("<Button-1>", _num, "+")
def _caps(*args):
if e.get() == "":
set_status("error")
return
if capsbtn["text"][0] == "+":
if os.system("setleds +caps < %s" % (e.get())) != 0:
set_status("error")
capsbtn["text"] = "-caps"
else:
if os.system("setleds -caps < %s" % (e.get())) != 0:
set_status("error")
capsbtn["text"] = "+caps"
capsbtn.bind("<Button-1>", _caps, "+")
def _scroll(*args):
if e.get() == "":
set_status("error")
return
if scrollbtn["text"][0] == "+":
if os.system("setleds +scroll < %s" % (e.get())) != 0:
set_status("error")
scrollbtn["text"] = "-scroll"
else:
if os.system("setleds -scroll > %s" % (e.get())) != 0:
set_status("error")
scrollbtn["text"] = "+scroll"
scrollbtn.bind("<Button-1>", _scroll, "+")
top.mainloop()