clickable text

How is it possible to create a text control that can respond to clicks
within certain ranges of characters? I need to keep a reference to
each section of text so they can be removed, and these ranges need to
be updated when the position of their content changes. I have been
looking at RichTextCtrl but I don't see how to solve this.

Hi,
if you are using RichTextCtrl, it should be fairly easy, check the
demo for that widget (a link "The wxPython Web Site" near the bottom
of the sample text)
in the code, the relevant bits are (with the accompaining code):

    def OnURL(self, evt):
        wx.MessageBox(evt.GetString(), "URL Clicked")

...
        self.rtc.Bind(wx.EVT_TEXT_URL, self.OnURL)
...

        self.rtc.BeginURL("http://wxPython.org/"\)
        self.rtc.WriteText("The wxPython Web Site")
        self.rtc.EndURL();

If I understand the problem with changing the text correctly, it may
be done automatically in this widget, as the style or URL etc.
boundaries remain relative to the other text (hopefully?).

For another approach you can check
wx.html
Of course, it can be also done manually (i.e. maintain the text
indices for the "links" and determine the action on click depending on
the clicked text location), but this might not be appropriate for most
cases.

hth,
  vbr

···

2010/4/9 targ <tazg2000@gmail.com>:

How is it possible to create a text control that can respond to clicks
within certain ranges of characters? I need to keep a reference to
each section of text so they can be removed, and these ranges need to
be updated when the position of their content changes. I have been
looking at RichTextCtrl but I don't see how to solve this.

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, reply using "remove me" as the subject.

Okay, it does update the position and I can read it with GetURLStart
and GetURLEnd inside the event handler... but I don't see how to
access it outside the event handler. I tried this:

def OnURL(self, event):
    self.clicked_url = event

But it doesn't work as expected. clicked_url.GetURLStart/GetURLEnd
always return 1 and 0.

Obviously RichTextCtrl keeps track of these URLs interally, but where
can I get that information directly?

···

On Apr 9, 4:58 am, Vlastimil Brom <vlastimil.b...@gmail.com> wrote:

2010/4/9 targ <tazg2...@gmail.com>:

> How is it possible to create a text control that can respond to clicks
> within certain ranges of characters? I need to keep a reference to
> each section of text so they can be removed, and these ranges need to
> be updated when the position of their content changes. I have been
> looking at RichTextCtrl but I don't see how to solve this.

> --
> To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
> or visithttp://groups.google.com/group/wxPython-users?hl=en

> To unsubscribe, reply using "remove me" as the subject.

Hi,
if you are using RichTextCtrl, it should be fairly easy, check the
demo for that widget (a link "The wxPython Web Site" near the bottom
of the sample text)
in the code, the relevant bits are (with the accompaining code):

def OnURL\(self, evt\):
    wx\.MessageBox\(evt\.GetString\(\), &quot;URL Clicked&quot;\)

