wxPython和STC Margins - 顶部和底部

时间:2013-01-16 13:20:07

标签: python wxpython wxwidgets scintilla

enter image description here

有没有办法在程序的顶部和底部为3和4实现填充?

或者是否有像添加\ n等的解决方法....

我觉得行号和样式文本太靠近顶部和底部了。

2 个答案:

答案 0 :(得分:1)

如何使用嵌套在sizer中的相同颜色的面板作为一种肮脏的解决方法?

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

对于您的代码,请按如下所示进行修改:

  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)

答案 1 :(得分:0)

不,我不认为Scintilla有一个控制顶部和底部边距大小的属性。

相关问题