Created
October 27, 2016 14:01
-
-
Save Torxed/96bf39d0377e193bbcd2025fc365e9fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyglet | |
from pyglet.gl import * | |
# REQUIRES: AVBin | |
pyglet.options['audio'] = ('alsa', 'openal', 'silent') | |
key = pyglet.window.key | |
# xfce4-notifyd | |
class main(pyglet.window.Window): | |
def __init__ (self): | |
super(main, self).__init__(800, 800, fullscreen = False) | |
self.x, self.y = 0, 0 | |
self.bg = pyglet.sprite.Sprite(pyglet.image.load('background.jpg')) | |
self.sprites = {} | |
self.sprites['2-test'] = pyglet.sprite.Sprite(pyglet.image.load('kitten.jpg')) | |
self.sprites['2-test'].x = 30 | |
self.sprites['2-test'].y = 30 | |
self.alive = 1 | |
def on_draw(self): | |
self.render() | |
def on_close(self): | |
self.alive = 0 | |
def on_mouse_motion(self, x, y, dx, dy): | |
print('Moved:', (x,y), (dx, dy)) | |
def on_mouse_release(self, x, y, button, modifiers): | |
pass | |
def on_mouse_press(self, x, y, button, modifiers): | |
print('Mousclick:', x, y, button) | |
def on_mouse_drag(self, x, y, dx, dy, button, modifiers): | |
pass | |
def on_key_release(self, symbol, modifiers): | |
pass | |
def on_key_press(self, symbol, modifiers): | |
if symbol == key.ESC: # [ESC] | |
self.alive = 0 | |
def draw_line(self, xy, dxy, color=(1, 1, 1, 1)): | |
glColor4f(*color) | |
glBegin(GL_LINES) | |
glVertex2f(xy[0], xy[1]) | |
glVertex2f(dxy[0], dxy[1]) | |
glEnd() | |
def render(self): | |
self.clear() | |
self.bg.draw() | |
for sprite_name, sprite in self.sprites.items(): | |
sprite.draw() | |
self.draw_line((10,10), (100,100)) | |
self.flip() | |
def run(self): | |
while self.alive == 1: | |
self.render() | |
# -----------> This is key <---------- | |
# This is what replaces pyglet.app.run() | |
# but is required for the GUI to not freeze | |
# | |
event = self.dispatch_events() | |
x = main() | |
x.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment