@@ -113,6 +113,7 @@ def __init__(self, parent, controller, tree):
113113 self ._marked_cell = None
114114 self ._make_bindings ()
115115 self ._write_steps (self ._controller )
116+ self .autosize ()
116117 self ._tree = tree
117118 self ._has_been_clicked = False
118119 self ._counter = 0 # Workaround for double delete actions
@@ -145,7 +146,16 @@ def _set_cells(self):
145146 CellRenderer (col_size , max_col_size , auto_col_size , word_wrap ))
146147 self .SetRowLabelSize (wx .grid .GRID_AUTOSIZE )
147148 self .SetColLabelSize (0 )
148- self .SetDefaultColSize (col_size , resizeExistingCols = True )
149+ if not auto_col_size and not word_wrap :
150+ self .SetDefaultColSize (col_size , resizeExistingCols = True )
151+ else :
152+ self .SetDefaultColSize (wx .grid .GRID_AUTOSIZE , resizeExistingCols = True )
153+
154+ if auto_col_size :
155+ self .Bind (grid .EVT_GRID_CMD_COL_SIZE , self .OnCellColSizeChanged )
156+ else :
157+ self .Unbind (grid .EVT_GRID_CMD_COL_SIZE )
158+
149159 if word_wrap :
150160 self .SetDefaultRowSize (wx .grid .GRID_AUTOSIZE )
151161 self .SetDefaultCellOverflow (False ) # DEBUG
@@ -195,15 +205,15 @@ def OnSettingsChanged(self, data):
195205 '''Redraw the colors if the color settings are modified'''
196206 section , setting = data .keys
197207 if section == 'Grid' :
198- if 'text' in setting or 'background' in setting :
199- self ._colorize_grid ()
200- elif 'font' in setting :
208+ if 'font' in setting :
201209 self ._set_fonts (update_cells = True )
202210 elif ('col size' in setting
203211 or 'max col size' in setting
204- or 'auto size cols' in setting ):
212+ or 'auto size cols' in setting
213+ or 'word wrap' in setting ):
205214 self ._set_cells ()
206- self .ForceRefresh ()
215+ self ._colorize_grid ()
216+ self .autosize ()
207217
208218 def OnSelectCell (self , event ):
209219 self ._cell_selected = True
@@ -375,7 +385,11 @@ def _colorize_grid(self):
375385 self ._parent .highlight (selection_content , expand = False )
376386
377387 def highlight (self , text , expand = True ):
378- self ._colorizer .colorize (text )
388+ wx .CallAfter (self ._colorizer .colorize , text )
389+
390+ def autosize (self ):
391+ wx .CallAfter (self .AutoSizeColumns , False )
392+ wx .CallAfter (self .AutoSizeRows , False )
379393
380394 def _get_single_selection_content_or_none_on_first_call (self ):
381395 if self ._cell_selected :
@@ -395,6 +409,8 @@ def _format_comments(self, data):
395409
396410 def cell_value_edited (self , row , col , value ):
397411 self ._execute (ChangeCellValue (row , col , value ))
412+ wx .CallAfter (self .AutoSizeColumn , col , False )
413+ wx .CallAfter (self .AutoSizeRow , row , False )
398414
399415 def get_selected_datafile_controller (self ):
400416 return self ._controller .datafile_controller
@@ -529,8 +545,7 @@ def OnKeyDown(self, event):
529545 # print("DEBUG: key pressed " + str(keycode) + " + " + str(control_down))
530546 # event.Skip() # DEBUG seen this skip as soon as possible
531547 if keycode == wx .WXK_CONTROL or \
532- (keycode == ord ('M' ) and (
533- control_down or event .AltDown ())): # keycode == wx.WXK_CONTROL
548+ (keycode == ord ('M' ) and (control_down or event .AltDown ())): # keycode == wx.WXK_CONTROL
534549 self .show_cell_information ()
535550 elif keycode == ord ('C' ) and control_down :
536551 # print("DEBUG: captured Control-C\n")
@@ -548,14 +563,14 @@ def OnKeyDown(self, event):
548563 event .Skip ()
549564 elif event .AltDown () and keycode == wx .WXK_RETURN :
550565 self ._move_cursor_down (event )
551- # event.Skip() #DEBUG was moving down 2 rows
566+ # event.Skip()
552567 elif keycode == wx .WXK_WINDOWS_MENU :
553568 self .OnCellRightClick (event )
554569 elif keycode in [wx .WXK_RETURN , wx .WXK_BACK ]:
555570 if _iscelleditcontrolshown :
556571 self .save ()
557- # event.Skip() #DEBUG was moving left and down with RETURN
558572 self ._move_grid_cursor (event , keycode )
573+ # event.Skip()
559574 elif (control_down or event .AltDown ()) and \
560575 keycode == wx .WXK_SPACE : # Avoid Mac CMD
561576 self ._open_cell_editor_with_content_assist ()
@@ -681,6 +696,10 @@ def OnCellRightClick(self, event):
681696 def OnSelectAll (self , event ):
682697 self .SelectAll ()
683698
699+ def OnCellColSizeChanged (self , event ):
700+ wx .CallAfter (self .AutoSizeRows , False )
701+ event .Skip ()
702+
684703 def OnCellLeftClick (self , event ):
685704 self ._tooltips .hide ()
686705 # if event.GetModifiers() == wx.MOD_CONTROL:
0 commit comments