Foros del Web » Programando para Internet » Python »

ayuda!!! con codigo

Estas en el tema de ayuda!!! con codigo en el foro de Python en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 25/02/2009, 19:41
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 16 años, 6 meses
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")
  #2 (permalink)  
Antiguo 25/02/2009, 19:43
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 16 años, 6 meses
Puntos: 1
Respuesta: ayuda!!! con codigo

Código pythom:
Ver original
  1. ]
  2.  
  3.        
  4.  
  5. for flag,text in table:
  6.             if flag & modType:
  7.              
  8.  
  9.   st = st + text + " "
  10.  
  11.         if not st:
  12.             st =
  13.  
  14. 'UNKNOWN'
  15.  
  16.         return st
  17.  
  18.  
  19.  
  20.  
  21. #-------------------------------------------------------------------
  22.  
  23. ---
  24.  
  25. _USE_PANEL = 1
  26.  
  27. def runTest(frame, nb, log):
  28.     if not
  29.  
  30. _USE_PANEL:
  31.         ed = p = MySTC(nb, -1, log)
  32.  
  33.     else:
  34.         p
  35.  
  36. = wx.Panel(nb, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE)
  37.         ed =
  38.  
  39. MySTC(p, -1, log)
  40.         s = wx.BoxSizer(wx.HORIZONTAL)
  41.        
  42.  
  43. s.Add(ed, 1, wx.EXPAND)
  44.         p.SetSizer(s)
  45.        
  46.  
  47. p.SetAutoLayout(True)
  48.  
  49.  
  50.     #ed.SetBufferedDraw(False)
  51.    
  52.  
  53. #ed.StyleClearAll()
  54.     #ed.SetScrollWidth(800)
  55.    
  56.  
  57. #ed.SetWrapMode(True)
  58.     #ed.SetUseAntiAliasing(False)    
  59.    
  60.  
  61. #ed.SetViewEOL(True)
  62.  
  63.     #ed.CmdKeyClear(stc.STC_KEY_BACK,
  64.     #    
  65.  
  66.            stc.STC_SCMOD_CTRL)
  67.    
  68.  
  69. #ed.CmdKeyAssign(stc.STC_KEY_BACK,
  70.     #                
  71.  
  72. stc.STC_SCMOD_CTRL,
  73.     #                stc.STC_CMD_DELWORDLEFT)
  74.  
  75.  
  76.  
  77.   ed.SetText(demoText)
  78.  
  79.     if wx.USE_UNICODE:
  80.         import
  81.  
  82. codecs
  83.         decode = codecs.lookup("utf-8")[1]
  84.  
  85.        
  86.  
  87. ed.GotoPos(ed.GetLength())
  88.         ed.AddText("\n\nwx.StyledTextCtrl
  89.  
  90. can also do Unicode:\n")
  91.         uniline = ed.GetCurrentLine()
  92.      
  93.  
  94.   unitext, l = decode('\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd - '
  95.  
  96.  
  97.                            
  98.  
  99. '\xd0\xbb\xd1\x83\xd1\x87\xd1\x88\xd0\xb8\xd0\xb9 '
  100.                  
  101.  
  102.            '\xd1\x8f\xd0\xb7\xd1\x8b\xd0\xba
  103.  
  104. \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd0\xbc\xd0\xbc\xd0
  105.  
  106. \xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x8f!\n\n')
  107.  
  108.  
  109.        ed.AddText('\tRussian: ')
  110.         ed.AddText(unitext)
  111.        
  112.  
  113. ed.GotoPos(0)
  114.     #else:
  115.     #    
  116.  
  117. #ed.StyleSetFontEncoding(stc.STC_STYLE_DEFAULT,
  118.  
  119. wx.FONTENCODING_KOI8)
  120.     #    #text =
  121.  
  122. u'\u041f\u0438\u0442\u043e\u043d -
  123.  
  124. \u043b\u0443\u0447\u0448\u0438\u0439 \u044f\u0437\u044b\u043a
  125.  
  126. \n\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e
  127.  
  128. \u0432\u0430\u043d\u0438\u044f!'
  129.     #    #text =
  130.  
  131. text.encode('koi8-r')
  132.     #    
  133.  
  134. #ed.StyleSetFontEncoding(stc.STC_STYLE_DEFAULT,
  135.  
  136. wx.FONTENCODING_BIG5)
  137.     #    #text = u'Python
  138.  
  139. \u662f\u6700\u597d\u7684\u7de8\u7a0b\u8a9e\u8a00\uff01'
  140.     #    
  141.  
  142. #text = text.encode('big5')
  143.     #    ed.GotoPos(ed.GetLength())
  144.    
  145.  
  146. #    ed.AddText('\n\n' + text)
  147.        
  148.     ed.EmptyUndoBuffer()
  149.  
  150.    
  151.  
  152.  # make some styles
  153.     ed.StyleSetSpec(stc.STC_STYLE_DEFAULT,
  154.  
  155. "size:%d,face:%s" % (pb, face3))
  156.     ed.StyleClearAll()
  157.    
  158.  
  159. ed.StyleSetSpec(1, "size:%d,bold,face:%s,fore:#0000FF" % (pb,
  160.  
  161. face1))
  162.     ed.StyleSetSpec(2, "face:%s,italic,fore:#FF0000,size:%d"
  163.  
  164. % (face2, pb))
  165.     ed.StyleSetSpec(3, "face:%s,bold,size:%d" %
  166.  
  167. (face2, pb))
  168.     ed.StyleSetSpec(4, "face:%s,size:%d" % (face1,
  169.  
  170. pb-1))
  171.  
  172.     # Now set some text to those styles...  Normally this
  173.  
  174. would be
  175.     # done in an event handler that happens when text needs
  176.  
  177. displayed.
  178.     ed.StartStyling(98, 0xff)
  179.     ed.SetStyling(6, 1)  #
  180.  
  181. set style for 6 characters using style 1
  182.  
  183.     ed.StartStyling(190,
  184.  
  185. 0xff)
  186.     ed.SetStyling(20, 2)
  187.  
  188.     ed.StartStyling(310, 0xff)
  189.    
  190.  
  191. ed.SetStyling(4, 3)
  192.     ed.SetStyling(2, 0)
  193.     ed.SetStyling(10,
  194.  
  195. 4)
  196.  
  197.  
  198.     # line numbers in the margin
  199.     ed.SetMarginType(0,
  200.  
  201. stc.STC_MARGIN_NUMBER)
  202.     ed.SetMarginWidth(0, 22)
  203.    
  204.  
  205. ed.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "size:%d,face:%s" % (pb-2,
  206.  
  207. face1))
  208.  
  209.     # setup some markers
  210.     ed.SetMarginType(1,
  211.  
  212. stc.STC_MARGIN_SYMBOL)
  213.     ed.MarkerDefine(0,
  214.  
  215. stc.STC_MARK_ROUNDRECT, "#CCFF00", "RED")
  216.     ed.MarkerDefine(1,
  217.  
  218. stc.STC_MARK_CIRCLE, "FOREST GREEN", "SIENNA")
  219.    
  220.  
  221. ed.MarkerDefine(2, stc.STC_MARK_SHORTARROW, "blue", "blue")
  222.    
  223.  
  224. ed.MarkerDefine(3, stc.STC_MARK_ARROW, "#00FF00", "#00FF00")
  225.  
  226.     #
  227.  
  228. put some markers on some lines
  229.     ed.MarkerAdd(17, 0)
  230.    
  231.  
  232. ed.MarkerAdd(18, 1)
  233.     ed.MarkerAdd(19, 2)
  234.     ed.MarkerAdd(20, 3)
  235.  
  236.  
  237.    ed.MarkerAdd(20, 0)
  238.  
  239.  
  240.     # and finally, an indicator or two
  241.    
  242.  
  243. ed.IndicatorSetStyle(0, stc.STC_INDIC_SQUIGGLE)
  244.    
  245.  
  246. ed.IndicatorSetForeground(0, wx.RED)
  247.     ed.IndicatorSetStyle(1,
  248.  
  249. stc.STC_INDIC_DIAGONAL)
  250.     ed.IndicatorSetForeground(1, wx.BLUE)
  251.    
  252.  
  253.  ed.IndicatorSetStyle(2, stc.STC_INDIC_STRIKE)
  254.    
  255.  
  256. ed.IndicatorSetForeground(2, wx.RED)
  257.  
  258.     ed.StartStyling(836,
  259.  
  260. stc.STC_INDICS_MASK)
  261.     ed.SetStyling(10, stc.STC_INDIC0_MASK)
  262.    
  263.  
  264. ed.SetStyling(8, stc.STC_INDIC1_MASK)
  265.     ed.SetStyling(10,
  266.  
  267. stc.STC_INDIC2_MASK | stc.STC_INDIC1_MASK)
  268.  
  269.  
  270.     # some test
  271.  
  272. stuff...
  273.     if debug:
  274.         print "GetTextLength(): ",
  275.  
  276. ed.GetTextLength(), len(ed.GetText())
  277.         print "GetText(): ",
  278.  
  279. repr(ed.GetText())
  280.         print
  281.         print "GetStyledText(98,
  282.  
  283. 104): ", repr(ed.GetStyledText(98, 104)), len(ed.GetStyledText(98,
  284.  
  285. 104))
  286.         print
  287.         print "GetCurLine(): ",
  288.  
  289. repr(ed.GetCurLine())
  290.         ed.GotoPos(5)
  291.         print
  292.  
  293. "GetCurLine(): ", repr(ed.GetCurLine())
  294.         print
  295.         print
  296.  
  297. "GetLine(1): ", repr(ed.GetLine(1))
  298.         print
  299.        
  300.  
  301. ed.SetSelection(25, 35)
  302.         print "GetSelectedText(): ",
  303.  
  304. repr(ed.GetSelectedText())
  305.         print "GetTextRange(25, 35): ",
  306.  
  307. repr(ed.GetTextRange(25, 35))
  308.         print "FindText(0, max,
  309.  
  310. 'indicators'): ",
  311.         print ed.FindText(0, ed.GetTextLength(),
  312.  
  313. "indicators")
  314.         if wx.USE_UNICODE:
  315.             end =
  316.  
  317. ed.GetLength()
  318.             start = ed.PositionFromLine(uniline)
  319.      
  320.  
  321.        print "GetTextRange(%d, %d): " % (start, end),
  322.            
  323.  
  324. print repr(ed.GetTextRange(start, end))
  325.  
  326.  
  327.    
  328.  
  329. wx.CallAfter(ed.GotoPos, 0)
  330.     return p
  331.  
  332.  
  333.  
  334. #-------------------------------------------------------------------
  335.  
  336. ---
  337.  
  338.  
  339. overview = """\
  340. <html><body>
  341. Once again, no docs yet.  
  342.  
  343. <b>Sorry.</b>  But <a href="data/stc.h.html">this</a>
  344. and <a
  345.  
  346. href="http://www.scintilla.org/ScintillaDoc.html">this</a> should
  347. be
  348.  
  349. helpful.
  350. </body><html>
  351. """
  352.  
  353.  
  354. if __name__ == '__main__':
  355.     import
  356.  
  357. sys,os
  358.     import run
  359.     run.main(['',
  360.  
  361. os.path.basename(sys.argv[0])] + sys.argv[1:])
  #3 (permalink)  
