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 ...@@ -2,7 +2,8 @@ from src.server import GestureServer
from src.window import FullscreenWindow from src.window import FullscreenWindow
from src.trackers.basic import BasicTracker 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 # Create server
server = GestureServer() server = GestureServer()
......
...@@ -12,17 +12,19 @@ from src.trackers.transform import TransformationTracker ...@@ -12,17 +12,19 @@ from src.trackers.transform import TransformationTracker
from src.trackers.tap import TapTracker from src.trackers.tap import TapTracker
from src.screen import screen_size 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() pygame.init()
FULLSCREEN = '-f' in sys.argv[1:]
# Config # Config
FINGER_RADIUS = 20 FINGER_RADIUS = 20
CENTROID_RADIUS = 15 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 BG_COLOR = 0, 0, 0
LINE_COLOR = 128, 128, 128 LINE_COLOR = 128, 128, 128
...@@ -42,7 +44,7 @@ BEAM_INCREMENT = .8 ...@@ -42,7 +44,7 @@ BEAM_INCREMENT = .8
MAX_SCALE = 10 MAX_SCALE = 10
# Create canvas GUI # 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) screen = pygame.display.set_mode((W, H), flags)
......
...@@ -3,22 +3,29 @@ import logging ...@@ -3,22 +3,29 @@ import logging
from src.logger import Logger from src.logger import Logger
# Parse arguments # Parse arguments
parser = argparse.ArgumentParser(description='Basic test program for usage ' def create_parser():
'of multi-touch API.') parser = argparse.ArgumentParser(description='Basic test program for usage '
parser.add_argument('--log', metavar='LOG_LEVEL', default='INFO', 'of multi-touch API.')
choices=['DEBUG', 'INFO', 'WARNING'], parser.add_argument('--log', metavar='LOG_LEVEL', default='INFO',
help='set log level (defaults to INFO)') choices=['DEBUG', 'INFO', 'WARNING'],
parser.add_argument('--logfile', metavar='FILENAME', help='set log level (defaults to INFO)')
help='filename for the log file (the log is printed to ' parser.add_argument('--logfile', metavar='FILENAME',
'stdout by default)') help='filename for the log file (the log is printed to '
args = parser.parse_args() 'stdout by default)')
return parser
def parse_args(parser):
args = parser.parse_args()
# Configure logger
log_config = {'level': getattr(logging, args.log)}
# Configure logger if args.logfile:
log_config = {'level': getattr(logging, args.log)} log_config['filename'] = args.logfile
if args.logfile: Logger.configure(**log_config)
log_config['filename'] = args.logfile
Logger.configure(**log_config) return args
...@@ -2,7 +2,8 @@ from src.server import GestureServer ...@@ -2,7 +2,8 @@ from src.server import GestureServer
from src.window import FullscreenWindow from src.window import FullscreenWindow
from src.trackers.tap import TapTracker 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 # Create server
server = GestureServer() server = GestureServer()
......
...@@ -2,7 +2,8 @@ from src.server import GestureServer ...@@ -2,7 +2,8 @@ from src.server import GestureServer
from src.window import FullscreenWindow from src.window import FullscreenWindow
from src.trackers.transform import TransformationTracker 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 # Create server
server = GestureServer() 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