...
self.rtc.Bind(wx.EVT_TEXT_URL, self.OnURL)
...

    self\.rtc\.BeginURL\(&quot;http://wxPython.org/&quot;\)
    self\.rtc\.WriteText\(&quot;The wxPython Web Site&quot;\)
    self\.rtc\.EndURL\(\);

If I understand the problem with changing the text correctly, it may
be done automatically in this widget, as the style or URL etc.
boundaries remain relative to the other text (hopefully?).

For another approach you can check
wx.html
Of course, it can be also done manually (i.e. maintain the text
indices for the "links" and determine the action on click depending on
the clicked text location), but this might not be appropriate for most
cases.

hth,
vbr

Well, here's what I'm using for now:

    def OnURL(self, event):
        for child in
event.GetEventObject().GetBuffer().GetChild(0).GetChildren():
            if child.GetRange() == (event.GetURLStart(),
event.GetURLEnd()):
                self.clicked_url = child

Hoping there is a better way.

···

On Apr 9, 4:43 pm, targ <tazg2...@gmail.com> wrote:

On Apr 9, 4:58 am, Vlastimil Brom <vlastimil.b...@gmail.com> wrote:

> 2010/4/9 targ <tazg2...@gmail.com>:

> > How is it possible to create a text control that can respond to clicks
> > within certain ranges of characters? I need to keep a reference to
> > each section of text so they can be removed, and these ranges need to
> > be updated when the position of their content changes. I have been
> > looking at RichTextCtrl but I don't see how to solve this.

> > --
> > To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
> > or visithttp://groups.google.com/group/wxPython-users?hl=en

> > To unsubscribe, reply using "remove me" as the subject.

> Hi,
> if you are using RichTextCtrl, it should be fairly easy, check the
> demo for that widget (a link "The wxPython Web Site" near the bottom
> of the sample text)
> in the code, the relevant bits are (with the accompaining code):

> def OnURL(self, evt):
> wx.MessageBox(evt.GetString(), "URL Clicked")

> ...
> self.rtc.Bind(wx.EVT_TEXT_URL, self.OnURL)
> ...

> self.rtc.BeginURL("http://wxPython.org/&quot;\)
> self.rtc.WriteText("The wxPython Web Site")
> self.rtc.EndURL();

> If I understand the problem with changing the text correctly, it may
> be done automatically in this widget, as the style or URL etc.
> boundaries remain relative to the other text (hopefully?).

> For another approach you can check
> wx.html
> Of course, it can be also done manually (i.e. maintain the text
> indices for the "links" and determine the action on click depending on
> the clicked text location), but this might not be appropriate for most
> cases.

> hth,
> vbr

Okay, it does update the position and I can read it with GetURLStart
and GetURLEnd inside the event handler... but I don't see how to
access it outside the event handler. I tried this:

def OnURL(self, event):
self.clicked_url = event

But it doesn't work as expected. clicked_url.GetURLStart/GetURLEnd
always return 1 and 0.

Obviously RichTextCtrl keeps track of these URLs interally, but where
can I get that information directly?

Still unsolved... I need to be able to completely remove the URLs. I
can remove the range of text that contains a URL, but if I insert text
there it is treated as a URL again.

Even if I clear the entire control, the next text that is inserted is
treated as whichever URL the insertion point was last inside of.

What are the tasks you need to do in this program?
If I understand correctly, you first programmatically write some
richtext containing links, which should be active and respond to
clicks.
Then the editor content should be modified - programmatically or manually?
Do the changes concern exactly the link text or other text parts too?
In the wxpython demo for rtc it seems, that the link text can be
normally edited, deleted or copied manually.
When dealing with the text changes programmatically, i would guess, it
should be at least possible, to generate the new content after
clearing the editor.
Admittedly, I haven't used this widget very extensively, probably
others might have more relevant suggestions.
hth,
  vbr

···

2010/4/10 targ <tazg2000@gmail.com>:

Still unsolved... I need to be able to completely remove the URLs. I
can remove the range of text that contains a URL, but if I insert text
there it is treated as a URL again.

Even if I clear the entire control, the next text that is inserted is
treated as whichever URL the insertion point was last inside of.

The primary author of the RTC is subscribed to the wx-users list, so you may be able to get an answer there.

···

On 4/9/10 4:24 PM, targ wrote:

Still unsolved... I need to be able to completely remove the URLs. I
can remove the range of text that contains a URL, but if I insert text
there it is treated as a URL again.

Even if I clear the entire control, the next text that is inserted is
treated as whichever URL the insertion point was last inside of.

--
Robin Dunn
Software Craftsman

Here's how to see the problem in the rtc demo:

- move the insertion point over the URL
- Ctrl+A and delete
- type something

The URL doesn't actually get deleted, only its text does. Whatever you
type will become clickable and have the URL's style. My workaround is
to add a space at the end of the text and move the insertion point to
the end position before replacing the URL text.

···

On Apr 10, 3:37 pm, Vlastimil Brom <vlastimil.b...@gmail.com> wrote:

2010/4/10 targ <tazg2...@gmail.com>:

> Still unsolved... I need to be able to completely remove the URLs. I
> can remove the range of text that contains a URL, but if I insert text
> there it is treated as a URL again.

> Even if I clear the entire control, the next text that is inserted is
> treated as whichever URL the insertion point was last inside of.

What are the tasks you need to do in this program?
If I understand correctly, you first programmatically write some
richtext containing links, which should be active and respond to
clicks.
Then the editor content should be modified - programmatically or manually?
Do the changes concern exactly the link text or other text parts too?
In the wxpython demo for rtc it seems, that the link text can be
normally edited, deleted or copied manually.
When dealing with the text changes programmatically, i would guess, it
should be at least possible, to generate the new content after
clearing the editor.
Admittedly, I haven't used this widget very extensively, probably
others might have more relevant suggestions.
hth,
vbr