Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWayland is required even though wxPython programs runs under wayland #2557

Open
bhepple opened this issue Jun 8, 2024 · 5 comments
Open

Comments

@bhepple
Copy link

bhepple commented Jun 8, 2024

Operating system: Void Linux
wxPython version & source: wxPython-4.2.1_4 from voidlinux repo
Python version & source: python3-3.12.3_1

Description of the problem:
On linux, wxPython programs can run under wayland for example in the sway WM.

However, if XWayland is not available and enabled they will not run:

Unable to access the X Display, is $DISPLAY set properly?

Any wxPython program will do eg:

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        super(MyFrame, self).__init__(parent, title=title)
        top_panel = wx.Panel(self)
        top_panel_sizer = wx.BoxSizer(wx.VERTICAL)
        top_panel.SetSizer(top_panel_sizer)
        collapsible_pane = wx.CollapsiblePane(top_panel, label="Collapsible Pane",
                                              style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE)
        self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged, collapsible_pane)
        pane = collapsible_pane.GetPane()
        pane_sizer = wx.BoxSizer(wx.VERTICAL)
        pane.SetSizer(pane_sizer)
        text_box = wx.TextCtrl(pane, value = "foo")
        pane_sizer.Add(text_box, 1, wx.ALL | wx.EXPAND, 5)
        top_panel_sizer.Add(collapsible_pane, 1, wx.ALL | wx.EXPAND, 5)
        
    def OnPaneChanged(self, evt=None):
        self.Layout()
        
if __name__ == "__main__":
    app = wx.App()
    frm = MyFrame(None, title="Minimal wxPython Program")
    frm.Show()
    app.MainLoop()
@swt2c
Copy link
Collaborator

swt2c commented Jun 11, 2024

Confirmed. wxPython calls XOpenDisplay unconditionally here:
https://github.com/wxWidgets/Phoenix/blob/master/src/app_ex.cpp#L303

@swt2c
Copy link
Collaborator

swt2c commented Jun 11, 2024

You can probably hack around this problem by monkey-patching IsDisplayAvailable:

wx.PyApp.IsDisplayAvailable = lambda _: True

I wonder if the check still makes sense, but it does seem at least somewhat useful. If I remove it on a system with no display (e.g., over an SSH connection), wxPython startup will just hang there.

@bhepple
Copy link
Author

bhepple commented Jun 11, 2024

Thanks for that - works just fine without Xwayland now.

The problem for me is that my Xwayland is rather buggy and brings down the sway session occasionally - so this should be a life changer.

@bhepple
Copy link
Author

bhepple commented Jun 11, 2024

Up to you if you want to close this. I'm OK with the patch but I still think it's a bit janky that otherwise you must have Xwayland.

@swt2c
Copy link
Collaborator

swt2c commented Jun 11, 2024

No, this is definitely an issue that we need to address. I'm just not sure how exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants