473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

wxpython grid GRIDTABLE_NOTIFY_ROWS_DELETED

Hello,
I have written a small program which dynamically displays data from a
data structure in a wx.grid. The grid reacts as expected when the data
structure is enlarged: a new row is added and filled with data. When
data is removed, the data is deleted as expected, but instead of being
removed, a row is being added to the grid. Can anyone explain why?
Here is sample code to illustrate what I mean.
Thanks in advance
Piet
import wx
import wx.grid
#---------------------------------------------------------------------------

class XmlTableModel(wx.grid.PyGridTableBase):
def __init__(self,headers,data):
wx.grid.PyGridTableBase.__init__(self)
self.headers = headers
self.data = data

def GetNumberRows(self):
return len(self.data)

def GetNumberCols(self):
return len(self.headers)

def RemoveData(self,rowNum):
self.data.pop()
self.GetView().ProcessTableMessage(wx.grid.GridTab leMessage(self,wx.grid.GRIDTABLE_NOTIFY_ROWS_DELET ED,1))

def AddData(self,data):
self.data.append(data)
self.GetView().ProcessTableMessage(wx.grid.GridTab leMessage(self,wx.grid.GRIDTABLE_NOTIFY_ROWS_APPEN DED,1))

def IsEmptyCell(self, row, col):
try:
if self.data[row][col] != "":
return True
else:
return False
except:
return False

def GetValue(self, row, col):
return self.data[row][col]

def SetValue(self, row, col, value):
self.data[row][col] = value

def GetColLabelValue(self, col):
return self.headers[col]

def GetDefaultColLabelSize(self):
return 100

def GetRowLabelValue(self, row):
return self.data[row][0]
#---------------------------------------------------------------------------

class TestFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Simple Table Model Demo",
size=(640,480))
self.panel = wx.Panel(self, -1, style=0)
self.grid = wx.grid.Grid(self.panel)
self.headers = ["Eins","Zwei","Drei","Vier"]
self.data = [["A1","A2","A3","A4"],
["B1","B2","B3","B4"],
["C1","C2","C3","C4"],
["D1","D2","D3","D4"]]
self.grid.SetTable(XmlTableModel(self.headers,self .data),
True)
self.AddBtn = wx.Button(self.panel, -1, "Add Entry")
self.AddBtn.SetDefault()
self.Bind(wx.EVT_BUTTON, self.OnAddEntry, self.AddBtn)
self.RemoveBtn = wx.Button(self.panel, -1, "Remove Entry")
self.Bind(wx.EVT_BUTTON, self.OnRemoveEntry, self.RemoveBtn)
self.bs = wx.BoxSizer(wx.VERTICAL)
self.bs.Add(self.grid, 1, wx.GROW|wx.ALL, 5)
self.bs.Add(self.AddBtn)
self.bs.Add(self.RemoveBtn)
self.panel.SetSizer(self.bs)

def OnAddEntry(self, evt):
self.grid.GetTable().AddData(["NA1","NA2","NA3","NA4"])

def OnRemoveEntry(self, evt):
self.grid.GetTable().RemoveData(0)

#---------------------------------------------------------------------------

if __name__ == '__main__':
import sys
app = wx.PySimpleApp()
frame = TestFrame(None)
frame.Show(True)
app.MainLoop()
#---------------------------------------------------------------------------
Jul 18 '05 #1
1 4590

Change the message call in RemoveData() to

self.GetView().ProcessTableMessage(wx.grid.GridTab leMessage(
self,wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, len(data), 1))

The ..._ROW_DELETED message requires two args, the index of the first
row and the number of rows to be removed. Similarly for colums.

/Jean Brouwers
ProphICy Semiconductor, Inc.

PS) Also, check the DoUpdate() method in this example

<http://www.bitpim.org/pyxr/c/projects/bitpim/bpmedia.py.html>
In article <39**************************@posting.google.com >, Piet
<pi********@gmx.de> wrote:
Hello,
I have written a small program which dynamically displays data from a
data structure in a wx.grid. The grid reacts as expected when the data
structure is enlarged: a new row is added and filled with data. When
data is removed, the data is deleted as expected, but instead of being
removed, a row is being added to the grid. Can anyone explain why?
Here is sample code to illustrate what I mean.
Thanks in advance
Piet
import wx
import wx.grid
#---------------------------------------------------------------------------

