<s> """<STR_LIT>""" <EOL> __license__ = "<STR_LIT>" <EOL> import sys <EOL> from PyQt4 import QtCore , QtGui <EOL> from PyQt4 . QtCore import Qt <EOL> from PyQt4 . Qsci import QsciScintilla , QsciLexerPython <EOL> from PyQt4 . QtGui import QApplication <EOL> from PyQt4 . QtCore import QThread , QEvent <EOL> RedirectionEventId = QEvent . User + <NUM_LIT:100> <EOL> sys_stderr = None <EOL> sys_stdout = None <EOL> sys_stdin = None <EOL> try : <EOL> import openalea . lpy . gui . py2exe_release <EOL> py2exe_release = True <EOL> except : <EOL> py2exe_release = False <EOL> class MultipleRedirection : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * streams ) : <EOL> """<STR_LIT>""" <EOL> self . streams = streams <EOL> def write ( self , str ) : <EOL> """<STR_LIT>""" <EOL> for stream in self . streams : <EOL> stream . write ( str ) <EOL> class ThreadedRedirection : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , guistream ) : <EOL> """<STR_LIT>""" <EOL> self . guistream = guistream <EOL> def write ( self , str ) : <EOL> """<STR_LIT>""" <EOL> if self . guistream . thread ( ) != QThread . currentThread ( ) : <EOL> sys_stdout . write ( str ) <EOL> e = QEvent ( QEvent . Type ( RedirectionEventId ) ) <EOL> e . txt = str <EOL> QApplication . postEvent ( self . guistream , e ) <EOL> pass <EOL> else : <EOL> self . guistream . write ( str ) <EOL> class GraphicalStreamRedirection : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> global sys_stdout , sys_stderr , sys_stdin <EOL> if sys_stdout is None : sys_stdout = sys . stdout <EOL> if sys_stderr is None : sys_stderr = sys . stderr <EOL> if sys_stdin is None : sys_stdin = sys . stdin <EOL> sys . stdout = ThreadedRedirection ( self ) <EOL> if py2exe_release : <EOL> sys . stderr = ThreadedRedirection ( self ) <EOL> else : <EOL> sys . stderr = MultipleRedirection ( sys_stderr , ThreadedRedirection ( self ) ) <EOL> sys . stdin = self <EOL> def __del__ ( self ) : <EOL> sys . stdout = sys_stdout <EOL> sys . stderr = sys_stderr <EOL> sys . stdin = sys_stdin <EOL> def customEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if event . type ( ) == RedirectionEventId : <EOL> self . write ( event . txt ) <EOL> def multipleRedirection ( self , enabled ) : <EOL> self . multipleStdErrRedirection ( enabled ) <EOL> self . multipleStdOutRedirection ( enabled ) <EOL> def multipleStdOutRedirection ( self , enabled = True ) : <EOL> """<STR_LIT>""" <EOL> if enabled : <EOL> sys . stdout = MultipleRedirection ( sys_stdout , ThreadedRedirection ( self ) ) <EOL> else : <EOL> sys . stdout = sys_stdout <EOL> def multipleStdErrRedirection ( self , enabled = True ) : <EOL> """<STR_LIT>""" <EOL> if enabled : <EOL> sys . stderr = MultipleRedirection ( sys_stderr , ThreadedRedirection ( self ) ) <EOL> else : <EOL> sys . stderr = sys_stderr <EOL> class SciShell ( QsciScintilla , GraphicalStreamRedirection ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , interpreter , message = "<STR_LIT>" , log = '<STR_LIT>' , parent = None ) : <EOL> """<STR_LIT>""" <EOL> QsciScintilla . __init__ ( self , parent ) <EOL> GraphicalStreamRedirection . __init__ ( self ) <EOL> self . interpreter = interpreter <EOL> self . setAutoIndent ( True ) <EOL> self . setAutoCompletionThreshold ( <NUM_LIT:2> ) <EOL> self . setAutoCompletionSource ( QsciScintilla . AcsDocument ) <EOL> self . setLexer ( QsciLexerPython ( self ) ) <EOL> self . incrementalSearchString = "<STR_LIT>" <EOL> self . incrementalSearchActive = False <EOL> self . inRawMode = False <EOL> self . echoInput = True <EOL> self . historyLists = { } <EOL> self . maxHistoryEntries = <NUM_LIT:30> <EOL> self . _history = [ ] <EOL> self . histidx = - <NUM_LIT:1> <EOL> self . reading = <NUM_LIT:0> <EOL> try : <EOL> sys . ps1 <EOL> except AttributeError : <EOL> sys . ps1 = "<STR_LIT>" <EOL> try : <EOL> sys . ps2 <EOL> except AttributeError : <EOL> sys . ps2 = "<STR_LIT>" <EOL> self . more = False <EOL> self . execlines = [ ] <EOL> self . write ( '<STR_LIT>' % <EOL> ( sys . version , sys . platform ) ) <EOL> self . write ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . write ( message + '<STR_LIT:\n>' ) <EOL> self . write ( "<STR_LIT>" ) <EOL> self . write ( sys . ps1 ) <EOL> self . keymap = { <EOL> Qt . Key_Backspace : self . __QScintillaDeleteBack , <EOL> Qt . Key_Delete : self . __QScintillaDelete , <EOL> Qt . Key_Return : self . __QScintillaNewline , <EOL> Qt . Key_Enter : self . __QScintillaNewline , <EOL> Qt . Key_Tab : self . __QScintillaTab , <EOL> Qt . Key_Left : self . __QScintillaCharLeft , <EOL> Qt . Key_Right : self . __QScintillaCharRight , <EOL> Qt . Key_Up : self . __QScintillaLineUp , <EOL> Qt . Key_Down : self . __QScintillaLineDown , <EOL> Qt . Key_Home : self . __QScintillaVCHome , <EOL> Qt . Key_End : self . __QScintillaLineEnd , <EOL> } <EOL> self . connect ( self , QtCore . SIGNAL ( '<STR_LIT>' ) , <EOL> self . __completionListSelected ) <EOL> self . setFocus ( ) <EOL> self . setFocusPolicy ( QtCore . Qt . StrongFocus ) <EOL> def customEvent ( self , event ) : <EOL> GraphicalStreamRedirection . customEvent ( self , event ) <EOL> QsciScintilla . customEvent ( self , event ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> QsciScintilla . clear ( self ) <EOL> def get_interpreter ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . interpreter <EOL> def flush ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def isatty ( self ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT:1> <EOL> def readline ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reading = <NUM_LIT:1> <EOL> line , col = self . __getEndPos ( ) <EOL> self . setCursorPosition ( line , col ) <EOL> buf = "<STR_LIT>" <EOL> if len ( buf ) == <NUM_LIT:0> : <EOL> return '<STR_LIT:\n>' <EOL> else : <EOL> return buf <EOL> def write ( self , s ) : <EOL> """<STR_LIT>""" <EOL> line , col = self . __getEndPos ( ) <EOL> self . setCursorPosition ( line , col ) <EOL> self . insert ( s ) <EOL> line , col = self . __getEndPos ( ) <EOL> self . setCursorPosition ( line , col ) <EOL> self . prline , self . prcol = self . getCursorPosition ( ) <EOL> self . ensureCursorVisible ( ) <EOL> self . ensureLineVisible ( line ) <EOL> def __getEndPos ( self ) : <EOL> """<STR_LIT>""" <EOL> line = self . lines ( ) - <NUM_LIT:1> <EOL> return ( line , self . lineLength ( line ) ) <EOL> def paste ( self ) : <EOL> """<STR_LIT>""" <EOL> lines = unicode ( QtGui . QApplication . clipboard ( ) . text ( ) ) <EOL> self . __executeLines ( lines ) <EOL> def __middleMouseButton ( self ) : <EOL> """<STR_LIT>""" <EOL> lines = unicode ( QtGui . QApplication . clipboard ( ) . text ( <EOL> QtGui . QClipboard . Selection ) ) <EOL> self . __executeLines ( lines ) <EOL> def __executeLines ( self , lines ) : <EOL> """<STR_LIT>""" <EOL> for line in lines . splitlines ( True ) : <EOL> if line . endswith ( "<STR_LIT:\r\n>" ) : <EOL> fullline = True <EOL> cmd = line [ : - <NUM_LIT:2> ] <EOL> elif line . endswith ( "<STR_LIT:\r>" ) or line . endswith ( "<STR_LIT:\n>" ) : <EOL> fullline = True <EOL> cmd = line [ : - <NUM_LIT:1> ] <EOL> else : <EOL> fullline = False <EOL> self . __insertTextAtEnd ( line ) <EOL> if fullline : <EOL> self . __executeCommand ( cmd ) <EOL> def __executeCommand ( self , cmd ) : <EOL> """<STR_LIT>""" <EOL> if not cmd : cmd = '<STR_LIT>' <EOL> else : <EOL> if len ( self . _history ) == self . maxHistoryEntries : <EOL> del self . _history [ <NUM_LIT:0> ] <EOL> self . _history . append ( QtCore . QString ( cmd ) ) <EOL> self . histidx = - <NUM_LIT:1> <EOL> if ( cmd . endswith ( '<STR_LIT:?>' ) ) : <EOL> self . __showHelp ( cmd ) <EOL> return <EOL> self . execlines . append ( str ( cmd ) ) <EOL> source = '<STR_LIT:\n>' . join ( self . execlines ) <EOL> self . more = self . interpreter . runsource ( source ) <EOL> if self . more : <EOL> self . write ( sys . ps2 ) <EOL> else : <EOL> self . write ( sys . ps1 ) <EOL> self . execlines = [ ] <EOL> def __insertText ( self , s ) : <EOL> """<STR_LIT>""" <EOL> line , col = self . getCursorPosition ( ) <EOL> self . insertAt ( s , line , col ) <EOL> self . setCursorPosition ( line , col + len ( str ( s ) ) ) <EOL> def __insertTextAtEnd ( self , s ) : <EOL> """<STR_LIT>""" <EOL> line , col = self . __getEndPos ( ) <EOL> self . setCursorPosition ( line , col ) <EOL> self . insert ( s ) <EOL> self . prline , self . prcol = self . __getEndPos ( ) <EOL> self . setCursorPosition ( self . prline , self . prcol ) <EOL> def __isCursorOnLastLine ( self ) : <EOL> """<STR_LIT>""" <EOL> cline , ccol = self . getCursorPosition ( ) <EOL> return cline == self . lines ( ) - <NUM_LIT:1> <EOL> def contextMenuEvent ( self , e ) : <EOL> pass <EOL> def mousePressEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> self . setFocus ( ) <EOL> if event . button ( ) == Qt . MidButton : <EOL> self . __middleMouseButton ( ) <EOL> else : <EOL> QsciScintilla . mousePressEvent ( self , event ) <EOL> def keyPressEvent ( self , ev ) : <EOL> """<STR_LIT>""" <EOL> txt = ev . text ( ) <EOL> key = ev . key ( ) <EOL> ctrl = ev . modifiers ( ) & Qt . ControlModifier <EOL> shift = ev . modifiers ( ) & Qt . ShiftModifier <EOL> if ( self . keymap . has_key ( key ) and not shift and not ctrl ) : <EOL> self . keymap [ key ] ( ) <EOL> elif ev == QtGui . QKeySequence . Paste : <EOL> self . paste ( ) <EOL> elif self . __isCursorOnLastLine ( ) and txt . length ( ) : <EOL> QsciScintilla . keyPressEvent ( self , ev ) <EOL> self . incrementalSearchActive = True <EOL> if ( txt == '<STR_LIT:.>' ) : <EOL> self . __showDynCompletion ( ) <EOL> elif ( ctrl or shift ) : <EOL> QsciScintilla . keyPressEvent ( self , ev ) <EOL> else : <EOL> ev . ignore ( ) <EOL> def __QScintillaTab ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . isListActive ( ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_TAB ) <EOL> elif self . __isCursorOnLastLine ( ) : <EOL> line , index = self . getCursorPosition ( ) <EOL> buf = unicode ( self . text ( line ) ) . replace ( sys . ps1 , "<STR_LIT>" ) . replace ( sys . ps2 , "<STR_LIT>" ) <EOL> if self . more and not buf [ : index - len ( sys . ps2 ) ] . strip ( ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_TAB ) <EOL> def __QScintillaDeleteBack ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __isCursorOnLastLine ( ) : <EOL> line , col = self . getCursorPosition ( ) <EOL> ac = self . isListActive ( ) <EOL> oldLength = self . text ( line ) . length ( ) <EOL> if self . text ( line ) . startsWith ( sys . ps1 ) : <EOL> if col > len ( sys . ps1 ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_DELETEBACK ) <EOL> elif self . text ( line ) . startsWith ( sys . ps2 ) : <EOL> if col > len ( sys . ps2 ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_DELETEBACK ) <EOL> elif col > <NUM_LIT:0> : <EOL> self . SendScintilla ( QsciScintilla . SCI_DELETEBACK ) <EOL> def __QScintillaDelete ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __isCursorOnLastLine ( ) : <EOL> if self . hasSelectedText ( ) : <EOL> lineFrom , indexFrom , lineTo , indexTo = self . getSelection ( ) <EOL> if self . text ( lineFrom ) . startsWith ( sys . ps1 ) : <EOL> if indexFrom >= len ( sys . ps1 ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_CLEAR ) <EOL> elif self . text ( lineFrom ) . startsWith ( sys . ps2 ) : <EOL> if indexFrom >= len ( sys . ps2 ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_CLEAR ) <EOL> elif indexFrom >= <NUM_LIT:0> : <EOL> self . SendScintilla ( QsciScintilla . SCI_CLEAR ) <EOL> self . setSelection ( lineTo , indexTo , lineTo , indexTo ) <EOL> else : <EOL> self . SendScintilla ( QsciScintilla . SCI_CLEAR ) <EOL> def __QScintillaNewline ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __isCursorOnLastLine ( ) : <EOL> if self . isListActive ( ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_NEWLINE ) <EOL> elif self . reading : <EOL> self . reading = <NUM_LIT:0> <EOL> else : <EOL> self . incrementalSearchString = "<STR_LIT>" <EOL> self . incrementalSearchActive = False <EOL> line , col = self . __getEndPos ( ) <EOL> self . setCursorPosition ( line , col ) <EOL> buf = unicode ( self . text ( line ) ) . replace ( sys . ps1 , "<STR_LIT>" ) . replace ( sys . ps2 , "<STR_LIT>" ) <EOL> self . insert ( '<STR_LIT:\n>' ) <EOL> self . __executeCommand ( buf ) <EOL> else : <EOL> s = self . selectedText ( ) <EOL> self . __insertTextAtEnd ( s ) <EOL> def __QScintillaCharLeft ( self , allLinesAllowed = False ) : <EOL> """<STR_LIT>""" <EOL> if self . __isCursorOnLastLine ( ) or allLinesAllowed : <EOL> line , col = self . getCursorPosition ( ) <EOL> if self . text ( line ) . startsWith ( sys . ps1 ) : <EOL> if col > len ( sys . ps1 ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_CHARLEFT ) <EOL> elif self . text ( line ) . startsWith ( sys . ps2 ) : <EOL> if col > len ( sys . ps2 ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_CHARLEFT ) <EOL> elif col > <NUM_LIT:0> : <EOL> self . SendScintilla ( QsciScintilla . SCI_CHARLEFT ) <EOL> def __QScintillaCharRight ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __isCursorOnLastLine ( ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_CHARRIGHT ) <EOL> def __QScintillaVCHome ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . isListActive ( ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_VCHOME ) <EOL> elif self . __isCursorOnLastLine ( ) : <EOL> line , col = self . getCursorPosition ( ) <EOL> if self . text ( line ) . startsWith ( sys . ps1 ) : <EOL> col = len ( sys . ps1 ) <EOL> elif self . text ( line ) . startsWith ( sys . ps2 ) : <EOL> col = len ( sys . ps2 ) <EOL> else : <EOL> col = <NUM_LIT:0> <EOL> self . setCursorPosition ( line , col ) <EOL> def __QScintillaLineEnd ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . isListActive ( ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_LINEEND ) <EOL> elif self . __isCursorOnLastLine ( ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_LINEEND ) <EOL> def __QScintillaLineUp ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . isListActive ( ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_LINEUP ) <EOL> else : <EOL> line , col = self . __getEndPos ( ) <EOL> buf = unicode ( self . text ( line ) ) . replace ( sys . ps1 , "<STR_LIT>" ) . replace ( sys . ps2 , "<STR_LIT>" ) <EOL> if buf and self . incrementalSearchActive : <EOL> if self . incrementalSearchString : <EOL> idx = self . __rsearchHistory ( self . incrementalSearchString , <EOL> self . histidx ) <EOL> if idx >= <NUM_LIT:0> : <EOL> self . histidx = idx <EOL> self . __useHistory ( ) <EOL> else : <EOL> idx = self . __rsearchHistory ( buf ) <EOL> if idx >= <NUM_LIT:0> : <EOL> self . histidx = idx <EOL> self . incrementalSearchString = buf <EOL> self . __useHistory ( ) <EOL> else : <EOL> if self . histidx < <NUM_LIT:0> : <EOL> self . histidx = len ( self . _history ) <EOL> if self . histidx > <NUM_LIT:0> : <EOL> self . histidx = self . histidx - <NUM_LIT:1> <EOL> self . __useHistory ( ) <EOL> def __QScintillaLineDown ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . isListActive ( ) : <EOL> self . SendScintilla ( QsciScintilla . SCI_LINEDOWN ) <EOL> else : <EOL> line , col = self . __getEndPos ( ) <EOL> buf = unicode ( self . text ( line ) ) . replace ( sys . ps1 , "<STR_LIT>" ) . replace ( sys . ps2 , "<STR_LIT>" ) <EOL> if buf and self . incrementalSearchActive : <EOL> if self . incrementalSearchString : <EOL> idx = self . __searchHistory ( self . incrementalSearchString , self . histidx ) <EOL> if idx >= <NUM_LIT:0> : <EOL> self . histidx = idx <EOL> self . __useHistory ( ) <EOL> else : <EOL> idx = self . __searchHistory ( buf ) <EOL> if idx >= <NUM_LIT:0> : <EOL> self . histidx = idx <EOL> self . incrementalSearchString = buf <EOL> self . __useHistory ( ) <EOL> else : <EOL> if self . histidx >= <NUM_LIT:0> and self . histidx < len ( self . _history ) : <EOL> self . histidx += <NUM_LIT:1> <EOL> self . __useHistory ( ) <EOL> def __useHistory ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . histidx < len ( self . _history ) : <EOL> cmd = self . _history [ self . histidx ] <EOL> else : <EOL> cmd = QtCore . QString ( ) <EOL> self . incrementalSearchString = "<STR_LIT>" <EOL> self . incrementalSearchActive = False <EOL> self . setCursorPosition ( self . prline , self . prcol + len ( self . more and sys . ps1 or sys . ps2 ) ) <EOL> self . setSelection ( self . prline , self . prcol , self . prline , self . lineLength ( self . prline ) ) <EOL> self . removeSelectedText ( ) <EOL> self . __insertText ( cmd ) <EOL> def __searchHistory ( self , txt , startIdx = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if startIdx == - <NUM_LIT:1> : <EOL> idx = <NUM_LIT:0> <EOL> else : <EOL> idx = startIdx + <NUM_LIT:1> <EOL> while idx < len ( self . _history ) and not self . _history [ idx ] . startsWith ( txt ) : <EOL> idx += <NUM_LIT:1> <EOL> return idx <EOL> def __rsearchHistory ( self , txt , startIdx = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if startIdx == - <NUM_LIT:1> : <EOL> idx = len ( self . _history ) - <NUM_LIT:1> <EOL> else : <EOL> idx = startIdx - <NUM_LIT:1> <EOL> while idx >= <NUM_LIT:0> and not self . _history [ idx ] . startsWith ( txt ) : <EOL> idx -= <NUM_LIT:1> <EOL> return idx <EOL> def focusNextPrevChild ( self , next ) : <EOL> """<STR_LIT>""" <EOL> if next and self . more : <EOL> return False <EOL> return QsciScintilla . focusNextPrevChild ( self , next ) <EOL> def __get_current_line ( self ) : <EOL> """<STR_LIT>""" <EOL> line , col = self . __getEndPos ( ) <EOL> self . setCursorPosition ( line , col ) <EOL> buf = unicode ( self . text ( line ) ) . replace ( sys . ps1 , "<STR_LIT>" ) . replace ( sys . ps2 , "<STR_LIT>" ) <EOL> text = buf . split ( ) [ - <NUM_LIT:1> ] [ : - <NUM_LIT:1> ] <EOL> return text <EOL> def __showHelp ( self , text ) : <EOL> self . __executeCommand ( '<STR_LIT>' % ( text [ : - <NUM_LIT:1> ] , ) ) <EOL> def __showDynCompletion ( self ) : <EOL> """<STR_LIT>""" <EOL> text = self . __get_current_line ( ) <EOL> try : <EOL> locals = self . interpreter . locals <EOL> obj = eval ( text , globals ( ) , self . interpreter . locals ) <EOL> l = dir ( obj ) <EOL> self . __showCompletions ( l , text ) <EOL> except : pass <EOL> def __showCompletions ( self , tcompletions , text ) : <EOL> """<STR_LIT>""" <EOL> if len ( tcompletions ) == <NUM_LIT:0> : <EOL> return <EOL> completions = [ ] <EOL> for i , c in enumerate ( tcompletions ) : <EOL> if c [ <NUM_LIT:0> ] != "<STR_LIT:_>" : <EOL> completions . append ( c ) <EOL> if len ( completions ) > <NUM_LIT:1> : <EOL> completions . sort ( ) <EOL> comps = QtCore . QStringList ( ) <EOL> for comp in completions : <EOL> comps . append ( comp ) <EOL> self . showUserList ( <NUM_LIT:1> , comps ) <EOL> else : <EOL> txt = completions [ <NUM_LIT:0> ] <EOL> if text != "<STR_LIT>" : <EOL> txt = txt . replace ( text , "<STR_LIT>" ) <EOL> self . __insertText ( txt ) <EOL> def __completionListSelected ( self , id , txt ) : <EOL> """<STR_LIT>""" <EOL> line , col = self . __getEndPos ( ) <EOL> self . setCursorPosition ( line , col ) <EOL> buf = unicode ( self . text ( line ) ) <EOL> ind = len ( buf ) - buf . rfind ( "<STR_LIT:.>" ) - <NUM_LIT:1> <EOL> if id == <NUM_LIT:1> : <EOL> txt = unicode ( txt [ ind : ] ) <EOL> self . __insertText ( txt ) <EOL> def dragEnterEvent ( self , event ) : <EOL> event . setAccepted ( event . mimeData ( ) . hasFormat ( "<STR_LIT>" ) ) <EOL> def dragMoveEvent ( self , event ) : <EOL> if ( event . mimeData ( ) . hasFormat ( "<STR_LIT>" ) ) : <EOL> event . setDropAction ( QtCore . Qt . MoveAction ) <EOL> event . accept ( ) <EOL> else : <EOL> event . ignore ( ) <EOL> def dropEvent ( self , event ) : <EOL> if ( event . mimeData ( ) . hasFormat ( "<STR_LIT>" ) ) : <EOL> line = event . mimeData ( ) . text ( ) <EOL> self . __insertTextAtEnd ( line ) <EOL> self . setFocus ( ) <EOL> event . setDropAction ( QtCore . Qt . MoveAction ) <EOL> event . accept ( ) <EOL> else : <EOL> event . ignore ( ) <EOL> def main ( ) : <EOL> from code import InteractiveInterpreter as Interpreter <EOL> a = QtGui . QApplication ( sys . argv ) <EOL> import signal ; signal . signal ( signal . SIGINT , signal . SIG_DFL ) <EOL> interpreter = Interpreter ( ) <EOL> aw = SciShell ( interpreter ) <EOL> aw . resize ( <NUM_LIT> , <NUM_LIT> ) <EOL> aw . show ( ) <EOL> a . exec_ ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
