Do you have control of the content in the html file?
You can catch clicks by capturing and vetoing a window navigation attempt with
a key string embedded in the location: With a small change to your html file, and
capturing the EVT_WEB_VIEW_NAVIGATING event, we have this python program:
import wx, os
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))
self.Bind(wx.html2.EVT_WEB_VIEW_NAVIGATING, self.OnNavigate,self.browser)
CATCH_STRING = “catch-this-click:”
def OnNavigate(self,evt):
targetUrl=evt.GetURL()
#print "Navigate Target: ",targetUrl
if self.CATCH_STRING in targetUrl:
passed_data = targetUrl.split(self.CATCH_STRING,2)[1]
print "Click Caught! Data = ",passed_data
evt.Veto() # prevent actual navigation.
else:
pass # let it do the normal thing...
if name == ‘main’:
app = wx.App()
dialog = MyBrowser(None, -1)
url = os.path.join(os.getcwd(), ‘test2.htm’)
print "loading url ",url
dialog.browser.LoadURL(url)
dialog.Show()
app.MainLoop()
and this test file test2.htm:
Click here
Will that be enough for your needs?
···
On Friday, February 7, 2014 4:18:40 AM UTC-5, RedHotChiliPepper wrote:
I have the following python script
…
Is there a way for a python function to be bound to the “click”?