2018-07-06 19:27:44

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

Paul

2018-07-07 01:18:28

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.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2018-07-07 01:21:47

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...

Facts with Tom MacDonald, Adam Calhoun, and Dax
End racism
End division
Become united

2018-07-07 04:19:27 (edited by Amit 2018-07-07 04: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

There once was a moviestar icon.
Who prefered to sleep with the light on.
They learnt how to code, devices sure glowed,
and lit the night using python.

2018-07-07 11:37:23

it doesn't on my end

Paul

2018-07-07 11:38:51

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.

Paul

2018-07-08 13:29:00

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

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2018-07-08 14:45:58

@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.

Paul

2018-07-08 21:15:45

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

Facts with Tom MacDonald, Adam Calhoun, and Dax
End racism
End division
Become united

2018-07-08 21:20:33

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

Paul

2018-07-09 01:03:44

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

Facts with Tom MacDonald, Adam Calhoun, and Dax
End racism
End division
Become united

2018-07-09 16:33:30

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.

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2018-07-09 18:52:47

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

Paul

2018-07-09 19:21:31

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

Facts with Tom MacDonald, Adam Calhoun, and Dax
End racism
End division
Become united

2018-07-09 19:50:10

what's the error you're getting?

Paul

2018-07-09 22:13:53

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

Facts with Tom MacDonald, Adam Calhoun, and Dax
End racism
End division
Become united

2018-07-09 22:19:14

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?

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2018-07-09 22:48:15

the thing is, the file works with file redirection.

Paul

2018-07-10 04:45:48

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

There once was a moviestar icon.
Who prefered to sleep with the light on.
They learnt how to code, devices sure glowed,
and lit the night using python.

2018-07-10 10:16:55

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

Paul

2018-07-10 16:58:04

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

There once was a moviestar icon.
Who prefered to sleep with the light on.
They learnt how to code, devices sure glowed,
and lit the night using python.

2018-07-10 18:35:01 (edited by pauliyobo 2018-07-10 18: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

Paul

2018-07-10 20:00:01

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.

Facts with Tom MacDonald, Adam Calhoun, and Dax
End racism
End division
Become united