problem with RichTextCtrl.SetSelectionRange

From: Ben Kaplan <bskaplan14@yahoo.com>
To: wxPython Users <wxPython-users@lists.wxwidgets.org>
Sent: Friday, December 12, 2008 11:57:56 PM
Subject: problem with RichTextCtrl.SetSelectionRange

In the docs, RichTextCtrl.SetSelectionRange says a range of (-1,-1) should
result in no selection. When I tried it, I got a PyAssertionError. Am I doing
something wrong or is this a bug in wx? This is on Mac OS 10.5, Python 2.6.1,
wxPython 2.8.9.1.

I was looking through the wx source and I think this is actually a bug in the new wxPython docs. The wxWidgets docs don't say this and the assertion has been in the code since the method was added. The -1,-1 meaning "no selection" should be in the documentation for GetSelectionRange, not SetSelectionRange.

···

----- Original Message ----

Traceback (most recent call last):
  File "rtcerror.py", line 13, in
    richtext.SetSelectionRange(rt.RichTextRange(-1,-1))
  File
"//usr/local/lib/wxPython-unicode-2.8.9.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/richtext.py",
line 3229, in SetSelectionRange
    return _richtext.RichTextCtrl_SetSelectionRange(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "range1.GetStart() > range1.GetEnd()"
failed at /BUILD/wxPython-src-2.8.9.1/src/richtext/richtextctrl.cpp(3373) in
SetSelectionRange()

Code:

import wx
import wx.richtext as rt

app = wx.PySimpleApp()
frame = wx.Frame(None, id=wx.ID_ANY, size=(300,300))
richtext = rt.RichTextCtrl(frame, id=wx.ID_ANY)
richtext.AppendText("Hello")

def destroy(evt) :
    frame.Destroy()
frame.Bind(wx.EVT_CLOSE, destroy)
frame.Show()
richtext.SetSelectionRange(rt.RichTextRange(-1,-1))
app.MainLoop()