📄 stcstyleeditor.py
字号:
#-----------------------------------------------------------------------------
# Name: STCStyleEditor.py
# Purpose: Style editor for the wxStyledTextCtrl
#
# Author: Riaan Booysen
#
# Created: 2001/08/20
# RCS-ID: $Id: STCStyleEditor.py,v 1.7 2006/06/03 19:51:39 RD Exp $
# Copyright: (c) 2001 - 2005 Riaan Booysen
# Licence: wxWidgets license
#-----------------------------------------------------------------------------
#Boa:Dialog:STCStyleEditDlg
""" Style editor for the wxStyledTextCtrl.
Reads in property style definitions from a config file.
Modified styled can be saved (and optionally applied to a given list of STCs)
It can also maintain a Common definition dictionary of font names, colours and
sizes which can be shared across multiple language style definitions.
This is also used to store platform specific settings as fonts and sizes
vary with platform.
The following items are defined in the stc-styles.rc.cfg file.
common.defs.msw - Common definition dictionary used on wxMSW
common.defs.gtk - Common definition dictionary used on wxGTK
common.defs.mac - Common definition dictionary used on wxMAC
common.styleidnames - STC styles shared by all languages
Each supported language defines the following groups:
[<language>]
displaysrc - Example source to display in the editor
braces - Dictionary defining the (line, column) for showing 'good' and 'bad'
brace matching (both keys optional)
keywords - Space separated list of keywords
lexer - wxSTC constant for the language lexer
styleidnames - Dictionary of language specific style numbers and names
[style.<language>] - The users current style values
[style.<language>.default] - Default style values (can be reverted from)
0 or more predefined style groups or 'themes'
[style.<language>.<predefined name>]
Currently the following languages are supported:
python, html, xml, cpp, text, props
Other languages can be added by just defining the above settings for them in
the config file (if wxSTC implements them).
Use the initSTC function to initialise your wxSTC from a config file.
"""
import os, sys, string, pprint, copy
import wx
from wx.lib.anchors import LayoutAnchors
import wx.stc
import wxPython.stc # needed names from 2.4 for config files
settingsIdNames = {-1: 'Selection', -2: 'Caret', -3: 'Edge'}
commonPropDefs = {'fore': '#888888', 'size': 8,
'face': ''}
styleCategoryDescriptions = {
'----Language----': 'Styles specific to the language',
'----Standard----': 'Styles shared by all languages',
'----Settings----': 'Properties set by STC methods',
'----Common----': 'User definable values that can be shared between languages'}
platformSettings = {'__WXMSW__': ('msw', 8),
'__WXGTK__': ('gtk', 10),
'__WXMAC__': ('mac', 11)}
[wxID_STCSTYLEEDITDLG, wxID_STCSTYLEEDITDLGADDCOMMONITEMBTN,
wxID_STCSTYLEEDITDLGBGCOLBTN, wxID_STCSTYLEEDITDLGBGCOLCB,
wxID_STCSTYLEEDITDLGBGCOLDEFCB, wxID_STCSTYLEEDITDLGBGCOLOKBTN,
wxID_STCSTYLEEDITDLGCANCELBTN, wxID_STCSTYLEEDITDLGCONTEXTHELPBUTTON1,
wxID_STCSTYLEEDITDLGELEMENTLB, wxID_STCSTYLEEDITDLGFACECB,
wxID_STCSTYLEEDITDLGFACEDEFCB, wxID_STCSTYLEEDITDLGFACEOKBTN,
wxID_STCSTYLEEDITDLGFGCOLBTN, wxID_STCSTYLEEDITDLGFGCOLCB,
wxID_STCSTYLEEDITDLGFGCOLDEFCB, wxID_STCSTYLEEDITDLGFGCOLOKBTN,
wxID_STCSTYLEEDITDLGFIXEDWIDTHCHK, wxID_STCSTYLEEDITDLGOKBTN,
wxID_STCSTYLEEDITDLGPANEL1, wxID_STCSTYLEEDITDLGPANEL2,
wxID_STCSTYLEEDITDLGPANEL3, wxID_STCSTYLEEDITDLGPANEL4,
wxID_STCSTYLEEDITDLGREMOVECOMMONITEMBTN, wxID_STCSTYLEEDITDLGSIZECB,
wxID_STCSTYLEEDITDLGSIZEOKBTN, wxID_STCSTYLEEDITDLGSPEEDSETTINGCH,
wxID_STCSTYLEEDITDLGSTATICBOX1, wxID_STCSTYLEEDITDLGSTATICBOX2,
wxID_STCSTYLEEDITDLGSTATICLINE1, wxID_STCSTYLEEDITDLGSTATICTEXT2,
wxID_STCSTYLEEDITDLGSTATICTEXT3, wxID_STCSTYLEEDITDLGSTATICTEXT4,
wxID_STCSTYLEEDITDLGSTATICTEXT6, wxID_STCSTYLEEDITDLGSTATICTEXT7,
wxID_STCSTYLEEDITDLGSTATICTEXT8, wxID_STCSTYLEEDITDLGSTATICTEXT9,
wxID_STCSTYLEEDITDLGSTC, wxID_STCSTYLEEDITDLGSTYLEDEFST,
wxID_STCSTYLEEDITDLGTABOLDCB, wxID_STCSTYLEEDITDLGTABOLDDEFCB,
wxID_STCSTYLEEDITDLGTAEOLFILLEDCB, wxID_STCSTYLEEDITDLGTAEOLFILLEDDEFCB,
wxID_STCSTYLEEDITDLGTAITALICCB, wxID_STCSTYLEEDITDLGTAITALICDEFCB,
wxID_STCSTYLEEDITDLGTASIZEDEFCB, wxID_STCSTYLEEDITDLGTAUNDERLINEDCB,
wxID_STCSTYLEEDITDLGTAUNDERLINEDDEFCB,
] = [wx.NewId() for _init_ctrls in range(47)]
class STCStyleEditDlg(wx.Dialog):
""" Style editor for the wxStyledTextCtrl """
_custom_classes = {'wx.Window': ['wx.stc.StyledTextCtrl'],}
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Dialog.__init__(self, id=wxID_STCSTYLEEDITDLG,
name='STCStyleEditDlg', parent=prnt, pos=wx.Point(567, 292),
size=wx.Size(493, 482),
style=wx.WANTS_CHARS | wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
title=self.stc_title)
self.SetClientSize(wx.Size(485, 455))
self.SetAutoLayout(True)
self.SetSizeHints(425, 400, -1, -1)
self.Center(wx.BOTH)
self.Bind(wx.EVT_SIZE, self.OnStcstyleeditdlgSize)
self.speedsettingCh = wx.Choice(choices=[],
id=wxID_STCSTYLEEDITDLGSPEEDSETTINGCH, name='speedsettingCh',
parent=self, pos=wx.Point(96, 28), size=wx.Size(380, 21),
style=0)
self.speedsettingCh.SetConstraints(LayoutAnchors(self.speedsettingCh,
True, True, True, False))
self.speedsettingCh.SetHelpText('The speed setting allows you to revert to one of the predefined style sets. This will overwrite your current settings when tha dialog is posted.')
self.speedsettingCh.Bind(wx.EVT_CHOICE, self.OnSpeedsettingchChoice,
id=wxID_STCSTYLEEDITDLGSPEEDSETTINGCH)
self.elementLb = wx.ListBox(choices=[],
id=wxID_STCSTYLEEDITDLGELEMENTLB, name='elementLb', parent=self,
pos=wx.Point(8, 70), size=wx.Size(175, 128), style=0)
self.elementLb.SetConstraints(LayoutAnchors(self.elementLb, True, True,
True, False))
self.elementLb.SetHelpText('Select a style here to edit it. Common definitions can be added and maintained here. A common definition is a property that can be shared between styles and special cased per platform.')
self.elementLb.Bind(wx.EVT_LISTBOX, self.OnElementlbListbox,
id=wxID_STCSTYLEEDITDLGELEMENTLB)
self.addCommonItemBtn = wx.Button(id=wxID_STCSTYLEEDITDLGADDCOMMONITEMBTN,
label='Add', name='addCommonItemBtn', parent=self, pos=wx.Point(8,
200), size=wx.Size(88, 17), style=0)
self.addCommonItemBtn.SetToolTipString('Add new Common definition')
self.addCommonItemBtn.Bind(wx.EVT_BUTTON, self.OnAddsharebtnButton,
id=wxID_STCSTYLEEDITDLGADDCOMMONITEMBTN)
self.removeCommonItemBtn = wx.Button(id=wxID_STCSTYLEEDITDLGREMOVECOMMONITEMBTN,
label='Remove', name='removeCommonItemBtn', parent=self,
pos=wx.Point(96, 200), size=wx.Size(88, 17), style=0)
self.removeCommonItemBtn.SetToolTipString('Remove the selected Common definition')
self.removeCommonItemBtn.Bind(wx.EVT_BUTTON,
self.OnRemovesharebtnButton,
id=wxID_STCSTYLEEDITDLGREMOVECOMMONITEMBTN)
self.styleDefST = wx.StaticText(id=wxID_STCSTYLEEDITDLGSTYLEDEFST,
label='(nothing selected)', name='styleDefST', parent=self,
pos=wx.Point(96, 8), size=wx.Size(376, 16),
style=wx.ST_NO_AUTORESIZE)
self.styleDefST.SetFont(wx.Font(self.style_font_size, wx.SWISS,
wx.NORMAL, wx.BOLD, False, ''))
self.styleDefST.SetConstraints(LayoutAnchors(self.styleDefST, True,
True, True, False))
self.staticLine1 = wx.StaticLine(id=wxID_STCSTYLEEDITDLGSTATICLINE1,
name='staticLine1', parent=self, pos=wx.Point(48, 64),
size=wx.Size(135, 0), style=wx.LI_HORIZONTAL)
self.staticLine1.SetConstraints(LayoutAnchors(self.staticLine1, True,
True, True, False))
self.staticText6 = wx.StaticText(id=wxID_STCSTYLEEDITDLGSTATICTEXT6,
label='Style', name='staticText6', parent=self, pos=wx.Point(8,
56), size=wx.Size(40, 13), style=0)
self.staticText8 = wx.StaticText(id=wxID_STCSTYLEEDITDLGSTATICTEXT8,
label='Style def:', name='staticText8', parent=self,
pos=wx.Point(8, 8), size=wx.Size(88, 13), style=0)
self.staticText9 = wx.StaticText(id=wxID_STCSTYLEEDITDLGSTATICTEXT9,
label='SpeedSetting:', name='staticText9', parent=self,
pos=wx.Point(8, 32), size=wx.Size(88, 13), style=0)
self.panel3 = wx.Panel(id=wxID_STCSTYLEEDITDLGPANEL3, name='panel3',
parent=self, pos=wx.Point(199, 56), size=wx.Size(160, 120),
style=wx.TAB_TRAVERSAL)
self.panel3.SetConstraints(LayoutAnchors(self.panel3, False, True, True,
False))
self.panel4 = wx.Panel(id=wxID_STCSTYLEEDITDLGPANEL4, name='panel4',
parent=self, pos=wx.Point(364, 56), size=wx.Size(114, 120),
style=wx.TAB_TRAVERSAL)
self.panel4.SetConstraints(LayoutAnchors(self.panel4, False, True, True,
False))
self.panel1 = wx.Panel(id=wxID_STCSTYLEEDITDLGPANEL1, name='panel1',
parent=self, pos=wx.Point(202, 177), size=wx.Size(149, 40),
style=wx.TAB_TRAVERSAL)
self.panel1.SetConstraints(LayoutAnchors(self.panel1, False, True, True,
False))
self.panel2 = wx.Panel(id=wxID_STCSTYLEEDITDLGPANEL2, name='panel2',
parent=self, pos=wx.Point(364, 178), size=wx.Size(112, 40),
style=wx.TAB_TRAVERSAL)
self.panel2.SetConstraints(LayoutAnchors(self.panel2, False, True, True,
False))
self.stc = wx.stc.StyledTextCtrl(id=wxID_STCSTYLEEDITDLGSTC, name='stc',
parent=self, pos=wx.Point(8, 224), size=wx.Size(469, 191),
style=wx.SUNKEN_BORDER)
self.stc.SetConstraints(LayoutAnchors(self.stc, True, True, True, True))
self.stc.SetHelpText('The style preview window. Click or move the cursor over a specific style to select the style for editing in the editors above.')
self.stc.Bind(wx.EVT_LEFT_UP, self.OnUpdateUI)
self.stc.Bind(wx.EVT_KEY_UP, self.OnUpdateUI)
self.contextHelpButton1 = wx.ContextHelpButton(parent=self,
pos=wx.Point(8, 423), size=wx.Size(24, 24), style=wx.BU_AUTODRAW)
self.contextHelpButton1.SetConstraints(LayoutAnchors(self.contextHelpButton1,
True, False, False, True))
self.okBtn = wx.Button(id=wxID_STCSTYLEEDITDLGOKBTN, label='OK',
name='okBtn', parent=self, pos=wx.Point(316, 423),
size=wx.Size(75, 23), style=0)
self.okBtn.SetConstraints(LayoutAnchors(self.okBtn, False, False, True,
True))
self.okBtn.SetToolTipString('Save changes to the config file')
self.okBtn.Bind(wx.EVT_BUTTON, self.OnOkbtnButton,
id=wxID_STCSTYLEEDITDLGOKBTN)
self.cancelBtn = wx.Button(id=wxID_STCSTYLEEDITDLGCANCELBTN,
label='Cancel', name='cancelBtn', parent=self, pos=wx.Point(400,
423), size=wx.Size(75, 23), style=0)
self.cancelBtn.SetConstraints(LayoutAnchors(self.cancelBtn, False,
False, True, True))
self.cancelBtn.SetToolTipString('Close dialog without saving changes')
self.cancelBtn.Bind(wx.EVT_BUTTON, self.OnCancelbtnButton,
id=wxID_STCSTYLEEDITDLGCANCELBTN)
self.staticText4 = wx.StaticText(id=wxID_STCSTYLEEDITDLGSTATICTEXT4,
label='Face:', name='staticText4', parent=self.panel1,
pos=wx.Point(0, 0), size=wx.Size(48, 13), style=0)
self.fixedWidthChk = wx.CheckBox(id=wxID_STCSTYLEEDITDLGFIXEDWIDTHCHK,
label='', name='fixedWidthChk', parent=self.panel1,
pos=wx.Point(0, 23), size=wx.Size(16, 19), style=0)
self.fixedWidthChk.SetToolTipString('Check this for Fixed Width fonts')
self.fixedWidthChk.Bind(wx.EVT_CHECKBOX, self.OnFixedwidthchkCheckbox,
id=wxID_STCSTYLEEDITDLGFIXEDWIDTHCHK)
self.faceCb = wx.ComboBox(choices=[], id=wxID_STCSTYLEEDITDLGFACECB,
name='faceCb', parent=self.panel1, pos=wx.Point(17, 18),
size=wx.Size(101, 21), style=0, value='')
self.staticText7 = wx.StaticText(id=wxID_STCSTYLEEDITDLGSTATICTEXT7,
label='Size:', name='staticText7', parent=self.panel2,
pos=wx.Point(0, 0), size=wx.Size(40, 13), style=0)
self.sizeCb = wx.ComboBox(choices=[], id=wxID_STCSTYLEEDITDLGSIZECB,
name='sizeCb', parent=self.panel2, pos=wx.Point(0, 17),
size=wx.Size(80, 21), style=0, value='')
self.sizeOkBtn = wx.Button(id=wxID_STCSTYLEEDITDLGSIZEOKBTN, label='ok',
name='sizeOkBtn', parent=self.panel2, pos=wx.Point(80, 17),
size=wx.Size(32, 21), style=0)
self.faceOkBtn = wx.Button(id=wxID_STCSTYLEEDITDLGFACEOKBTN, label='ok',
name='faceOkBtn', parent=self.panel1, pos=wx.Point(117, 18),
size=wx.Size(32, 21), style=0)
self.fgColBtn = wx.Button(id=wxID_STCSTYLEEDITDLGFGCOLBTN,
label='Foreground', name='fgColBtn', parent=self.panel3,
pos=wx.Point(8, 16), size=wx.Size(96, 16), style=0)
self.fgColBtn.Bind(wx.EVT_BUTTON, self.OnFgcolbtnButton,
id=wxID_STCSTYLEEDITDLGFGCOLBTN)
self.fgColCb = wx.ComboBox(choices=[], id=wxID_STCSTYLEEDITDLGFGCOLCB,
name='fgColCb', parent=self.panel3, pos=wx.Point(8, 32),
size=wx.Size(96, 21), style=0, value='')
self.fgColOkBtn = wx.Button(id=wxID_STCSTYLEEDITDLGFGCOLOKBTN,
label='ok', name='fgColOkBtn', parent=self.panel3,
pos=wx.Point(104, 32), size=wx.Size(32, 21), style=0)
self.staticText3 = wx.StaticText(id=wxID_STCSTYLEEDITDLGSTATICTEXT3,
label='default', name='staticText3', parent=self.panel3,
pos=wx.Point(112, 15), size=wx.Size(38, 16), style=0)
self.fgColDefCb = wx.CheckBox(id=wxID_STCSTYLEEDITDLGFGCOLDEFCB,
label='checkBox1', name='fgColDefCb', parent=self.panel3,
pos=wx.Point(136, 31), size=wx.Size(16, 16), style=0)
self.bgColBtn = wx.Button(id=wxID_STCSTYLEEDITDLGBGCOLBTN,
label='Background', name='bgColBtn', parent=self.panel3,
pos=wx.Point(8, 64), size=wx.Size(96, 16), style=0)
self.bgColBtn.Bind(wx.EVT_BUTTON, self.OnBgcolbtnButton,
id=wxID_STCSTYLEEDITDLGBGCOLBTN)
self.bgColCb = wx.ComboBox(choices=[], id=wxID_STCSTYLEEDITDLGBGCOLCB,
name='bgColCb', parent=self.panel3, pos=wx.Point(8, 80),
size=wx.Size(96, 21), style=0, value='')
self.bgColOkBtn = wx.Button(id=wxID_STCSTYLEEDITDLGBGCOLOKBTN,
label='ok', name='bgColOkBtn', parent=self.panel3,
pos=wx.Point(104, 80), size=wx.Size(32, 21), style=0)
self.staticBox2 = wx.StaticBox(id=wxID_STCSTYLEEDITDLGSTATICBOX2,
label='Text attributes', name='staticBox2', parent=self.panel4,
pos=wx.Point(0, 0), size=wx.Size(112, 112), style=0)
self.staticBox2.SetConstraints(LayoutAnchors(self.staticBox2, False,
True, True, False))
self.staticBox2.SetHelpText('Text attribute flags.')
self.staticText2 = wx.StaticText(id=wxID_STCSTYLEEDITDLGSTATICTEXT2,
label='default', name='staticText2', parent=self.panel4,
pos=wx.Point(64, 12), size=wx.Size(40, 16), style=0)
self.taBoldDefCb = wx.CheckBox(id=wxID_STCSTYLEEDITDLGTABOLDDEFCB,
label='checkBox1', name='taBoldDefCb', parent=self.panel4,
pos=wx.Point(88, 27), size=wx.Size(16, 16), style=0)
self.taItalicDefCb = wx.CheckBox(id=wxID_STCSTYLEEDITDLGTAITALICDEFCB,
label='checkBox1', name='taItalicDefCb', parent=self.panel4,
pos=wx.Point(88, 48), size=wx.Size(16, 16), style=0)
self.taUnderlinedDefCb = wx.CheckBox(id=wxID_STCSTYLEEDITDLGTAUNDERLINEDDEFCB,
label='checkBox1', name='taUnderlinedDefCb', parent=self.panel4,
pos=wx.Point(88, 70), size=wx.Size(16, 16), style=0)
self.taEOLfilledDefCb = wx.CheckBox(id=wxID_STCSTYLEEDITDLGTAEOLFILLEDDEFCB,
label='checkBox1', name='taEOLfilledDefCb', parent=self.panel4,
pos=wx.Point(88, 92), size=wx.Size(16, 16), style=0)
self.taEOLfilledCb = wx.CheckBox(id=wxID_STCSTYLEEDITDLGTAEOLFILLEDCB,
label='EOL filled', name='taEOLfilledCb', parent=self.panel4,
pos=wx.Point(8, 92), size=wx.Size(80, 16), style=0)
self.taEOLfilledCb.Bind(wx.EVT_CHECKBOX, self.OnTaeoffilledcbCheckbox,
id=wxID_STCSTYLEEDITDLGTAEOLFILLEDCB)
self.taUnderlinedCb = wx.CheckBox(id=wxID_STCSTYLEEDITDLGTAUNDERLINEDCB,
label='Underlined', name='taUnderlinedCb', parent=self.panel4,
pos=wx.Point(8, 70), size=wx.Size(80, 16), style=0)
self.taUnderlinedCb.Bind(wx.EVT_CHECKBOX, self.OnTaunderlinedcbCheckbox,
id=wxID_STCSTYLEEDITDLGTAUNDERLINEDCB)
self.taItalicCb = wx.CheckBox(id=wxID_STCSTYLEEDITDLGTAITALICCB,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -