Skip to content

Commit

Permalink
Merge pull request #13 from nir/unstable
Browse files Browse the repository at this point in the history
fix example games scripts
  • Loading branch information
nir authored Feb 3, 2020
2 parents b406ff1 + b25e3ed commit e219be3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
3 changes: 2 additions & 1 deletion examples/pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@

import pyglet.window.key as key

p0 = os.path.abspath('.')
p0 = os.path.abspath(os.path.dirname(__file__))
p1 = os.path.abspath(os.path.join(p0, '..'))

sys.path.insert(0, p1)
os.chdir(p0)

import jupylet.color

Expand Down
5 changes: 1 addition & 4 deletions examples/spaceship.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@
import sys
import os


p0 = os.path.abspath('.')
p0 = os.path.abspath(os.path.dirname(__file__))
p1 = os.path.abspath(os.path.join(p0, '..'))

sys.path.insert(0, p1)

import jupylet.color

from jupylet.app import App
from jupylet.label import Label
from jupylet.sprite import Sprite
Expand Down
32 changes: 23 additions & 9 deletions jupylet/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import time
import sys
import io
import os
import re

import PIL.Image
Expand All @@ -53,7 +54,23 @@
__all__ = ['App']


WARNING = 'Will run the game in a window since on Mac computers only "window" mode is supported at the moment :-('
BINDER_WARNING = 'Game video will be compressed and may include noticeable artifacts and latency since it is streamed from a remote binder server. This is expected. If you install Jupylet on your computer video quality will be high.'


def is_binder_env():
return 'BINDER_REQUEST' in os.environ


def start_xvfb():
global xvfb
import xvfbwrapper
xvfb = xvfbwrapper.Xvfb()
xvfb.start()


# Start virtual frame buffer if running in binder.
if is_binder_env():
start_xvfb()


_thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=4)
Expand Down Expand Up @@ -506,13 +523,10 @@ def __init__(self, width=512, height=512, mode='jupyter', buffer=False, resource

assert mode in ['window', 'jupyter', 'hidden']

if False: #platform.system() == 'Darwin':

assert mode not in ['both', 'hidden'], WARNING
if mode == 'jupyter':
mode = 'window'
sys.stderr.write(WARNING + '\n')
self._show_mac_warning = True
if is_binder_env() and quality is None:
quality = 20
sys.stderr.write(BINDER_WARNING + '\n')
self._show_binder_warning = True

super(App, self).__init__(fake_time=(mode=='hidden'))

Expand Down Expand Up @@ -562,7 +576,7 @@ def run(self, interval=1/60):

assert self.window._context, 'Window has closed. Create a new app object to run.'

hasattr(self, '_show_mac_warning') and sys.stderr.write(WARNING + '\n')
hasattr(self, '_show_binder_warning') and sys.stderr.write(BINDER_WARNING + '\n')

self._run_timestamp = time.time()

Expand Down

0 comments on commit e219be3

Please sign in to comment.