1

Hi all.
So, I've been playing with pyglet in this months and a thing I noticed was that even if my application got an error it wouldn't raise it.
I even tried with this example.

from pyglet import app
from pyglet.window import key, window

win  = window()

@win.event
def on_key_press(symbol, modifiers):
    if symbol == key.R:
        raise RuntimeError("testing...")
app.run().

But this example, won't raise any error once the window is running.
Is that how it should work or is my pyglet broken?
How could I fix it?
Thanks big_smile

If you want to get in touch with me you can follow me on Twitter
have a nice day.
Paul

Thumbs up

2

Strange, raises a traceback error on my end in the IDLE console. If running it from a command prompt it should dump the traceback there, I've notplayed around much with raising exceptions or debugging like this, though you could read up on pythons exception handling [here] if needed. Also if thats the exact code, the "W" on the window function should be capitalized:

rom pyglet import app
from pyglet.window import key, Window

win  = Window()

@win.event
def on_key_press(symbol, modifiers):
    if symbol == key.R:
        raise RuntimeError("testing...")
app.run()
-BrushTone v1.3.1: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

Thumbs up

3

Maybe that's it, blind people don't use Idle, it sucks for us. SO if it isn't that, then where would the error go, possibly to the python prompt, but if there isn't one...

I'm a cat! What's mine is mine, and what's yours is mine to :P XD

Thumbs up

4 (edited by Amit 2018-07-07 03:39:55)

Hi,
It doesn't raise errors here either. Wonder what's wrong...
*edit*
I wrote this code and it is now raising the exception properly. Give it a go.
from pyglet.window import Window, key
from pyglet import app
window=Window(300,400,caption="test")
@window.event
def on_key_press(symbol,modifiers):
    if symbol==key.R:
        raise RuntimeError ("test")
app.run()
Regards,
Amit

Thumbs up

5

it doesn't on my end

If you want to get in touch with me you can follow me on Twitter
have a nice day.
Paul

Thumbs up

6

sorry for double posting
@post2
I don't need to handle exceptions I need to trace down errors, because for example when I have multiple files and  there's a syntax error, the window won't notify me of that error.

If you want to get in touch with me you can follow me on Twitter
have a nice day.
Paul

Thumbs up

7

paul. I use try and except condition to handle these and log the error in a .log file. You can also inform the user by putting a code that makes their screen reader say an error has acurd, and stuff like this

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

Thumbs up

8

@7 I could do it that way, but I would prefer seeing errors at runtime. If I can't manage to fix it somehow, I'll use the logging system.

If you want to get in touch with me you can follow me on Twitter
have a nice day.
Paul

Thumbs up

9

Mine produces erroes, god mine does ever lol, I think something is wrong with my python lol the errors it produces.

I'm a cat! What's mine is mine, and what's yours is mine to :P XD

Thumbs up

10

does it raise the RuntimeError or doesn't even start in your end?

If you want to get in touch with me you can follow me on Twitter
have a nice day.
Paul

Thumbs up

11

no it starts, I see the window pop up, then it freaks the fuck out and I get this huge ass traceback.

I'm a cat! What's mine is mine, and what's yours is mine to :P XD

Thumbs up

12

You can make it speak the error. Instead of writing the string in to a file, make the screen reader speak it. If you like to have a gui stile error, You may use WX to show a message with ok and cancel buttons, yes and no buttons, ok or cancel buttons, etc.

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

Thumbs up

13

the thing is, that it won't catch even try and except, I tried allready.
If it doesn't I can not make it speak the error

If you want to get in touch with me you can follow me on Twitter
have a nice day.
Paul

Thumbs up

14

Mine doesn't even load the little code example in the doc properly, so yeah.

I'm a cat! What's mine is mine, and what's yours is mine to :P XD

Thumbs up

15

what's the error you're getting?

If you want to get in touch with me you can follow me on Twitter
have a nice day.
Paul

Thumbs up