Antiguo 25/02/2009, 19:43
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 16 años, 6 meses
Puntos: 1
Respuesta: ayuda!!! con codigo

run.py
Código pythom:
Ver original
  1. #!/usr/bin/env python
  2. #----------------------------------------------------------------------------
  3. # Name:         run.py
  4. # Purpose:      Simple framework for running individual demos
  5. #
  6. # Author:       Robin Dunn
  7. #
  8. # Created:      6-March-2000
  9. # RCS-ID:       $Id: run.py 53286 2008-04-21 15:33:51Z RD $
  10. # Copyright:    (c) 2000 by Total Control Software
  11. # Licence:      wxWindows license
  12. #----------------------------------------------------------------------------
  13.  
  14. """
  15. This program will load and run one of the individual demos in this
  16. directory within its own frame window.  Just specify the module name
  17. on the command line.
  18. """
  19.  
  20. import wx
  21. import wx.lib.inspection
  22. import wx.lib.mixins.inspection
  23. import sys, os
  24.  
  25. # stuff for debugging
  26. print "wx.version:", wx.version()
  27. print "pid:", os.getpid()
  28. ##raw_input("Press Enter...")
  29.  
  30. assertMode = wx.PYAPP_ASSERT_DIALOG
  31. ##assertMode = wx.PYAPP_ASSERT_EXCEPTION
  32.  
  33.  
  34. #----------------------------------------------------------------------------
  35.  
  36. class Log:
  37.     def WriteText(self, text):
  38.         if text[-1:] == '\n':
  39.             text = text[:-1]
  40.         wx.LogMessage(text)
  41.     write = WriteText
  42.  
  43.  
  44. class RunDemoApp(wx.App, wx.lib.mixins.inspection.InspectionMixin):
  45.     def __init__(self, name, module, useShell):
  46.         self.name = name
  47.         self.demoModule = module
  48.         self.useShell = useShell
  49.         wx.App.__init__(self, redirect=False)
  50.  
  51.  
  52.     def OnInit(self):
  53.         wx.Log_SetActiveTarget(wx.LogStderr())
  54.  
  55.         self.SetAssertMode(assertMode)
  56.         self.Init()  # InspectionMixin
  57.  
  58.         frame = wx.Frame(None, -1, "RunDemo: " + self.name, pos=(50,50), size=(200,100),
  59.                         style=wx.DEFAULT_FRAME_STYLE, name="run a sample")
  60.         frame.CreateStatusBar()
  61.  
  62.         menuBar = wx.MenuBar()
  63.         menu = wx.Menu()
  64.         item = menu.Append(-1, "&Widget Inspector\tF6", "Show the wxPython Widget Inspection Tool")
  65.         self.Bind(wx.EVT_MENU, self.OnWidgetInspector, item)
  66.         item = menu.Append(-1, "E&xit\tCtrl-Q", "Exit demo")
  67.         self.Bind(wx.EVT_MENU, self.OnExitApp, item)
  68.         menuBar.Append(menu, "&File")
  69.  
  70.         ns = {}
  71.         ns['wx'] = wx
  72.         ns['app'] = self
  73.         ns['module'] = self.demoModule
  74.         ns['frame'] = frame
  75.        
  76.         frame.SetMenuBar(menuBar)
  77.         frame.Show(True)
  78.         frame.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
  79.  
  80.         win = self.demoModule.runTest(frame, frame, Log())
  81.  
  82.         # a window will be returned if the demo does not create
  83.         # its own top-level window
  84.         if win:
  85.             # so set the frame to a good size for showing stuff
  86.             frame.SetSize((640, 480))
  87.             win.SetFocus()
  88.             self.window = win
  89.             ns['win'] = win
  90.             frect = frame.GetRect()
  91.  
  92.         else:
  93.             # It was probably a dialog or something that is already
  94.             # gone, so we're done.
  95.             frame.Destroy()
  96.             return True
  97.  
  98.         self.SetTopWindow(frame)
  99.         self.frame = frame
  100.         #wx.Log_SetActiveTarget(wx.LogStderr())
  101.         #wx.Log_SetTraceMask(wx.TraceMessages)
  102.  
  103.         if self.useShell:
  104.             # Make a PyShell window, and position it below our test window
  105.             from wx import py
  106.             shell = py.shell.ShellFrame(None, locals=ns)
  107.             frect.OffsetXY(0, frect.height)
  108.             frect.height = 400
  109.             shell.SetRect(frect)
  110.             shell.Show()
  111.  
  112.             # Hook the close event of the test window so that we close
  113.             # the shell at the same time
  114.             def CloseShell(evt):
  115.                 if shell:
  116.                     shell.Close()
  117.                 evt.Skip()
  118.             frame.Bind(wx.EVT_CLOSE, CloseShell)
  119.                    
  120.         return True
  121.  
  122.  
  123.     def OnExitApp(self, evt):
  124.         self.frame.Close(True)
  125.  
  126.  
  127.     def OnCloseFrame(self, evt):
  128.         if hasattr(self, "window") and hasattr(self.window, "ShutdownDemo"):
  129.             self.window.ShutdownDemo()
  130.         evt.Skip()
  131.  
  132.     def OnWidgetInspector(self, evt):
  133.         wx.lib.inspection.InspectionTool().Show()
  134.    
  135.  
  136. #----------------------------------------------------------------------------
  137.  
  138.  
  139. def main(argv):
  140.     useShell = False
  141.     for x in range(len(sys.argv)):
  142.         if sys.argv[x] in ['--shell', '-shell', '-s']:
  143.             useShell = True
  144.             del sys.argv[x]
  145.             break
  146.            
  147.     if len(argv) < 2:
  148.         print "Please specify a demo module name on the command-line"
  149.         raise SystemExit
  150.  
  151.     name, ext  = os.path.splitext(argv[1])
  152.     module = __import__(name)
  153.  
  154.  
  155.     app = RunDemoApp(name, module, useShell)
  156.     app.MainLoop()
  157.  
  158.  
  159.  
  160. if __name__ == "__main__":
  161.     main(sys.argv)
  #4 (permalink)  
