26ee3a06e2
commands, also added a default template that uses the text editor for any unknown file type. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34473 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
163 lines
5.5 KiB
Python
163 lines
5.5 KiB
Python
#----------------------------------------------------------------------------
|
|
# Name: XmlEditor.py
|
|
# Purpose: Abstract Code Editor for pydocview tbat uses the Styled Text Control
|
|
#
|
|
# Author: Peter Yared
|
|
#
|
|
# Created: 8/15/04
|
|
# CVS-ID: $Id$
|
|
# Copyright: (c) 2004-2005 ActiveGrid, Inc.
|
|
# License: wxWindows License
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
import wx
|
|
import string
|
|
import STCTextEditor
|
|
import CodeEditor
|
|
|
|
|
|
class XmlDocument(CodeEditor.CodeDocument):
|
|
|
|
pass
|
|
|
|
|
|
class XmlView(CodeEditor.CodeView):
|
|
|
|
|
|
def GetCtrlClass(self):
|
|
""" Used in split window to instantiate new instances """
|
|
return XmlCtrl
|
|
|
|
|
|
def GetAutoCompleteHint(self):
|
|
pos = self.GetCtrl().GetCurrentPos()
|
|
if pos == 0:
|
|
return None, None
|
|
|
|
validLetters = string.letters + string.digits + '_:'
|
|
word = ''
|
|
while (True):
|
|
pos = pos - 1
|
|
if pos < 0:
|
|
break
|
|
char = chr(self.GetCtrl().GetCharAt(pos))
|
|
if char not in validLetters:
|
|
break
|
|
word = char + word
|
|
|
|
return None, word
|
|
|
|
|
|
def GetAutoCompleteDefaultKeywords(self):
|
|
return XMLKEYWORDS
|
|
|
|
|
|
class XmlService(CodeEditor.CodeService):
|
|
|
|
|
|
def __init__(self):
|
|
CodeEditor.CodeService.__init__(self)
|
|
|
|
|
|
class XmlCtrl(CodeEditor.CodeCtrl):
|
|
|
|
|
|
def __init__(self, parent, id=-1, style=wx.NO_FULL_REPAINT_ON_RESIZE):
|
|
CodeEditor.CodeCtrl.__init__(self, parent, id, style)
|
|
self.SetLexer(wx.stc.STC_LEX_XML)
|
|
self.SetProperty("fold.html", "1")
|
|
|
|
|
|
def GetMatchingBraces(self):
|
|
return "<>[]{}()"
|
|
|
|
|
|
def CanWordWrap(self):
|
|
return True
|
|
|
|
|
|
def SetViewDefaults(self):
|
|
CodeEditor.CodeCtrl.SetViewDefaults(self, configPrefix = "Xml", hasWordWrap = True, hasTabs = True)
|
|
|
|
|
|
def GetFontAndColorFromConfig(self):
|
|
return CodeEditor.CodeCtrl.GetFontAndColorFromConfig(self, configPrefix = "Xml")
|
|
|
|
|
|
def UpdateStyles(self):
|
|
CodeEditor.CodeCtrl.UpdateStyles(self)
|
|
|
|
if not self.GetFont():
|
|
return
|
|
|
|
faces = { 'font' : self.GetFont().GetFaceName(),
|
|
'size' : self.GetFont().GetPointSize(),
|
|
'size2': self.GetFont().GetPointSize() - 2,
|
|
'color' : "%02x%02x%02x" % (self.GetFontColor().Red(), self.GetFontColor().Green(), self.GetFontColor().Blue())
|
|
}
|
|
|
|
# White space
|
|
self.StyleSetSpec(wx.stc.STC_H_DEFAULT, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces)
|
|
# Comment
|
|
self.StyleSetSpec(wx.stc.STC_H_COMMENT, "face:%(font)s,fore:#007F00,italic,face:%(font)s,size:%(size)d" % faces)
|
|
# Number
|
|
self.StyleSetSpec(wx.stc.STC_H_NUMBER, "face:%(font)s,fore:#007F7F,size:%(size)d" % faces)
|
|
# String
|
|
self.StyleSetSpec(wx.stc.STC_H_SINGLESTRING, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces)
|
|
self.StyleSetSpec(wx.stc.STC_H_DOUBLESTRING, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces)
|
|
# Tag
|
|
self.StyleSetSpec(wx.stc.STC_H_TAG, "face:%(font)s,fore:#00007F,bold,size:%(size)d" % faces)
|
|
# Attributes
|
|
self.StyleSetSpec(wx.stc.STC_H_ATTRIBUTE, "face:%(font)s,fore:#00007F,bold,size:%(size)d" % faces)
|
|
|
|
|
|
class XmlOptionsPanel(STCTextEditor.TextOptionsPanel):
|
|
|
|
def __init__(self, parent, id):
|
|
STCTextEditor.TextOptionsPanel.__init__(self, parent, id, configPrefix = "Xml", label = "XML", hasWordWrap = True, hasTabs = True)
|
|
|
|
|
|
XMLKEYWORDS = [
|
|
"ag:connectionstring", "ag:datasource", "ag:editorBounds", "ag:label", "ag:name", "ag:shortLabel", "ag:type",
|
|
"element", "fractionDigits", "length", "minOccurs", "name", "objtype", "refer", "schema", "type", "xpath", "xmlns",
|
|
"xs:complexType", "xs:element", "xs:enumeration", "xs:field", "xs:key", "xs:keyref", "xs:schema", "xs:selector"
|
|
]
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Icon Bitmaps - generated by encode_bitmaps.py
|
|
#----------------------------------------------------------------------------
|
|
from wx import ImageFromStream, BitmapFromImage
|
|
import cStringIO
|
|
|
|
|
|
def getXMLData():
|
|
return \
|
|
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
|
|
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
|
|
\x00\x01\x1aIDAT8\x8d\xed\x92?N\xc3P\x0c\xc6\x7fv\xf2\x924\xa8E*7\xe1\n\xbd\
|
|
\x01G\xa8\xd8\x989\x05S/\xd0\x0110\xf4$\xa0J\xdd\x18\x18XY\x82\xa0\xad\xd2\
|
|
\xfc\xe9{f\x08-\x02\xc1\xd4\x85\x01/\xb6l\xd9\xdf\xf7\xd9\x16\xd1\x88CL\x0f\
|
|
\xea\xfe\x13\x03\xc4\xae\xcf\x8d\xb6\x84\xba\x84m\x83e\x03\xa8\x96\x88F`\x86\
|
|
\xf5\x06\xc8\xba\x80\xf4\x08\xda\x1a\xf2cB04q\xcc\xe7\x0bb\xbb\xbf\x85\xd75\
|
|
\xf2\xb1K\xc9\x12\xa8\x9aO\x84o\x88\xb6\x0bbxx\x04\xc5e\xe0:%\xe5\xd4\xa0j:\
|
|
\x0f\xd4\x93\x82\xcd\xe9\x19\xf5\xa4\xd8\xd7\x97\xe2\x904\x82D\x89bA\xa5\xad\
|
|
!\x85\xb0\x82|,\x94S#\x1fw\xb8\xbe?\xc4\x8d.\xf0\xfd\xe1\x9e\x81\x7fk\x91\
|
|
\xd6\x83\x05\xcc\x0c\xf5\xea\xf0U@\xfb\xec\x9bw\x0c\x00\xe2\xab\xd1\x17\t\
|
|
\xd9\xcc \x80o\xc1D\x11\xbb<1^\n\xf0\xbf\xacy\x03\xf4~\xc8g0{R\xe2\x9b\xc5\
|
|
\x8aM\x03\xd4\xe0=\xb8\xb4;\x88\xc6 \nQ\x1e\xe1W\x1e\x89\xc1W\xe0\xb7\xa0=Hr\
|
|
\xb8{\x0e\xc8\xff+\x1f>\xe0\x1d~\xafr\x13\x04HY"\x00\x00\x00\x00IEND\xaeB`\
|
|
\x82'
|
|
|
|
|
|
def getXMLBitmap():
|
|
return BitmapFromImage(getXMLImage())
|
|
|
|
def getXMLImage():
|
|
stream = cStringIO.StringIO(getXMLData())
|
|
return ImageFromStream(stream)
|
|
|
|
def getXMLIcon():
|
|
return wx.IconFromBitmap(getXMLBitmap())
|