AW: [wxPython-users] Troubles with GetSelectedRows()
Micha Reiser
micha.reiser at famreiser.ath.cx
Mon Sep 4 13:48:22 PDT 2006
Thx for your help...
Now it works fine (this). But when i will delete a row from the table it
deletes the right values but (visual) the last row???
I attached a small example with the problem. With double click you delete
one row.
Thx for Help =
Micha
-----Urspr=FCngliche Nachricht-----
Von: Robin Dunn [mailto:robin at alldunn.com] =
Gesendet: Montag, 4. September 2006 19:47
An: wxPython-users at lists.wxwidgets.org
Betreff: Re: [wxPython-users] Troubles with GetSelectedRows()
Micha Reiser wrote:
> Hello
> =
> I Created a Grid with CreateGrid (in the real probramm I had a TableBase).
> =
> Now, when I try to detect the selected Row with GetSelectedRows() I
receive
> all the time an empty list?
> =
There are different kinds of selections in the Grid class, and =
GetSelectedRows only returns those rows that are selected using the row =
labels. There are also col selections that are made the same way with =
col labels, and also block selections (dragging across a range of cells) =
and cell selections (selecting individual cells) and each of them have =
their own methods for retrieving the selections. (Yes, I agree that =
this is ugly and awkward...)
-- =
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
-------------- next part --------------
import wx
import wx.grid
class TableBuchen( wx.grid.PyGridTableBase ):
def __init__( self, data, rowLabels =3D [], colLabels=3D[] ):
wx.grid.PyGridTableBase.__init__( self )
self.colLabels =3D {}
for i in range(len(colLabels)):
self.colLabels[i] =3D colLabels[i]
self.rowLabels =3D {}
print rowLabels
for i in range(len(rowLabels)):
self.rowLabels[i] =3D rowLabels[i]
self.data =3D data
def GetNumberRows( self ):
return len( self.rowLabels )
def GetNumberCols( self ):
return len( self.colLabels )
def IsEmptyCell( self, row, col ):
return self.data.get( ( row, col ) ) is not None
def GetValue( self, row, col ):
value =3D self.data.get( ( row, col ) )
if value =3D=3D None:
return ''
else:
return value
def SetValue( self, row, col, value ):
self.data[( row, col )] =3D value
def AppendRows( self, numRows=3D1 ):
for i in range( numRows ):
self.rowLabels[len( self.rowLabels )+1] =3D len(self.rowLabels)=
+1
#Tabelle informieren, dass neue Rows angeh=C3=A4nkt wurden
msg =3D wx.grid.GridTableMessage( self,
wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED,
numRows ) #Wie viele Rows
self.GetView().ProcessTableMessage( msg )
return True
def AppendCols( self, numCols=3D1 ):
return False
def GetColLabelValue( self, col ):
return str( self.colLabels.get(col, str(col)) )
def GetRowLabelValue( self, row ):
return str( self.rowLabels.get(row, str(row)) )
def SetColLabelValue( self, col, value ):
self.colLabels[col] =3D str( value )
def SetRowLabelValue( self, row, value ):
self.rowLabels[row] =3D str( value )
def DeleteRows( self, pos, numRows ):
for i in range( numRows ):
if self.rowLabels.has_key(pos + i):
del self.rowLabels[pos+i]
for x in range( self.GetNumberCols()+1 ):
if self.data.has_key( ( pos + i, x ) ):
del self.data[pos+ i, x]
msg =3D wx.grid.GridTableMessage( self,
wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, pos,
numRows ) #Wie viele Rows
self.GetView().ProcessTableMessage( msg )
return True
def Clear( self ):
"""Alles l=F6schen"""
self.DeleteRows( 0, self.GetNumberRows() )
=
class Grid(wx.grid.Grid):
def __init__(self, parent):
wx.grid.Grid.__init__(self, parent)
collabels =3D ["one", "two", "three", "four"]
self.SetTable(TableBuchen({}, [], collabels), True)
self.SetSelectionMode(wx.grid.Grid.SelectRows)
for i in range(15):
self.GetTable().AppendRows(1)
for x in range(4):
self.GetTable().SetValue(i, x, str(i+x))
self.Bind(wx.grid.EVT_GRID_CMD_CELL_LEFT_DCLICK, self.OnDClick)
=
def OnDClick(self, evt):
if self.IsSelection():
row =3D self.GetSelectionBlockTopLeft()[0][0]
self.DeleteRows(row, 1)
=
if __name__ =3D=3D '__main__':
app =3D wx.PySimpleApp()
frame =3D wx.Frame(None)
=
panel =3D wx.Panel(frame)
grid =3D Grid(panel)
grid.SetSize(grid.GetBestSize())
panel.Fit()
frame.SetSize(frame.GetBestSize())
frame.Show()
app.MainLoop()
=20
More information about the wxpython-users
mailing list