Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/02/2009, 19:41
iozk
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 16 años
Puntos: 1
ayuda!!! con codigo

me encontre unos ejemplos de wx.estiledtextctrl y no les entiendo
y quiero que me ayuden a simplificarlo en una clase para usarlo en un frame
Código pythom:
Ver original
  1. #
  2. # 11/21/2003 - Jeff Grimmett ([email protected])
  3. #
  4. # o
  5.  
  6. wx.TheClipboard.Flush() generates a warning on program exit.
  7. #
  8.  
  9. import  wx
  10. import  wx.stc  as  stc
  11.  
  12. import  images
  13.  
  14. #-------------------------------------------------------------------
  15.  
  16. ---
  17.  
  18. debug = 1
  19.  
  20.  
  21. demoText = """\
  22. This editor is provided by a class
  23.  
  24. named wx.StyledTextCtrl.  As
  25. the name suggests, you can define
  26.  
  27. styles that can be applied to
  28. sections of text.  This will typically
  29.  
  30. be used for things like
  31. syntax highlighting code editors, but I'm
  32.  
  33. sure that there are other
  34. applications as well.  A style is a
  35.  
  36. combination of font, point size,
  37. foreground and background colours.  
  38.  
  39. The editor can handle
  40. proportional fonts just as easily as
  41.  
  42. monospaced fonts, and various
  43. styles can use different sized
  44.  
  45. fonts.
  46.  
  47. There are a few canned language lexers and colourizers
  48.  
  49. included,
  50. (see the next demo) or you can handle the colourization
  51.  
  52. yourself.
  53. If you do you can simply register an event handler and the
  54.  
  55. editor
  56. will let you know when the visible portion of the text
  57.  
  58. needs
  59. styling.
  60.  
  61. wx.StyledTextCtrl also supports setting markers in
  62.  
  63. the margin...
  64.  
  65.  
  66.  
  67.  
  68. ...and indicators within the text.  You can use
  69.  
  70. these for whatever
  71. you want in your application.  Cut, Copy, Paste,
  72.  
  73. Drag and Drop of
  74. text works, as well as virtually unlimited Undo and
  75.  
  76. Redo
  77. capabilities, (right click to try it out.)
  78. """
  79.  
  80. if wx.Platform
  81.  
  82. == '__WXMSW__':
  83.     face1 = 'Arial'
  84.     face2 = 'Times New Roman'
  85.    
  86.  
  87.  face3 = 'Courier New'
  88.     pb = 10
  89. else:
  90.     face1 = 'Helvetica'
  91.    
  92.  
  93. face2 = 'Times'
  94.     face3 = 'Courier'
  95.     pb = 12
  96.  
  97.  
  98. #-------------------------------------------------------------------
  99.  
  100. ---
  101. # This shows how to catch the Modified event from the
  102.  
  103. wx.StyledTextCtrl
  104.  
  105. class MySTC(stc.StyledTextCtrl):
  106.     def
  107.  
  108. __init__(self, parent, ID, log):
  109.        
  110.  
  111. stc.StyledTextCtrl.__init__(self, parent, ID)
  112.         self.log =
  113.  
  114. log
  115.  
  116.         self.Bind(stc.EVT_STC_DO_DROP, self.OnDoDrop)
  117.        
  118.  
  119. self.Bind(stc.EVT_STC_DRAG_OVER, self.OnDragOver)
  120.        
  121.  
  122. self.Bind(stc.EVT_STC_START_DRAG, self.OnStartDrag)
  123.        
  124.  
  125. self.Bind(stc.EVT_STC_MODIFIED, self.OnModified)
  126.  
  127.        
  128.  
  129. self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
  130.  
  131.     def
  132.  
  133. OnDestroy(self, evt):
  134.         # This is how the clipboard contents
  135.  
  136. can be preserved after
  137.         # the app has exited.
  138.        
  139.  
  140. wx.TheClipboard.Flush()
  141.         evt.Skip()
  142.  
  143.  
  144.     def
  145.  
  146. OnStartDrag(self, evt):
  147.         self.log.write("OnStartDrag: %d,
  148.  
  149. %s\n"
  150.                        % (evt.GetDragAllowMove(),
  151.  
  152. evt.GetDragText()))
  153.  
  154.         if debug and evt.GetPosition() < 250:
  155.  
  156.  
  157.           evt.SetDragAllowMove(False)     # you can prevent moving
  158.  
  159. of text (only copy)
  160.             evt.SetDragText("DRAGGED TEXT") #
  161.  
  162. you can change what is dragged
  163.             #evt.SetDragText("")      
  164.  
  165.        # or prevent the drag with empty text
  166.  
  167.  
  168.     def
  169.  
  170. OnDragOver(self, evt):
  171.         self.log.write(
  172.            
  173.  
  174. "OnDragOver: x,y=(%d, %d)  pos: %d  DragResult: %d\n"
  175.             %
  176.  
  177. (evt.GetX(), evt.GetY(), evt.GetPosition(), evt.GetDragResult())
  178.    
  179.  
  180.         )
  181.  
  182.         if debug and evt.GetPosition() < 250:
  183.            
  184.  
  185. evt.SetDragResult(wx.DragNone)   # prevent dropping at the beginning
  186.  
  187. of the buffer
  188.  
  189.  
  190.     def OnDoDrop(self, evt):
  191.        
  192.  
  193. self.log.write("OnDoDrop: x,y=(%d, %d)  pos: %d  DragResult: %d\n"
  194.  
  195.  
  196.                      "\ttext: %s\n"
  197.                        %
  198.  
  199. (evt.GetX(), evt.GetY(), evt.GetPosition(), evt.GetDragResult(),
  200.    
  201.  
  202.                       evt.GetDragText()))
  203.  
  204.         if debug and
  205.  
  206. evt.GetPosition() < 500:
  207.             evt.SetDragText("DROPPED TEXT")
  208.  
  209.  # Can change text if needed
  210.            
  211.  
  212. #evt.SetDragResult(wx.DragNone)  # Can also change the drag
  213.  
  214. operation, but it
  215.                                              # is
  216.  
  217. probably better to do it in OnDragOver so
  218.                            
  219.  
  220.                   # there is visual feedback
  221.  
  222.            
  223.  
  224. #evt.SetPosition(25)             # Can also change position, but I'm
  225.  
  226. not sure why
  227.                                              # you
  228.  
  229. would want to...
  230.  
  231.  
  232.  
  233.  
  234.     def OnModified(self, evt):
  235.        
  236.  
  237. self.log.write("""OnModified
  238.         Mod type:     %s
  239.         At
  240.  
  241. position:  %d
  242.         Lines added:  %d
  243.         Text Length:  %d
  244.      
  245.  
  246.    Text:         %s\n""" % (
  247.  
  248. self.transModType(evt.GetModificationType()),
  249.                        
  250.  
  251.            evt.GetPosition(),
  252.                                  
  253.  
  254. evt.GetLinesAdded(),
  255.                                  
  256.  
  257. evt.GetLength(),
  258.                                  
  259.  
  260. repr(evt.GetText()) ))
  261.  
  262.  
  263.     def transModType(self, modType):
  264.        
  265.  
  266.  st = ""
  267.         table = [(stc.STC_MOD_INSERTTEXT, "InsertText"),
  268.    
  269.  
  270.               (stc.STC_MOD_DELETETEXT, "DeleteText"),
  271.                
  272.  
  273.   (stc.STC_MOD_CHANGESTYLE, "ChangeStyle"),
  274.                  
  275.  
  276. (stc.STC_MOD_CHANGEFOLD, "ChangeFold"),
  277.                  
  278.  
  279. (stc.STC_PERFORMED_USER, "UserFlag"),
  280.                  
  281.  
  282. (stc.STC_PERFORMED_UNDO, "Undo"),
  283.                  
  284.  
  285. (stc.STC_PERFORMED_REDO, "Redo"),
  286.                  
  287.  
  288. (stc.STC_LASTSTEPINUNDOREDO, "Last-Undo/Redo"),
  289.                  
  290.  
  291. (stc.STC_MOD_CHANGEMARKER, "ChangeMarker"),
  292.                  
  293.  
  294. (stc.STC_MOD_BEFOREINSERT, "B4-Insert"),
  295.                  
  296.  
  297. (stc.STC_MOD_BEFOREDELETE, "B4-Delete")