Skip to content

wxPython's GetHandle() returns 0 with wxPython 3.0/4.0 on Linux #349

@cztomczak

Description

@cztomczak

On Linux with wxPython 3.x / 4.x window handle is not yet available even though Show() was called and it causes in the wxpython.py example to open two windows, one blank window and another window with CEF browser. This effect is because window handle passed to CEF is 0, thus CEF creates a top-level window on its own.

The solution is to delay embedding browser by a bit and window handle becomes available then. Time of 1ms is not enough, 10ms seems fine, but to be sure I've used 20ms. Example works fine with such code:

        # On Linux must show before embedding browser, so that handle
        # is available (Issue #347).
        if LINUX:
            self.Show()
            # In wxPython 3.0 and wxPython 4.0 handle is still
            # not yet available, must delay embedding browser
            # (Issue #349).
            if wx.version().startswith("3.") or wx.version().startswith("4."):
                wx.CallLater(20, self.embed_browser)
            else:
                # This works fine in wxPython 2.8
                self.embed_browser()
        else:
            self.embed_browser()
            self.Show()

Issue originally reported on the Forum:
https://groups.google.com/d/topic/cefpython/ZBXEdOR3svw/discussion

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions