Repository: psychopy/psychopy

Issue:
[Bug]: Screen selection fails with pyglet on Ubuntu 22.04 LTS
### PsychoPy Version

2023.2.2

### What OS are your PsychoPy running on?

Linux-based systems

### Bug Description

Creating a window with `screen != 0` fails:

```
win = Window(
    size=_SCREEN_SIZE,
    color=_BACKGROUND_COLOR,
    units="norm",
    winType="pyglet",
    fullscr=True,
    allowGUI=False,
    monitor=monitor,
    screen=0,
)
```

The error raised is:

```
Traceback (most recent call last):
  File "/home/meguser/Projects/meg-sophie-schwartz/psychopy-faces.py", line 33, in <module>
    win = Window(
  File "/home/meguser/pyvenv/meg-sophie-schwartz/lib/python3.10/site-packages/psychopy/visual/window.py", line 469, in __init__
    self.backend = backends.getBackend(win=self, backendConf=backendConf)
  File "/home/meguser/pyvenv/meg-sophie-schwartz/lib/python3.10/site-packages/psychopy/visual/backends/__init__.py", line 61, in getBackend
    return Backend(win, *args, **kwargs)
  File "/home/meguser/pyvenv/meg-sophie-schwartz/lib/python3.10/site-packages/psychopy/visual/backends/pygletbackend.py", line 183, in __init__
    display = pyglet.canvas.Display(x_screen=win.screen)
  File "/home/meguser/pyvenv/meg-sophie-schwartz/lib/python3.10/site-packages/pyglet/canvas/xlib.py", line 127, in __init__
    raise NoSuchDisplayException(
pyglet.canvas.xlib.NoSuchDisplayException: Display "None" has no screen 1
Exception ignored in: <function Window.__del__ at 0x7ff44f9aa290>
Traceback (most recent call last):
  File "/home/meguser/pyvenv/meg-sophie-schwartz/lib/python3.10/site-packages/psychopy/visual/window.py", line 647, in __del__
    self.close()
  File "/home/meguser/pyvenv/meg-sophie-schwartz/lib/python3.10/site-packages/psychopy/visual/window.py", line 2536, in close
    self.backend.close()  # moved here, dereferencing the window prevents
AttributeError: 'NoneType' object has no attribute 'close'
```

### Expected Behaviour

With screen=1, the window should open in full screen on our second monitor.

### Additional context

The screen selection here https://github.com/psychopy/psychopy/blob/c5d0cbed79f3c73372fb37d3fc4f1fd4c8d76de2/psychopy/visual/backends/pygletbackend.py#L183
seems too restrictive/limited. In my case, both screen seem to have `x_screen=0`:

```
import pyglet

display = pyglet.canvas.Display()
display.get_screens()
# [XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7fd6e819b610>, x=0, y=1080, width=1920, height=1080, xinerama=1),
#  XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 0x7fd6e819b610>, x=0, y=0, width=1920, height=1080, xinerama=1)]
display.get_screens()[0].display.x_screen
# >>> 0
display.get_screens()[1].display.x_screen
# >>> 0
```

Removing the argument `x_screen=` in the line 183 solves the problem.



Discussion:

Resolving patch:
diff --git a/psychopy/visual/backends/pygletbackend.py b/psychopy/visual/backends/pygletbackend.py
--- a/psychopy/visual/backends/pygletbackend.py
+++ b/psychopy/visual/backends/pygletbackend.py
@@ -180,7 +180,7 @@ def __init__(self, win, backendConf=None):
                 win.multiSample = False
 
         if platform.system() == 'Linux':
-            display = pyglet.canvas.Display(x_screen=win.screen)
+            display = pyglet.canvas.Display()
             allScrs = display.get_screens()
         else:
             if pyglet.version < '1.4':
@@ -334,7 +334,7 @@ def __init__(self, win, backendConf=None):
             # (but need to alter x,y handling then)
             self.winHandle.set_mouse_visible(False)
         if not win.pos:
-            # work out where the centre should be 
+            # work out where the centre should be
             if win.useRetina:
                 win.pos = [(thisScreen.width - win.clientSize[0]/2) / 2,
                            (thisScreen.height - win.clientSize[1]/2) / 2]


Test patch: