]>
Commit | Line | Data |
---|---|---|
1f780e48 RD |
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 | ||
26ee3a06 RD |
66 | def __init__(self, parent, id=-1, style=wx.NO_FULL_REPAINT_ON_RESIZE): |
67 | CodeEditor.CodeCtrl.__init__(self, parent, id, style) | |
1f780e48 RD |
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): | |
aca310e5 | 81 | CodeEditor.CodeCtrl.SetViewDefaults(self, configPrefix = "Xml", hasWordWrap = True, hasTabs = True, hasFolding=True) |
1f780e48 RD |
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 | |
02b800ce | 112 | self.StyleSetSpec(wx.stc.STC_H_ATTRIBUTE, "face:%(font)s,fore:#007F7F,bold,size:%(size)d" % faces) |
1f780e48 RD |
113 | |
114 | ||
115 | class XmlOptionsPanel(STCTextEditor.TextOptionsPanel): | |
116 | ||
117 | def __init__(self, parent, id): | |
aca310e5 | 118 | STCTextEditor.TextOptionsPanel.__init__(self, parent, id, configPrefix = "Xml", label = "XML", hasWordWrap = True, hasTabs = True, hasFolding=True) |
1f780e48 RD |
119 | |
120 | ||
02b800ce RD |
121 | def GetIcon(self): |
122 | return getXMLIcon() | |
123 | ||
124 | ||
1f780e48 RD |
125 | XMLKEYWORDS = [ |
126 | "ag:connectionstring", "ag:datasource", "ag:editorBounds", "ag:label", "ag:name", "ag:shortLabel", "ag:type", | |
127 | "element", "fractionDigits", "length", "minOccurs", "name", "objtype", "refer", "schema", "type", "xpath", "xmlns", | |
128 | "xs:complexType", "xs:element", "xs:enumeration", "xs:field", "xs:key", "xs:keyref", "xs:schema", "xs:selector" | |
129 | ] | |
130 | ||
1f780e48 RD |
131 | #---------------------------------------------------------------------------- |
132 | # Icon Bitmaps - generated by encode_bitmaps.py | |
133 | #---------------------------------------------------------------------------- | |
134 | from wx import ImageFromStream, BitmapFromImage | |
1f780e48 RD |
135 | import cStringIO |
136 | ||
137 | ||
138 | def getXMLData(): | |
139 | return \ | |
140 | '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ | |
141 | \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ | |
02b800ce RD |
142 | \x00\x01\x08IDAT8\x8dc\xdc{\xf6\xde\x7f\x064p\xfb\xd1K\x06\x06\x06\x06\x86\ |
143 | \xd7o\xbf2\xd4\xa5\xb93\xa2\xcb\xa3\x80\xbdg\xef\xfd\xbf\xff\xed?\x1c_\xf9\ | |
144 | \x04\xc13\xd6\x1f\xff\xbf\xeb\xf9\xff\xff\xcds\xf6\xfcgdbf\xc0\x85\x99\xb0\ | |
145 | \x19\xfa\xe5\x17\x82m\xee\xed\xcc\x90Z\xb7\x08\xc3\x950\xc0\x82\xcc\xf9\xfa\ | |
146 | \x07\xc1~\xfd\xf6+\xc3\xeb\xad{\x19\x1e?y\x89\xd7\x07,\xe8\x1aa\xb6\x9b{;300\ | |
147 | 00(\xfdb`88\x7f\x19N\x03\x98`\x01\x86\xac\xf9\xd3o\xa8+\xa0\xfc\x07\x0f\x1e\ | |
148 | \xe3w\x01\xb2\x9f\xd15\xbf\xfa\x8e\xd7\x07\x0cL\xaf\xdf~%[3\xdc\x050\x8d\xa4\ | |
149 | jf````LkX\xfa\x7f\x8a\xcdi\xe2T\xe3r\x01\x03\x03\x03\xc3\xa7#\x13H\xd6|\xea1\ | |
150 | \x03jB\x12\xae\xffO\x14\x8d\x0cP\x0cx\xdb\xc8\xc8 \\\xff\x9f\xe1m#"\xf9c\xd3\ | |
151 | \x84b\xc0\xec\xa68\xb8j\x98fdM\xc8\x86\xc1\xd4 \xcb32213\xfc\xdc\x95\xfb\x9f\ | |
152 | \xdc0`A\xe6\x90\x03\x00\x11\x95\x8b;4e.A\x00\x00\x00\x00IEND\xaeB`\x82' | |
1f780e48 RD |
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(): | |
bbf7159c | 163 | return wx.IconFromBitmap(getXMLBitmap()) |