No Highlight of text selection

Morton Publications morton1611 at preservedwords.com
Mon Jan 1 08:40:31 PST 2007


Using "tipWindow," "fancyStaticText," and Robin's helpful "Wordwrap" module=
, I have made a tooltip like popup that can display html formatted text (bo=
ld, italic, color, etc). I use it to show Bible verses in the popup with a =
"motion" mouse event when the mouse is over a Bible reference in an htmlWin=
dow. It works well except for two problems,

1. The highlightimg from the selected word from Html "SelectWord" follows t=
he mouse all over the window. This is annoying. I need to hide this highlig=
hting. I have tried various Freeze and Thaw combinations to no avail. What =
is the solution? =


2. When the cursor moves to empty space from a word, the word remains highl=
ighted and the popup (if a reference) remains displayed. Even if the cursor=
 is on the other side of the window (as long as it doesn't cross over anoth=
er word, then that word is highlighted). I've tried to find a way to make a=
 wx.Rect from the highlight to set bounds, but havent succeeded. Any sugges=
tions?

Below is the popup calling code and popup class.

def OnReadPopup(self, event):
  pos =3D event.GetPosition()
  focus =3D self.FindFocus()
  npos =3D self.leftHtml.CalcUnscrolledPosition(pos)
  spos =3D focus.GetScreenPosition()
  self.leftHtml.SelectWord(npos)
  ref =3D self.leftHtml.SelectionToText()
  if ref =3D=3D self.popRef:
    pass
  else:
   #self.leftHtml.Freeze()
   self.popRef =3D ref
   try: self.toolwin.Destroy()
   except: pass
   if '_' in ref:
    ref, verse =3D search.popText(ref, 3)          =

    verse =3D '^%s},  $Authorized Version, 1769 Edition}\n\n%s' % (self.pop=
Ref, verse)
    #wx.TipWindow(self.leftHtml, verse, 300) =

   =

    self.toolwin =3D Popup(self, verse)
    self.toolwin.Position(spos, (pos[0]-30, pos[1]+25))
    self.toolwin.Show()
  =

  #self.leftHtml.Thaw()
  event.Skip()
  self.leftHtml.Refresh()


class Popup(wx.PopupWindow):
 def __init__(self, parent, verse):
  wx.PopupWindow.__init__(self, parent)
  self.SetBackgroundColour("#FFFFCC")  =

  verse =3D re.sub(r'<i>', r'{', verse[:-1])
  verse =3D re.sub(r'</i>', r'}', verse)
  verse =3D wordwrap(verse, 400, wx.ClientDC(self))
  verse =3D re.sub(r'{', r'<font style=3D"italic">', verse)
  verse =3D re.sub(r'}', r'</font>', verse)
  verse =3D re.sub(r'\^', r'<font weight=3D"bold">', verse)
  verse =3D re.sub(r'\$', r'<font color=3D"navy">', verse)
  st =3D fancytext.StaticFancyText(self, -1, verse, pos=3D(10,5))

  sz =3D st.GetBestSize()
  self.SetSize( (sz.width+15, sz.height+15) )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200701=
01/bb635b02/attachment.htm


More information about the wxpython-users mailing list