wx.html2 does not work in a dialog on OSX

86 views
Skip to first unread message

Rish

unread,
Jan 13, 2012, 1:31:58 AM1/13/12
to wxPython-users
Hi Robin, et al,

I'm running into an issue that I'd like to understand better. Using
the new wx.html2 in wxPython 2.9.3.1, I found that it does not work in
the context of a wx.Dialog and only works in wx.Frame on OSX. What it
does is it will issue the EVT_WEB_VIEW_NAVIGATING but thats as far as
it goes and it shows only a blank white page. This can be an issue if
I need the UI to suspend execution until the browser is closed.

Here is a simple script that will demonstrate this. You can see if
you use the Show() method, the URL will get loaded properly, but the
ShowModal() one fails. Has anyone else encountered this? I'm curious
to hear solutions/fixes/etc.

Thanks!


import wx
import wx.html2

class MyBrowser(wx.Dialog):

def __init__(self, *args, **kwds):
wx.Dialog.__init__(self, *args, **kwds)
sizer = wx.BoxSizer(wx.VERTICAL)
self.browser = wx.html2.WebView.New(self)
sizer.Add(self.browser, 1, wx.EXPAND, 10)
self.SetSizer(sizer)
self.SetSize((700, 700))

if __name__ == '__main__':
app = wx.PySimpleApp()
dialog = MyBrowser(None, -1)
dialog.browser.LoadURL("http://www.google.com")

# Does not
work:

#dialog.Show()

#dialog.Destroy()

# Does work, but you need to suspend execution
somehow:
dialog.Show()

app.MainLoop()

Rish

unread,
Jan 13, 2012, 1:42:41 AM1/13/12
to wxPython-users
# Close the dialog to continue.

import wx
import wx.html2

class MyBrowser(wx.Dialog):

def __init__(self, *args, **kwds):
wx.Dialog.__init__(self, *args, **kwds)
sizer = wx.BoxSizer(wx.VERTICAL)
self.browser = wx.html2.WebView.New(self)
sizer.Add(self.browser, 1, wx.EXPAND, 10)
self.SetSizer(sizer)
self.SetSize((700, 700))

if __name__ == '__main__':
app = wx.PySimpleApp()
dialog = MyBrowser(None, -1)
dialog.browser.LoadURL("http://www.google.com")

# Does not
work:

dialog.ShowModal()

dialog.Destroy()

# Does
work:
dialog = MyBrowser(None, -1)
dialog.browser.LoadURL("http://www.google.com")
dialog.Show()

app.MainLoop()

CJC

unread,
Jan 13, 2012, 11:25:15 AM1/13/12
to wxpytho...@googlegroups.com

Hi Rish

can you tested this. Thanks.
wx.html2_dialog.pyw

Rish

unread,
Jan 13, 2012, 3:27:06 PM1/13/12
to wxPython-users
Hi CJC,

Thanks for replying.
I tested that, and it works, but it is using the Show() method of the
dialog class, instead of the ShowModal(). If you take a look at the
code snippet I posted earlier, it does the same thing (i.e. works
under dialog.Show() but not under dialog.ShowModal()).

I'm trying to understand why ShowModal() breaks this class and causes
the browser to refuse to load the given URL.

Thanks for your help,

-Rish

On Jan 13, 8:25 am, CJC <jcie.pyt...@gmail.com> wrote:
> Hi Rish
>
> can you tested this. Thanks.
>
>  wx.html2_dialog.pyw
> 2KViewDownload

Robin Dunn

unread,
Jan 13, 2012, 3:59:14 PM1/13/12
to wxpytho...@googlegroups.com
On 1/12/12 10:31 PM, Rish wrote:
> Hi Robin, et al,
>
> I'm running into an issue that I'd like to understand better. Using
> the new wx.html2 in wxPython 2.9.3.1, I found that it does not work in
> the context of a wx.Dialog and only works in wx.Frame on OSX. What it
> does is it will issue the EVT_WEB_VIEW_NAVIGATING but thats as far as
> it goes and it shows only a blank white page. This can be an issue if
> I need the UI to suspend execution until the browser is closed.
>
> Here is a simple script that will demonstrate this. You can see if
> you use the Show() method, the URL will get loaded properly, but the
> ShowModal() one fails. Has anyone else encountered this? I'm curious
> to hear solutions/fixes/etc.
>

I'm not sure what's going on. Since I made a modified sample to
experiment with it I went ahead and made a new ticket for it and
attached the sample there.

http://trac.wxwidgets.org/ticket/13863

--
Robin Dunn
Software Craftsman
http://wxPython.org

Reply all
Reply to author
Forward
0 new messages