Updating a wxgrid in real time

I’m currently using a grid together with gridTableBase in the following way:

  • the gridTableBase holds a reference to a list of objects that can be displayed on the grid. The list may be updated in other application threads.
  • the gridTableBase also has a wxTimer. Each time the timer fires an event, I’m comparing the current list length with the length from the previous timer event. If the lengths differs, I’m notifying the grid that the number of rows has changed accordingly.
    Now, I’m unsure if this is the right way to update the grid widget. For example, I’m concerned with what may happen when some objects get removed from the list in a thread other than the GUI one. The grid could request from the table base an item from an index that is no longer valid(because the timer has yet to fire an event in order to notify the grid that the list length has changed). Currently I’m protecting myself from this behavior by handling such exception in the table model, but I feel there could be a better design for what I’m trying to accomplish…I just can’t find one atm :(.

Any input on how you would handle something like this would be much appreciated.

I'm currently using a grid together with gridTableBase in the following way:

  * the gridTableBase holds a reference to a list of objects that can be
    displayed on the grid. The list may be updated in other application
    threads.
  * the gridTableBase also has a wxTimer. Each time the timer fires an
    event, I'm comparing the current list length with the length from
    the previous timer event. If the lengths differs, I'm notifying the
    grid that the number of rows has changed accordingly.

I use a data container which sends out a notification (via wx.PostEvent or wx.lib.pubsub) to the grid every time something has changed. I subclassed the numpy.ndarray class as data container for that purpose but you could do this with a nested list object as well.
Have a look at
http://sourceforge.net/p/lorentz/code/576/tree/trunk/peak_o_mat/datagrid/tablebase.py
for my implementaion.

Now, I'm unsure if this is the right way to update the grid widget. For
example, I'm concerned with what may happen when some objects get
removed from the list in a thread other than the GUI one. The grid could
request from the table base an item from an index that is no
longervalid(because the timer has yet to fire an event in order to
notify the grid that the list length has changed). Currently I'm
protecting myself from this behavior by handling such exception in the
table model, but I feel there could be a better design for what I'm
trying to accomplish...I just can't find one atm :(.

That won't happen if you implement the methods
GetNumberRows and GetNumberCols of your tablebase class.

Regards, Christian

···

Am 23.06.13 10:44, schrieb Alexandru Popa:

Your solution seems to be an implementation of the observer/observable pattern, with the container acting as the observable. Thank you for the response, this seems to be of help in other areas of my code as well !

···

On Sun, Jun 23, 2013 at 5:16 PM, Christian K. ckkart@hoc.net wrote:

Am 23.06.13 10:44, schrieb Alexandru Popa:

I’m currently using a grid together with gridTableBase in the following way:

  • the gridTableBase holds a reference to a list of objects that can be

    displayed on the grid. The list may be updated in other application

    threads.

  • the gridTableBase also has a wxTimer. Each time the timer fires an

    event, I’m comparing the current list length with the length from

    the previous timer event. If the lengths differs, I’m notifying the

    grid that the number of rows has changed accordingly.

I use a data container which sends out a notification (via wx.PostEvent or wx.lib.pubsub) to the grid every time something has changed. I subclassed the numpy.ndarray class as data container for that purpose but you could do this with a nested list object as well.

Have a look at

http://sourceforge.net/p/lorentz/code/576/tree/trunk/peak_o_mat/datagrid/tablebase.py

for my implementaion.

Now, I’m unsure if this is the right way to update the grid widget. For

example, I’m concerned with what may happen when some objects get

removed from the list in a thread other than the GUI one. The grid could

request from the table base an item from an index that is no

longervalid(because the timer has yet to fire an event in order to

notify the grid that the list length has changed). Currently I’m

protecting myself from this behavior by handling such exception in the

table model, but I feel there could be a better design for what I’m

trying to accomplish…I just can’t find one atm :(.

That won’t happen if you implement the methods

GetNumberRows and GetNumberCols of your tablebase class.

Regards, Christian

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/5Qjyv0TDkcI/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.