-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathasublim.py
executable file
·98 lines (91 loc) · 2.55 KB
/
asublim.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
#!/usr/bin/env python
import pyosd
import sys, time
import getopt
from random import Random
random=Random()
font="fixed"
color="LawnGreen"
inputStream=sys.stdin
delayShowMax=100
delayShowMin=10
delayWordMax=50
delayWordMin=10
width=1024
height=768
timeout=1
helpstr="[options]\n\
\n\
Options:\n\
-h\n\
--help Print this help\n\
\n\
--timeout Timeout in seconds for automatic refresh\n\
-c\n\
--color\n\
--colour Specify text colour\n\
-f\n\
--font Specify X font string\n\
-F\n\
--file Specify input file (default stdin)\n\
--delayShowMax Maximum display time in usecs\n\
--delayShowMin Minimum display time in usecs\n\
--delayWordMax Maximum delay between words in usecs\n\
--delayWordMin Minimum delay between words in usecs\n\
--screen-width Specify screen width\n\
--screen-height Specify screen height\n\n"
opts="ht:c:f:F:S:s:D:d:w:y:"
longopts=["help", "timeout=", "color=", "colour=", "font=", "file=", "delayShowMax=", "delayShowMin=", "delayWordMax=", "delayWordMin=", "screen-width=", "screen-height="]
if(len(sys.argv)>1):
try:
optlist, args=getopt.getopt(sys.argv[1:], opts, longopts)
except getopt.GetoptError as err:
sys.stderr.write(str(err)+"\n")
sys.stderr.write("Usage:\t"+sys.argv[0]+" "+helpstr)
sys.exit(1)
for opt in optlist:
optname=opt[0]
if optname in ["-h", "--help"]:
sys.stderr.write("Usage:\t"+sys.argv[0]+" "+helpstr)
sys.exit()
elif optname in ["-c", "--color", "--colour"]:
color=opt[1]
elif optname in ["-f", "--font"]:
font=opt[1]
elif optname in ["-F", "--file"]:
inputStream=open(opt[1], 'r')
elif optname=="--delayShowMax":
delayShowMax=int(opt[1])
elif optname=="--delayShowMin":
delayShowMin=int(opt[1])
elif optname=="--delayWordMax":
delayWordMax=int(opt[1])
elif optname=="--delayWordMin":
delayWordMin=int(opt[1])
elif optname in ["-x", "--screen-width"]:
width=int(opt[1])
elif optname in ["-y", "--screen-height"]:
height=int(opt[1])
elif optname=="--timeout":
timeout=int(opt[1])
def usleep(ms):
time.sleep(ms*0.0001)
def set_pos(x, y):
osd.set_horizontal_offset(x)
osd.set_vertical_offset(y)
def displayWord(word):
set_pos(random.randint(0, width), random.randint(0, height))
osd.display(word)
osd.show()
usleep(random.randint(delayShowMin, delayShowMax))
osd.hide()
usleep(random.randint(delayWordMin, delayWordMax))
osd=pyosd.osd(font, color)
osd.set_outline_colour("black")
osd.set_timeout(timeout)
def main():
for line in inputStream.xreadlines():
for word in line.replace("\0", " ").split():
displayWord(word)
main()
osd.wait_until_no_display()