I'm trying to create a widget that will be used for editing a python
dictionary. I'm sure there are numerous ways to do it, but it seems that
a wxGrid provides about the right basic functionality. It just needs a
little bit of adjustment.
To edit a dictionary I only need 2 columns - one for the keys, the other
for the values. The widget also needs to be resizable as its window is
resized. However wxGrid seems to leave a 'blank' area to the right past
the last column. I wanted to try to adjust it so that each column is
always exactly half the width of the widget, so I created an EVT_SIZE
handler to do this.
Problem is that this handler creates some new problems:
1> when the grid starts up, there is a 'blemish' or odd blank area
that obscures part of the
first several cells.
2> the entry box where you edit a cell contents starts up with the
wrong width. Its just a very
small square. If you adjust the width of the first column it
corrects itself until you resize the
What am I doing wrong here? Is there a method that I should call which
would to execute the grid's default onsize functionality?
There is a 3rd but less pressing problem. adjusting the width of the
first colum tends to push the end of the 2nd column past the edge of the
widget's window. I can't find anyway to override the column adjust
method in order to correct this. Anyone have any ideas on how I can
Of course, I might be on the wrong track completely. Perhaps a wxGrid is
the wrong way to go here. It initally seemed as if it had all the basic
functionality that I needed.
My code is attached below as well as .jpg that shows the defects I'm
trying to correct
> Problem is that this handler creates some new problems:
> 1> when the grid starts up, there is a 'blemish' or odd blank area
> that obscures part of the
> first several cells.
It's the wxTextCrl used for the in place edit, (IPE.) Apparently when the
frame sizers move things around and you resize columns, the IPE control
doesn't get moved. The fix is to disable IPE and then enable it again
causing it's location to be recalculated.
> 2> the entry box where you edit a cell contents starts up with the
> wrong width. Its just a very
> small square. If you adjust the width of the first column it
> corrects itself until you resize the
> window again.
You provided the panel with an EVT_SIZE where you adjust the size of the
columns. However the default EVT_SIZE handler for the panel would have
called self.Layout() to take care of the sizer. The wxGrid was never getting
size events and so it was never resizing it's top edit control. You can
either call self.Layout to add in the functionality you overrode, or call
event.Skip so the default handler gets called. Your call to self.grid.Layout
had no effect because the grid itself doesn't have any sizers or layout
Here are my changes:
def OnGridSize( self, event ):
sbx,trash = self.grid.vscrollbar.GetSizeTuple()
sbx = sbx / 2
sbx = 1
gx,gy = self.grid.GetSizeTuple()
ax = gx/2-sbx
self.grid.SetColumnWidth( 0, ax )
self.grid.SetColumnWidth( 1, ax )
self.grid.SetEditInPlace(false) ## here
self.grid.SetEditInPlace(true) ## here
event.Skip() ## and here