Antiguo 28/02/2009, 20:20
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 16 años, 6 meses
Puntos: 1
Respuesta: ayuda!!! con codigo

ya intente hacerlo pero me han salido unos errores

Código python:
Ver original
  1. import wx
  2. import wx.stc as stc
  3.  
  4.  
  5.  
  6. class Log:
  7.     def WriteText(self, text):
  8.         if text[-1:] == '\n':
  9.             text = text[:-1]
  10.         wx.LogMessage(text)
  11.     write = WriteText
  12. debug = 1
  13. log = Log
  14.  
  15. class Style(stc.StyledTextCtrl):
  16.     def __init__(self, parent, id):
  17.         stc.StyledTextCtrl.__init__(self, parent, id)
  18.         self.log = log
  19.  
  20.        
  21.         self.Bind(stc.EVT_STC_DO_DROP, self.OnDoDrop)
  22.         self.Bind(stc.EVT_STC_DRAG_OVER, self.OnDragOver)
  23.         self.Bind(stc.EVT_STC_START_DRAG, self.OnStartDrag)
  24.         self.Bind(stc.EVT_STC_MODIFIED, self.OnModified)
  25.  
  26.  
  27.  
  28.     def OnStartDrag(self, evt):
  29.         self.log.write("OnStartDrag: %d, %s\n"
  30.                        % (evt.GetDragAllowMove(), evt.GetDragText()))
  31.  
  32.         if debug and evt.GetPosition() < 250:
  33.             evt.SetDragAllowMove(False)     # you can prevent moving of text (only copy)
  34.             evt.SetDragText("DRAGGED TEXT") # you can change what is dragged
  35.            
  36.     def OnDragOver(self, evt):
  37.         self.log.write(
  38.             "OnDrag: x,y=(%d, %d)  pos: %d  DragResult: %d\n"
  39.             % (evt.GetX(), evt.GetY(), evt.GetPosition(), evt.GetDragResult())
  40.             )
  41.  
  42.         if debug and evt.GetPosition() < 250:
  43.             evt.SetDragResult(wx.DragNone)
  44.            
  45.     def OnDoDrop(self, evt):
  46.         self.log.write("OnDrop: x,y=(%d, %d) pos: %d DragResult: %d\n" "\ttext: %s\n"
  47.                        % (evt.GetX(), evt.GetY(), evt.GetPosition(), evt.GetDragResult(),
  48.                           evt.GetDragText()))
  49.         if debug and evt.GetPosition() < 500:
  50.             evt.SetDragText("DROPPED TEXT")
  51.  
  52.     def OnModified(self, evt):
  53.         self.log.write("""OnModified
  54.        Mod type:     %s
  55.        At position:  %d
  56.        Lines added:  %d
  57.        Text Length:  %d
  58.        Text:         %s\n""" % ( self.transModType(evt.GetModificationType()),
  59.                                   evt.GetPosition(),
  60.                                   evt.GetLinesAdded(),
  61.                                   evt.GetLength(),
  62.                                   repr(evt.GetText() )))
  63.  
  64.     def transModType(self, modType):
  65.         st = ""
  66.         table = [(stc.STC_MOD_INSERTTEXT, "InsertText"),
  67.                  (stc.STC_MOD_DELETETEXT, "DeleteText"),
  68.                  (stc.STC_MOD_CHANGESTYLE, "ChangeStyle"),
  69.                  (stc.STC_MOD_CHANGEFOLD, "ChangeFold"),
  70.                  (stc.STC_PERFORMED_USER, "UserFlag"),
  71.                  (stc.STC_PERFORMED_UNDO, "Undo"),
  72.                  (stc.STC_PERFORMED_REDO, "Redo"),
  73.                  (stc.STC_LASTSTEPINUNDOREDO, "Last-Undo/Redo"),
  74.                  (stc.STC_MOD_CHANGEMARKER, "ChangeMarker"),
  75.                  (stc.STC_MOD_BEFOREINSERT, "B4-Insert"),
  76.                  (stc.STC_MOD_BEFOREDELETE, "B4-Delete")
  77.                  ]
  78.  
  79.         for flag,text in table:
  80.             if flag & modType:
  81.                 st = st + text + " "
  82.  
  83.         if not st:
  84.             st = 'UNKNOWN'
  85.  
  86.         return st
  87.    
  88.    
  89.  
  90. class Mystyle(wx.Frame):
  91.     def __init__(self, parent, id, title):
  92.         wx.Frame.__init__(self, parent, id, title)
  93.  
  94.         style = Style(self, -1)
  95.  
  96.         self.Show(True)
  97.  
  98. app = wx.App()
  99. Mystyle( None, -1, "stylado")
  100. app.MainLoop()

aver si lo pueden probar y decirme porque no funciona que es el str que me falta
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:24.