<s> """<STR_LIT>""" <EOL> from os import listdir , stat <EOL> from os . path import basename , isdir , join <EOL> from time import localtime , strftime <EOL> from pyface . api import ImageResource <EOL> from pyface . viewer . api import TableColumnProvider , TableContentProvider <EOL> from pyface . viewer . api import TableLabelProvider , TableViewer <EOL> from traits . api import Instance , Str <EOL> class FileTableContentProvider ( TableContentProvider ) : <EOL> """<STR_LIT>""" <EOL> def get_elements ( self , element ) : <EOL> """<STR_LIT>""" <EOL> if isdir ( element ) : <EOL> elements = [ <EOL> join ( element , filename ) for filename in listdir ( element ) <EOL> ] <EOL> else : <EOL> elements = [ ] <EOL> return elements <EOL> class FileTableLabelProvider ( TableLabelProvider ) : <EOL> """<STR_LIT>""" <EOL> FOLDER = ImageResource ( '<STR_LIT>' ) <EOL> DOCUMENT = ImageResource ( '<STR_LIT>' ) <EOL> def get_image ( self , viewer , element , column_index = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if isdir ( element ) : <EOL> image = self . FOLDER <EOL> else : <EOL> image = self . DOCUMENT <EOL> return image <EOL> def get_text ( self , viewer , element , column_index = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> details = stat ( element ) <EOL> if column_index == <NUM_LIT:0> : <EOL> label = basename ( element ) <EOL> elif column_index == <NUM_LIT:1> : <EOL> label = str ( int ( details . st_size ) / <NUM_LIT:1000> ) + '<STR_LIT>' <EOL> else : <EOL> label = strftime ( '<STR_LIT>' , localtime ( details . st_mtime ) ) <EOL> return label <EOL> class FileTableColumnProvider ( TableColumnProvider ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _column_labels = [ '<STR_LIT:Name>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . column_count = len ( self . _column_labels ) <EOL> return <EOL> def get_label ( self , viewer , column_index ) : <EOL> """<STR_LIT>""" <EOL> return self . _column_labels [ column_index ] <EOL> def get_alignment ( self , viewer , column_index ) : <EOL> """<STR_LIT>""" <EOL> if column_index == <NUM_LIT:1> : <EOL> alignment = '<STR_LIT:right>' <EOL> else : <EOL> alignment = '<STR_LIT:left>' <EOL> return alignment <EOL> class FileTableViewer ( TableViewer ) : <EOL> """<STR_LIT>""" <EOL> column_provider = Instance ( FileTableColumnProvider , ( ) ) <EOL> content_provider = Instance ( FileTableContentProvider , ( ) ) <EOL> label_provider = Instance ( FileTableLabelProvider , ( ) ) </s>
