Hi,
I have to insert a link from dialog box, but insert doble link, my code:
def OnInsertLink(self, event):
self.urlStyle = rt.TextAttrEx()
self.urlStyle.SetTextColour(wx.BLUE)
self.urlStyle.SetFontUnderlined(True)
self.dlg = wx.TextEntryDialog(self, "Link Url")
if self.dlg.ShowModal():
self.link = self.dlg.GetValue()
self.seleccion = self.text_ctrl.GetSelection()
self.text = self.text_ctrl.GetValue()[self.seleccion[0]:self.seleccion[1]]
self.text_ctrl.BeginStyle(self.urlStyle)
self.text_ctrl.BeginURL(self.link)
self.text_ctrl.WriteText(self.text)
self.text_ctrl.EndURL()
self.text_ctrl.EndStyle()
self.text_ctrl.SetInsertionPoint(self.seleccion[1] + 1)
self.dlg.Destroy()
any suggestions?
Thanks
···
–
SIN ETIQUETAS.[ PUNTO ]
http://jyr.tumblr.com
http://blog.opentumblr.com
Mike,
I select a word in the richTextCtrl and from dialog box will inserted a hyperlink, but inserted word double double example:
www.google.comwww.google.com
···
On Thu, Jul 9, 2009 at 8:40 AM, Mike Driscoll kyosohma@gmail.com wrote:
Jair,
I’m confused. What is a “doble link”? Your code looks like it should
insert a clickable hyperlink to me. What is it doing that you don’t
like?
–
SIN ETIQUETAS.[ PUNTO ]
http://jyr.tumblr.com
http://blog.opentumblr.com
Che_M
4
What happens when you remove this line?:
self.text_ctrl.WriteText(self.text)
Che
···
On Thu, Jul 9, 2009 at 12:08 AM, Jair Gaxiola jyr.gaxiola@gmail.com wrote:
Hi,
I have to insert a link from dialog box, but insert doble link, my code:
def OnInsertLink(self, event):
self.urlStyle = rt.TextAttrEx()
self.urlStyle.SetTextColour(wx.BLUE)
self.urlStyle.SetFontUnderlined(True)
self.dlg = wx.TextEntryDialog(self, "Link Url")
if self.dlg.ShowModal():
self.link = self.dlg.GetValue()
self.seleccion = self.text_ctrl.GetSelection()
self.text = self.text_ctrl.GetValue()[self.seleccion[0]:self.seleccion[1]]
self.text_ctrl.BeginStyle(self.urlStyle)
self.text_ctrl.BeginURL(self.link)
self.text_ctrl.WriteText(self.text)
self.text_ctrl.EndURL()
self.text_ctrl.EndStyle()
self.text_ctrl.SetInsertionPoint(self.seleccion[1] + 1)
self.dlg.Destroy()
any suggestions?
Fixed, my new code:
def OnInsertLink(self, event):
self.urlStyle = rt.TextAttrEx()
self.urlStyle.SetTextColour(wx.BLUE)
self.urlStyle.SetFontUnderlined(True)
self.dlg = wx.TextEntryDialog(self, "Link Url")
if self.dlg.ShowModal():
self.link = self.dlg.GetValue()
self.seleccion = self.text_ctrl.GetSelection()
self.text = self.text_ctrl.GetValue()[self.seleccion[0]:self.seleccion[1]]
self.text_ctrl.BeginStyle(self.urlStyle)
self.text_ctrl.BeginURL(self.link)
self.text_ctrl.WriteText(self.text)
self.text_ctrl.EndURL()
self.text_ctrl.EndStyle()
self.text_ctrl.SetInsertionPoint(self.seleccion[1] + 1)
self.text_ctrl.SetSelection(self.seleccion[1],self.seleccion[1] * 2)
self.text_ctrl.DeleteSelection()
self.dlg.Destroy()
Thanks for suggestions
···
On Wed, Jul 8, 2009 at 11:08 PM, Jair Gaxiola jyr.gaxiola@gmail.com wrote:
Hi,
I have to insert a link from dialog box, but insert doble link, my code:
def OnInsertLink(self, event):
self.urlStyle = rt.TextAttrEx()
self.urlStyle.SetTextColour(wx.BLUE)
self.urlStyle.SetFontUnderlined(True)
self.dlg = wx.TextEntryDialog(self, "Link Url")
if self.dlg.ShowModal():
self.link = self.dlg.GetValue()
self.seleccion = self.text_ctrl.GetSelection()
self.text = self.text_ctrl.GetValue()[self.seleccion[0]:self.seleccion[1]]
self.text_ctrl.BeginStyle(self.urlStyle)
self.text_ctrl.BeginURL(self.link)
self.text_ctrl.WriteText(self.text)
self.text_ctrl.EndURL()
self.text_ctrl.EndStyle()
self.text_ctrl.SetInsertionPoint(self.seleccion[1] + 1)
self.dlg.Destroy()
any suggestions?
–
SIN ETIQUETAS.[ PUNTO ]
http://jyr.tumblr.com
http://blog.opentumblr.com
Of course, I used SetStyle the correct code is:
def OnInsertLink(self, event):
self.attr = rt.TextAttrEx()
self.attr.SetTextColour(wx.BLUE)
self.attr.SetFontUnderlined(True)
self.dlg = wx.TextEntryDialog(self, "Link Url")
if self.dlg.ShowModal():
self.link = self.dlg.GetValue()
self.attr.SetURL(self.link)
if self.text_ctrl.HasSelection():
r = self.text_ctrl.GetSelectionRange()
self.text_ctrl.SetInsertionPointEnd()
self.text_ctrl.SetStyleEx(r, self.attr)
self.dlg.Destroy()
Thanks, for your help
···
On Thu, Jul 9, 2009 at 9:12 PM, Robin Dunn robin@alldunn.com wrote:
Jair Gaxiola wrote:
On Thu, Jul 9, 2009 at 8:40 AM, Mike Driscoll <kyosohma@gmail.com > > mailto:kyosohma@gmail.com> wrote:
Jair,
I'm confused. What is a "doble link"? Your code looks like it should
insert a clickable hyperlink to me. What is it doing that you don't
like?
Mike,
I select a word in the richTextCtrl and from dialog box will inserted a
hyperlink, but inserted word double double example:
So in other words, the text is already present in the document, and then
you write it again with styles set. And you wonder why it is now there
twice?
You probably just want to use SetStyle(range, textAttr) and don’t worry
about the beginning, ending and writing.
–
SIN ETIQUETAS.[ PUNTO ]
http://jyr.tumblr.com
http://blog.opentumblr.com