added any key exit
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import curses
|
import curses
|
||||||
import os
|
import os,sys
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
import signal
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
|
||||||
@@ -87,6 +88,12 @@ def drawdigital(win,y,x,t):
|
|||||||
for c in range(len(hrs)):
|
for c in range(len(hrs)):
|
||||||
drawdigit(win,y,x+4*c,hrs[c])
|
drawdigit(win,y,x+4*c,hrs[c])
|
||||||
|
|
||||||
|
def readinput(win):
|
||||||
|
try:
|
||||||
|
return win.getch()
|
||||||
|
except:
|
||||||
|
return ""
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
stdscr=curses.initscr()
|
stdscr=curses.initscr()
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
@@ -108,7 +115,15 @@ def main():
|
|||||||
drawcircle(stdscr,cy,cx,r/2)
|
drawcircle(stdscr,cy,cx,r/2)
|
||||||
drawdigital(stdscr,1,1,t)
|
drawdigital(stdscr,1,1,t)
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
time.sleep(options.refresh)
|
#time.sleep(options.refresh)
|
||||||
|
signal.signal(signal.SIGALRM, readinput)
|
||||||
|
signal.alarm(int(options.refresh))
|
||||||
|
userinput=readinput(stdscr)
|
||||||
|
if userinput!="":
|
||||||
|
curses.nocbreak()
|
||||||
|
stdscr.keypad(0)
|
||||||
|
curses.endwin()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
curses.nocbreak()
|
curses.nocbreak()
|
||||||
@@ -122,7 +137,7 @@ usage='''Usage: %prog [options]
|
|||||||
parser=OptionParser(usage=usage)
|
parser=OptionParser(usage=usage)
|
||||||
parser.add_option("-s",action="store_true",dest="seconds",default=False,
|
parser.add_option("-s",action="store_true",dest="seconds",default=False,
|
||||||
help="Show seconds [%default]")
|
help="Show seconds [%default]")
|
||||||
parser.add_option("-r",type="float",dest="refresh",default=3,
|
parser.add_option("-r",type="int",dest="refresh",default=3,
|
||||||
help="Refresh rate in seconds [%default]")
|
help="Refresh rate in seconds [%default]")
|
||||||
global options
|
global options
|
||||||
(options,args)=parser.parse_args()
|
(options,args)=parser.parse_args()
|
||||||
|
|||||||
Reference in New Issue
Block a user