1 #----------------------------------------------------------------------------
3 # Purpose: Abstract Code Editor for pydocview tbat uses the Styled Text Control
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
22 class HtmlDocument(CodeEditor
.CodeDocument
):
27 class HtmlView(CodeEditor
.CodeView
):
30 def GetCtrlClass(self
):
31 """ Used in split window to instantiate new instances """
35 def GetAutoCompleteHint(self
):
36 pos
= self
.GetCtrl().GetCurrentPos()
40 validLetters
= string
.letters
+ string
.digits
+ '_!-'
46 char
= chr(self
.GetCtrl().GetCharAt(pos
))
47 if char
not in validLetters
:
54 def GetAutoCompleteDefaultKeywords(self
):
58 ## def _CreateControl(self, parent, id):
59 ## import wx # wxBug: When inlining the import of the appropriate html control below, have to specifically import wx for some reason
60 ## self._notebook = wx.Notebook(parent, wx.NewId(), style = wx.NB_BOTTOM)
61 ## self._textEditor = HtmlCtrl(self._notebook, id)
62 ## if wx.Platform =='__WXMSW__':
63 ## import wxPython.iewin
64 ## self._browserCtrl = wxPython.iewin.wxIEHtmlWin(self._notebook, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE)
67 ## self._browserCtrl = wx.html.HtmlWindow(self._notebook, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE)
68 ## self._notebook.AddPage(self._textEditor, _("Edit"))
69 ## self._notebook.AddPage(self._browserCtrl, _("View"))
70 ## self._insertMode = True
71 ## wx.EVT_NOTEBOOK_PAGE_CHANGED(self._notebook, self._notebook.GetId(), self.OnNotebookChanging)
72 ## return self._textEditor
75 ## def _CreateSizer(self, frame):
76 ## sizer = wx.BoxSizer(wx.HORIZONTAL)
77 ## sizer.Add(self._notebook, 1, wx.EXPAND)
78 ## frame.SetSizer(sizer)
79 ## frame.SetAutoLayout(True)
82 ## def OnNotebookChanging(self, event):
83 ## if event.GetSelection() == 0: # Going to the edit page
84 ## pass # self._textEditor.Refresh()
85 ## elif event.GetSelection() == 1: # Going to the browser page
86 ## text = self._textEditor.GetText()
87 ## if wx.Platform == '__WXMSW__':
88 ## path = os.path.join(tempfile.gettempdir(), "temp.html")
89 ## file = open(path, 'w')
92 ## self._browserCtrl.Navigate("file://" + path)
94 ## self._browserCtrl.SetPage(text)
98 class HtmlService(CodeEditor
.CodeService
):
102 CodeEditor
.CodeService
.__init
__(self
)
105 class HtmlCtrl(CodeEditor
.CodeCtrl
):
108 def __init__(self
, parent
, id=-1, style
=wx
.NO_FULL_REPAINT_ON_RESIZE
):
109 CodeEditor
.CodeCtrl
.__init
__(self
, parent
, id, style
)
110 self
.SetLexer(wx
.stc
.STC_LEX_HTML
)
111 self
.SetProperty("fold.html", "1")
114 def GetMatchingBraces(self
):
118 def CanWordWrap(self
):
122 def SetViewDefaults(self
):
123 CodeEditor
.CodeCtrl
.SetViewDefaults(self
, configPrefix
= "Html", hasWordWrap
= False, hasTabs
= True)
126 def GetFontAndColorFromConfig(self
):
127 return CodeEditor
.CodeCtrl
.GetFontAndColorFromConfig(self
, configPrefix
= "Html")
130 def UpdateStyles(self
):
131 CodeEditor
.CodeCtrl
.UpdateStyles(self
)
133 if not self
.GetFont():
136 faces
= { 'font' : self
.GetFont().GetFaceName(),
137 'size' : self
.GetFont().GetPointSize(),
138 'size2': self
.GetFont().GetPointSize() - 2,
139 'color' : "%02x%02x%02x" % (self
.GetFontColor().Red(), self
.GetFontColor().Green(), self
.GetFontColor().Blue())
143 self
.StyleSetSpec(wx
.stc
.STC_H_DEFAULT
, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces
)
145 self
.StyleSetSpec(wx
.stc
.STC_H_COMMENT
, "face:%(font)s,fore:#007F00,italic,face:%(font)s,size:%(size)d" % faces
)
147 self
.StyleSetSpec(wx
.stc
.STC_H_NUMBER
, "face:%(font)s,fore:#007F7F,size:%(size)d" % faces
)
149 self
.StyleSetSpec(wx
.stc
.STC_H_SINGLESTRING
, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces
)
150 self
.StyleSetSpec(wx
.stc
.STC_H_DOUBLESTRING
, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces
)
152 self
.StyleSetSpec(wx
.stc
.STC_H_TAG
, "face:%(font)s,fore:#00007F,bold,size:%(size)d" % faces
)
154 self
.StyleSetSpec(wx
.stc
.STC_H_ATTRIBUTE
, "face:%(font)s,fore:#00007F,bold,size:%(size)d" % faces
)
157 class HtmlOptionsPanel(STCTextEditor
.TextOptionsPanel
):
159 def __init__(self
, parent
, id):
160 STCTextEditor
.TextOptionsPanel
.__init
__(self
, parent
, id, configPrefix
= "Html", label
= "HTML", hasWordWrap
= True, hasTabs
= True)
164 "A", "ABBR", "ACRONYM", "ADDRESS", "APPLET", "AREA", "B", "BASE", "BASEFONT", "BDO", "BIG", "BLOCKQUOTE",
165 "BODY", "BR", "BUTTON", "CAPTION", "CENTER", "CITE", "CODE", "COL", "COLGROUP", "DD", "DEL", "DFN", "DIR",
166 "DIV", "DL", "DT", "EM", "FIELDSET", "FONT", "FORM", "FRAME", "FRAMESET", "H1", "H2", "H3", "H4", "H5", "H6",
167 "HEAD", "HR", "HTML", "I", "IFRAME", "IMG", "INPUT", "INS", "ISINDEX", "KBD", "LABEL", "LEGEND", "LI", "LINK",
168 "MAP", "MENU", "META", "NOFRAMES", "NOSCRIPT", "OBJECT", "OL", "OPTGROUP", "OPTION", "P", "PARAM",
169 "PRE", "Q", "S", "SAMP", "SCRIPT", "SELECT", "SMALL", "SPAN", "STRIKE", "STRONG", "STYLE", "SUB", "SUP",
170 "TABLE", "TBODY", "TD", "TEXTAREA", "TFOOT", "TH", "THEAD", "TITLE", "TR", "TT", "U", "UL", "VAR", "XML",
171 "XMLNS", "ACCEPT-CHARSET", "ACCEPT", "ACCESSKEY", "ACTION", "ALIGN", "ALINK", "ALT",
172 "ARCHIVE", "AXIS", "BACKGROUND", "BGCOLOR", "BORDER", "CELLPADDING", "CELLSPACING", "CHAR",
173 "CHAROFF", "CHARSET", "CHECKED", "CLASS", "CLASSID", "CLEAR", "CODEBASE", "CODETYPE",
174 "COLOR", "COLS", "COLSPAN", "COMPACT", "CONTENT", "COORDS", "DATA", "DATAFLD", "DATAFORMATAS",
175 "DATAPAGESIZE", "DATASRC", "DATETIME", "DECLARE", "DEFER", "DISABLED", "ENCTYPE",
176 "EVENT", "FACE", "FOR", "FRAMEBORDER", "HEADERS", "HEIGHT", "HREF", "HREFLANG", "HSPACE",
177 "HTTP-EQUIV", "ID", "ISMAP", "LANG", "LANGUAGE", "LEFTMARGIN", "LONGDESC",
178 "MARGINWIDTH", "MARGINHEIGHT", "MAXLENGTH", "MEDIA", "METHOD", "MULTIPLE", "NAME", "NOHREF",
179 "NORESIZE", "NOSHADE", "NOWRAP", "ONBLUR", "ONCHANGE", "ONCLICK", "ONDBLCLICK",
180 "ONFOCUS", "ONKEYDOWN", "ONKEYPRESS", "ONKEYUP", "ONLOAD", "ONMOUSEDOWN", "ONMOUSEMOVE",
181 "ONMOUSEOVER", "ONMOUSEOUT", "ONMOUSEUP", "ONRESET", "ONSELECT", "ONSUBMIT", "ONUNLOAD",
182 "PROFILE", "PROMPT", "READONLY", "REL", "REV", "ROWS", "ROWSPAN", "RULES", "SCHEME", "SCOPE",
183 "SELECTED", "SHAPE", "SIZE", "SRC", "STANDBY", "START", "SUMMARY", "TABINDEX",
184 "TARGET", "TOPMARGIN", "TYPE", "USEMAP", "VALIGN", "VALUE", "VALUETYPE",
185 "VERSION", "VLINK", "VSPACE", "WIDTH", "TEXT", "PASSWORD", "CHECKBOX", "RADIO", "SUBMIT", "RESET",
186 "FILE", "HIDDEN", "IMAGE", "PUBLIC", "!DOCTYPE",
187 "ADD_DATE", "LAST_MODIFIED", "LAST_VISIT"
191 #----------------------------------------------------------------------------
192 # Icon Bitmaps - generated by encode_bitmaps.py
193 #----------------------------------------------------------------------------
194 from wx
import ImageFromStream
, BitmapFromImage
200 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
201 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
202 \x00\x00\xd3IDAT8\x8dcddbf\xa0\x040\xfe\xbf\xd1\xf3\x9f\x12\x03X\xfe}\xbeI\
203 \x91\x0b\x98(\xd2=(\x0c`\x90W\xd2\xfc\x0f\x030\xb6\xbc\x92\xe6\x7f\x1d\x03\
204 \xf3\xffN\xae\xde\xff\xff\xff\xff\xff\xdf\xc0\xd8\xfa\xff\xb5;O\xfe_\xbb\xf3\
205 \xe4\xbf\x8e\x819\\\xcd\xd7_\xff\xff\xb3<|x\x9dAAY\x0b\xc5\xd0\x07w\xaf1\xd8\
206 \xdbZ0\xec\xdd\xb5\x85\x81\x81\x81\x81\xe1\xdd\xf3\x1b\x0c\xab\x97\xcef\xe0`\
207 ca\xf8\xfa\xf1\x19\\\x1d\x17+\x03\x03\x0b\x03\x03\x03Cqq>\xc3\xd3\x17o\x18V,\
208 ]\n\x97de\xe7\x81\xb3\x199\xc4\x18\x0e\x1d:\xc2 "*\xce\xf0\x8f\x11!\x8e\xd3\
209 \x0b\xd8\xd8\xa7\x8e\xed\xf9\x7f\xf1\xcca\x14o\xca+i\xfeg\xfc{:\x95\xa2\x844\
210 \xf0\xd1H\xb1\x01\x8c\x94\xe6F\x8a]\x00\x00YXz\xf0\x97\x87\'\x1a\x00\x00\x00\
215 return BitmapFromImage(getHTMLImage())
218 stream
= cStringIO
.StringIO(getHTMLData())
219 return ImageFromStream(stream
)
222 return wx
.IconFromBitmap(getHTMLBitmap())