class XmlTableModel(wx.grid.PyGridTableBase):
def __init__(self,headers,data):
wx.grid.PyGridTableBase.__init__(self)
self.headers = headers
self.data = data

def GetNumberRows(self):
return len(self.data)

def GetNumberCols(self):
return len(self.headers)

def RemoveData(self,rowNum):
self.data.pop()

self.GetView().ProcessTableMessage(wx.grid.GridTab leMessage(self,wx.grid.GRIDT
ABLE_NOTIFY_ROWS_DELETED,1))

def AddData(self,data):
self.data.append(data)

self.GetView().ProcessTableMessage(wx.grid.GridTab leMessage(self,wx.grid.GRIDT
ABLE_NOTIFY_ROWS_APPENDED,1))

def IsEmptyCell(self, row, col):
try:
if self.data[row][col] != "":
return True
else:
return False
except:
return False

def GetValue(self, row, col):
return self.data[row][col]

def SetValue(self, row, col, value):
self.data[row][col] = value

def GetColLabelValue(self, col):
return self.headers[col]

def GetDefaultColLabelSize(self):
return 100

def GetRowLabelValue(self, row):
return self.data[row][0]
#---------------------------------------------------------------------------

class TestFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Simple Table Model Demo",
size=(640,480))
self.panel = wx.Panel(self, -1, style=0)
self.grid = wx.grid.Grid(self.panel)
self.headers = ["Eins","Zwei","Drei","Vier"]
self.data = [["A1","A2","A3","A4"],
["B1","B2","B3","B4"],
["C1","C2","C3","C4"],
["D1","D2","D3","D4"]]
self.grid.SetTable(XmlTableModel(self.headers,self .data),
True)
self.AddBtn = wx.Button(self.panel, -1, "Add Entry")
self.AddBtn.SetDefault()
self.Bind(wx.EVT_BUTTON, self.OnAddEntry, self.AddBtn)
self.RemoveBtn = wx.Button(self.panel, -1, "Remove Entry")
self.Bind(wx.EVT_BUTTON, self.OnRemoveEntry, self.RemoveBtn)
self.bs = wx.BoxSizer(wx.VERTICAL)
self.bs.Add(self.grid, 1, wx.GROW|wx.ALL, 5)
self.bs.Add(self.AddBtn)
self.bs.Add(self.RemoveBtn)
self.panel.SetSizer(self.bs)

def OnAddEntry(self, evt):
self.grid.GetTable().AddData(["NA1","NA2","NA3","NA4"])

def OnRemoveEntry(self, evt):
self.grid.GetTable().RemoveData(0)

#---------------------------------------------------------------------------

if __name__ == '__main__':
import sys
app = wx.PySimpleApp()
frame = TestFrame(None)
frame.Show(True)
app.MainLoop()
#---------------------------------------------------------------------------

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: scottmallory | last post by:
Greetings, I am new to Python...and I am having some difficulty updating a grid (wx.grid.PyGridTableBase). Everything works just fine (adding /deleting/ resizing rows, cols) except updating...
1
by: Sam the Cat | last post by:
using "from wxPython.wx import *" under python2.3 I cannot seem to find the wxGrid class -- it says its undefined -- am I missing something obvious ? I know the globalspace import is not the best,...
6
by: rbann11 | last post by:
Hi, I am looking for example code that consists of just a frame and a grid(10x2). The grid must fill the its parent even if the frame is resized. Thanks in advance, Roger
1
by: Kiran | last post by:
Hello All, I created a grid, where I register events every time the user changes an existing value inside the grid control. Right now, I am using the event: EVT_GRID_CELL_CHANGE. However, I...
2
by: Kiran | last post by:
Hello All, I am writing an app in wxPython using a grid. I need to be able to recognize what cell in the grid the user is hovering over with the mouse. How to do this? I tried XYToCell(x, y),...
3
by: Jordan | last post by:
Hey Peoples, I'm wonderg if there is a way to make a subclass of wx.grid.Grid in which the coloumn labels for the grid appear on the bottom of the grid instead of the top. 1 2 3 4 5 a| | ...
4
by: BH | last post by:
Hi ! I have a small problem with wx.Grid and scrollbars. Scrollbars definitively dissapears after resizing the frame. Thx for help ...
9
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the...
15
by: Gilles Ganault | last post by:
Hello Since Python is such a productive language, I'd really like to be able to use it to write GUI apps for Windows, but business apps require rich widgets like (DB)grids, calendars, etc. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.