Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

wx.EVT_TEXT_URL

120 views
Skip to first unread message

Udgam Mehetre

unread,
Mar 26, 2014, 2:48:39 PM3/26/14
to wxpytho...@googlegroups.com
Hello all!
 I am using a wx.textctrl widget to display some urls. I want the url to open in a browser when the user clicks on the links. I read that implementing wx.TE_RICH and wx.TE_AUTO_URL would let me achieve this (click-able urls). I also binded the widget instance to an event, as follows:

>>OutputText=wx.TextCtrl(panel ,pos =(10,10),size=(700,300), style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH|wx.TE_AUTO_URL)

>>OutputText.Bind(wx.EVT_TEXT_URL,self.openurl)

Now, what happens is, if even the mouseover happens, this event is triggered. I mean, if one just brings the cursor on the url, the event is called, instead of triggering when actual 'click' happens.
I am sure my implementation of the wx.EVT_TEXT_URL maybe the fault. Hence my question...where am I possibly wrong? What do I change to set it right?

Thanks in advance!

Regards,
Udgam Mehetre

Boštjan Mejak

unread,
Mar 26, 2014, 5:57:28 PM3/26/14
to wxpytho...@googlegroups.com
​Try using the self.
self.OutputText = wx.TextCtrl(.......)
and then here
self.OutputText.Bind(wx.EVT_TEXT_URL, self.openurl)

uvmgr8

unread,
Mar 27, 2014, 5:24:21 AM3/27/14
to wxpytho...@googlegroups.com
Isnt the self.widget_instance about scope of the widget? My problem is that the wx.EVT_TEXT_URL doesn't work (or I dont know how it works) as I need it to work. Whlie the url is displayed as hyperlink, the wx.EVT_TEXT_URL triggers even if I drag my mouse over the hyperlink. I need it to do so only if I click on the hyperlink.


--
You received this message because you are subscribed to a topic in the Google Groups "wxPython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/5tzwrFjpb1M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Udgam Mehetre

" Imagination is the only weapon in the war against reality."

Boštjan Mejak

unread,
Mar 27, 2014, 7:05:33 AM3/27/14
to wxpytho...@googlegroups.com
def openurl(self, event):
    if event.MouseEvent.LeftUp():
        # Put the code
​ ​
that you have here
​    ​
event.Skip()


This is how your openurl() method should be formed.
Is it?

Metallicow

unread,
Mar 31, 2014, 1:01:07 AM3/31/14
to wxpytho...@googlegroups.com

Here, I'll help ya out. This is a simple one, but not exactly obvious at times to some folks.
See the attached demo.
URLTextCtrl.py

uvmgr8

unread,
Mar 31, 2014, 2:18:39 AM3/31/14
to wxpytho...@googlegroups.com
@Metallicow,
THANK YOU!

Bostjan did mention the mouse function, but I couldnt exactly implement it. Your code even helped me in using webbrowser :)

Again, thanks Bostjan and Metallicow!


--
You received this message because you are subscribed to a topic in the Google Groups "wxPython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/5tzwrFjpb1M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages