Stani的Python编辑器 - 更改语法高亮

3 投票
1 回答
1397 浏览
提问于 2025-04-15 20:17

在看了Stani的Python IDE后,我发现这个软件有很多实用的功能。不过,它不支持自定义语法高亮颜色。

在作者网站的问答中提到:

“- 除非你手动编辑sm/wxp/stc.py,否则无法更改颜色。”

所以我尝试自己查看一下这段代码,想要找到一个功能齐全的IDE。

stc.py文件似乎是作者对Robin Dunn原始wxPython代码的修改。在处理各种事件的代码中,似乎有一部分是用来决定不同语法颜色的。

我只想把背景颜色改成黑色,把黑色的文字改成白色,如果其他所有内容都能在这两种新颜色下显示出来,那我就很满意了。

有没有人尝试过这样做?谢谢!

编辑:大约在第441行的代码

def SetStyles(self)

是这些代码吗?

编辑^2:有没有人能找到光标闪烁的颜色设置?还是说这个设置有点“更”难以修改?

编辑^3:到目前为止,我在第441行的SetStyles函数中修改了十六进制颜色值。

    def SetStyles(self):
    # anti-aliasing
    if hasattr(self,'SetUseAntiAliasing'):
        self.SetUseAntiAliasing(True)

    #INDICATOR STYLES FOR ERRORS (self.errorMark)
    self.IndicatorSetStyle(2, wx_stc.STC_INDIC_SQUIGGLE)
    self.IndicatorSetForeground(2, wx.RED)

    #import dialogs.stcStyleEditor
    if 1:#dialogs.stcStyleEditor.SetStyles(self, self.config):
        self.StyleSetSpec(wx_stc.STC_P_DEFAULT, "face:%(mono)s,fore:#B0B0B0,size:%(size)d" % self.faces)
        self.StyleClearAll()

        # Global default styles for all languages  B0B0B0= gray
        self.StyleSetSpec(wx_stc.STC_STYLE_DEFAULT,     "face:%(mono)s,fore:#B0B0B0,back:#00000,size:%(size)d" % self.faces)
        self.StyleSetSpec(wx_stc.STC_STYLE_LINENUMBER,  "back:#C0C0C0,face:%(mono)s,size:%(size)d" % self.faces)
        self.StyleSetSpec(wx_stc.STC_STYLE_CONTROLCHAR, "face:%(mono)s,fore:#B0B0B0" % self.faces)
        self.StyleSetSpec(wx_stc.STC_STYLE_BRACELIGHT,  "fore:#B0B0B0,back:#0000FF,bold")
        self.StyleSetSpec(wx_stc.STC_STYLE_BRACEBAD,    "fore:#B0B0B0,back:#FF0000,bold")

        # Python styles
        # White space
        self.StyleSetSpec(wx_stc.STC_P_DEFAULT, "face:%(mono)s,fore:#000000,back:#000000,size:%(size)d" % self.faces)
        # Comment
        self.StyleSetSpec(wx_stc.STC_P_COMMENTLINE, "face:%(mono)s,fore:#F70909,back:#000000,italic,size:%(size)d" % self.faces)
        # Number
        self.StyleSetSpec(wx_stc.STC_P_NUMBER, "face:%(mono)s,fore:#FFFFFF,size:%(size)d" % self.faces)
        # String
        self.StyleSetSpec(wx_stc.STC_P_STRING, "face:%(mono)s,fore:#34C640,size:%(size)d" % self.faces)
        # Single quoted string
        self.StyleSetSpec(wx_stc.STC_P_CHARACTER, "face:%(mono)s,fore:#43AB4E,size:%(size)d" % self.faces)
        # Keyword (Class, def, etc.)
        self.StyleSetSpec(wx_stc.STC_P_WORD, "face:%(mono)s,fore:#FF9100,bold,size:%(size)d" % self.faces)
        # Triple quotes
        self.StyleSetSpec(wx_stc.STC_P_TRIPLE, "face:%(mono)s,fore:#7F0000,size:%(size)d" % self.faces)
        # Triple double quotes
        self.StyleSetSpec(wx_stc.STC_P_TRIPLEDOUBLE, "face:%(mono)s,fore:#7F0000,size:%(size)d" % self.faces)
        # Class name definition (Name of the class)
        self.StyleSetSpec(wx_stc.STC_P_CLASSNAME, "face:%(mono)s,fore:#00AEFF,bold,size:%(size)d" % self.faces)
        # Function or method name definition (bright blue = #0011FF)
        self.StyleSetSpec(wx_stc.STC_P_DEFNAME, "face:%(mono)s,fore:#FFFF00,bold,size:%(size)d" % self.faces)
        # Operators (+ - /)
        self.StyleSetSpec(wx_stc.STC_P_OPERATOR, "face:%(mono)s,fore:#FFFFFF,bold,size:%(size)d" % self.faces)
        # Identifiers (this was all the same color - > self.SetTopWindow(self.frame))
        self.StyleSetSpec(wx_stc.STC_P_IDENTIFIER, "fore:#FFFFFF")
        # Comment-blocks
        self.StyleSetSpec(wx_stc.STC_P_COMMENTBLOCK, "face:%(mono)s,fore:#990000,back:#C0C0C0,italic,size:%(size)d" % self.faces)
        # End of line where string is not closed
        self.StyleSetSpec(wx_stc.STC_P_STRINGEOL, "face:%(mono)s,fore:#B1CCB0,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % self.faces)

这样做可以使用黑色背景,并把其他颜色改得更亮。

仍然存在的问题:

1. 类标识符(“self.”、“classname.”等)和“.”后面的文本颜色是一样的,但这就是原来的样子,感觉不容易改。

2. 鼠标光标位置的标记(闪烁的“|”)仍然是黑色,在新的背景下变得不可见。

3. 这个应用程序支持鼠标悬停在变量上时弹出变量来源的描述吗?(就像在pyscripter中那样)

1 个回答

0

我上面提到的代码基本上解决了这个问题,所以我就把这个问题关闭了。

撰写回答