Hmmmm, there's still something I can't understand. If I simply modify the code of the function OnButton1 as follows, everything works fine:
def OnButton1(self, event) :
for i in range(0, 19999) :
self.grid.SetColSize(i, 0)
self.grid.table.ResetView(self.grid)
I mean, 19999 columns are hidden and only one is displayed.
But then if I press button 2, again the gui becomes very slow. It seems a pretty strange behavior to me...
···
Date: Mon, 20 Oct 2008 21:17:50 +0200
From: raffaello <barbarossa.platz@gmail.com>
Subject: Re: [wxpython-users] wx.Grid, Hiding columns
To: wxpython-users@lists.wxwidgets.org
Message-ID:
<5caf8fc00810201217rfe09fdcwc2059267228e3d1d@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"I am afraid you want too much from your RAM: I tried your code, only
reducing the number of columns to 200, and it runs smoothly.
Unless there's a compelling necessity to have all data included at the same
time in one grid (that nobody could swallow it in one gulp), I suggest that
you put the data into a database, and trust the selection of the ones the
user wants to see at any given moment to a SELECT query: the resulting
output should arrive much faster.BTW in databases the number of columns is usually fixed, because they
describe the categories of data, while the rows -containing the actual data-
vary: so rows tend to become more numerous than columns.2008/10/20 Massi <massi_srb@msn.com>
I post a little example code to show what I mean (I simply modified one
of the example of the demo), just run the code, press button 1 and then
button 2 and, for example, try to use the scrollbar. That simulates exact=ly
what happens in my program.
import wx
import wx.grid as gridlibclass HugeTable(gridlib.PyGridTableBase):
def __init__(self, log):
gridlib.PyGridTableBase.__init__(self)
self.log =3D log
self._rows =3D self.GetNumberRows()
self._cols =3D self.GetNumberCols()def ResetView(self, grid):
grid.BeginBatch()
for current, new, delmsg, addmsg in [(self._rows,
self.GetNumberRows(), gridlib.GRIDTABLE_NOTIFY_ROWS_DELETED,
gridlib.GRIDTABLE_NOTIFY_ROWS_APPENDED),
(self._cols, self.GetNumberCols(),
gridlib.GRIDTABLE_NOTIFY_COLS_DELETED,
gridlib.GRIDTABLE_NOTIFY_COLS_APPENDED),]:
if new < current:
msg =3D gridlib.GridTableMessage(self,delmsg,new,current-=new)
grid.ProcessTableMessage(msg)
elif new > current:
msg =3D gridlib.GridTableMessage(self,addmsg,new-current)
grid.ProcessTableMessage(msg)
self.UpdateValues(grid)
grid.EndBatch()
self._rows =3D self.GetNumberRows()
self._cols =3D self.GetNumberCols()
grid.AdjustScrollbars()
grid.ForceRefresh()def UpdateValues(self, grid):
msg =3D gridlib.GridTableMessage(self,
gridlib.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
grid.ProcessTableMessage(msg)def GetNumberRows(self):
return 100def GetNumberCols(self):
return 20000def GetValue(self, row, col):
return str( (row, col) )class HugeTableGrid(gridlib.Grid):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)
self.table =3D HugeTable(log)
self.SetTable(self.table, True)#------------------------------------------------------------------------=
---
class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, -1, "", size=3D(840, 680))
sizer =3D wx.BoxSizer(wx.VERTICAL)
self.grid =3D HugeTableGrid(self, log)
self.grid.SetColMinimalAcceptableWidth(0)
b1 =3D wx.Button(self, -1, "1")
b2 =3D wx.Button(self, -1, "2")
sizer.Add(self.grid, 1, wx.ALL|wx.EXPAND, 5)
sizer.Add(b1, 0, wx.ALL, 5)
sizer.Add(b2, 0, wx.ALL, 5)
self.SetSizer(sizer)self.Bind(wx.EVT_BUTTON, self.OnButton1, b1)
self.Bind(wx.EVT_BUTTON, self.OnButton2, b2)def OnButton1(self, event) :
for i in range(0, 20000) :
self.grid.SetColSize(i, 0)
self.grid.table.ResetView(self.grid)def OnButton2(self, event) :
self.grid.SetColSize(10, 100)
self.grid.table.ResetView(self.grid)if __name__ =3D=3D '__main__':
import sys
app =3D wx.PySimpleApp()
frame =3D TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()