youngej@magpage.com wrote:
I'm trying to resize wxGrid columns when the wxGrid is
resized. I have looked at all the examples, but so
far no joy. I'm probably doing something wrong. The
following code is a complete program which demonstrates
the problem. The grid displays scrollbars (unneeded),
but the cells themselves all appear to be in a one
character wide columnI am using Linux, RH6.0, Python-1.5.2-7, and
wxPython-2.1.15-1 installed from an rpm file.TIA for any help provided ...
#-------------------------------------------------
#!/usr/bin/pythonfrom wxPython.wx import *
from wxPython.grid import *#-------------------------------------------------
class GridTest(wxGrid):
def __init__(self, parent):
wxGrid.__init__(self, parent, -1)
self.CreateGrid(7, 3)
self.SetColLabelValue(0, 'Column 1')
self.SetColLabelValue(1, 'Column 2')
self.SetColLabelValue(2, 'Column 3')
self.SetRowLabelSize(0)
self.SetMargins(0, 0)
self.AutoSizeColumns(true)
# comment out the following line to see the grid
EVT_SIZE(self, self.OnSize)def OnSize(self, event):
size = event.GetSize()
x = size.width
x0 = (20 * x) / 100
x1 = (30 * x) / 100
x2 = x - x0 - x1
print "resizing x = ", x, ": ", x0, x1, x2
self.SetColSize(0, x0)
self.SetColSize(1, x1)
self.SetColSize(2, x2)
print "packet grid resized:", \
self.GetColSize(0), \
self.GetColSize(1), \
self.GetColSize(2)
self.Refresh()
+++ event.Skip()
#-------------------------------------------------
class TestFrame(wxFrame):
def __init__(self, parent):
wxFrame.__init__(self, parent, -1,
"Grid Test",
size=(640,480))
grid = GridTest(self)
#-------------------------------------------------
if __name__ == '__main__':
import sys
app = wxPySimpleApp()
frame = TestFrame(None)
frame.Show(true)
app.MainLoop()
#-------------------------------------------------
add event.Skip() in OnSize method in order grid to be resized
Niki Spahiev
e-mail: niki@vintech.bg
···
____________________________________________________________________
Get free email and a permanent address at Net@ddress Mail