Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b359129

Browse files
committed
Fix wxpython.py example on Linux for wxPython 3.0/4.0 (cztomczak#349)
wx.IconFromBitmap is not available on Linux.
1 parent e74777a commit b359129

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

examples/wxpython.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,23 @@ def __init__(self):
8787
# is available (Issue #347).
8888
if LINUX:
8989
self.Show()
90-
self.embed_browser()
90+
# In wxPython 3.0 and wxPython 4.0 handle is still
91+
# not yet available, must delay embedding browser
92+
# (Issue #349).
93+
if wx.version().startswith("3.") or wx.version().startswith("4."):
94+
wx.CallLater(20, self.embed_browser)
95+
else:
96+
# This works fine in wxPython 2.8
97+
self.embed_browser()
9198
else:
9299
self.embed_browser()
93100
self.Show()
94101

95102
def setup_icon(self):
96103
icon_file = os.path.join(os.path.abspath(os.path.dirname(__file__)),
97104
"resources", "wxpython.png")
98-
if os.path.exists(icon_file):
105+
# wx.IconFromBitmap is not available on Linux in wxPython 3.0/4.0
106+
if os.path.exists(icon_file) and hasattr(wx, "IconFromBitmap"):
99107
icon = wx.IconFromBitmap(wx.Bitmap(icon_file, wx.BITMAP_TYPE_PNG))
100108
self.SetIcon(icon)
101109

@@ -132,7 +140,7 @@ def OnSize(self, _):
132140
0, 0, 0)
133141
elif LINUX:
134142
(x, y) = (0, 0)
135-
(width, height) = self.browser_panel.GetSizeTuple()
143+
(width, height) = self.browser_panel.GetSize().Get()
136144
self.browser.SetBounds(x, y, width, height)
137145
self.browser.NotifyMoveOrResizeStarted()
138146

0 commit comments

Comments
 (0)