def _create_window(): CONFIG_DB_CURSOR.execute( 'SELECT app_width, app_height FROM screen_resolution_config') screen_resolution_config = CONFIG_DB_CURSOR.fetchall() monitor_resolution_config = (windll.user32.GetSystemMetrics(0), windll.user32.GetSystemMetrics(1)) USER_DB_CURSOR.execute('SELECT fullscreen FROM graphics') if USER_DB_CURSOR.fetchone( )[0] and monitor_resolution_config in screen_resolution_config: window = Window(width=monitor_resolution_config[0], height=monitor_resolution_config[1], caption='Railway Station Simulator', style='borderless', fullscreen=False, vsync=False) window.set_fullscreen(True) return window USER_DB_CURSOR.execute('SELECT app_width, app_height FROM graphics') screen_resolution = USER_DB_CURSOR.fetchone() return Window(width=screen_resolution[0], height=screen_resolution[1], caption='Railway Station Simulator', style='borderless', fullscreen=False, vsync=False)
def main(): # Create the main window window = Window(800, 600, visible=False, caption="FF:Tactics.py", style='dialog') # Create the default camera and have it always updating camera = Camera((-600, -300, 1400, 600), (400, 300), 300, speed=PEPPY) clock.schedule(camera.update) # Load the first scene world = World(window, camera) world.transition(MainMenuScene) # centre the window on whichever screen it is currently on window.set_location(window.screen.width / 2 - window.width / 2, window.screen.height / 2 - window.height / 2) # clear and flip the window # otherwise we see junk in the buffer before the first frame window.clear() window.flip() # make the window visible at last window.set_visible(True) # finally, run the application pyglet.app.run()
def render(self, mode: str = 'human'): """ Render the current screen using the given mode. Args: mode: the mode to render the screen using - 'human': render in a window using GTK - 'rgb_array': render in the back-end and return a matrix Returns: None if mode is 'human' or a matrix if mode is 'rgb_array' """ # if the mode is RGB, return the screen as a NumPy array if mode == 'rgb_array': return self.game.screen # if the mode is human, create a viewer and display the screen elif mode == 'human': from pyglet.window import Window from gym.envs.classic_control.rendering import SimpleImageViewer if self.viewer is None: self.viewer = SimpleImageViewer() self.viewer.window = Window( width=SCREEN_WIDTH, height=SCREEN_HEIGHT, caption=self.spec.id, ) self.viewer.imshow(self.game.screen) return self.viewer.isopen # otherwise the render mode is not supported, raise an error else: raise ValueError('unsupported render mode: {}'.format(repr(mode)))
def prepare(self, options): self.window = Window( fullscreen=options.fullscreen, vsync=options.vsync, visible=False, resizable=True) self.window.on_draw = self.draw_window self.world = World() self.player = Player(self.world) self.camera = GameItem( position=origin, update=CameraMan(self.player, (3, 2, 0)), ) self.level_loader = Level(self) success = self.start_level(1) if not success: logging.error("ERROR, can't load level 1") sys.exit(1) self.update(1/60) self.window.push_handlers(KeyHandler(self.player)) self.render = Render(self.world, self.window, self.camera) self.render.init() self.music = Music() self.music.load() self.music.play()
def create_window(self, **kwargs): combined_kwargs = {} combined_kwargs.update(self.base_options) combined_kwargs.update(kwargs) self.window = Window(**combined_kwargs) self.window.push_handlers(self) return self.window
def imshow(self, img, caption=None): height, width, _ = img.shape pitch = -3 * width if self.window is None: self.window = Window(width=width, height=height, vsync=False) self.width = width self.height = height self.isopen = True data = img.tobytes() image = pyglet.image.ImageData(width, height, "RGB", data, pitch=pitch) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) texture = image.get_texture() texture.width = self.width texture.height = self.height self.window.clear() self.window.switch_to() self.window.dispatch_events() texture.blit(0, 0) self.window.flip() if caption is not None: self.window.set_caption(caption)
def setUp(self): self.w = Window(width=1, height=1, visible=False) self.s = Sprite( 10, 10, 10, 10, Image2d.from_image( SolidColorImagePattern((0, 0, 0, 0)).create_image(1, 1))) assert (self.s.x, self.s.y) == (10, 10)
def __init__(self, size=(DEFAULT_WIDTH, DEFAULT_HEIGHT), title='MegaMinerAI Bland Title Text', fullscreen=False): self.window = Window(width=size[0], height=size[1], caption=title, visible=True, fullscreen=fullscreen, resizable=True, style=Window.WINDOW_STYLE_DEFAULT, vsync=False, display=None, context=None, config=None) self.updates = [] # Set up the event dispatcher self.ed = EventDispatcher() self.ed.register_class_for_events(self) # Build the game loader self.loader = gameloader.GameLoader(self.ed) #Build the renderer self.renderer = renderer.Renderer() # Request updates self.request_update_on_draw(self.renderer.init_frame, 0) self.request_update_on_draw(self.renderer.draw_frame, 100)
def imshow(self, arr, caption): if self.window is None: height, width, _ = arr.shape self.window = Window(width=width, height=height, display=self.display, vsync=False, resizable=True) self.width = width self.height = height self.isopen = True assert len(arr.shape) == 3 height, width, _ = arr.shape image = pyglet.image.ImageData(width, height, 'RGB', arr.tobytes(), pitch=-3 * width) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) texture = image.get_texture() texture.width = self.width texture.height = self.height self.window.clear() self.window.switch_to() self.window.dispatch_events() texture.blit(0, 0) self.window.flip() self.window.set_caption(caption)
def __init__(self): self.win = Window(fullscreen=True, visible=False) self.clockDisplay = clock.ClockDisplay() glClearColor(0.2, 0.2, 0.2, 1) self.camera = Camera((0, 0), 250) self.space = pymunk.Space() #2 self.space.gravity = (0, -500.0) self.space.damping = 0.999 self.map = alone.Map(self.space) self.player = alone.Player(*self.map.to_world(1, 2)) self.space.add(self.player.box, self.player.body) self.space.add_collision_handler(0, 0, None, None, self.print_collision, None) self.balls = [] self.lamps = [alone.Lamp(*self.map.to_world(4, 3))] #self.powerups = [alone.Powerup(*self.map.to_world(1, 4))] darkImage = pyglet.resource.image('dark.png') winSize = self.win.get_size() self.darkness = pyglet.sprite.Sprite(darkImage, x=0, y=0) self.darkness.scale = winSize[0] / darkImage.width backgroundImage = pyglet.resource.image('background.png') self.background = pyglet.sprite.Sprite(backgroundImage, x=0, y=0) self.background.scale = winSize[0] / backgroundImage.width self.camera.setTarget(0, 0)
def prepare(self, options): self.window = Window( fullscreen=options.fullscreen, vsync=False, visible=False, resizable=True) self.window.on_draw = self.draw self.projection = Projection(self.window.width, self.window.height) self.window.on_resize = self.projection.resize self.world = World() self.camera = Camera() self.world.add( GameItem( camera=self.camera, position=Origin, move=WobblyOrbit(32, 1, speed=-0.5), ) ) self.render = Render(self.world) self.render.init() pyglet.clock.schedule(self.update) self.clock_display = pyglet.clock.ClockDisplay() vs = VertexShader(join('flyinghigh', 'shaders', 'lighting.vert')) fs = FragmentShader(join('flyinghigh', 'shaders', 'lighting.frag')) shader = ShaderProgram(vs, fs) shader.use()
def __init__(self, background_color=dark_gray, clock=mono_clock.get_time): # lazy load, partially to avoid auto-formatter that wants to # do imports, *then* dict setting from pyglet import gl from pyglet.window import Window self._background_color = Vector4f(background_color) self.clock = clock self.current_time = 0 self.prev_time = 0 # can bump down `samples` if performance is hurting config = gl.Config(depth_size=0, double_buffer=True, alpha_size=8, sample_buffers=1, samples=4, vsync=False, major_version=3, minor_version=3) display = pyglet.canvas.get_display() screen = display.get_screens()[0] self._win = Window(resizable=False, fullscreen=True, screen=screen, config=config, style='borderless', vsync=True) self._win.event(self.on_key_press) atexit.register(self._on_close) self.context = mgl.create_context(require=int('%i%i0' % (config.major_version, config.minor_version))) self.context.viewport = (0, 0, self.width, self.height) self.context.enable(mgl.BLEND) self.frame_period # do this before we've drawn anything # in principle, should be disconnected from the window # but we're saving time & mental energy self.cam = Camera(projection=height_ortho(self.width, self.height))
def __init__(self, window=None): if window is None: display = pyglet.canvas.get_display() screen = display.get_screens()[0] config = screen.get_best_config() context = config.create_context(None) window = Window(width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, config=config, context=context) self.window = window
def __init__(self, width, height, display=None): from pyglet.window import Window self.sheet = SpriteSheet() self.display = display self.window = Window(width=width * self.sheet.BLOCK_WIDTH, height=height * self.sheet.BLOCK_WIDTH, display=self.display) self.isopen = True self.init_blend()
def open(self): """Open the window.""" self._window = Window( caption=self.caption, height=self.height, width=self.width, vsync=False, resizable=True, )
def test_motion(self): w = Window(200, 200) try: w.push_handlers(self) while not w.has_exit: w.dispatch_events() finally: w.close() self.user_verify('Pass test?', take_screenshot=False)
def test_caption(self): try: w1 = Window(400, 200, resizable=True) w2 = Window(400, 200, resizable=True) count = 1 w1.set_caption('Window caption %d' % count) w2.set_caption(u'\u00bfHabla espa\u00f1ol?') last_time = time.time() while not (w1.has_exit or w2.has_exit): if time.time() - last_time > 1: count += 1 w1.set_caption('Window caption %d' % count) last_time = time.time() w1.dispatch_events() w2.dispatch_events() finally: w1.close() w2.close() self.user_verify('Pass test?', take_screenshot=False)
def test_set_exclusive_mouse(self): self.width, self.height = 200, 200 self.w = w = Window(self.width, self.height) try: w.push_handlers(self) while not w.has_exit: w.dispatch_events() finally: w.close() self.user_verify('Pass test?', take_screenshot=False)
def test_resize(self): w = Window(200, 200, resizable=True) try: w.push_handlers(self) while not w.has_exit: window_util.draw_client_border(w) w.flip() w.dispatch_events() finally: w.close() self.user_verify('Pass test?', take_screenshot=False)
def test_set_fullscreen(self): self.w = w = Window(200, 200) try: w.push_handlers(self) w.push_handlers(WindowEventLogger()) self.on_expose() while not w.has_exit: w.dispatch_events() finally: w.close() self.user_verify('Pass test?', take_screenshot=False)
def test_set_icon(self): self.width, self.height = 200, 200 self.w = w = Window(self.width, self.height) try: w.set_icon( image.load(self.get_test_data_file('images', 'icon1.png'))) w.dispatch_events() self.user_verify('Does the window have a yellow A icon?', take_screenshot=False) finally: w.close()
def __init__(self): gl.glEnable(gl.GL_TEXTURE_2D) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) self.window = Window(width=640, height=360, resizable=True) self.window.config.alpha_size = 8 gl.glEnable(gl.GL_BLEND) self.window.set_caption('KeysManiac (development build)') Grid.set_factor_from_resolution(*self.window.get_size()) self.window.push_handlers(self) self.scene = None
def test_main(self): width, height = self.window_size self.window = w = Window(width, height, visible=False, resizable=True) w.push_handlers(self) self.render() w.set_visible() while not w.has_exit: w.dispatch_events() w.close()
def __init__(self, screen_width=1000, screen_height=1200, update_fps=45, refresh_fps=15, init_pos=(200, 500), seed=10992, goal=(800, 700), threshold=1): self.screen = Window(width=screen_width, height=screen_height, vsync=False) self.screen_height = screen_height self.screen_width = screen_width self.max_velocity = 30 self.steering = 0 self.space = pymunk.Space() self.draw_options = pymunk.pyglet_util.DrawOptions() self.update_fps = update_fps self.refresh_fps = refresh_fps self.space.iterations = 10 self.space.sleep_time_threshold = 0.5 self.static_body = self.space.static_body shape = pymunk.Segment(self.static_body, (1, 1), (1, screen_height), 1.0) self.space.add(shape) shape.collision_type = COLLTYPE_EDGE shape.elasticity = 1 shape.friction = 1 self.action_space = spaces.Box(low=np.array([-5, -5]), high=np.array([5, 5])) self.state_space = spaces.Box(low=np.array([-self.max_velocity, -self.max_velocity, 0, 0, 0]), high=np.array( [self.max_velocity, self.max_velocity, screen_width, screen_height, 360])) global COL COL = False self.init_pos = init_pos shape = pymunk.Segment(self.static_body, (screen_width, 1), (screen_width, screen_height), 1.0) self.space.add(shape) shape.elasticity = 1 shape.friction = 1 shape.collision_type = COLLTYPE_EDGE self.seed = seed random.seed(seed) self.goal = goal self.threshold = threshold shape = pymunk.Segment(self.static_body, (1, 1), (screen_width, 1), 1.0) self.space.add(shape) shape.elasticity = 1 shape.friction = 1 shape.collision_type = COLLTYPE_EDGE self.goalcol = 3 shape = pymunk.Segment(self.static_body, (1, screen_height), (screen_width, screen_height), 1.0) self.space.add(shape) shape.collision_type = COLLTYPE_EDGE shape.elasticity = 1 shape.friction = 1 self.add_obs(2, 50) self.add_actor(init_pos) h = self.space.add_collision_handler(COLLTYPE_OBS, COLLTYPE_ACT) h.begin = colls f = self.space.add_collision_handler(COLLTYPE_EDGE, COLLTYPE_ACT) f.begin = colls
def test_set_visible(self): self.width, self.height = 200, 200 self.w = w = Window(self.width, self.height) try: w.push_handlers(self) while not w.has_exit: glClear(GL_COLOR_BUFFER_BIT) w.flip() w.dispatch_events() finally: w.close() self.user_verify('Pass test?', take_screenshot=False)
def __init__(self, width=640, height=480, title="App"): assert not MyWindow.defined MyWindow.defined = True self.window = Window(width=width, height=height, caption=title) @self.window.event def on_key_press(symbol, modifiers): self.on_key_press(symbol, modifiers) @self.window.event def on_draw(): self.on_draw()
def test_set_size(self): self.width, self.height = 200, 200 self.w = w = Window(self.width, self.height) try: w.push_handlers(self) while not w.has_exit: window_util.draw_client_border(w) w.flip() w.dispatch_events() finally: w.close() self.user_verify('Pass test?', take_screenshot=False)
def __init__(self, width, height): # display initializations self.__window = Window(width, height, vsync=True) self.__background_color = (0, 0, 0, 1.0) # self._fps_display = pyglet.clock.ClockDisplay() self.__key_state_handler = key.KeyStateHandler() self.__scene = None self.__window.event(self.on_draw) self.__window.push_handlers(self.__key_state_handler) self.__camera = None #schedule regular updates pyglet.clock.schedule_interval(self.update, 1 / 100.0)
def __init__(self, fullscreen): self.fullscreen = fullscreen self.config = Config() self.Instance = vlc.Instance() self.player = self.Instance.media_player_new() media = self.Instance.media_new(self.config.configs['playlist'][1]) self.player.set_media(media) #self.player = media.Player() #track = media.load(self.config.configs['playlist'][1]) #self.player.queue(track) self.texts = ['Movies', 'TV', 'Music', 'Options'] self.index = 0 self.maxIndex = 3 self.mainWindow = Window(fullscreen=self.fullscreen) self.label = Label(self.config.ui['greeting'], font_name='Monospace', font_size=24, x=self.mainWindow.width // 2, y=self.mainWindow.height // 2, anchor_x='center', anchor_y='center') @self.mainWindow.event def on_draw(): self.mainWindow.clear() self.label.draw() # if self.player.get_texture(): # self.player.get_texture().blit(0, 0) @self.mainWindow.event def on_key_press(symbol, modifiers): if symbol == key.UP: if self.index == self.maxIndex: self.index = 0 else: self.index += 1 elif symbol == key.DOWN: if self.index == 0: self.index = self.maxIndex else: self.index -= 1 elif symbol == key.SPACE: #self.player = vlc.MediaPlayer(self.config.configs['playlist'][1]) #self.player.play() self.player.set_xwindow(self.GetHandle()) self.player.play() elif symbol == key.RETURN: self.player.pause() self.label.text = self.texts[self.index]
def _create_shadow_window(): global _shadow_window import pyglet if not pyglet.options['shadow_window'] or _is_epydoc: return from pyglet.window import Window _shadow_window = Window(width=1, height=1, visible=False) _shadow_window.switch_to() from pyglet import app app.windows.remove(_shadow_window)