wx.RichTextCtrl cursor

Chris Mellon wrote:

···

On 9/4/07, Steve Holden <steve@holdenweb.com> wrote:

I am told (by a client: my Linux system is still in storage) that on
some platforms the cursor refuses to disappear from the RichtextCtrl
even when it loses focus.

This was very disappointing as I had written a chunk of code to
demonstrate that (on Windows, which *is* available to me) the cursor
disappears from the control when focus is taken away.

I attach the code, which on Windows makes the cursor disappear every
time the timer ticks.

Can anyone tell me a way to remove the cursor programmatically from the
control even on platforms where this program doesn't do so?

regards
  Steve
--

<code snipped>

It looks like this has to do with the implementation of wxCaret. On
MSW, there's a native GDI object for implementing carets, and thats
what used so the system handles the case when the app doesn't have
focus. On Gtk and OS X the generic implementation is used, which
doesn't check for the wxApp activity. It would be fairly easy to add
it, but I don't know enough (anything) about the platform conventions.
It's also possible that there could/should be a native implementation
of wxCaret for those platforms. This would be a good topic for wx-dev.

As a workaround, try this:

import wx
import wx.richtext

if __name__ == '__main__':
    app = wx.App()
    f = wx.Frame(None)
    rt = wx.richtext.RichTextCtrl(f)
    def WinOrParentHasFocus(win):
        fwin = wx.Window.FindFocus()
        while win:
            if win is fwin:
                return True
            else:
                win = win.GetParent()

    def OnIdle(evt):
        if app.IsActive() and WinOrParentHasFocus(rt):
            rt.GetCaret().Show()
        else:
            rt.GetCaret().Hide()
    f.Show()
    rt.Bind(wx.EVT_IDLE, OnIdle)
    app.MainLoop()

Chris:

Thanks very much for bringing these methods to my attention. I'll see if I can get something to work for the client from this.

regards
  Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------