chrono.py: 0 est équivalent à la chaine vide

This commit is contained in:
Jephté Clain 2017-10-17 21:46:01 +04:00
parent 9c5b46b372
commit 6130c2ff7f
1 changed files with 8 additions and 1 deletions

View File

@ -32,6 +32,12 @@ def playSound(name=None):
def isnum(i): def isnum(i):
return type(i) in (IntType, LongType) return type(i) in (IntType, LongType)
RE_NUM = re.compile(r'\d+$')
def numof(s):
if isnum(s): return s
elif s is None: return None
elif RE_NUM.match(str(s)) is not None: return int(str(s))
else: return s
DEFAULT_TIMEOUT = '5' DEFAULT_TIMEOUT = '5'
@ -99,11 +105,13 @@ class Chrono:
return Timedelta(seconds=timeout) return Timedelta(seconds=timeout)
def set_timeout(self, timeout=None): def set_timeout(self, timeout=None):
if timeout == '': timeout = None
if timeout is not None and not isnum(timeout): if timeout is not None and not isnum(timeout):
tmp = parse_desthour(str(timeout)) tmp = parse_desthour(str(timeout))
if tmp is None: tmp = parse_timeout(timeout) if tmp is None: tmp = parse_timeout(timeout)
if tmp is None: tmp = int(timeout) * 60 if tmp is None: tmp = int(timeout) * 60
timeout = tmp timeout = tmp
if timeout == 0: timeout = None
self.timeout = timeout self.timeout = timeout
if timeout is None: self.initial = '00:00' if timeout is None: self.initial = '00:00'
else: self.initial = self.__format(self.__delta(timeout)) else: self.initial = self.__format(self.__delta(timeout))
@ -334,7 +342,6 @@ d'arrivée, et que la durée est calculée automatiquement""")
timeout = o.timeout timeout = o.timeout
if timeout is None: timeout = DEFAULT_TIMEOUT if timeout is None: timeout = DEFAULT_TIMEOUT
elif timeout == '': timeout = None
o.timeout = timeout o.timeout = timeout
run_chronometre(o.timeout, o.autostart) run_chronometre(o.timeout, o.autostart)