<s> import wx <EOL> import wx . stc as stc <EOL> import keyword <EOL> __version__ = <NUM_LIT:0.5> <EOL> __author__ = "<STR_LIT>" <EOL> __email__ = "<STR_LIT>" <EOL> __license__ = "<STR_LIT>" <EOL> class IPythonHistoryPanel ( wx . Panel ) : <EOL> def __init__ ( self , parent , flt_empty = True , <EOL> flt_doc = True , flt_cmd = True , flt_magic = True ) : <EOL> wx . Panel . __init__ ( self , parent , - <NUM_LIT:1> ) <EOL> text_ctrl = PythonSTC ( self , - <NUM_LIT:1> ) <EOL> st_filt = wx . StaticText ( self , - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . filter_empty = wx . CheckBox ( self , - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . filter_doc = wx . CheckBox ( self , - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . filter_cmd = wx . CheckBox ( self , - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . filter_magic = wx . CheckBox ( self , - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . options = { '<STR_LIT>' : { '<STR_LIT:value>' : '<STR_LIT:True>' , <EOL> '<STR_LIT>' : self . filter_empty , '<STR_LIT:True>' : True , '<STR_LIT:False>' : False , <EOL> '<STR_LIT>' : lambda x : None } , <EOL> '<STR_LIT>' : { '<STR_LIT:value>' : '<STR_LIT:True>' , <EOL> '<STR_LIT>' : self . filter_doc , '<STR_LIT:True>' : True , '<STR_LIT:False>' : False , <EOL> '<STR_LIT>' : lambda x : None } , <EOL> '<STR_LIT>' : { '<STR_LIT:value>' : '<STR_LIT:True>' , <EOL> '<STR_LIT>' : self . filter_cmd , '<STR_LIT:True>' : True , '<STR_LIT:False>' : False , <EOL> '<STR_LIT>' : lambda x : None } , <EOL> '<STR_LIT>' : { '<STR_LIT:value>' : '<STR_LIT:True>' , <EOL> '<STR_LIT>' : self . filter_magic , '<STR_LIT:True>' : True , '<STR_LIT:False>' : False , <EOL> '<STR_LIT>' : lambda x : None } , <EOL> } <EOL> self . reloadOptions ( self . options ) <EOL> self . filter_empty . Bind ( wx . EVT_CHECKBOX , self . evtCheckEmptyFilter ) <EOL> self . filter_doc . Bind ( wx . EVT_CHECKBOX , self . evtCheckDocFilter ) <EOL> self . filter_cmd . Bind ( wx . EVT_CHECKBOX , self . evtCheckCmdFilter ) <EOL> self . filter_magic . Bind ( wx . EVT_CHECKBOX , self . evtCheckMagicFilter ) <EOL> sizer = wx . BoxSizer ( wx . VERTICAL ) <EOL> sizer . Add ( text_ctrl , <NUM_LIT:1> , wx . EXPAND ) <EOL> sizer . AddMany ( [ ( <NUM_LIT:5> , <NUM_LIT:5> ) , <EOL> st_filt , <EOL> ( <NUM_LIT:10> , <NUM_LIT:10> ) , <EOL> self . filter_empty , <EOL> self . filter_doc , <EOL> self . filter_cmd , <EOL> self . filter_magic , <EOL> ( <NUM_LIT:10> , <NUM_LIT:10> ) , <EOL> ] ) <EOL> self . SetAutoLayout ( True ) <EOL> sizer . Fit ( self ) <EOL> sizer . SetSizeHints ( self ) <EOL> self . SetSizer ( sizer ) <EOL> self . text_ctrl = text_ctrl <EOL> text_ctrl . EmptyUndoBuffer ( ) <EOL> text_ctrl . Colourise ( <NUM_LIT:0> , - <NUM_LIT:1> ) <EOL> text_ctrl . SetMarginType ( <NUM_LIT:1> , stc . STC_MARGIN_NUMBER ) <EOL> text_ctrl . SetMarginWidth ( <NUM_LIT:1> , <NUM_LIT:15> ) <EOL> def write ( self , history_line ) : <EOL> add = True <EOL> if self . filter_empty . GetValue ( ) == True and history_line == '<STR_LIT>' : <EOL> add = False <EOL> if len ( history_line ) > <NUM_LIT:0> : <EOL> if self . filter_doc . GetValue ( ) == True and history_line [ - <NUM_LIT:1> : ] == '<STR_LIT:?>' : <EOL> add = False <EOL> if self . filter_cmd . GetValue ( ) == True and history_line [ <NUM_LIT:0> ] == '<STR_LIT:!>' : <EOL> add = False <EOL> if self . filter_magic . GetValue ( ) == True and history_line [ <NUM_LIT:0> ] == '<STR_LIT:%>' : <EOL> add = False <EOL> if add : <EOL> self . text_ctrl . AppendText ( history_line + '<STR_LIT:\n>' ) <EOL> def processOptionCheckedEvt ( self , event , name ) : <EOL> if event . IsChecked ( ) : <EOL> self . options [ name ] [ '<STR_LIT:value>' ] = '<STR_LIT:True>' <EOL> else : <EOL> self . options [ name ] [ '<STR_LIT:value>' ] = '<STR_LIT:False>' <EOL> self . updateOptionTracker ( name , <EOL> self . options [ name ] [ '<STR_LIT:value>' ] ) <EOL> def evtCheckEmptyFilter ( self , event ) : <EOL> self . processOptionCheckedEvt ( event , '<STR_LIT>' ) <EOL> def evtCheckDocFilter ( self , event ) : <EOL> self . processOptionCheckedEvt ( event , '<STR_LIT>' ) <EOL> def evtCheckCmdFilter ( self , event ) : <EOL> self . processOptionCheckedEvt ( event , '<STR_LIT>' ) <EOL> def evtCheckMagicFilter ( self , event ) : <EOL> self . processOptionCheckedEvt ( event , '<STR_LIT>' ) <EOL> def getOptions ( self ) : <EOL> return self . options <EOL> def reloadOptions ( self , options ) : <EOL> self . options = options <EOL> for key in list ( self . options . keys ( ) ) : <EOL> value = self . options [ key ] [ '<STR_LIT:value>' ] <EOL> self . options [ key ] [ '<STR_LIT>' ] . SetValue ( self . options [ key ] [ value ] ) <EOL> self . options [ key ] [ '<STR_LIT>' ] ( value ) <EOL> def updateOptionTracker ( self , name , value ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def setOptionTrackerHook ( self , func ) : <EOL> '''<STR_LIT>''' <EOL> self . updateOptionTracker = func <EOL> if wx . Platform == '<STR_LIT>' : <EOL> faces = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:8> , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> } <EOL> elif wx . Platform == '<STR_LIT>' : <EOL> faces = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:8> , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> } <EOL> else : <EOL> faces = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:size>' : <NUM_LIT:8> , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> } <EOL> class PythonSTC ( stc . StyledTextCtrl ) : <EOL> fold_symbols = <NUM_LIT:3> <EOL> def __init__ ( self , parent , ID , <EOL> pos = wx . DefaultPosition , size = wx . DefaultSize , <EOL> style = <NUM_LIT:0> ) : <EOL> stc . StyledTextCtrl . __init__ ( self , parent , ID , pos , size , style ) <EOL> self . SetLexer ( stc . STC_LEX_PYTHON ) <EOL> self . SetKeyWords ( <NUM_LIT:0> , "<STR_LIT:U+0020>" . join ( keyword . kwlist ) ) <EOL> self . SetEOLMode ( stc . STC_EOL_CRLF ) <EOL> self . SetEdgeMode ( stc . STC_EDGE_LINE ) <EOL> self . SetEdgeColumn ( <NUM_LIT> ) <EOL> self . SetEdgeColour ( wx . LIGHT_GREY ) <EOL> self . SetLayoutCache ( stc . STC_CACHE_PAGE ) <EOL> self . SetMarginType ( <NUM_LIT:2> , stc . STC_MARGIN_SYMBOL ) <EOL> self . SetMarginMask ( <NUM_LIT:2> , stc . STC_MASK_FOLDERS ) <EOL> self . SetMarginSensitive ( <NUM_LIT:2> , True ) <EOL> self . SetMarginWidth ( <NUM_LIT:2> , <NUM_LIT:12> ) <EOL> if self . fold_symbols == <NUM_LIT:0> : <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEROPEN , stc . STC_MARK_ARROWDOWN , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDER , stc . STC_MARK_ARROW , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERSUB , stc . STC_MARK_EMPTY , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERTAIL , stc . STC_MARK_EMPTY , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEREND , stc . STC_MARK_EMPTY , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEROPENMID , stc . STC_MARK_EMPTY , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERMIDTAIL , stc . STC_MARK_EMPTY , "<STR_LIT>" , "<STR_LIT>" ) <EOL> elif self . fold_symbols == <NUM_LIT:1> : <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEROPEN , stc . STC_MARK_MINUS , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDER , stc . STC_MARK_PLUS , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERSUB , stc . STC_MARK_EMPTY , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERTAIL , stc . STC_MARK_EMPTY , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEREND , stc . STC_MARK_EMPTY , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEROPENMID , stc . STC_MARK_EMPTY , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERMIDTAIL , stc . STC_MARK_EMPTY , "<STR_LIT>" , "<STR_LIT>" ) <EOL> elif self . fold_symbols == <NUM_LIT:2> : <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEROPEN , stc . STC_MARK_CIRCLEMINUS , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDER , stc . STC_MARK_CIRCLEPLUS , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERSUB , stc . STC_MARK_VLINE , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERTAIL , stc . STC_MARK_LCORNERCURVE , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEREND , stc . STC_MARK_CIRCLEPLUSCONNECTED , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEROPENMID , stc . STC_MARK_CIRCLEMINUSCONNECTED , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERMIDTAIL , stc . STC_MARK_TCORNERCURVE , "<STR_LIT>" , "<STR_LIT>" ) <EOL> elif self . fold_symbols == <NUM_LIT:3> : <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEROPEN , stc . STC_MARK_BOXMINUS , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDER , stc . STC_MARK_BOXPLUS , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERSUB , stc . STC_MARK_VLINE , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERTAIL , stc . STC_MARK_LCORNER , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEREND , stc . STC_MARK_BOXPLUSCONNECTED , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDEROPENMID , stc . STC_MARK_BOXMINUSCONNECTED , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . MarkerDefine ( stc . STC_MARKNUM_FOLDERMIDTAIL , stc . STC_MARK_TCORNER , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . Bind ( stc . EVT_STC_UPDATEUI , self . OnUpdateUI ) <EOL> self . Bind ( stc . EVT_STC_MARGINCLICK , self . OnMarginClick ) <EOL> self . Bind ( wx . EVT_KEY_DOWN , self . OnKeyPressed ) <EOL> self . StyleSetSpec ( stc . STC_STYLE_DEFAULT , "<STR_LIT>" % faces ) <EOL> self . StyleClearAll ( ) <EOL> self . StyleSetSpec ( stc . STC_STYLE_DEFAULT , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_STYLE_LINENUMBER , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_STYLE_CONTROLCHAR , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_STYLE_BRACELIGHT , "<STR_LIT>" ) <EOL> self . StyleSetSpec ( stc . STC_STYLE_BRACEBAD , "<STR_LIT>" ) <EOL> self . StyleSetSpec ( stc . STC_P_DEFAULT , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_COMMENTLINE , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_NUMBER , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_STRING , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_CHARACTER , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_WORD , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_TRIPLE , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_TRIPLEDOUBLE , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_CLASSNAME , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_DEFNAME , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_OPERATOR , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_IDENTIFIER , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_COMMENTBLOCK , "<STR_LIT>" % faces ) <EOL> self . StyleSetSpec ( stc . STC_P_STRINGEOL , "<STR_LIT>" % faces ) <EOL> self . SetCaretForeground ( "<STR_LIT>" ) <EOL> def OnKeyPressed ( self , event ) : <EOL> if self . CallTipActive ( ) : <EOL> self . CallTipCancel ( ) <EOL> key = event . GetKeyCode ( ) <EOL> if key == <NUM_LIT:32> and event . ControlDown ( ) : <EOL> pos = self . GetCurrentPos ( ) <EOL> if event . ShiftDown ( ) : <EOL> self . CallTipSetBackground ( "<STR_LIT>" ) <EOL> self . CallTipShow ( pos , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> kw = keyword . kwlist [ : ] <EOL> kw . sort ( ) <EOL> self . AutoCompSetIgnoreCase ( False ) <EOL> for i in range ( len ( kw ) ) : <EOL> if kw [ i ] in keyword . kwlist : <EOL> kw [ i ] = kw [ i ] <EOL> self . AutoCompShow ( <NUM_LIT:0> , "<STR_LIT:U+0020>" . join ( kw ) ) <EOL> else : <EOL> event . Skip ( ) <EOL> def OnUpdateUI ( self , evt ) : <EOL> braceAtCaret = - <NUM_LIT:1> <EOL> braceOpposite = - <NUM_LIT:1> <EOL> charBefore = None <EOL> caretPos = self . GetCurrentPos ( ) <EOL> if caretPos > <NUM_LIT:0> : <EOL> charBefore = self . GetCharAt ( caretPos - <NUM_LIT:1> ) <EOL> styleBefore = self . GetStyleAt ( caretPos - <NUM_LIT:1> ) <EOL> if charBefore and chr ( charBefore ) in "<STR_LIT>" and styleBefore == stc . STC_P_OPERATOR : <EOL> braceAtCaret = caretPos - <NUM_LIT:1> <EOL> if braceAtCaret < <NUM_LIT:0> : <EOL> charAfter = self . GetCharAt ( caretPos ) <EOL> styleAfter = self . GetStyleAt ( caretPos ) <EOL> if charAfter and chr ( charAfter ) in "<STR_LIT>" and styleAfter == stc . STC_P_OPERATOR : <EOL> braceAtCaret = caretPos <EOL> if braceAtCaret >= <NUM_LIT:0> : <EOL> braceOpposite = self . BraceMatch ( braceAtCaret ) <EOL> if braceAtCaret != - <NUM_LIT:1> and braceOpposite == - <NUM_LIT:1> : <EOL> self . BraceBadLight ( braceAtCaret ) <EOL> else : <EOL> self . BraceHighlight ( braceAtCaret , braceOpposite ) <EOL> def OnMarginClick ( self , evt ) : <EOL> if evt . GetMargin ( ) == <NUM_LIT:2> : <EOL> if evt . GetShift ( ) and evt . GetControl ( ) : <EOL> self . FoldAll ( ) <EOL> else : <EOL> lineClicked = self . LineFromPosition ( evt . GetPosition ( ) ) <EOL> if self . GetFoldLevel ( lineClicked ) & stc . STC_FOLDLEVELHEADERFLAG : <EOL> if evt . GetShift ( ) : <EOL> self . SetFoldExpanded ( lineClicked , True ) <EOL> self . Expand ( lineClicked , True , True , <NUM_LIT:1> ) <EOL> elif evt . GetControl ( ) : <EOL> if self . GetFoldExpanded ( lineClicked ) : <EOL> self . SetFoldExpanded ( lineClicked , False ) <EOL> self . Expand ( lineClicked , False , True , <NUM_LIT:0> ) <EOL> else : <EOL> self . SetFoldExpanded ( lineClicked , True ) <EOL> self . Expand ( lineClicked , True , True , <NUM_LIT:100> ) <EOL> else : <EOL> self . ToggleFold ( lineClicked ) <EOL> def FoldAll ( self ) : <EOL> lineCount = self . GetLineCount ( ) <EOL> expanding = True <EOL> for lineNum in range ( lineCount ) : <EOL> if self . GetFoldLevel ( lineNum ) & stc . STC_FOLDLEVELHEADERFLAG : <EOL> expanding = not self . GetFoldExpanded ( lineNum ) <EOL> break <EOL> lineNum = <NUM_LIT:0> <EOL> while lineNum < lineCount : <EOL> level = self . GetFoldLevel ( lineNum ) <EOL> if level & stc . STC_FOLDLEVELHEADERFLAG and ( level & stc . STC_FOLDLEVELNUMBERMASK ) == stc . STC_FOLDLEVELBASE : <EOL> if expanding : <EOL> self . SetFoldExpanded ( lineNum , True ) <EOL> lineNum = self . Expand ( lineNum , True ) <EOL> lineNum = lineNum - <NUM_LIT:1> <EOL> else : <EOL> lastChild = self . GetLastChild ( lineNum , - <NUM_LIT:1> ) <EOL> self . SetFoldExpanded ( lineNum , False ) <EOL> if lastChild > lineNum : <EOL> self . HideLines ( lineNum + <NUM_LIT:1> , lastChild ) <EOL> lineNum = lineNum + <NUM_LIT:1> <EOL> def Expand ( self , line , doExpand , force = False , visLevels = <NUM_LIT:0> , level = - <NUM_LIT:1> ) : <EOL> lastChild = self . GetLastChild ( line , level ) <EOL> line = line + <NUM_LIT:1> <EOL> while line <= lastChild : <EOL> if force : <EOL> if visLevels > <NUM_LIT:0> : <EOL> self . ShowLines ( line , line ) <EOL> else : <EOL> self . HideLines ( line , line ) <EOL> else : <EOL> if doExpand : <EOL> self . ShowLines ( line , line ) <EOL> if level == - <NUM_LIT:1> : <EOL> level = self . GetFoldLevel ( line ) <EOL> if level & stc . STC_FOLDLEVELHEADERFLAG : <EOL> if force : <EOL> if visLevels > <NUM_LIT:1> : <EOL> self . SetFoldExpanded ( line , True ) <EOL> else : <EOL> self . SetFoldExpanded ( line , False ) <EOL> line = self . Expand ( line , doExpand , force , visLevels - <NUM_LIT:1> ) <EOL> else : <EOL> if doExpand and self . GetFoldExpanded ( line ) : <EOL> line = self . Expand ( line , True , force , visLevels - <NUM_LIT:1> ) <EOL> else : <EOL> line = self . Expand ( line , False , force , visLevels - <NUM_LIT:1> ) <EOL> else : <EOL> line = line + <NUM_LIT:1> <EOL> return line </s>
