]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/tool/XmlEditor.py
Added the ActiveGrid IDE as a sample application
[wxWidgets.git] / wxPython / samples / ide / activegrid / tool / XmlEditor.py
1 #----------------------------------------------------------------------------
2 # Name: XmlEditor.py
3 # Purpose: Abstract Code Editor for pydocview tbat uses the Styled Text Control
4 #
5 # Author: Peter Yared
6 #
7 # Created: 8/15/04
8 # CVS-ID: $Id$
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
12
13
14 import wx
15 import string
16 import STCTextEditor
17 import CodeEditor
18
19
20 class XmlDocument(CodeEditor.CodeDocument):
21
22 pass
23
24
25 class XmlView(CodeEditor.CodeView):
26
27
28 def GetCtrlClass(self):
29 """ Used in split window to instantiate new instances """
30 return XmlCtrl
31
32
33 def GetAutoCompleteHint(self):
34 pos = self.GetCtrl().GetCurrentPos()
35 if pos == 0:
36 return None, None
37
38 validLetters = string.letters + string.digits + '_:'
39 word = ''
40 while (True):
41 pos = pos - 1
42 if pos < 0:
43 break
44 char = chr(self.GetCtrl().GetCharAt(pos))
45 if char not in validLetters:
46 break
47 word = char + word
48
49 return None, word
50
51
52 def GetAutoCompleteDefaultKeywords(self):
53 return XMLKEYWORDS
54
55
56 class XmlService(CodeEditor.CodeService):
57
58
59 def __init__(self):
60 CodeEditor.CodeService.__init__(self)
61
62
63 class XmlCtrl(CodeEditor.CodeCtrl):
64
65
66 def __init__(self, parent, ID = -1, style = wx.NO_FULL_REPAINT_ON_RESIZE):
67 CodeEditor.CodeCtrl.__init__(self, parent, ID, style)
68 self.SetLexer(wx.stc.STC_LEX_XML)
69 self.SetProperty("fold.html", "1")
70
71
72 def GetMatchingBraces(self):
73 return "<>[]{}()"
74
75
76 def CanWordWrap(self):
77 return True
78
79
80 def SetViewDefaults(self):
81 CodeEditor.CodeCtrl.SetViewDefaults(self, configPrefix = "Xml", hasWordWrap = True, hasTabs = True)
82
83
84 def GetFontAndColorFromConfig(self):
85 return CodeEditor.CodeCtrl.GetFontAndColorFromConfig(self, configPrefix = "Xml")
86
87
88 def UpdateStyles(self):
89 CodeEditor.CodeCtrl.UpdateStyles(self)
90
91 if not self.GetFont():
92 return
93
94 faces = { 'font' : self.GetFont().GetFaceName(),
95 'size' : self.GetFont().GetPointSize(),
96 'size2': self.GetFont().GetPointSize() - 2,
97 'color' : "%02x%02x%02x" % (self.GetFontColor().Red(), self.GetFontColor().Green(), self.GetFontColor().Blue())
98 }
99
100 # White space
101 self.StyleSetSpec(wx.stc.STC_H_DEFAULT, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces)
102 # Comment
103 self.StyleSetSpec(wx.stc.STC_H_COMMENT, "face:%(font)s,fore:#007F00,italic,face:%(font)s,size:%(size)d" % faces)
104 # Number
105 self.StyleSetSpec(wx.stc.STC_H_NUMBER, "face:%(font)s,fore:#007F7F,size:%(size)d" % faces)
106 # String
107 self.StyleSetSpec(wx.stc.STC_H_SINGLESTRING, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces)
108 self.StyleSetSpec(wx.stc.STC_H_DOUBLESTRING, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces)
109 # Tag
110 self.StyleSetSpec(wx.stc.STC_H_TAG, "face:%(font)s,fore:#00007F,bold,size:%(size)d" % faces)
111 # Attributes
112 self.StyleSetSpec(wx.stc.STC_H_ATTRIBUTE, "face:%(font)s,fore:#00007F,bold,size:%(size)d" % faces)
113
114
115 class XmlOptionsPanel(STCTextEditor.TextOptionsPanel):
116
117 def __init__(self, parent, id):
118 STCTextEditor.TextOptionsPanel.__init__(self, parent, id, configPrefix = "Xml", label = "XML", hasWordWrap = True, hasTabs = True)
119
120
121 XMLKEYWORDS = [
122 "ag:connectionstring", "ag:datasource", "ag:editorBounds", "ag:label", "ag:name", "ag:shortLabel", "ag:type",
123 "element", "fractionDigits", "length", "minOccurs", "name", "objtype", "refer", "schema", "type", "xpath", "xmlns",
124 "xs:complexType", "xs:element", "xs:enumeration", "xs:field", "xs:key", "xs:keyref", "xs:schema", "xs:selector"
125 ]
126
127
128 #----------------------------------------------------------------------------
129 # Icon Bitmaps - generated by encode_bitmaps.py
130 #----------------------------------------------------------------------------
131 from wx import ImageFromStream, BitmapFromImage
132 from wx import EmptyIcon
133 import cStringIO
134
135
136 def getXMLData():
137 return \
138 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
139 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
140 \x00\x01\x18IDAT8\x8d\xed\x92=N\xc3P\x0c\xc7\x7f~\xc9K\xd2\xa0\x16\xa9\xdc\
141 \x84+\xf4\x06\x1c\xa1\x12\x133\xa7`\xea\x05\xba\xc0\xc0\xd0\x93\x80*uc``e\t\
142 \x82\xb6J\xf3Q?3D\x04\x81`\xea\xc2\x80\x17K\xb6\xfc\xff\xb0-ff\x1c\x10\xee\
143 \x90\xe1\xbf\x01\x10s}\x0em\tu\t\xfb\x06\xcbFP\xad\x11\x17\x81\x196\x18!\xdb\
144 \x02\xd2#hk\xc8\x8f\t\xc1p\x89g\xb9\\\x11\xdb\xfd-\xbcn\x91\xa8C\x94,\x81\
145 \xaa\xe9\x19\xe4\x1b\xa3}R\xf3\xf0\x08\x0e\x9f\x81\xef\x9c\x94s\x83\xaa\xe92\
146 P\xcf\nv\xa7g\xd4\xb3\xa2\xef\xaf\xc5#i\x04\x89#\x8a\x05\'m\r)\x84\r\xe4S\
147 \xa1\x9c\x1b\xf9\xb4\xe3\xd5\xe1\x18?\xb9@\x87\xe3^\x81\xbe\xb5H\xab`\x013\
148 \xc3\xa9\xf3h\x15pC\xfa\xe1\x0f\x05\x00\xf1\xd5\xe4\x8b\x85la\x10@[0q\x88]\
149 \x9e\x18/\x05\xe8/k\xde\x01\x83\x1f\xea\x19,\x9e\x1c\xf1\xcdj\xc3\xae\x01jP\
150 \x05\x9fv\x07q1\x88\x83(\x8f\xd0\x8d"1h\x05\xba\x077\x80$\x87\xbb\xe7\x80\
151 \xfc\xbf\xf2\xe1\x00\xef\x8c\xb8x\x06\x07\xd1$\xff\x00\x00\x00\x00IEND\xaeB`\
152 \x82'
153
154
155 def getXMLBitmap():
156 return BitmapFromImage(getXMLImage())
157
158 def getXMLImage():
159 stream = cStringIO.StringIO(getXMLData())
160 return ImageFromStream(stream)
161
162 def getXMLIcon():
163 icon = EmptyIcon()
164 icon.CopyFromBitmap(getXMLBitmap())
165 return icon