<s> """<STR_LIT>""" <EOL> import os <EOL> from pyface . qt import QtCore , QtGui <EOL> from pyface . image_resource import ImageResource <EOL> from traits . api import ( Any , Bool , Callable , Event , HasStrictTraits , Instance , <EOL> Int , List , NO_COMPARE , Property , TraitListEvent ) <EOL> from traitsui . tabular_adapter import TabularAdapter <EOL> from traitsui . ui_traits import Image <EOL> from editor import Editor <EOL> from tabular_model import TabularModel <EOL> TRAITS_DEBUG = ( os . getenv ( '<STR_LIT>' ) is not None ) <EOL> class HeaderEventFilter ( QtCore . QObject ) : <EOL> def __init__ ( self , editor ) : <EOL> super ( HeaderEventFilter , self ) . __init__ ( ) <EOL> self . editor = editor <EOL> def eventFilter ( self , obj , event ) : <EOL> if event . type ( ) == QtCore . QEvent . ContextMenu : <EOL> self . editor . _on_column_context_menu ( event . pos ( ) ) <EOL> return True <EOL> return False <EOL> class TabularEditor ( Editor ) : <EOL> """<STR_LIT>""" <EOL> update = Event <EOL> refresh = Event <EOL> selected = Any <EOL> multi_selected = List <EOL> selected_row = Int ( - <NUM_LIT:1> ) <EOL> multi_selected_rows = List ( Int ) <EOL> activated = Any ( comparison_mode = NO_COMPARE ) <EOL> activated_row = Int ( comparison_mode = NO_COMPARE ) <EOL> clicked = Instance ( '<STR_LIT>' ) <EOL> dclicked = Instance ( '<STR_LIT>' ) <EOL> right_clicked = Instance ( '<STR_LIT>' ) <EOL> right_dclicked = Instance ( '<STR_LIT>' ) <EOL> column_clicked = Instance ( '<STR_LIT>' ) <EOL> column_right_clicked = Instance ( '<STR_LIT>' ) <EOL> scroll_to_row = Event ( Int ) <EOL> scrollable = True <EOL> row = Any <EOL> edit = Bool ( False ) <EOL> adapter = Instance ( TabularAdapter ) <EOL> model = Instance ( TabularModel ) <EOL> images = Any ( { } ) <EOL> image_resources = Any ( { } ) <EOL> image = Image <EOL> header_event_filter = Any ( ) <EOL> widget_factory = Callable ( lambda * args , ** kwds : _TableView ( * args , ** kwds ) ) <EOL> def init ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> factory = self . factory <EOL> adapter = self . adapter = factory . adapter <EOL> self . model = TabularModel ( editor = self ) <EOL> control = self . control = self . widget_factory ( self ) <EOL> if factory . multi_select : <EOL> self . sync_value ( factory . selected , '<STR_LIT>' , '<STR_LIT>' , <EOL> is_list = True ) <EOL> self . sync_value ( factory . selected_row , '<STR_LIT>' , '<STR_LIT>' , <EOL> is_list = True ) <EOL> else : <EOL> self . sync_value ( factory . selected , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . sync_value ( factory . selected_row , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if factory . multi_select : <EOL> slot = self . _on_rows_selection <EOL> else : <EOL> slot = self . _on_row_selection <EOL> signal = '<STR_LIT>' <EOL> QtCore . QObject . connect ( self . control . selectionModel ( ) , <EOL> QtCore . SIGNAL ( signal ) , slot ) <EOL> self . sync_value ( factory . update , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . sync_value ( factory . refresh , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . sync_value ( factory . activated , '<STR_LIT>' , '<STR_LIT:to>' ) <EOL> self . sync_value ( factory . activated_row , '<STR_LIT>' , '<STR_LIT:to>' ) <EOL> self . sync_value ( factory . clicked , '<STR_LIT>' , '<STR_LIT:to>' ) <EOL> self . sync_value ( factory . dclicked , '<STR_LIT>' , '<STR_LIT:to>' ) <EOL> self . sync_value ( factory . right_clicked , '<STR_LIT>' , '<STR_LIT:to>' ) <EOL> self . sync_value ( factory . right_dclicked , '<STR_LIT>' , '<STR_LIT:to>' ) <EOL> self . sync_value ( factory . column_clicked , '<STR_LIT>' , '<STR_LIT:to>' ) <EOL> self . sync_value ( factory . column_right_clicked , '<STR_LIT>' , '<STR_LIT:to>' ) <EOL> self . sync_value ( factory . scroll_to_row , '<STR_LIT>' , '<STR_LIT>' ) <EOL> signal = QtCore . SIGNAL ( '<STR_LIT>' ) <EOL> QtCore . QObject . connect ( control , signal , self . _on_activate ) <EOL> signal = QtCore . SIGNAL ( '<STR_LIT>' ) <EOL> QtCore . QObject . connect ( control , signal , self . _on_click ) <EOL> signal = QtCore . SIGNAL ( '<STR_LIT>' ) <EOL> QtCore . QObject . connect ( control , signal , self . _on_right_click ) <EOL> signal = QtCore . SIGNAL ( '<STR_LIT>' ) <EOL> QtCore . QObject . connect ( control , signal , self . _on_dclick ) <EOL> signal = QtCore . SIGNAL ( '<STR_LIT>' ) <EOL> QtCore . QObject . connect ( control . horizontalHeader ( ) , signal , self . _on_column_click ) <EOL> control . setContextMenuPolicy ( QtCore . Qt . CustomContextMenu ) <EOL> signal = QtCore . SIGNAL ( '<STR_LIT>' ) <EOL> QtCore . QObject . connect ( control , signal , self . _on_context_menu ) <EOL> self . header_event_filter = HeaderEventFilter ( self ) <EOL> control . horizontalHeader ( ) . installEventFilter ( self . header_event_filter ) <EOL> try : <EOL> self . context_object . on_trait_change ( <EOL> self . update_editor , self . extended_name + '<STR_LIT>' , dispatch = '<STR_LIT>' ) <EOL> except : <EOL> pass <EOL> if factory . auto_update : <EOL> self . context_object . on_trait_change ( <EOL> self . refresh_editor , self . extended_name + '<STR_LIT>' , dispatch = '<STR_LIT>' ) <EOL> for image_resource in factory . images : <EOL> self . _add_image ( image_resource ) <EOL> self . on_trait_change ( self . refresh_editor , '<STR_LIT>' , <EOL> dispatch = '<STR_LIT>' ) <EOL> self . on_trait_change ( self . update_editor , '<STR_LIT>' , <EOL> dispatch = '<STR_LIT>' ) <EOL> def dispose ( self ) : <EOL> """<STR_LIT>""" <EOL> self . context_object . on_trait_change ( <EOL> self . update_editor , self . extended_name + '<STR_LIT>' , remove = True ) <EOL> if self . factory . auto_update : <EOL> self . context_object . on_trait_change ( <EOL> self . refresh_editor , self . extended_name + '<STR_LIT>' , remove = True ) <EOL> self . on_trait_change ( self . refresh_editor , '<STR_LIT>' , <EOL> remove = True ) <EOL> self . on_trait_change ( self . update_editor , '<STR_LIT>' , <EOL> remove = True ) <EOL> self . adapter . cleanup ( ) <EOL> super ( TabularEditor , self ) . dispose ( ) <EOL> def update_editor ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _no_update : <EOL> self . model . reset ( ) <EOL> if self . factory . multi_select : <EOL> self . _multi_selected_changed ( self . multi_selected ) <EOL> else : <EOL> self . _selected_changed ( self . selected ) <EOL> def refresh_editor ( self ) : <EOL> """<STR_LIT>""" <EOL> self . control . viewport ( ) . update ( ) <EOL> def callx ( self , func , * args , ** kw ) : <EOL> """<STR_LIT>""" <EOL> old = self . _no_update <EOL> self . _no_update = True <EOL> try : <EOL> func ( * args , ** kw ) <EOL> finally : <EOL> self . _no_update = old <EOL> def setx ( self , ** keywords ) : <EOL> """<STR_LIT>""" <EOL> old = self . _no_notify <EOL> self . _no_notify = True <EOL> try : <EOL> for name , value in keywords . items ( ) : <EOL> setattr ( self , name , value ) <EOL> finally : <EOL> self . _no_notify = old <EOL> def restore_prefs ( self , prefs ) : <EOL> """<STR_LIT>""" <EOL> cws = prefs . get ( '<STR_LIT>' ) <EOL> num_columns = len ( self . adapter . columns ) <EOL> if cws is not None and num_columns == len ( cws ) : <EOL> for column in xrange ( num_columns ) : <EOL> self . control . setColumnWidth ( column , cws [ column ] ) <EOL> def save_prefs ( self ) : <EOL> """<STR_LIT>""" <EOL> widths = [ self . control . columnWidth ( column ) <EOL> for column in xrange ( len ( self . adapter . columns ) ) ] <EOL> return { '<STR_LIT>' : widths } <EOL> def _add_image ( self , image_resource ) : <EOL> """<STR_LIT>""" <EOL> image = image_resource . create_icon ( ) <EOL> self . image_resources [ image_resource ] = image <EOL> self . images [ image_resource . name ] = image <EOL> return image <EOL> def _get_image ( self , image ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( image , basestring ) : <EOL> self . image = image <EOL> image = self . image <EOL> if isinstance ( image , ImageResource ) : <EOL> result = self . image_resources . get ( image ) <EOL> if result is not None : <EOL> return result <EOL> return self . _add_image ( image ) <EOL> return self . images . get ( image ) <EOL> def _mouse_click ( self , index , trait ) : <EOL> """<STR_LIT>""" <EOL> event = TabularEditorEvent ( editor = self , row = index . row ( ) , <EOL> column = index . column ( ) ) <EOL> setattr ( self , trait , event ) <EOL> def _update_changed ( self ) : <EOL> self . update_editor ( ) <EOL> def _refresh_changed ( self ) : <EOL> self . refresh_editor ( ) <EOL> def _selected_changed ( self , new ) : <EOL> if not self . _no_update : <EOL> try : <EOL> selected_row = self . value . index ( new ) <EOL> except Exception as e : <EOL> if TRAITS_DEBUG : <EOL> from traits . api import raise_to_debug <EOL> raise_to_debug ( ) <EOL> else : <EOL> self . _selected_row_changed ( selected_row ) <EOL> def _selected_row_changed ( self , selected_row ) : <EOL> if not self . _no_update : <EOL> smodel = self . control . selectionModel ( ) <EOL> if selected_row == - <NUM_LIT:1> : <EOL> smodel . clearSelection ( ) <EOL> else : <EOL> smodel . select ( self . model . index ( selected_row , <NUM_LIT:0> ) , <EOL> QtGui . QItemSelectionModel . ClearAndSelect | <EOL> QtGui . QItemSelectionModel . Rows ) <EOL> def _multi_selected_changed ( self , new ) : <EOL> if not self . _no_update : <EOL> values = self . value <EOL> try : <EOL> rows = [ values . index ( i ) for i in new ] <EOL> except : <EOL> pass <EOL> else : <EOL> self . _multi_selected_rows_changed ( rows ) <EOL> def _multi_selected_items_changed ( self , event ) : <EOL> values = self . value <EOL> try : <EOL> added = [ values . index ( item ) for item in event . added ] <EOL> removed = [ values . index ( item ) for item in event . removed ] <EOL> except : <EOL> pass <EOL> else : <EOL> list_event = TraitListEvent ( <NUM_LIT:0> , added , removed ) <EOL> self . _multi_selected_rows_items_changed ( list_event ) <EOL> def _multi_selected_rows_changed ( self , selected_rows ) : <EOL> if not self . _no_update : <EOL> smodel = self . control . selectionModel ( ) <EOL> selection = QtGui . QItemSelection ( ) <EOL> for row in selected_rows : <EOL> selection . select ( self . model . index ( row , <NUM_LIT:0> ) , self . model . index ( row , <NUM_LIT:0> ) ) <EOL> smodel . clearSelection ( ) <EOL> smodel . select ( selection , <EOL> QtGui . QItemSelectionModel . Select | <EOL> QtGui . QItemSelectionModel . Rows ) <EOL> def _multi_selected_rows_items_changed ( self , event ) : <EOL> smodel = self . control . selectionModel ( ) <EOL> for row in event . removed : <EOL> smodel . select ( self . model . index ( row , <NUM_LIT:0> ) , <EOL> QtGui . QItemSelectionModel . Deselect | <EOL> QtGui . QItemSelectionModel . Rows ) <EOL> for row in event . added : <EOL> smodel . select ( self . model . index ( row , <NUM_LIT:0> ) , <EOL> QtGui . QItemSelectionModel . Select | <EOL> QtGui . QItemSelectionModel . Rows ) <EOL> scroll_to_row_hint_map = { <EOL> '<STR_LIT>' : QtGui . QTableView . PositionAtCenter , <EOL> '<STR_LIT>' : QtGui . QTableView . PositionAtTop , <EOL> '<STR_LIT>' : QtGui . QTableView . PositionAtBottom , <EOL> '<STR_LIT>' : QtGui . QTableView . EnsureVisible , <EOL> } <EOL> def _scroll_to_row_changed ( self , row ) : <EOL> """<STR_LIT>""" <EOL> scroll_hint = self . scroll_to_row_hint_map . get ( self . factory . scroll_to_row_hint , self . control . PositionAtCenter ) <EOL> self . control . scrollTo ( self . model . index ( row , <NUM_LIT:0> ) , scroll_hint ) <EOL> def _on_activate ( self , index ) : <EOL> """<STR_LIT>""" <EOL> self . activated_row = row = index . row ( ) <EOL> self . activated = self . adapter . get_item ( self . object , self . name , row ) <EOL> def _on_click ( self , index ) : <EOL> """<STR_LIT>""" <EOL> self . _mouse_click ( index , '<STR_LIT>' ) <EOL> def _on_dclick ( self , index ) : <EOL> """<STR_LIT>""" <EOL> self . _mouse_click ( index , '<STR_LIT>' ) <EOL> def _on_column_click ( self , column ) : <EOL> event = TabularEditorEvent ( editor = self , row = <NUM_LIT:0> , column = column ) <EOL> setattr ( self , '<STR_LIT>' , event ) <EOL> def _on_right_click ( self , column ) : <EOL> event = TabularEditorEvent ( editor = self , row = <NUM_LIT:0> , column = column ) <EOL> setattr ( self , '<STR_LIT>' , event ) <EOL> def _on_column_right_click ( self , column ) : <EOL> event = TabularEditorEvent ( editor = self , row = <NUM_LIT:0> , column = column ) <EOL> setattr ( self , '<STR_LIT>' , event ) <EOL> def _on_row_selection ( self , added , removed ) : <EOL> """<STR_LIT>""" <EOL> self . _no_update = True <EOL> try : <EOL> indexes = self . control . selectionModel ( ) . selectedRows ( ) <EOL> if len ( indexes ) : <EOL> self . selected_row = indexes [ <NUM_LIT:0> ] . row ( ) <EOL> self . selected = self . adapter . get_item ( self . object , self . name , <EOL> self . selected_row ) <EOL> else : <EOL> self . selected_row = - <NUM_LIT:1> <EOL> self . selected = None <EOL> finally : <EOL> self . _no_update = False <EOL> def _on_rows_selection ( self , added , removed ) : <EOL> """<STR_LIT>""" <EOL> self . _no_update = True <EOL> try : <EOL> indexes = self . control . selectionModel ( ) . selectedRows ( ) <EOL> selected_rows = [ ] <EOL> selected = [ ] <EOL> for index in indexes : <EOL> row = index . row ( ) <EOL> selected_rows . append ( row ) <EOL> selected . append ( self . adapter . get_item ( self . object , self . name , <EOL> row ) ) <EOL> self . multi_selected_rows = selected_rows <EOL> self . multi_selected = selected <EOL> finally : <EOL> self . _no_update = False <EOL> def _on_context_menu ( self , pos ) : <EOL> column , row = self . control . columnAt ( pos . x ( ) ) , self . control . rowAt ( pos . y ( ) ) <EOL> menu = self . adapter . get_menu ( self . object , self . name , row , column ) <EOL> if menu : <EOL> self . _menu_context = { '<STR_LIT>' : self . object , <EOL> '<STR_LIT:object>' : self . object , <EOL> '<STR_LIT>' : self , <EOL> '<STR_LIT>' : column , <EOL> '<STR_LIT>' : row , <EOL> '<STR_LIT>' : self . adapter . get_item ( self . object , self . name , row ) , <EOL> '<STR_LIT:info>' : self . ui . info , <EOL> '<STR_LIT>' : self . ui . handler } <EOL> qmenu = menu . create_menu ( self . control , self ) <EOL> qmenu . exec_ ( self . control . mapToGlobal ( pos ) ) <EOL> self . _menu_context = None <EOL> def _on_column_context_menu ( self , pos ) : <EOL> column = self . control . columnAt ( pos . x ( ) ) <EOL> menu = self . adapter . get_column_menu ( self . object , self . name , - <NUM_LIT:1> , column ) <EOL> if menu : <EOL> self . _menu_context = { '<STR_LIT>' : self . object , '<STR_LIT:object>' : self . object , <EOL> '<STR_LIT>' : self , <EOL> '<STR_LIT>' : column , <EOL> '<STR_LIT:info>' : self . ui . info , <EOL> '<STR_LIT>' : self . ui . handler } <EOL> qmenu = menu . create_menu ( self . control , self ) <EOL> qmenu . exec_ ( self . control . mapToGlobal ( pos ) ) <EOL> self . _menu_context = None <EOL> else : <EOL> self . _on_column_right_click ( column ) <EOL> class TabularEditorEvent ( HasStrictTraits ) : <EOL> row = Int <EOL> column = Any <EOL> item = Property <EOL> editor = Instance ( TabularEditor ) <EOL> def _get_item ( self ) : <EOL> editor = self . editor <EOL> return editor . adapter . get_item ( editor . object , editor . name , self . row ) <EOL> class _ItemDelegate ( QtGui . QStyledItemDelegate ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , table_view ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QStyledItemDelegate . __init__ ( self , table_view ) <EOL> self . _horizontal_lines = table_view . _editor . factory . horizontal_lines <EOL> self . _vertical_lines = table_view . _editor . factory . vertical_lines <EOL> def paint ( self , painter , option , index ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QStyledItemDelegate . paint ( self , painter , option , index ) <EOL> painter . save ( ) <EOL> painter . setPen ( option . palette . color ( QtGui . QPalette . Dark ) ) <EOL> if self . _horizontal_lines : <EOL> painter . drawLine ( option . rect . bottomLeft ( ) , option . rect . bottomRight ( ) ) <EOL> if self . _vertical_lines : <EOL> painter . drawLine ( option . rect . topRight ( ) , option . rect . bottomRight ( ) ) <EOL> painter . restore ( ) <EOL> class _TableView ( QtGui . QTableView ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , editor ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QTableView . __init__ ( self ) <EOL> self . _initial_size = False <EOL> self . _editor = editor <EOL> self . setModel ( editor . model ) <EOL> factory = editor . factory <EOL> vheader = self . verticalHeader ( ) <EOL> if factory . show_row_titles : <EOL> vheader . setHighlightSections ( False ) <EOL> else : <EOL> vheader . hide ( ) <EOL> if factory . show_row_titles and factory . auto_resize_rows : <EOL> vheader . setResizeMode ( QtGui . QHeaderView . ResizeToContents ) <EOL> else : <EOL> size = vheader . minimumSectionSize ( ) <EOL> font = editor . adapter . get_font ( editor . object , editor . name , <NUM_LIT:0> ) <EOL> if font is not None : <EOL> size = max ( size , QtGui . QFontMetrics ( QtGui . QFont ( font ) ) . height ( ) ) <EOL> vheader . setDefaultSectionSize ( size ) <EOL> hheader = self . horizontalHeader ( ) <EOL> hheader . setStretchLastSection ( factory . stretch_last_section ) <EOL> if factory . show_titles : <EOL> hheader . setHighlightSections ( False ) <EOL> else : <EOL> hheader . hide ( ) <EOL> self . setShowGrid ( False ) <EOL> self . setItemDelegate ( _ItemDelegate ( self ) ) <EOL> self . setSelectionBehavior ( QtGui . QAbstractItemView . SelectRows ) <EOL> if factory . multi_select : <EOL> mode = QtGui . QAbstractItemView . ExtendedSelection <EOL> else : <EOL> mode = QtGui . QAbstractItemView . SingleSelection <EOL> self . setSelectionMode ( mode ) <EOL> self . setDragEnabled ( True ) <EOL> if factory . editable : <EOL> self . viewport ( ) . setAcceptDrops ( True ) <EOL> if factory . drag_move : <EOL> self . setDragDropMode ( QtGui . QAbstractItemView . InternalMove ) <EOL> self . setDropIndicatorShown ( True ) <EOL> def keyPressEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> editor = self . _editor <EOL> factory = editor . factory <EOL> if ( event . key ( ) in ( QtCore . Qt . Key_Enter , QtCore . Qt . Key_Return ) and <EOL> self . state ( ) != QtGui . QAbstractItemView . EditingState and <EOL> factory . editable and '<STR_LIT>' in factory . operations ) : <EOL> if factory . multi_select : <EOL> rows = editor . multi_selected_rows <EOL> row = rows [ <NUM_LIT:0> ] if len ( rows ) == <NUM_LIT:1> else - <NUM_LIT:1> <EOL> else : <EOL> row = editor . selected_row <EOL> if row != - <NUM_LIT:1> : <EOL> event . accept ( ) <EOL> self . edit ( editor . model . index ( row , <NUM_LIT:0> ) ) <EOL> elif ( event . key ( ) in ( QtCore . Qt . Key_Backspace , QtCore . Qt . Key_Delete ) and <EOL> factory . editable and '<STR_LIT>' in factory . operations ) : <EOL> event . accept ( ) <EOL> if factory . multi_select : <EOL> for row in reversed ( sorted ( editor . multi_selected_rows ) ) : <EOL> editor . model . removeRow ( row ) <EOL> elif editor . selected_row != - <NUM_LIT:1> : <EOL> editor . model . removeRow ( editor . selected_row ) <EOL> elif ( event . key ( ) == QtCore . Qt . Key_Insert and <EOL> factory . editable and '<STR_LIT>' in factory . operations ) : <EOL> event . accept ( ) <EOL> if factory . multi_select : <EOL> rows = sorted ( editor . multi_selected_rows ) <EOL> row = rows [ <NUM_LIT:0> ] if len ( rows ) else - <NUM_LIT:1> <EOL> else : <EOL> row = editor . selected_row <EOL> if row == - <NUM_LIT:1> : <EOL> row = editor . adapter . len ( editor . object , editor . name ) <EOL> editor . model . insertRow ( row ) <EOL> self . setCurrentIndex ( editor . model . index ( row , <NUM_LIT:0> ) ) <EOL> else : <EOL> QtGui . QTableView . keyPressEvent ( self , event ) <EOL> def sizeHint ( self ) : <EOL> """<STR_LIT>""" <EOL> sh = QtGui . QTableView . sizeHint ( self ) <EOL> width = <NUM_LIT:0> <EOL> for column in xrange ( len ( self . _editor . adapter . columns ) ) : <EOL> width += self . sizeHintForColumn ( column ) <EOL> sh . setWidth ( width ) <EOL> return sh <EOL> def resizeEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> QtGui . QTableView . resizeEvent ( self , event ) <EOL> parent = self . parent ( ) <EOL> if ( not self . _initial_size and parent and <EOL> ( self . isVisible ( ) or isinstance ( parent , QtGui . QMainWindow ) ) ) : <EOL> self . _initial_size = True <EOL> self . resizeColumnsToContents ( ) <EOL> def sizeHintForColumn ( self , column ) : <EOL> """<STR_LIT>""" <EOL> editor = self . _editor <EOL> if editor . factory . auto_resize : <EOL> return super ( _TableView , self ) . sizeHintForColumn ( column ) <EOL> width = editor . adapter . get_width ( editor . object , editor . name , column ) <EOL> if width > <NUM_LIT:1> : <EOL> return width <EOL> else : <EOL> return self . horizontalHeader ( ) . sectionSizeHint ( column ) <EOL> def resizeColumnsToContents ( self ) : <EOL> """<STR_LIT>""" <EOL> editor = self . _editor <EOL> if editor . factory . auto_resize : <EOL> return super ( _TableView , self ) . resizeColumnsToContents ( ) <EOL> available_space = self . viewport ( ) . width ( ) <EOL> hheader = self . horizontalHeader ( ) <EOL> percent_vals , percent_cols = [ ] , [ ] <EOL> for column in xrange ( len ( editor . adapter . columns ) ) : <EOL> width = editor . adapter . get_width ( editor . object , editor . name , column ) <EOL> if width > <NUM_LIT:1> : <EOL> available_space -= width <EOL> hheader . resizeSection ( column , width ) <EOL> else : <EOL> if width <= <NUM_LIT:0> : <EOL> width = <NUM_LIT:0.1> <EOL> percent_vals . append ( width ) <EOL> percent_cols . append ( column ) <EOL> percent_total = sum ( percent_vals ) <EOL> for i , column in enumerate ( percent_cols ) : <EOL> percent = percent_vals [ i ] / percent_total <EOL> width = max ( <NUM_LIT:30> , int ( percent * available_space ) ) <EOL> hheader . resizeSection ( column , width ) </s>
