Parses input, initializes everything and then runs the main loop of the program, which handles input and draws the scene.
()
| 104 | |
| 105 | |
| 106 | def main(): |
| 107 | """ |
| 108 | Parses input, initializes everything and then runs the main loop of the |
| 109 | program, which handles input and draws the scene. |
| 110 | """ |
| 111 | parser = argparse.ArgumentParser( |
| 112 | description='PySDL2 / cefpython example', |
| 113 | add_help=True |
| 114 | ) |
| 115 | parser.add_argument( |
| 116 | '-v', |
| 117 | '--verbose', |
| 118 | help='Turn on debug info', |
| 119 | dest='verbose', |
| 120 | action='store_true' |
| 121 | ) |
| 122 | parser.add_argument( |
| 123 | '-r', |
| 124 | '--renderer', |
| 125 | help='Specify hardware or software rendering', |
| 126 | default='hardware', |
| 127 | dest='renderer', |
| 128 | choices=['software', 'hardware'] |
| 129 | ) |
| 130 | args = parser.parse_args() |
| 131 | logLevel = logging.INFO |
| 132 | if args.verbose: |
| 133 | logLevel = logging.DEBUG |
| 134 | logging.basicConfig( |
| 135 | format='[%(filename)s %(levelname)s]: %(message)s', |
| 136 | level=logLevel |
| 137 | ) |
| 138 | logging.info("Using PySDL2 %s" % sdl2.__version__) |
| 139 | version = sdl2.SDL_version() |
| 140 | sdl2.SDL_GetVersion(version) |
| 141 | logging.info( |
| 142 | "Using SDL2 %s.%s.%s" % (version.major, version.minor, version.patch) |
| 143 | ) |
| 144 | # The following variables control the dimensions of the window |
| 145 | # and browser display area |
| 146 | width = 800 |
| 147 | height = 600 |
| 148 | # headerHeight is useful for leaving space for controls |
| 149 | # at the top of the window (future implementation?) |
| 150 | headerHeight = 0 |
| 151 | browserHeight = height - headerHeight |
| 152 | browserWidth = width |
| 153 | # Mouse wheel fudge to enhance scrolling |
| 154 | scrollEnhance = 40 |
| 155 | # desired frame rate |
| 156 | frameRate = 100 |
| 157 | # Initialise CEF for offscreen rendering |
| 158 | sys.excepthook = cef.ExceptHook |
| 159 | switches = { |
| 160 | # Tweaking OSR performance by setting the same Chromium flags |
| 161 | # as in upstream cefclient (Issue #240). |
| 162 | "disable-surfaces": "", |
| 163 | "disable-gpu": "", |
no test coverage detected