Question

enter image description here

Is there any way of implementing padding in the top and bottom of my program for 3 and 4?

Or is there a workaround like adding \n etc....

I feel asif the line numbers and the Styled text are too close to the top and bottom.

Was it helpful?

Solution 2

No, I don't think that Scintilla has a property that controls the size of the top and bottom margins.

OTHER TIPS

How about using panels of the same color nested inside the sizer as a dirty workaround?

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.NO_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.text.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#FFFFFF")

        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.panel_top = wx.Panel(self.panel, size = (20, -1))
        self.panel_top.SetBackgroundColour(wx.WHITE)
        self.panel_bottom = wx.Panel(self.panel, size = (20, -1))
        self.panel_bottom.SetBackgroundColour(wx.WHITE)

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

        self.border = wx.BoxSizer()
        self.border.Add(self.sizer, 1, wx.ALL | wx.EXPAND, border=20)

        self.panel.SetSizerAndFit(self.border)

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

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

    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()

For your code, modify it as follows:

  self.panel_top = wx.Panel(self.panel, size = (20, -1))
  self.panel_top.SetBackgroundColour(wx.BLACK)
  self.panel_bottom = wx.Panel(self.panel, size = (20, -1))
  self.panel_bottom.SetBackgroundColour(wx.BLACK)

  #### Add the STC to a Sizer. ####
  sizer = wx.BoxSizer(wx.VERTICAL)
  sizer.Add(self.panel_top, 0, wx.EXPAND,border=20)
  sizer.Add(self.text, 1, wx.EXPAND,border=20)
  sizer.Add(self.panel_bottom, 0, wx.EXPAND,border=20)
  self.panel.SetSizer(sizer)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top