From: Tomas Musil Date: Sat, 12 Oct 2013 22:24:30 +0000 (+0200) Subject: fix executable modules, more documentation X-Git-Url: http://git.tomasm.cz/imago.git/commitdiff_plain/90126edf1467ea467f28fb2bd12b10cc42c6d63f fix executable modules, more documentation --- diff --git a/doc/modules.rst b/doc/modules.rst index 75dba51..209dd33 100644 --- a/doc/modules.rst +++ b/doc/modules.rst @@ -12,3 +12,76 @@ hough .. automodule:: hough :members: + +geometry +-------- + +.. automodule:: geometry + :members: + + +filters +------- + +.. automodule:: filters + :members: + +linef +----- + +.. automodule:: linef + :members: + +gridf +----- + +.. automodule:: gridf + :members: + +intrsc +------ + +.. automodule:: intrsc + :members: + +k_means +------- + +.. automodule:: k_means + :members: + +manual +------ + +.. automodule:: manual + :members: + +sgf +--- + +.. automodule:: sgf + :members: + +im_debug +-------- + +.. automodule:: im_debug + :members: + +camera +------ + +.. automodule:: camera + :members: + +capture +------- + +.. automodule:: capture + :members: + +timer +----- + +.. automodule:: timer + :members: diff --git a/imago_pack/geometry.py b/imago_pack/geometry.py index 23f4095..60e679b 100644 --- a/imago_pack/geometry.py +++ b/imago_pack/geometry.py @@ -1,8 +1,10 @@ -"""Imago geometry module""" +"""Imago geometry module.""" from math import sin, cos, atan, pi class V(object): + """Class for vector manipulation.""" + def __init__(self, x, y): self.x = x self.y = y diff --git a/imago_pack/hough.py b/imago_pack/hough.py index ec8058c..473d750 100644 --- a/imago_pack/hough.py +++ b/imago_pack/hough.py @@ -1,3 +1,5 @@ +"""Hough transform module.""" + from math import sin, cos, pi from PIL import Image diff --git a/imago_pack/sgf.py b/imago_pack/sgf.py index 13543fe..3999f77 100644 --- a/imago_pack/sgf.py +++ b/imago_pack/sgf.py @@ -1,22 +1,26 @@ import sys -coords = 'abcdefghijklmnopqrs' +def main(): + coords = 'abcdefghijklmnopqrs' -board = sys.stdin.read().split('\n') -board = [line.split() for line in board] + board = sys.stdin.read().split('\n') + board = [line.split() for line in board] -black = [] -white = [] + black = [] + white = [] -for i in range(19): - for j in range(19): - if board[i][j] == 'B': - black.append((i, j)) - elif board[i][j] == 'W': - white.append((i, j)) + for i in range(19): + for j in range(19): + if board[i][j] == 'B': + black.append((i, j)) + elif board[i][j] == 'W': + white.append((i, j)) -#TODO version numbering -print "(;FF[4]GM[1]SZ[19]AP[Imago:0.1.0]" -print "AB" + ''.join('[' + coords[j] + coords[i] + ']' for (i, j) in black) -print "AW" + ''.join('[' + coords[j] + coords[i] + ']' for (i, j) in white) -print ")" + #TODO version numbering + print "(;FF[4]GM[1]SZ[19]AP[Imago:0.1.0]" + print "AB" + ''.join('[' + coords[j] + coords[i] + ']' for (i, j) in black) + print "AW" + ''.join('[' + coords[j] + coords[i] + ']' for (i, j) in white) + print ")" + +if __name__ == '__main__': + main() diff --git a/imago_pack/timer.py b/imago_pack/timer.py index bc8a5c3..b5ec3fb 100755 --- a/imago_pack/timer.py +++ b/imago_pack/timer.py @@ -59,78 +59,85 @@ class Timer: else: return False -parser = argparse.ArgumentParser(description=__doc__) -parser.add_argument('-m', type=int, default=10, - help="main time in minutes (default is 10)") -parser.add_argument('-b', type=int, nargs=2, default=[5, 20], - help="japanese byoyomi: number of periods, period length in" - " seconds (default is 5 periods, 20 seconds)") -parser.add_argument('-c', '--camera', dest='cam', action='store_true', - help="camera on") -parser.add_argument('-d', type=int, default=0, - help="video device id") -parser.add_argument('-r', type=int, nargs=2, default=[640, 480], - help="set camera resolution") -args = parser.parse_args() - - -pygame.init() -pygame.display.set_mode((600, 130)) -pygame.display.set_caption("Go timer") -screen = pygame.display.get_surface() - -clock = pygame.time.Clock() - -font = pygame.font.Font(pygame.font.match_font('monospace'), 80) -font2 = pygame.font.Font(None, 25) - -done = False -first = True - -main_time = args.m * 60 - -timers = (Timer(main_time, args.b[0], args.b[1]), Timer(main_time, args.b[0], args.b[1])) - -if args.cam: - capture = subprocess.Popen(['python', 'capture.py', '-c', '-d', str(args.d), '-r', - str(args.r[0]), - str(args.r[1])], stdin=subprocess.PIPE) -last = 0 - -while not done: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - done = True - elif event.type == pygame.KEYDOWN: - if time.time() - last < 0.7: - continue - last = time.time() - if first: - timers[0].start() - first = False +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('-m', type=int, default=10, + help="main time in minutes (default is 10)") + parser.add_argument('-b', type=int, nargs=2, default=[5, 20], + help="japanese byoyomi: number of periods, period length in" + " seconds (default is 5 periods, 20 seconds)") + parser.add_argument('-c', '--camera', dest='cam', action='store_true', + help="camera on") + parser.add_argument('-d', type=int, default=0, + help="video device id") + parser.add_argument('-r', type=int, nargs=2, default=[640, 480], + help="set camera resolution") + args = parser.parse_args() + + + pygame.init() + pygame.display.set_mode((600, 130)) + pygame.display.set_caption("Go timer") + screen = pygame.display.get_surface() + + clock = pygame.time.Clock() + + font = pygame.font.Font(pygame.font.match_font('monospace'), 80) + font2 = pygame.font.Font(None, 25) + + done = False + first = True + + main_time = args.m * 60 + + timers = (Timer(main_time, args.b[0], args.b[1]), Timer(main_time, args.b[0], args.b[1])) + + if args.cam: + capture = subprocess.Popen(['python', 'capture.py', '-c', '-d', str(args.d), '-r', + str(args.r[0]), + str(args.r[1])], stdin=subprocess.PIPE) + last = 0 + + while not done: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + elif event.type == pygame.KEYDOWN: + if time.time() - last < 0.7: + continue + last = time.time() + if first: + timers[0].start() + first = False + if args.cam: + print >> capture.stdin, "stop" + print >> capture.stdin, "take" + continue if args.cam: - print >> capture.stdin, "stop" print >> capture.stdin, "take" - continue - if args.cam: - print >> capture.stdin, "take" - for timer in timers: - if timer.is_running(): - timer.stop() - else: - timer.start() - - screen.fill([0, 0, 0]) - text1 = font.render(timers[0].get_time(), True, [128, 255, 128]) - screen.blit(text1, [10, 10]) - text2 = font.render(timers[1].get_time(), True, [128, 255, 128]) - screen.blit(text2, [300, 10]) - text3 = font2.render(timers[0].byost, True, [128, 255, 128]) - screen.blit(text3, [10, 90]) - text4 = font2.render(timers[1].byost, True, [128, 255, 128]) - screen.blit(text4, [300, 90]) - pygame.display.flip() - clock.tick(15) - -if args.cam: - print >> capture.stdin, "exit" + for timer in timers: + if timer.is_running(): + timer.stop() + else: + timer.start() + + screen.fill([0, 0, 0]) + text1 = font.render(timers[0].get_time(), True, [128, 255, 128]) + screen.blit(text1, [10, 10]) + text2 = font.render(timers[1].get_time(), True, [128, 255, 128]) + screen.blit(text2, [300, 10]) + text3 = font2.render(timers[0].byost, True, [128, 255, 128]) + screen.blit(text3, [10, 90]) + text4 = font2.render(timers[1].byost, True, [128, 255, 128]) + screen.blit(text4, [300, 90]) + pygame.display.flip() + clock.tick(15) + + if args.cam: + print >> capture.stdin, "exit" + +if __name__ == '__main__': + try: + main() + finally: + pygame.quit()