Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

control.py 20KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. # An Python interface to the Scintilla control.
  2. #
  3. # Exposes Python classes that allow you to use Scintilla as
  4. # a "standard" MFC edit control (eg, control.GetTextLength(), control.GetSel()
  5. # plus many Scintilla specific features (eg control.SCIAddStyledText())
  6. import array
  7. import os
  8. import struct
  9. import win32api
  10. import win32con
  11. import win32ui
  12. from pywin import default_scintilla_encoding
  13. from pywin.mfc import window
  14. from . import scintillacon
  15. # Load Scintilla.dll to get access to the control.
  16. # We expect to find this in the same directory as win32ui.pyd
  17. dllid = None
  18. if win32ui.debug: # If running _d version of Pythonwin...
  19. try:
  20. dllid = win32api.LoadLibrary(
  21. os.path.join(os.path.split(win32ui.__file__)[0], "Scintilla_d.DLL")
  22. )
  23. except (
  24. win32api.error
  25. ): # Not there - we dont _need_ a debug ver, so ignore this error.
  26. pass
  27. if dllid is None:
  28. try:
  29. dllid = win32api.LoadLibrary(
  30. os.path.join(os.path.split(win32ui.__file__)[0], "Scintilla.DLL")
  31. )
  32. except win32api.error:
  33. pass
  34. if dllid is None:
  35. # Still not there - lets see if Windows can find it by searching?
  36. dllid = win32api.LoadLibrary("Scintilla.DLL")
  37. # null_byte is str in py2k, bytes on py3k
  38. null_byte = "\0".encode("ascii")
  39. ## These are from Richedit.h - need to add to win32con or commctrl
  40. EM_GETTEXTRANGE = 1099
  41. EM_EXLINEFROMCHAR = 1078
  42. EM_FINDTEXTEX = 1103
  43. EM_GETSELTEXT = 1086
  44. EM_EXSETSEL = win32con.WM_USER + 55
  45. class ScintillaNotification:
  46. def __init__(self, **args):
  47. self.__dict__.update(args)
  48. class ScintillaControlInterface:
  49. def SCIUnpackNotifyMessage(self, msg):
  50. format = "iiiiPiiiPPiiii"
  51. bytes = win32ui.GetBytes(msg, struct.calcsize(format))
  52. (
  53. position,
  54. ch,
  55. modifiers,
  56. modificationType,
  57. text_ptr,
  58. length,
  59. linesAdded,
  60. msg,
  61. wParam,
  62. lParam,
  63. line,
  64. foldLevelNow,
  65. foldLevelPrev,
  66. margin,
  67. ) = struct.unpack(format, bytes)
  68. return ScintillaNotification(
  69. position=position,
  70. ch=ch,
  71. modifiers=modifiers,
  72. modificationType=modificationType,
  73. text_ptr=text_ptr,
  74. length=length,
  75. linesAdded=linesAdded,
  76. msg=msg,
  77. wParam=wParam,
  78. lParam=lParam,
  79. line=line,
  80. foldLevelNow=foldLevelNow,
  81. foldLevelPrev=foldLevelPrev,
  82. margin=margin,
  83. )
  84. def SCIAddText(self, text):
  85. self.SendMessage(
  86. scintillacon.SCI_ADDTEXT, text.encode(default_scintilla_encoding)
  87. )
  88. def SCIAddStyledText(self, text, style=None):
  89. # If style is None, text is assumed to be a "native" Scintilla buffer.
  90. # If style is specified, text is a normal string, and the style is
  91. # assumed to apply to the entire string.
  92. if style is not None:
  93. text = list(map(lambda char, style=style: char + chr(style), text))
  94. text = "".join(text)
  95. self.SendMessage(
  96. scintillacon.SCI_ADDSTYLEDTEXT, text.encode(default_scintilla_encoding)
  97. )
  98. def SCIInsertText(self, text, pos=-1):
  99. # SCIInsertText allows unicode or bytes - but if they are bytes,
  100. # the caller must ensure it is encoded correctly.
  101. if isinstance(text, str):
  102. text = text.encode(default_scintilla_encoding)
  103. self.SendScintilla(scintillacon.SCI_INSERTTEXT, pos, text + null_byte)
  104. def SCISetSavePoint(self):
  105. self.SendScintilla(scintillacon.SCI_SETSAVEPOINT)
  106. def SCISetUndoCollection(self, collectFlag):
  107. self.SendScintilla(scintillacon.SCI_SETUNDOCOLLECTION, collectFlag)
  108. def SCIBeginUndoAction(self):
  109. self.SendScintilla(scintillacon.SCI_BEGINUNDOACTION)
  110. def SCIEndUndoAction(self):
  111. self.SendScintilla(scintillacon.SCI_ENDUNDOACTION)
  112. def SCIGetCurrentPos(self):
  113. return self.SendScintilla(scintillacon.SCI_GETCURRENTPOS)
  114. def SCIGetCharAt(self, pos):
  115. # Must ensure char is unsigned!
  116. return chr(self.SendScintilla(scintillacon.SCI_GETCHARAT, pos) & 0xFF)
  117. def SCIGotoLine(self, line):
  118. self.SendScintilla(scintillacon.SCI_GOTOLINE, line)
  119. def SCIBraceMatch(self, pos, maxReStyle):
  120. return self.SendScintilla(scintillacon.SCI_BRACEMATCH, pos, maxReStyle)
  121. def SCIBraceHighlight(self, pos, posOpposite):
  122. return self.SendScintilla(scintillacon.SCI_BRACEHIGHLIGHT, pos, posOpposite)
  123. def SCIBraceBadHighlight(self, pos):
  124. return self.SendScintilla(scintillacon.SCI_BRACEBADLIGHT, pos)
  125. ####################################
  126. # Styling
  127. # def SCIColourise(self, start=0, end=-1):
  128. # NOTE - dependent on of we use builtin lexer, so handled below.
  129. def SCIGetEndStyled(self):
  130. return self.SendScintilla(scintillacon.SCI_GETENDSTYLED)
  131. def SCIStyleSetFore(self, num, v):
  132. return self.SendScintilla(scintillacon.SCI_STYLESETFORE, num, v)
  133. def SCIStyleSetBack(self, num, v):
  134. return self.SendScintilla(scintillacon.SCI_STYLESETBACK, num, v)
  135. def SCIStyleSetEOLFilled(self, num, v):
  136. return self.SendScintilla(scintillacon.SCI_STYLESETEOLFILLED, num, v)
  137. def SCIStyleSetFont(self, num, name, characterset=0):
  138. buff = (name + "\0").encode(default_scintilla_encoding)
  139. self.SendScintilla(scintillacon.SCI_STYLESETFONT, num, buff)
  140. self.SendScintilla(scintillacon.SCI_STYLESETCHARACTERSET, num, characterset)
  141. def SCIStyleSetBold(self, num, bBold):
  142. self.SendScintilla(scintillacon.SCI_STYLESETBOLD, num, bBold)
  143. def SCIStyleSetItalic(self, num, bItalic):
  144. self.SendScintilla(scintillacon.SCI_STYLESETITALIC, num, bItalic)
  145. def SCIStyleSetSize(self, num, size):
  146. self.SendScintilla(scintillacon.SCI_STYLESETSIZE, num, size)
  147. def SCIGetViewWS(self):
  148. return self.SendScintilla(scintillacon.SCI_GETVIEWWS)
  149. def SCISetViewWS(self, val):
  150. self.SendScintilla(scintillacon.SCI_SETVIEWWS, not (val == 0))
  151. self.InvalidateRect()
  152. def SCISetIndentationGuides(self, val):
  153. self.SendScintilla(scintillacon.SCI_SETINDENTATIONGUIDES, val)
  154. def SCIGetIndentationGuides(self):
  155. return self.SendScintilla(scintillacon.SCI_GETINDENTATIONGUIDES)
  156. def SCISetIndent(self, val):
  157. self.SendScintilla(scintillacon.SCI_SETINDENT, val)
  158. def SCIGetIndent(self, val):
  159. return self.SendScintilla(scintillacon.SCI_GETINDENT)
  160. def SCIGetViewEOL(self):
  161. return self.SendScintilla(scintillacon.SCI_GETVIEWEOL)
  162. def SCISetViewEOL(self, val):
  163. self.SendScintilla(scintillacon.SCI_SETVIEWEOL, not (val == 0))
  164. self.InvalidateRect()
  165. def SCISetTabWidth(self, width):
  166. self.SendScintilla(scintillacon.SCI_SETTABWIDTH, width, 0)
  167. def SCIStartStyling(self, pos, mask):
  168. self.SendScintilla(scintillacon.SCI_STARTSTYLING, pos, mask)
  169. def SCISetStyling(self, pos, attr):
  170. self.SendScintilla(scintillacon.SCI_SETSTYLING, pos, attr)
  171. def SCISetStylingEx(self, ray): # ray is an array.
  172. address, length = ray.buffer_info()
  173. self.SendScintilla(scintillacon.SCI_SETSTYLINGEX, length, address)
  174. def SCIGetStyleAt(self, pos):
  175. return self.SendScintilla(scintillacon.SCI_GETSTYLEAT, pos)
  176. def SCISetMarginWidth(self, width):
  177. self.SendScintilla(scintillacon.SCI_SETMARGINWIDTHN, 1, width)
  178. def SCISetMarginWidthN(self, n, width):
  179. self.SendScintilla(scintillacon.SCI_SETMARGINWIDTHN, n, width)
  180. def SCISetFoldFlags(self, flags):
  181. self.SendScintilla(scintillacon.SCI_SETFOLDFLAGS, flags)
  182. # Markers
  183. def SCIMarkerDefineAll(self, markerNum, markerType, fore, back):
  184. self.SCIMarkerDefine(markerNum, markerType)
  185. self.SCIMarkerSetFore(markerNum, fore)
  186. self.SCIMarkerSetBack(markerNum, back)
  187. def SCIMarkerDefine(self, markerNum, markerType):
  188. self.SendScintilla(scintillacon.SCI_MARKERDEFINE, markerNum, markerType)
  189. def SCIMarkerSetFore(self, markerNum, fore):
  190. self.SendScintilla(scintillacon.SCI_MARKERSETFORE, markerNum, fore)
  191. def SCIMarkerSetBack(self, markerNum, back):
  192. self.SendScintilla(scintillacon.SCI_MARKERSETBACK, markerNum, back)
  193. def SCIMarkerAdd(self, lineNo, markerNum):
  194. self.SendScintilla(scintillacon.SCI_MARKERADD, lineNo, markerNum)
  195. def SCIMarkerDelete(self, lineNo, markerNum):
  196. self.SendScintilla(scintillacon.SCI_MARKERDELETE, lineNo, markerNum)
  197. def SCIMarkerDeleteAll(self, markerNum=-1):
  198. self.SendScintilla(scintillacon.SCI_MARKERDELETEALL, markerNum)
  199. def SCIMarkerGet(self, lineNo):
  200. return self.SendScintilla(scintillacon.SCI_MARKERGET, lineNo)
  201. def SCIMarkerNext(self, lineNo, markerNum):
  202. return self.SendScintilla(scintillacon.SCI_MARKERNEXT, lineNo, markerNum)
  203. def SCICancel(self):
  204. self.SendScintilla(scintillacon.SCI_CANCEL)
  205. # AutoComplete
  206. def SCIAutoCShow(self, text):
  207. if type(text) in [type([]), type(())]:
  208. text = " ".join(text)
  209. buff = (text + "\0").encode(default_scintilla_encoding)
  210. return self.SendScintilla(scintillacon.SCI_AUTOCSHOW, 0, buff)
  211. def SCIAutoCCancel(self):
  212. self.SendScintilla(scintillacon.SCI_AUTOCCANCEL)
  213. def SCIAutoCActive(self):
  214. return self.SendScintilla(scintillacon.SCI_AUTOCACTIVE)
  215. def SCIAutoCComplete(self):
  216. return self.SendScintilla(scintillacon.SCI_AUTOCCOMPLETE)
  217. def SCIAutoCStops(self, stops):
  218. buff = (stops + "\0").encode(default_scintilla_encoding)
  219. self.SendScintilla(scintillacon.SCI_AUTOCSTOPS, 0, buff)
  220. def SCIAutoCSetAutoHide(self, hide):
  221. self.SendScintilla(scintillacon.SCI_AUTOCSETAUTOHIDE, hide)
  222. def SCIAutoCSetFillups(self, fillups):
  223. self.SendScintilla(scintillacon.SCI_AUTOCSETFILLUPS, fillups)
  224. # Call tips
  225. def SCICallTipShow(self, text, pos=-1):
  226. if pos == -1:
  227. pos = self.GetSel()[0]
  228. buff = (text + "\0").encode(default_scintilla_encoding)
  229. self.SendScintilla(scintillacon.SCI_CALLTIPSHOW, pos, buff)
  230. def SCICallTipCancel(self):
  231. self.SendScintilla(scintillacon.SCI_CALLTIPCANCEL)
  232. def SCICallTipActive(self):
  233. return self.SendScintilla(scintillacon.SCI_CALLTIPACTIVE)
  234. def SCICallTipPosStart(self):
  235. return self.SendScintilla(scintillacon.SCI_CALLTIPPOSSTART)
  236. def SCINewline(self):
  237. self.SendScintilla(scintillacon.SCI_NEWLINE)
  238. # Lexer etc
  239. def SCISetKeywords(self, keywords, kw_list_no=0):
  240. buff = (keywords + "\0").encode(default_scintilla_encoding)
  241. self.SendScintilla(scintillacon.SCI_SETKEYWORDS, kw_list_no, buff)
  242. def SCISetProperty(self, name, value):
  243. name_buff = array.array("b", (name + "\0").encode(default_scintilla_encoding))
  244. val_buff = array.array(
  245. "b", (str(value) + "\0").encode(default_scintilla_encoding)
  246. )
  247. address_name_buffer = name_buff.buffer_info()[0]
  248. address_val_buffer = val_buff.buffer_info()[0]
  249. self.SendScintilla(
  250. scintillacon.SCI_SETPROPERTY, address_name_buffer, address_val_buffer
  251. )
  252. def SCISetStyleBits(self, nbits):
  253. self.SendScintilla(scintillacon.SCI_SETSTYLEBITS, nbits)
  254. # Folding
  255. def SCIGetFoldLevel(self, lineno):
  256. return self.SendScintilla(scintillacon.SCI_GETFOLDLEVEL, lineno)
  257. def SCIToggleFold(self, lineno):
  258. return self.SendScintilla(scintillacon.SCI_TOGGLEFOLD, lineno)
  259. def SCIEnsureVisible(self, lineno):
  260. self.SendScintilla(scintillacon.SCI_ENSUREVISIBLE, lineno)
  261. def SCIGetFoldExpanded(self, lineno):
  262. return self.SendScintilla(scintillacon.SCI_GETFOLDEXPANDED, lineno)
  263. # right edge
  264. def SCISetEdgeColumn(self, edge):
  265. self.SendScintilla(scintillacon.SCI_SETEDGECOLUMN, edge)
  266. def SCIGetEdgeColumn(self):
  267. return self.SendScintilla(scintillacon.SCI_GETEDGECOLUMN)
  268. def SCISetEdgeMode(self, mode):
  269. self.SendScintilla(scintillacon.SCI_SETEDGEMODE, mode)
  270. def SCIGetEdgeMode(self):
  271. return self.SendScintilla(scintillacon.SCI_GETEDGEMODE)
  272. def SCISetEdgeColor(self, color):
  273. self.SendScintilla(scintillacon.SCI_SETEDGECOLOUR, color)
  274. def SCIGetEdgeColor(self):
  275. return self.SendScintilla(scintillacon.SCI_GETEDGECOLOR)
  276. # Multi-doc
  277. def SCIGetDocPointer(self):
  278. return self.SendScintilla(scintillacon.SCI_GETDOCPOINTER)
  279. def SCISetDocPointer(self, p):
  280. return self.SendScintilla(scintillacon.SCI_SETDOCPOINTER, 0, p)
  281. def SCISetWrapMode(self, mode):
  282. return self.SendScintilla(scintillacon.SCI_SETWRAPMODE, mode)
  283. def SCIGetWrapMode(self):
  284. return self.SendScintilla(scintillacon.SCI_GETWRAPMODE)
  285. class CScintillaEditInterface(ScintillaControlInterface):
  286. def close(self):
  287. self.colorizer = None
  288. def Clear(self):
  289. self.SendScintilla(win32con.WM_CLEAR)
  290. def FindText(self, flags, range, findText):
  291. """LPARAM for EM_FINDTEXTEX:
  292. typedef struct _findtextex {
  293. CHARRANGE chrg;
  294. LPCTSTR lpstrText;
  295. CHARRANGE chrgText;} FINDTEXTEX;
  296. typedef struct _charrange {
  297. LONG cpMin;
  298. LONG cpMax;} CHARRANGE;
  299. """
  300. findtextex_fmt = "llPll"
  301. ## Scintilla does not handle unicode in EM_FINDTEXT msg (FINDTEXTEX struct)
  302. txt_buff = (findText + "\0").encode(default_scintilla_encoding)
  303. txt_array = array.array("b", txt_buff)
  304. ft_buff = struct.pack(
  305. findtextex_fmt, range[0], range[1], txt_array.buffer_info()[0], 0, 0
  306. )
  307. ft_array = array.array("b", ft_buff)
  308. rc = self.SendScintilla(EM_FINDTEXTEX, flags, ft_array.buffer_info()[0])
  309. ftUnpacked = struct.unpack(findtextex_fmt, ft_array)
  310. return rc, (ftUnpacked[3], ftUnpacked[4])
  311. def GetSel(self):
  312. currentPos = self.SendScintilla(scintillacon.SCI_GETCURRENTPOS)
  313. anchorPos = self.SendScintilla(scintillacon.SCI_GETANCHOR)
  314. if currentPos < anchorPos:
  315. return (currentPos, anchorPos)
  316. else:
  317. return (anchorPos, currentPos)
  318. return currentPos
  319. def GetSelText(self):
  320. start, end = self.GetSel()
  321. txtBuf = array.array("b", null_byte * (end - start + 1))
  322. addressTxtBuf = txtBuf.buffer_info()[0]
  323. # EM_GETSELTEXT is documented as returning the number of chars
  324. # not including the NULL, but scintilla includes the NULL. A
  325. # quick glance at the scintilla impl doesn't make this
  326. # obvious - the NULL is included in the 'selection' object
  327. # and reflected in the length of that 'selection' object.
  328. # I expect that is a bug in scintilla and may be fixed by now,
  329. # but we just blindly assume that the last char is \0 and
  330. # strip it.
  331. self.SendScintilla(EM_GETSELTEXT, 0, addressTxtBuf)
  332. return txtBuf.tobytes()[:-1].decode(default_scintilla_encoding)
  333. def SetSel(self, start=0, end=None):
  334. if type(start) == type(()):
  335. assert (
  336. end is None
  337. ), "If you pass a point in the first param, the second must be None"
  338. start, end = start
  339. elif end is None:
  340. end = start
  341. if start < 0:
  342. start = self.GetTextLength()
  343. if end < 0:
  344. end = self.GetTextLength()
  345. assert start <= self.GetTextLength(), "The start postion is invalid (%d/%d)" % (
  346. start,
  347. self.GetTextLength(),
  348. )
  349. assert end <= self.GetTextLength(), "The end postion is invalid (%d/%d)" % (
  350. end,
  351. self.GetTextLength(),
  352. )
  353. cr = struct.pack("ll", start, end)
  354. crBuff = array.array("b", cr)
  355. addressCrBuff = crBuff.buffer_info()[0]
  356. rc = self.SendScintilla(EM_EXSETSEL, 0, addressCrBuff)
  357. def GetLineCount(self):
  358. return self.SendScintilla(win32con.EM_GETLINECOUNT)
  359. def LineFromChar(self, charPos=-1):
  360. if charPos == -1:
  361. charPos = self.GetSel()[0]
  362. assert (
  363. charPos >= 0 and charPos <= self.GetTextLength()
  364. ), "The charPos postion (%s) is invalid (max=%s)" % (
  365. charPos,
  366. self.GetTextLength(),
  367. )
  368. # return self.SendScintilla(EM_EXLINEFROMCHAR, charPos)
  369. # EM_EXLINEFROMCHAR puts charPos in lParam, not wParam
  370. return self.SendScintilla(EM_EXLINEFROMCHAR, 0, charPos)
  371. def LineIndex(self, line):
  372. return self.SendScintilla(win32con.EM_LINEINDEX, line)
  373. def ScrollCaret(self):
  374. return self.SendScintilla(win32con.EM_SCROLLCARET)
  375. def GetCurLineNumber(self):
  376. return self.LineFromChar(self.SCIGetCurrentPos())
  377. def GetTextLength(self):
  378. return self.SendScintilla(scintillacon.SCI_GETTEXTLENGTH)
  379. def GetTextRange(self, start=0, end=-1, decode=True):
  380. if end == -1:
  381. end = self.SendScintilla(scintillacon.SCI_GETTEXTLENGTH)
  382. assert end >= start, "Negative index requested (%d/%d)" % (start, end)
  383. assert (
  384. start >= 0 and start <= self.GetTextLength()
  385. ), "The start postion is invalid"
  386. assert end >= 0 and end <= self.GetTextLength(), "The end postion is invalid"
  387. initer = null_byte * (end - start + 1)
  388. buff = array.array("b", initer)
  389. addressBuffer = buff.buffer_info()[0]
  390. tr = struct.pack("llP", start, end, addressBuffer)
  391. trBuff = array.array("b", tr)
  392. addressTrBuff = trBuff.buffer_info()[0]
  393. num_bytes = self.SendScintilla(EM_GETTEXTRANGE, 0, addressTrBuff)
  394. ret = buff.tobytes()[:num_bytes]
  395. if decode:
  396. ret = ret.decode(default_scintilla_encoding)
  397. return ret
  398. def ReplaceSel(self, str):
  399. buff = (str + "\0").encode(default_scintilla_encoding)
  400. self.SendScintilla(scintillacon.SCI_REPLACESEL, 0, buff)
  401. def GetLine(self, line=-1):
  402. if line == -1:
  403. line = self.GetCurLineNumber()
  404. start = self.LineIndex(line)
  405. end = self.LineIndex(line + 1)
  406. return self.GetTextRange(start, end)
  407. def SetReadOnly(self, flag=1):
  408. return self.SendScintilla(win32con.EM_SETREADONLY, flag)
  409. def LineScroll(self, lines, cols=0):
  410. return self.SendScintilla(win32con.EM_LINESCROLL, cols, lines)
  411. def GetFirstVisibleLine(self):
  412. return self.SendScintilla(win32con.EM_GETFIRSTVISIBLELINE)
  413. def SetWordWrap(self, mode):
  414. if mode != win32ui.CRichEditView_WrapNone:
  415. raise ValueError("We dont support word-wrap (I dont think :-)")
  416. class CScintillaColorEditInterface(CScintillaEditInterface):
  417. ################################
  418. # Plug-in colorizer support
  419. def _GetColorizer(self):
  420. if not hasattr(self, "colorizer"):
  421. self.colorizer = self._MakeColorizer()
  422. return self.colorizer
  423. def _MakeColorizer(self):
  424. # Give parent a chance to hook.
  425. parent_func = getattr(self.GetParentFrame(), "_MakeColorizer", None)
  426. if parent_func is not None:
  427. return parent_func()
  428. from . import formatter
  429. ## return formatter.PythonSourceFormatter(self)
  430. return formatter.BuiltinPythonSourceFormatter(self)
  431. def Colorize(self, start=0, end=-1):
  432. c = self._GetColorizer()
  433. if c is not None:
  434. c.Colorize(start, end)
  435. def ApplyFormattingStyles(self, bReload=1):
  436. c = self._GetColorizer()
  437. if c is not None:
  438. c.ApplyFormattingStyles(bReload)
  439. # The Parent window will normally hook
  440. def HookFormatter(self, parent=None):
  441. c = self._GetColorizer()
  442. if c is not None: # No need if we have no color!
  443. c.HookFormatter(parent)
  444. class CScintillaEdit(window.Wnd, CScintillaColorEditInterface):
  445. def __init__(self, wnd=None):
  446. if wnd is None:
  447. wnd = win32ui.CreateWnd()
  448. window.Wnd.__init__(self, wnd)
  449. def SendScintilla(self, msg, w=0, l=0):
  450. return self.SendMessage(msg, w, l)
  451. def CreateWindow(self, style, rect, parent, id):
  452. self._obj_.CreateWindow("Scintilla", "Scintilla", style, rect, parent, id, None)