Numbered lists in wxRichTextCtrl

I saw in the wxWidgets documentation and richtext sample that the
functions wxRichTextCtrl.SetListStyle and wxRichTextCtrl.NumberList
are used to create numbered lists in a wxRichTextCtrl. However, both
these functions require a wxRichTextListStyleDefinition to be passed
to them, and I cannot find this class wrapped in wxPython. I know
how to set the correct bullet style to show numbers, but how does
one renumber lists in a wxRichTextCtrl in wxPython?

Thank you.

-- Timothy

From the demo:
self.rtc.BeginNumberedBullet(1, 100, 60)
self.rtc.Newline()
self.rtc.WriteText(“This is my first item. Note that
wxRichTextCtrl doesn’t automatically do numbering, but this will be
added later.”)
self.rtc.EndNumberedBullet()
self.rtc.BeginNumberedBullet(2, 100, 60)
self.rtc.Newline()
self.rtc.WriteText(“This is my second item.”)
self.rtc.EndNumberedBullet()

    self.rtc.BeginSymbolBullet('*', 100, 60)
    self.rtc.Newline()
    self.rtc.WriteText("Compatibility with wxTextCtrl API")
    self.rtc.EndSymbolBullet()
    self.rtc.BeginSymbolBullet('*', 100, 60)
    self.rtc.Newline()
    self.rtc.WriteText("wxRichTextStyleSheet with named

character and paragraph styles, and control for applying named
styles")
self.rtc.EndSymbolBullet()

···

On 13/05/14 00:07, Johnsons in DE
wrote:

    I saw in the wxWidgets documentation and richtext

sample that the functions wxRichTextCtrl.SetListStyle and
wxRichTextCtrl.NumberList are used to create numbered lists in a
wxRichTextCtrl. However, both these functions require a
wxRichTextListStyleDefinition to be passed to them, and I cannot
find this class wrapped in wxPython. I know how to set the
correct bullet style to show numbers, but how does one renumber
lists in a wxRichTextCtrl in wxPython?

    Thank you.



    -- Timothy

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

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)

Does anyone know if renumbering lists in a wxRichTextCtrl (which appears to be possible now in wxWidgets, as mentioned above) is possible in wxPython, and if so, how?

Thank you.

– Timothy