Question

I am trying to achieve a space where the underscore is on line 1 and line 5 to provide abit of padding between the line numbers and the code so it doesnt look so cluttered.

how would i achieve this?

enter image description here

Was it helpful?

Solution

Use .SetMarginLeft(width). Example:

import wx
import wx.stc as stc

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.panel = wx.Panel(self)

        self.text = stc.StyledTextCtrl(self.panel)
        self.text.SetWindowStyle(self.text.GetWindowStyle() | wx.DOUBLE_BORDER)
        self.text.StyleSetSpec(stc.STC_STYLE_DEFAULT, "size:15,face:Courier New")
        self.text.SetWrapMode(stc.STC_WRAP_WORD)
        self.text.SetMarginLeft(50)

        self.menu = wx.Menu()
        self.menu.Append(wx.ID_ABOUT, "&About", "Information about this program")
        self.menu_bar = wx.MenuBar()
        self.menu_bar.Append(self.menu, "&File")
        self.SetMenuBar(self.menu_bar)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.text, 1, wx.ALL | wx.EXPAND, 5)

        self.panel.SetSizerAndFit(self.sizer)

        self.text.Bind(stc.EVT_STC_CHANGE, self.OnChange)
        self.Show()

        self.text.SetText("Line!\n"*98)

    def OnChange(self, e):
        lines = self.text.GetLineCount()
        width = self.text.TextWidth(stc.STC_STYLE_LINENUMBER, str(lines)+" ")
        self.text.SetMarginWidth(0, width)


if __name__ == "__main__":
    app = wx.App(False)
    win = MainWindow(None)
    app.MainLoop()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top