Mageia Bugzilla – Attachment 14256 Details for
Bug 32696
Audio crashes with pyglet
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
Display a button to stop the program when plyaing a sound
test2_pyglet.py (text/plain), 1.30 KB, created by
papoteur
on 2024-01-07 12:38:00 CET
(
hide
)
Description:
Display a button to stop the program when plyaing a sound
Filename:
MIME Type:
Creator:
papoteur
Created:
2024-01-07 12:38:00 CET
Size:
1.30 KB
patch
obsolete
>import pyglet >from pyglet.gl import * > >class main (pyglet.window.Window): > def __init__ (self): > super(main, self).__init__(800, 600, fullscreen = False) > self.button_texture = pyglet.image.load('/usr/share/themes/Breeze-Dark/assets/togglebutton.png') > self.button = pyglet.sprite.Sprite(self.button_texture) > > self.sound = pyglet.media.load('/usr/share/sounds/purple/login.wav') > self.sound.play() > > self.alive = 1 > > def on_draw(self): > self.render() > > def on_close(self): > self.alive = 0 > > def on_mouse_press(self, x, y, button, modifiers): > if x > self.button.x and x < (self.button.x + self.button_texture.width): > if y > self.button.y and y < (self.button.y + self.button_texture.height): > self.alive = 0 > > def on_key_press(self, symbol, modifiers): > if symbol == 65307: # [ESC] > self.alive = 0 > > def render(self): > self.clear() > self.button.draw() > 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()
import pyglet from pyglet.gl import * class main (pyglet.window.Window): def __init__ (self): super(main, self).__init__(800, 600, fullscreen = False) self.button_texture = pyglet.image.load('/usr/share/themes/Breeze-Dark/assets/togglebutton.png') self.button = pyglet.sprite.Sprite(self.button_texture) self.sound = pyglet.media.load('/usr/share/sounds/purple/login.wav') self.sound.play() self.alive = 1 def on_draw(self): self.render() def on_close(self): self.alive = 0 def on_mouse_press(self, x, y, button, modifiers): if x > self.button.x and x < (self.button.x + self.button_texture.width): if y > self.button.y and y < (self.button.y + self.button_texture.height): self.alive = 0 def on_key_press(self, symbol, modifiers): if symbol == 65307: # [ESC] self.alive = 0 def render(self): self.clear() self.button.draw() 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()
View Attachment As Raw
Actions:
View
Attachments on
bug 32696
: 14256