Commits

Denilson Sá committed b92066c

Added argparse to win_size.py, also adding --help documentation.

Comments (0)

Files changed (1)

 from __future__ import division
 from __future__ import print_function
 
+import argparse
+
 # Easy way of importing pygame:
 # import pygame
 
     h = info.current_h + delta_height
     set_size(w, h)
 
+def parse_arguments():
+    parser = argparse.ArgumentParser(
+        description='Opens a window with the specified size.',
+        epilog='''This script uses Pygame to open a window painted with yellow
+        color. Use arrow keys to increase/decrese the window dimensions. The
+        current size <width>x<height> is shown at the window title, and also
+        printed to the stdout. In order to understand why this script was
+        written, read http://my.opera.com/CrazyTerabyte/blog/2011/10/13/nvidia-bug-when-rendering-windows-smaller-than-32x32''',
+        formatter_class=argparse.ArgumentDefaultsHelpFormatter
+    )
+    parser.add_argument(
+        'width',
+        action='store',
+        type=int,
+        help='initial window width'
+    )
+    parser.add_argument(
+        'height',
+        action='store',
+        type=int,
+        help='initial window height'
+    )
+    args = parser.parse_args()
+    return args
+
 def main():
+    options = parse_arguments()
+
     # pygame.init() will try to initialize all pygame modules, including
     # Cdrom and Audio. I'm not using such things, so let's initialize the
     # only really required module:
     pygame.display.init()
-    set_size(15, 15)
+    set_size(options.width, options.height)
 
     # This does not work... :-(
     pygame.key.set_repeat(500, 50)