Trying to add line numbers

20 views
Skip to first unread message

RF

unread,
Apr 19, 2021, 2:10:03 PM4/19/21
to wxPython-users
I'm trying to add line numbers to my StyledTextCtrl().

That last line below in my code snippet seems to be the correct way to add line numbers in the 0 margin but when I run my small app, there are no line numbers in the left margin at all. Am I missing a step? Do I have to do something else?

My code snippet:

import wx
import wx.stc

class testApp(wx.Frame):
def __init__(self, *args, **kw):
# ensure the parent's __init__ is called
super(testApp, self).__init__(*args, **kw)

self.editor = wx.stc.StyledTextCtrl(self, style=wx.TE_MULTILINE)
self.editor.SetScrollWidth(wx.stc.STC_CACHE_CARET)
#self.stc.EditToggleOvertype()
self.editor.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, "size:10,face:Courier New, fore: #dddddd, back: #000000")
self.editor.SetMarginWidth(1, 20)
self.editor.SetMarginType(0, wx.stc.STC_MARGIN_NUMBER)

self.CreateStatusBar()
self.SetStatusText("Welcome to testApp")

if __name__ == '__main__':
app = wx.App()
win = testApp(None, title='testApp')
win.SetPosition(wx.Point(400, 400))
win.Show()

app.MainLoop()

Anders Munch

unread,
Apr 20, 2021, 5:44:00 AM4/20/21
to wxpytho...@googlegroups.com

RF <ralphf...@gmail.com> wrote:

> self.editor.SetMarginWidth(1, 20)
> self.editor.SetMarginType(0, wx.stc.STC_MARGIN_NUMBER)

 

You are adding line numbers to margin 0, but you are setting the width of margin 1.

Add or change to:

   self.editor.SetMarginWidth(0, 20)

and your snippet works.

 

regards,Anders

 

Reply all
Reply to author
Forward
0 new messages