X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/90126edf1467ea467f28fb2bd12b10cc42c6d63f..f66ba63b152a265d8876cb1c82dc7ace7ce5f10a:/imago_pack/timer.py?ds=sidebyside diff --git a/imago_pack/timer.py b/imago_pack/timer.py index b5ec3fb..2419563 100755 --- a/imago_pack/timer.py +++ b/imago_pack/timer.py @@ -1,6 +1,12 @@ #!/usr/bin/env python -"""Go timer""" +"""Go timer. + +This module defines a UI that combines game clock with automatic game recording. +When player presses the clock, an image of the board is taken. The sequence of +images can later be analysed by Imago to produce a game record in abstract +notation. +""" import os import sys @@ -11,6 +17,7 @@ import subprocess import pygame class Timer: + """Keeps track of time remaining one player.""" def __init__(self, main_time, byop, byot): self._last = 0 self._elapsed = 0. @@ -21,6 +28,7 @@ class Timer: self._byo = False def get_time(self): + """Return string representation of remaining time.""" if self._last > 0: # when running: r_time = self._main_t - (time.time() - self._last + self._elapsed) if (r_time - int(r_time)) < 0.75: @@ -47,19 +55,24 @@ class Timer: return "{0:0>2}".format(int(r_time / 60)) + sep + "{0:0>2}".format(int(r_time % 60)) def start(self): + """Start the clock.""" self._last = time.time() def stop(self): + """Stop the clock.""" self._elapsed += time.time() - self._last self._last = 0 def is_running(self): + """Return True if the clock is running.""" if self._last > 0: return True else: return False def main(): + """Parse the arguments and run the clock.""" + # TODO refactor into smaller functions parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('-m', type=int, default=10, help="main time in minutes (default is 10)")