16

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    window = pyglet.window.Window()
  File "C:\Python27\lib\site-packages\pyglet\__init__.py", line 384, in __getattr__
    __import__(import_name)
  File "C:\Python27\lib\site-packages\pyglet\window\__init__.py", line 1896, in <module>
    gl._create_shadow_window()
  File "C:\Python27\lib\site-packages\pyglet\gl\__init__.py", line 208, in _create_shadow_window
    _shadow_window = Window(width=1, height=1, visible=False)
  File "C:\Python27\lib\site-packages\pyglet\window\win32\__init__.py", line 134, in __init__
    super(Win32Window, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\pyglet\window\__init__.py", line 501, in __init__
    display = get_platform().get_default_display()
  File "C:\Python27\lib\site-packages\pyglet\window\__init__.py", line 1845, in get_default_display
    return pyglet.canvas.get_display()
  File "C:\Python27\lib\site-packages\pyglet\canvas\__init__.py", line 77, in get_display
    from pyglet.app import displays
  File "C:\Python27\lib\site-packages\pyglet\app\__init__.py", line 154, in <module>
    from pyglet.app.base import EventLoop
  File "C:\Python27\lib\site-packages\pyglet\app\base.py", line 4, in <module>
    standard_library.install_aliases()
  File "C:\Python27\lib\site-packages\future\standard_library\__init__.py", line 483, in install_aliases
    import test
  File "c:\pythonprojects\pyglet_test\test.py", line 14, in <module>
    pyglet.app.run()
  File "C:\Python27\lib\site-packages\pyglet\app\__init__.py", line 138, in run
    event_loop.run()
NameError: global name 'event_loop' is not defined

I'm a cat! What's mine is mine, and what's yours is mine to :P XD

Thumbs up

17

My goodness! That's epic! And paul in that case i've got no idea haha. When you raise the error doesn't the window lose focus? or nothing changes?

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

Thumbs up

18

the thing is, the file works with file redirection.

If you want to get in touch with me you can follow me on Twitter
have a nice day.
Paul

Thumbs up

19

Hi,
at 16, [wow] that error is quite a mystery smile. I wonder does pyglet work with python 2?
And Paul, perhaps try reinstalling pyglet? because on my pc the code gives the error, however if I create the window without a caption parameter it doesn't.
Here it is:
Traceback (most recent call last):                                                                                     
  File "_ctypes/callbacks.c", line 232, in 'calling callback function'                                                 
  File "C:\python37\lib\site-packages\pyglet\window\win32\__init__.py", line 639, in f                                 
    result = event_handler(msg, wParam, lParam)                                                                         
  File "C:\python37\lib\site-packages\pyglet\window\win32\__init__.py", line 710, in _event_key                         
    self.dispatch_event(ev, symbol, modifiers)                                                                         
  File "C:\python37\lib\site-packages\pyglet\window\__init__.py", line 1232, in dispatch_event                         
    if EventDispatcher.dispatch_event(self, *args) != False:                                                           
  File "C:\python37\lib\site-packages\pyglet\event.py", line 357, in dispatch_event                                     
    if handler(*args):                                                                                                 
  File "C:\Users\Amit Aggarwal\Documents\test.py", line 7, in on_key_press                                             
    raise RuntimeError ("test")                                                                                         
RuntimeError: test                                                                                                     
Regards,
Amit

Thumbs up

20

@19
Yes pyglet works with py2.
About the caption, my windows are always withouth caption.

If you want to get in touch with me you can follow me on Twitter
have a nice day.
Paul

Thumbs up

21

Hi,
at 20, having a window without a caption isn't such a nice idea. Consider the fact that someone switched from your game for a  while, now it will be a bit difficult to locate which was the game in those  multiple running applications. IT's possible but this is not a good way to do it. You will give a name to your game right? interesting that the game doesn't have a title? smile
Regards,
Amit

Thumbs up

22 (edited by pauliyobo 2018-07-10 17:35:55)

@21, obviously until I am testing it I couldn't care less about the caption. Is not something which I bother with if I'm just testing what I coded

If you want to get in touch with me you can follow me on Twitter
have a nice day.
Paul

Thumbs up

23

Yes the issue turned out to be python 2, when I switched to python 3, the issue resolved itself. BUt I will not be using this, even with a window with nothing on it, its like 3 seconsd to load, too slow. Also, it is constantly complaining about sounds not being the right format, invalid bits per sample, etc., Screw that, I have some good quality sounds I don't want to down sample.

I'm a cat! What's mine is mine, and what's yours is mine to :P XD

Thumbs up