added any key exit
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
#!/usr/bin/python
|
||||
import curses
|
||||
import os
|
||||
import os,sys
|
||||
import time
|
||||
import math
|
||||
import signal
|
||||
from optparse import OptionParser
|
||||
|
||||
|
||||
@@ -86,6 +87,12 @@ def drawdigital(win,y,x,t):
|
||||
hrs=list('%02d %02d' % (t.tm_hour, t.tm_min))
|
||||
for c in range(len(hrs)):
|
||||
drawdigit(win,y,x+4*c,hrs[c])
|
||||
|
||||
def readinput(win):
|
||||
try:
|
||||
return win.getch()
|
||||
except:
|
||||
return ""
|
||||
|
||||
def main():
|
||||
stdscr=curses.initscr()
|
||||
@@ -108,7 +115,15 @@ def main():
|
||||
drawcircle(stdscr,cy,cx,r/2)
|
||||
drawdigital(stdscr,1,1,t)
|
||||
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:
|
||||
curses.nocbreak()
|
||||
@@ -122,7 +137,7 @@ usage='''Usage: %prog [options]
|
||||
parser=OptionParser(usage=usage)
|
||||
parser.add_option("-s",action="store_true",dest="seconds",default=False,
|
||||
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]")
|
||||
global options
|
||||
(options,args)=parser.parse_args()
|
||||
|
||||
Reference in New Issue
Block a user