Thank you for your reply.
I had seen that code in the RichTextCtrl sample in the wxPython
demo and know how to create numbered bullets. What I cannot figure
out is how to renumber a numbered list. The code you quoted from the
demo says “Note that wxRichTextCtrl doesn’t automatically do
numbering, but this will be added later,” but it seems like this has
changed now, at least in wxWidgets.
The reason I say this is because the wxWidgets richtext sample,
which I have attached, can renumber lists. In place of the above
quote from the wxPython demo, it says, “Note that wxRichTextCtrl can
apply numbering and bullets automatically based on list styles, but
this list is formatted explicitly by setting indents.” On lines 1905
and 1906 it has:
wxRichTextRange range =
m_richTextCtrl->GetSelectionRange();
m_richTextCtrl->SetListStyle(range, wxT("Numbered List 1"),
wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_RENUMBER);
And on lines 1937 and 1938:
wxRichTextRange range =
m_richTextCtrl->GetSelectionRange();
m_richTextCtrl->NumberList(range, NULL,
wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_RENUMBER);
which is a vast improvement over my Python code that attempts to do
the same thing (and is buggy):
selection = self.editor.GetSelectionRange()
pos = selection[0]
number = 1
while pos < selection[1]:
style.SetLeftIndent(50, len(str(number)) * 20 + 30)
style.SetBulletNumber(number)
line = self.editor.PositionToXY(pos)[1]
pos = self.editor.XYToPosition(0, line)
self.editor.SetStyle((pos, pos + 1), style)
pos += self.editor.GetLineLength(line) + 1
number += 1
The RichTextCtrl.NumberList function is in wxPython, but when I try
to use it I run into the problem I mentioned in my original post.
The use of this function seems to require that a
wxRichTextListStyleDefinition be created first, which I cannot find
in wxPython.
Am I missing something here? Could someone provide an example of how
the RichTextCtrl.NumberList function is used in wxPython? Thank you.
-- Timothy
richtext.cpp (78.8 KB)