<s> import Tkinter as tk <EOL> import ttk <EOL> from rwb . widgets import AutoScrollbar <EOL> class RobotMessages ( ttk . Frame ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> ttk . Frame . __init__ ( self , * args , ** kwargs ) <EOL> self . _show_level = { <EOL> "<STR_LIT>" : tk . BooleanVar ( self , value = False ) , <EOL> "<STR_LIT>" : tk . BooleanVar ( self , value = True ) , <EOL> "<STR_LIT>" : tk . BooleanVar ( self , value = True ) , <EOL> "<STR_LIT>" : tk . BooleanVar ( self , value = True ) , <EOL> "<STR_LIT>" : tk . BooleanVar ( self , value = True ) , <EOL> "<STR_LIT>" : tk . BooleanVar ( self , value = True ) , <EOL> "<STR_LIT>" : tk . BooleanVar ( self , value = True ) , <EOL> } <EOL> option_frame = ttk . Frame ( self ) <EOL> ttk . Label ( option_frame , text = "<STR_LIT>" ) . pack ( side = "<STR_LIT:left>" , padx = ( <NUM_LIT:0> , <NUM_LIT:8> ) ) <EOL> for level in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> cb = ttk . Checkbutton ( option_frame , <EOL> text = level , <EOL> variable = self . _show_level [ level ] , <EOL> onvalue = True , <EOL> offvalue = False , <EOL> command = self . refresh ) <EOL> cb . pack ( side = "<STR_LIT:left>" , padx = ( <NUM_LIT:0> , <NUM_LIT:8> ) ) <EOL> self . tree = ttk . Treeview ( self , columns = ( "<STR_LIT>" , "<STR_LIT:time>" , "<STR_LIT:message>" ) , <EOL> displaycolumns = ( "<STR_LIT>" , "<STR_LIT:time>" , "<STR_LIT:message>" ) , <EOL> show = ( "<STR_LIT>" , ) ) <EOL> self . tree . heading ( "<STR_LIT>" , text = "<STR_LIT>" ) <EOL> self . tree . heading ( "<STR_LIT:time>" , text = "<STR_LIT>" ) <EOL> self . tree . heading ( "<STR_LIT:message>" , text = "<STR_LIT>" ) <EOL> self . tree . column ( "<STR_LIT>" , width = <NUM_LIT:100> , stretch = False ) <EOL> self . tree . column ( "<STR_LIT:time>" , width = <NUM_LIT:100> , stretch = False ) <EOL> self . tree . column ( "<STR_LIT:message>" , stretch = True ) <EOL> vsb = ttk . Scrollbar ( self , command = self . tree . yview , orient = "<STR_LIT>" ) <EOL> hsb = ttk . Scrollbar ( self , command = self . tree . xview , orient = "<STR_LIT>" ) <EOL> self . tree . configure ( xscrollcommand = hsb . set , yscrollcommand = vsb . set ) <EOL> self . tree . tag_configure ( "<STR_LIT>" , foreground = "<STR_LIT>" ) <EOL> self . tree . tag_configure ( "<STR_LIT>" , foreground = "<STR_LIT>" ) <EOL> self . tree . tag_configure ( "<STR_LIT>" , background = "<STR_LIT>" ) <EOL> self . tree . tag_configure ( "<STR_LIT>" , foreground = "<STR_LIT>" ) <EOL> self . tree . tag_configure ( "<STR_LIT>" , foreground = "<STR_LIT>" ) <EOL> self . tree . tag_configure ( "<STR_LIT>" , background = "<STR_LIT>" ) <EOL> self . _cache = [ ] <EOL> option_frame . grid ( row = <NUM_LIT:0> , column = <NUM_LIT:0> , columnspan = <NUM_LIT:2> , sticky = "<STR_LIT>" , pady = <NUM_LIT:4> ) <EOL> vsb . grid ( row = <NUM_LIT:1> , column = <NUM_LIT:1> , sticky = "<STR_LIT>" ) <EOL> hsb . grid ( row = <NUM_LIT:2> , column = <NUM_LIT:0> , sticky = "<STR_LIT>" ) <EOL> self . tree . grid ( row = <NUM_LIT:1> , column = <NUM_LIT:0> , sticky = "<STR_LIT>" ) <EOL> self . grid_rowconfigure ( <NUM_LIT:1> , weight = <NUM_LIT:1> ) <EOL> self . grid_columnconfigure ( <NUM_LIT:0> , weight = <NUM_LIT:1> ) <EOL> def reset ( self ) : <EOL> self . _cache = [ ] <EOL> for item in self . tree . get_children ( "<STR_LIT>" ) : <EOL> self . tree . delete ( item ) <EOL> def refresh ( self ) : <EOL> '''<STR_LIT>''' <EOL> for item in self . tree . get_children ( "<STR_LIT>" ) : <EOL> self . tree . delete ( item ) <EOL> for data in self . _cache : <EOL> self . _add_tree_item ( data ) <EOL> def _add_tree_item ( self , data ) : <EOL> level , timestamp , message , event_id = data <EOL> tags = ( level , ) <EOL> strings = message . split ( "<STR_LIT:\n>" ) <EOL> if self . _show_level [ level ] . get ( ) : <EOL> node = self . tree . insert ( "<STR_LIT>" , "<STR_LIT:end>" , <EOL> values = ( level , timestamp , strings [ <NUM_LIT:0> ] , ) , <EOL> open = False , <EOL> tags = tags ) <EOL> for string in strings [ <NUM_LIT:1> : ] : <EOL> node = self . tree . insert ( "<STR_LIT>" , "<STR_LIT:end>" , <EOL> values = ( "<STR_LIT>" , "<STR_LIT>" , string ) , <EOL> open = False , <EOL> tags = tags ) <EOL> self . tree . see ( node ) <EOL> def add ( self , event_id , attrs ) : <EOL> '''<STR_LIT>''' <EOL> time = attrs [ "<STR_LIT>" ] . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:1> ] <EOL> data = ( attrs [ "<STR_LIT>" ] , time , attrs [ "<STR_LIT:message>" ] , event_id ) <EOL> self . _cache . append ( data ) <EOL> self . _add_tree_item ( data ) </s>
