Commit 2e6468ef authored by Taddeus Kroes's avatar Taddeus Kroes

Centralized argument parsing in test files.

parent 3b6bb1c6
......@@ -2,7 +2,8 @@ from src.server import GestureServer
from src.window import FullscreenWindow
from src.trackers.basic import BasicTracker
import tests.parse_arguments
from tests.parse_arguments import create_parser, parse_args
parse_args(create_parser())
# Create server
server = GestureServer()
......
......@@ -12,17 +12,19 @@ from src.trackers.transform import TransformationTracker
from src.trackers.tap import TapTracker
from src.screen import screen_size
import tests.parse_arguments
from tests.parse_arguments import create_parser, parse_args
parser = create_parser()
parser.add_argument('-f', '--fullscreen', action='store_true', default=False,
help='run in fullscreen')
args = parse_args(parser)
pygame.init()
FULLSCREEN = '-f' in sys.argv[1:]
# Config
FINGER_RADIUS = 20
CENTROID_RADIUS = 15
W, H = screen_size if FULLSCREEN else (640, 480)
W, H = screen_size if args.fullscreen else (640, 480)
BG_COLOR = 0, 0, 0
LINE_COLOR = 128, 128, 128
......@@ -42,7 +44,7 @@ BEAM_INCREMENT = .8
MAX_SCALE = 10
# Create canvas GUI
flags = pygame.FULLSCREEN if FULLSCREEN else 0
flags = pygame.FULLSCREEN if args.fullscreen else 0
screen = pygame.display.set_mode((W, H), flags)
......
......@@ -3,22 +3,29 @@ import logging
from src.logger import Logger
# Parse arguments
parser = argparse.ArgumentParser(description='Basic test program for usage '
'of multi-touch API.')
parser.add_argument('--log', metavar='LOG_LEVEL', default='INFO',
choices=['DEBUG', 'INFO', 'WARNING'],
help='set log level (defaults to INFO)')
parser.add_argument('--logfile', metavar='FILENAME',
help='filename for the log file (the log is printed to '
'stdout by default)')
args = parser.parse_args()
def create_parser():
parser = argparse.ArgumentParser(description='Basic test program for usage '
'of multi-touch API.')
parser.add_argument('--log', metavar='LOG_LEVEL', default='INFO',
choices=['DEBUG', 'INFO', 'WARNING'],
help='set log level (defaults to INFO)')
parser.add_argument('--logfile', metavar='FILENAME',
help='filename for the log file (the log is printed to '
'stdout by default)')
return parser
def parse_args(parser):
args = parser.parse_args()
# Configure logger
log_config = {'level': getattr(logging, args.log)}
# Configure logger
log_config = {'level': getattr(logging, args.log)}
if args.logfile:
log_config['filename'] = args.logfile
if args.logfile:
log_config['filename'] = args.logfile
Logger.configure(**log_config)
Logger.configure(**log_config)
return args
......@@ -2,7 +2,8 @@ from src.server import GestureServer
from src.window import FullscreenWindow
from src.trackers.tap import TapTracker
import tests.parse_arguments
from tests.parse_arguments import create_parser, parse_args
parse_args(create_parser())
# Create server
server = GestureServer()
......
......@@ -2,7 +2,8 @@ from src.server import GestureServer
from src.window import FullscreenWindow
from src.trackers.transform import TransformationTracker
import tests.parse_arguments
from tests.parse_arguments import create_parser, parse_args
parse_args(create_parser())
# Create server
server = GestureServer()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment