Quantcast

Clickable text (label)

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Clickable text (label)

Tomás Acauan Schertel
Is there a way to make a label clickable?
Like a web link, but not using any web related stuff.


--
Tomás Schertel
----------------------------------------------
Linux Registered User #304838
Arch Linux User
http://www.archlinux.org/
----------------------------------------------

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Andrea Gavana
Hi,

On 13 March 2012 21:28, Tomás Acauan Schertel wrote:
> Is there a way to make a label clickable?
> Like a web link, but not using any web related stuff.

See:

1) wx.lib.agw.hyperlink
2) wx.HyperlinkCtrl

If you don't like what these 2 guys do, I believe you can just tweak
wx.lib.stattext to do what you want.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Dietmar Schwertberger-2
In reply to this post by Tomás Acauan Schertel
Am 13.03.2012 21:28, schrieb Tomás Acauan Schertel:
> Is there a way to make a label clickable?
> Like a web link, but not using any web related stuff.
Sure, just bind the mouse event:
  wx.EVT_LEFT_DOWN(label, event_handler)
Should work...


Regards,

Dietmar




--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Robin Dunn
On 3/13/12 2:30 PM, Dietmar Schwertberger wrote:
> Am 13.03.2012 21:28, schrieb Tomás Acauan Schertel:
>> Is there a way to make a label clickable?
>> Like a web link, but not using any web related stuff.
> Sure, just bind the mouse event:
> wx.EVT_LEFT_DOWN(label, event_handler)
> Should work...

On some platforms, but not all.  On wxGTK the StaticText is not a real
widget so we're not always able to capture mouse events for it.  (IIRC
with some versions of GTK we can).

So if the OP doesn't want something that looks like a link like what you
get with one of the hyperlink controls then the best bet is to use the
generic static text widget in wx.lib.stattext as Andrea suggested and
bind the mouse events to it like what you suggest.

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

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Tomás Acauan Schertel
Thanks all for your replies.
I really liked wx.HyperlinkCtrl, but it opens my default web browser.
What I really like is a web link alike, but opening a wx.dialog.
Hope I can make myself clear.


--
Tomás Schertel
----------------------------------------------
Linux Registered User #304838
Arch Linux User
http://www.archlinux.org/
----------------------------------------------


On Tue, Mar 13, 2012 at 19:09, Robin Dunn <[hidden email]> wrote:
On 3/13/12 2:30 PM, Dietmar Schwertberger wrote:
Am 13.03.2012 21:28, schrieb Tomás Acauan Schertel:
Is there a way to make a label clickable?
Like a web link, but not using any web related stuff.
Sure, just bind the mouse event:
wx.EVT_LEFT_DOWN(label, event_handler)
Should work...

On some platforms, but not all.  On wxGTK the StaticText is not a real widget so we're not always able to capture mouse events for it.  (IIRC with some versions of GTK we can).

So if the OP doesn't want something that looks like a link like what you get with one of the hyperlink controls then the best bet is to use the generic static text widget in wx.lib.stattext as Andrea suggested and bind the mouse events to it like what you suggest.

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


--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Robin Dunn
On 3/13/12 4:57 PM, Tomás Acauan Schertel wrote:
> Thanks all for your replies.
> I really liked wx.HyperlinkCtrl, but it opens my default web browser.
> What I really like is a web link alike, but opening a wx.dialog.
> Hope I can make myself clear.
>

That is the default behavior.  To do what you want you can just catch
the EVT_HYPERLINK event and do what you need in that handler.

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

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Tomás Acauan Schertel
I've created a simple static text and used Bind to call a function. Like this:

text = wx.StaticText(id=-1, label='Click here', parent=panel, pos=(2, 97), size=(60, 30), style=0)
             
self.Bind(wx.EVT_LEFT_DOWN, self.OnClick, text)
       
def OnClick(self, event):
    print "Hi there"

But when I click on my text "Click here", nothing happens.
What Am I doing wrong?

--
Tomás Schertel
----------------------------------------------
Linux Registered User #304838
Arch Linux User
http://www.archlinux.org/
----------------------------------------------


On Tue, Mar 13, 2012 at 21:19, Robin Dunn <[hidden email]> wrote:
On 3/13/12 4:57 PM, Tomás Acauan Schertel wrote:
Thanks all for your replies.
I really liked wx.HyperlinkCtrl, but it opens my default web browser.
What I really like is a web link alike, but opening a wx.dialog.
Hope I can make myself clear.


