wx.EVT_TEXT_URL

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

​Try using the self.

self.OutputText = wx.TextCtrl(…)

and then here

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

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.

···

On 27 March 2014 03:27, Boštjan Mejak bostjan.galaxy@gmail.com wrote:

​Try using the self.

self.OutputText = wx.TextCtrl(…)

and then here

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

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-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


Udgam Mehetre

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

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?

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 (1.84 KB)

···

On Wednesday, March 26, 2014 1:48:39 PM UTC-5, Udgam Mehetre wrote:

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

@Metallicow,
THANK YOU!

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

Again, thanks Bostjan and Metallicow!

···

On 31 March 2014 10:31, Metallicow metaliobovinus@gmail.com wrote:

On Wednesday, March 26, 2014 1:48:39 PM UTC-5, Udgam Mehetre wrote:

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

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

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-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


Udgam Mehetre

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