1 #----------------------------------------------------------------------------
3 # Purpose: PHP Script Editor for pydocview tbat uses the Styled Text Control
9 # Copyright: (c) 2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
22 class PHPDocument(CodeEditor
.CodeDocument
):
27 class PHPView(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
):
57 #----------------------------------------------------------------------------
58 # Methods for OutlineService
59 #----------------------------------------------------------------------------
61 def DoLoadOutlineCallback(self
, force
=False):
62 outlineService
= wx
.GetApp().GetService(OutlineService
.OutlineService
)
63 if not outlineService
:
66 outlineView
= outlineService
.GetView()
70 treeCtrl
= outlineView
.GetTreeCtrl()
74 view
= treeCtrl
.GetCallbackView()
75 newCheckSum
= self
.GenCheckSum()
77 if view
and view
is self
:
78 if self
._checkSum
== newCheckSum
:
80 self
._checkSum
= newCheckSum
82 treeCtrl
.DeleteAllItems()
84 document
= self
.GetDocument()
88 filename
= document
.GetFilename()
90 rootItem
= treeCtrl
.AddRoot(os
.path
.basename(filename
))
91 treeCtrl
.SetDoSelectCallback(rootItem
, self
, None)
95 text
= self
.GetValue()
99 INTERFACE_PATTERN
= 'interface[ \t]+\w+'
100 CLASS_PATTERN
= '((final|abstract)[ \t]+)?((public|private|protected)[ \t]+)?(static[ \t]+)?class[ \t]+\w+((implements|extends)\w+)?'
101 FUNCTION_PATTERN
= '(abstract[ \t]+)?((public|private|protected)[ \t]+)?(static[ \t]+)?function[ \t]+?\w+\(.*?\)'
102 interfacePat
= re
.compile(INTERFACE_PATTERN
, re
.M|re
.S
)
103 classPat
= re
.compile(CLASS_PATTERN
, re
.M|re
.S
)
104 funcPat
= re
.compile(FUNCTION_PATTERN
, re
.M|re
.S
)
105 pattern
= re
.compile('^[ \t]*('+ CLASS_PATTERN
+ '.*?{|' + FUNCTION_PATTERN
+ '|' + INTERFACE_PATTERN
+'\s*?{).*?$', re
.M|re
.S
)
107 iter = pattern
.finditer(text
)
108 indentStack
= [(0, rootItem
)]
110 line
= pattern
.string
[pattern
.start(0):pattern
.end(0)]
111 foundLine
= classPat
.search(line
)
113 indent
= foundLine
.start(0)
114 itemStr
= foundLine
.string
[foundLine
.start(0):foundLine
.end(0)]
116 foundLine
= funcPat
.search(line
)
118 indent
= foundLine
.start(0)
119 itemStr
= foundLine
.string
[foundLine
.start(0):foundLine
.end(0)]
121 foundLine
= interfacePat
.search(line
)
123 indent
= foundLine
.start(0)
124 itemStr
= foundLine
.string
[foundLine
.start(0):foundLine
.end(0)]
127 parentItem
= rootItem
129 lastItem
= indentStack
.pop()
130 while lastItem
[0] >= indent
:
131 lastItem
= indentStack
.pop()
132 indentStack
.append(lastItem
)
133 parentItem
= lastItem
[1]
135 item
= treeCtrl
.AppendItem(parentItem
, itemStr
)
136 treeCtrl
.SetDoSelectCallback(item
, self
, (pattern
.end(0), pattern
.start(0) + indent
)) # select in reverse order because we want the cursor to be at the start of the line so it wouldn't scroll to the right
137 indentStack
.append((indent
, item
))
139 treeCtrl
.Expand(rootItem
)
144 class PHPService(CodeEditor
.CodeService
):
148 CodeEditor
.CodeService
.__init
__(self
)
151 class PHPCtrl(CodeEditor
.CodeCtrl
):
154 def __init__(self
, parent
, ID
= -1, style
= wx
.NO_FULL_REPAINT_ON_RESIZE
):
155 CodeEditor
.CodeCtrl
.__init
__(self
, parent
, ID
, style
)
156 self
.SetLexer(wx
.stc
.STC_LEX_HTML
)
158 self
.SetKeyWords(4, string
.join(PHPKEYWORDS
))
159 self
.SetProperty("fold.html", "1")
162 def CanWordWrap(self
):
166 def SetViewDefaults(self
):
167 CodeEditor
.CodeCtrl
.SetViewDefaults(self
, configPrefix
= "PHP", hasWordWrap
= True, hasTabs
= True)
170 def GetFontAndColorFromConfig(self
):
171 return CodeEditor
.CodeCtrl
.GetFontAndColorFromConfig(self
, configPrefix
= "PHP")
174 def UpdateStyles(self
):
175 CodeEditor
.CodeCtrl
.UpdateStyles(self
)
177 if not self
.GetFont():
180 faces
= { 'font' : self
.GetFont().GetFaceName(),
181 'size' : self
.GetFont().GetPointSize(),
182 'size2': self
.GetFont().GetPointSize() - 2,
183 'color' : "%02x%02x%02x" % (self
.GetFontColor().Red(), self
.GetFontColor().Green(), self
.GetFontColor().Blue())
189 self
.StyleSetSpec(wx
.stc
.STC_H_DEFAULT
, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces
)
191 self
.StyleSetSpec(wx
.stc
.STC_H_COMMENT
, "face:%(font)s,fore:#007F00,italic,face:%(font)s,size:%(size)d" % faces
)
193 self
.StyleSetSpec(wx
.stc
.STC_H_NUMBER
, "face:%(font)s,fore:#007F7F,size:%(size)d" % faces
)
195 self
.StyleSetSpec(wx
.stc
.STC_H_SINGLESTRING
, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces
)
196 self
.StyleSetSpec(wx
.stc
.STC_H_DOUBLESTRING
, "face:%(font)s,fore:#7F007F,face:%(font)s,size:%(size)d" % faces
)
198 self
.StyleSetSpec(wx
.stc
.STC_H_TAG
, "face:%(font)s,fore:#00007F,bold,size:%(size)d" % faces
)
200 self
.StyleSetSpec(wx
.stc
.STC_H_ATTRIBUTE
, "face:%(font)s,fore:#00007F,bold,size:%(size)d" % faces
)
204 self
.StyleSetSpec(wx
.stc
.STC_HPHP_DEFAULT
, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces
)
205 self
.StyleSetSpec(wx
.stc
.STC_HPHP_COMMENT
, "face:%(font)s,fore:#007F00,italic,face:%(font)s,size:%(size)d" % faces
)
206 self
.StyleSetSpec(wx
.stc
.STC_HPHP_COMMENTLINE
, "face:%(font)s,fore:#007F00,italic,face:%(font)s,size:%(size)d" % faces
)
207 self
.StyleSetSpec(wx
.stc
.STC_HPHP_NUMBER
, "face:%(font)s,fore:#007F7F,size:%(size)d" % faces
)
208 self
.StyleSetSpec(wx
.stc
.STC_HPHP_SIMPLESTRING
, "face:%(font)s,fore:#7F007F,size:%(size)d" % faces
)
209 self
.StyleSetSpec(wx
.stc
.STC_HPHP_HSTRING
, "face:%(font)s,fore7F007F,face:%(font)s,size:%(size)d" % faces
)
210 self
.StyleSetSpec(wx
.stc
.STC_HPHP_HSTRING_VARIABLE
, "face:%(font)s,fore:#007F7F,italic,bold,face:%(font)s,size:%(size)d" % faces
)
211 self
.StyleSetSpec(wx
.stc
.STC_HPHP_VARIABLE
, "face:%(font)s,fore:#000000,face:%(font)s,size:%(size)d" % faces
)
212 self
.StyleSetSpec(wx
.stc
.STC_HPHP_OPERATOR
, "face:%(font)s,size:%(size)d" % faces
)
213 self
.StyleSetSpec(wx
.stc
.STC_HPHP_WORD
, "face:%(font)s,fore:#00007F,bold,size:%(size)d" % faces
) # keyword
216 class PHPOptionsPanel(STCTextEditor
.TextOptionsPanel
):
218 def __init__(self
, parent
, id):
219 STCTextEditor
.TextOptionsPanel
.__init
__(self
, parent
, id, configPrefix
= "PHP", label
= "PHP", hasWordWrap
= True, hasTabs
= True)
223 "and", "or", "xor", "__FILE__", "exception", "__LINE__", "array", "as", "break", "case",
224 "class", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif",
225 "empty", "enddeclare", "endfor", "endforeach", "endif", "endswith", "endwhile", "eval",
226 "exit", "extends", "for", "foreach", "function", "global", "if", "include", "include_once",
227 "isset", "list", "new", "print", "require", "require_once", "return", "static", "switch",
228 "unset", "use", "var", "while", "__FUNCTION__", "__CLASS__", "__METHOD__", "final", "php_user_filter",
229 "interface", "implements", "extends", "public", "private", "protected", "abstract", "clone", "try", "catch",
230 "throw", "cfunction", "old_function",
231 "$_SERVER", "$_ENV", "$_COOKIE", "$_GET", "$_POST", "$_FILES", "$_REQUEST", "$_SESSION", "$GLOBALS", "$php_errormsg",
232 "PHP_VERSION", "PHP_OS", "PHP_EOL", "DEFAULT_INCLUDE_PATH", "PEAR_INSTALL_DIR", "PEAR_EXTENSION_DIR",
233 "PHP_EXTENSION_DIR", "PHP_BINDIR", "PHP_LIBDIR", "PHP_DATADIR", "PHP_SYSCONFDIR", "PHP_LOCALSTATEDIR",
234 "PHP_CONFIG_FILE_PATH", "PHP_OUTPUT_HANDLER_START", "PHP_OUTPUT_HANDLER_CONT", "PHP_OUTPUT_HANDLER_END",
235 "E_ERROR", "E_WARNING", "E_PARSE", "E_NOTICE", "E_CORE_ERROR", "E_CORE_WARNING", "E_COMPILE_ERROR",
236 "E_COMPILE_WARNING", "E_USER_ERROR", "E_USER_WARNING", "E_USER_NOTICE", "E_ALL", "E_STRICT",
237 "TRUE", "FALSE", "NULL", "ZEND_THREAD_SAFE",
238 "EXTR_OVERWRITE", "EXTR_SKIP", "EXTR_PREFIX_SAME", "EXTR_PREFIX_ALL", "EXTR_PREFIX_INVALID",
239 "EXTR_PREFIX_IF_EXISTS", "EXTR_IF_EXISTS", "SORT_ASC", "SORT_DESC", "SORT_REGULAR", "SORT_NUMERIC",
240 "SORT_STRING", "CASE_LOWER", "CASE_UPPER", "COUNT_NORMAL", "COUNT_RECURSIVE", "ASSERT_ACTIVE",
241 "ASSERT_CALLBACK", "ASSERT_BAIL", "ASSERT_WARNING", "ASSERT_QUIET_EVAL", "CONNECTION_ABORTED",
242 "CONNECTION_NORMAL", "CONNECTION_TIMEOUT", "INI_USER", "INI_PERDIR", "INI_SYSTEM", "INI_ALL",
243 "M_E", "M_LOG2E", "M_LOG10E", "M_LN2", "M_LN10", "M_PI", "M_PI_2", "M_PI_4", "M_1_PI", "M_2_PI",
244 "M_2_SQRTPI", "M_SQRT2", "M_SQRT1_2", "CRYPT_SALT_LENGTH", "CRYPT_STD_DES", "CRYPT_EXT_DES", "CRYPT_MD5",
245 "CRYPT_BLOWFISH", "DIRECTORY_SEPARATOR", "SEEK_SET", "SEEK_CUR", "SEEK_END", "LOCK_SH", "LOCK_EX", "LOCK_UN",
246 "LOCK_NB", "HTML_SPECIALCHARS", "HTML_ENTITIES", "ENT_COMPAT", "ENT_QUOTES", "ENT_NOQUOTES", "INFO_GENERAL",
247 "INFO_CREDITS", "INFO_CONFIGURATION", "INFO_MODULES", "INFO_ENVIRONMENT", "INFO_VARIABLES", "INFO_LICENSE",
248 "INFO_ALL", "CREDITS_GROUP", "CREDITS_GENERAL", "CREDITS_SAPI", "CREDITS_MODULES", "CREDITS_DOCS",
249 "CREDITS_FULLPAGE", "CREDITS_QA", "CREDITS_ALL", "STR_PAD_LEFT", "STR_PAD_RIGHT", "STR_PAD_BOTH",
250 "PATHINFO_DIRNAME", "PATHINFO_BASENAME", "PATHINFO_EXTENSION", "PATH_SEPARATOR", "CHAR_MAX", "LC_CTYPE",
251 "LC_NUMERIC", "LC_TIME", "LC_COLLATE", "LC_MONETARY", "LC_ALL", "LC_MESSAGES", "ABDAY_1", "ABDAY_2",
252 "ABDAY_3", "ABDAY_4", "ABDAY_5", "ABDAY_6", "ABDAY_7", "DAY_1", "DAY_2", "DAY_3", "DAY_4", "DAY_5",
253 "DAY_6", "DAY_7", "ABMON_1", "ABMON_2", "ABMON_3", "ABMON_4", "ABMON_5", "ABMON_6", "ABMON_7", "ABMON_8",
254 "ABMON_9", "ABMON_10", "ABMON_11", "ABMON_12", "MON_1", "MON_2", "MON_3", "MON_4", "MON_5", "MON_6", "MON_7",
255 "MON_8", "MON_9", "MON_10", "MON_11", "MON_12", "AM_STR", "PM_STR", "D_T_FMT", "D_FMT", "T_FMT", "T_FMT_AMPM",
256 "ERA", "ERA_YEAR", "ERA_D_T_FMT", "ERA_D_FMT", "ERA_T_FMT", "ALT_DIGITS", "INT_CURR_SYMBOL", "CURRENCY_SYMBOL",
257 "CRNCYSTR", "MON_DECIMAL_POINT", "MON_THOUSANDS_SEP", "MON_GROUPING", "POSITIVE_SIGN", "NEGATIVE_SIGN",
258 "INT_FRAC_DIGITS", "FRAC_DIGITS", "P_CS_PRECEDES", "P_SEP_BY_SPACE", "N_CS_PRECEDES", "N_SEP_BY_SPACE",
259 "P_SIGN_POSN", "N_SIGN_POSN", "DECIMAL_POINT", "RADIXCHAR", "THOUSANDS_SEP", "THOUSEP", "GROUPING",
260 "YESEXPR", "NOEXPR", "YESSTR", "NOSTR", "CODESET", "LOG_EMERG", "LOG_ALERT", "LOG_CRIT", "LOG_ERR",
261 "LOG_WARNING", "LOG_NOTICE", "LOG_INFO", "LOG_DEBUG", "LOG_KERN", "LOG_USER", "LOG_MAIL", "LOG_DAEMON",
262 "LOG_AUTH", "LOG_SYSLOG", "LOG_LPR", "LOG_NEWS", "LOG_UUCP", "LOG_CRON", "LOG_AUTHPRIV", "LOG_LOCAL0",
263 "LOG_LOCAL1", "LOG_LOCAL2", "LOG_LOCAL3", "LOG_LOCAL4", "LOG_LOCAL5", "LOG_LOCAL6", "LOG_LOCAL7",
264 "LOG_PID", "LOG_CONS", "LOG_ODELAY", "LOG_NDELAY", "LOG_NOWAIT", "LOG_PERROR"
268 #----------------------------------------------------------------------------
269 # Icon Bitmaps - generated by encode_bitmaps.py
270 #----------------------------------------------------------------------------
271 from wx
import ImageFromStream
, BitmapFromImage
277 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
278 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
279 \x00\x00{IDAT8\x8dclh8\xf0\x9f\x81\x02\xc0D\x89f\xaa\x18\xc0\x82M0<\\\x1c\
280 \xce^\xb9\xf2%y.\xd0\xd4\xd4$\xde\x05\xf8l\x0c\x0f\x17\x87\x8baS\xc7x\xfd\
281 \xfa\xf5\xff\xc8\xb6]\xbf~\x1d\xc3\x05\xf8\xc4\x98\x90\x05\xae_\xbf\x8e\xa1\
282 \x88\x90\xd8 \x8aF\x98\x93`~\xc3\x05\xd0\xd5\xc1\r\x80\t\xc0B\xf7\xfa\xf5\
283 \xeb(l\\\xeaP\xbc\x80\x1c\x85\xb8\xd8\xe8|&b\x9c\x8dn;2`\x1c\xf0\xdc\x08\x00\
284 \x8e\xf2S\xed\xb0\xbe\xaa\xbc\x00\x00\x00\x00IEND\xaeB`\x82'
287 return BitmapFromImage(getPHPImage())
290 stream
= cStringIO
.StringIO(getPHPData())
291 return ImageFromStream(stream
)
294 return wx
.IconFromBitmap(getPHPBitmap())