That is the default behavior.  To do what you want you can just catch the EVT_HYPERLINK event and do what you need in that handler.


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

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Andrea Gavana
Hi,

On 14 March 2012 04:42, Tomás Acauan Schertel wrote:

> I've created a simple static text and used Bind to call a function. Like
> this:
>
> text = wx.StaticText(id=-1, label='Click here', parent=panel, pos=(2, 97),
> size=(60, 30), style=0)
>
> self.Bind(wx.EVT_LEFT_DOWN, self.OnClick, text)
>
> def OnClick(self, event):
>     print "Hi there"
>
> But when I click on my text "Click here", nothing happens.
> What Am I doing wrong?

Don't use the standard wx.StaticText (as Robin suggested already),
simply use wx.lib.stattext or one of the HyperlinkCtrl I suggested
before. Both solutions will work (for the second one you just need to
catch the EVT_HYPERLINK event and do whatever you need).

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Tomás Acauan Schertel
Thanks guys. I did it.
I used a wx.HyperlinkCtrl with bind, as you said.


--
Tomás Schertel
----------------------------------------------
Linux Registered User #304838
Arch Linux User
http://www.archlinux.org/
----------------------------------------------


On Wed, Mar 14, 2012 at 05:21, Andrea Gavana <[hidden email]> wrote:
Hi,

On 14 March 2012 04:42, Tomás Acauan Schertel wrote:
> I've created a simple static text and used Bind to call a function. Like
> this:
>
> text = wx.StaticText(id=-1, label='Click here', parent=panel, pos=(2, 97),
> size=(60, 30), style=0)
>
> self.Bind(wx.EVT_LEFT_DOWN, self.OnClick, text)
>
> def OnClick(self, event):
>     print "Hi there"
>
> But when I click on my text "Click here", nothing happens.
> What Am I doing wrong?

Don't use the standard wx.StaticText (as Robin suggested already),
simply use wx.lib.stattext or one of the HyperlinkCtrl I suggested
before. Both solutions will work (for the second one you just need to
catch the EVT_HYPERLINK event and do whatever you need).

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/


--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Robin Dunn
In reply to this post by Tomás Acauan Schertel
On 3/13/12 8:42 PM, Tomás Acauan Schertel wrote:

> I've created a simple static text and used Bind to call a function. Like
> this:
>
> text = wx.StaticText(id=-1, label='Click here', parent=panel, pos=(2,
> 97), size=(60, 30), style=0)
>
> self.Bind(wx.EVT_LEFT_DOWN, self.OnClick, text)
>
> def OnClick(self, event):
>      print "Hi there"
>
> But when I click on my text "Click here", nothing happens.
> What Am I doing wrong?

I see you're now using the HyperLinkCtrl but here is some info about why
this didn't work for you.  The mouse events are not command events, so
they are only sent to the window where they happened and are not
propagated up the parent chain.  So in other words, the mouse events for
text (if static texts on your platform and wx version are able to
generate mouse events) will never be seen by self in your example above,
only by text.  So you need to bind the handler to text instead of self.

http://wiki.wxpython.org/self.Bind_vs._self.button.Bind



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

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Valco
This post has NOT been accepted by the mailing list yet.
This post was updated on .
Hello

I'm having the same problem...
I am using

self.pak = hl.HyperLinkCtrl(panelHelp, wx.ID_ANY, 'Here', pos=(35,80))
self.pak.Bind(wx.EVT_HYPERLINK, self.OnPrint)

but when I click 'Here', my web browser opens, and I only want to open an wx.Dialog box.
Please help... what's wrong here?

Thanks...
Valco
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clickable text (label)

Valco
This post has NOT been accepted by the mailing list yet.
Valco wrote
I'm having the same problem...
I am using

self.pak = hl.HyperLinkCtrl(panelHelp, wx.ID_ANY, 'Here', pos=(35,80))
self.pak.Bind(wx.EVT_HYPERLINK, self.OnPrint)

but when I click 'Here', my web browser opens, and I only want to open an wx.Dialog box.
Please help... what's wrong here?

Thanks...
Valco
Problem solved, I made these changes:

        self.pak = hl.HyperLinkCtrl(panelHelp, wx.ID_ANY, 'Here', pos=(35,80))
        self.pak.Bind(hl.EVT_HYPERLINK_LEFT, self.OnPrint)
        self.pak.AutoBrowse(False)

Loading...