Setting data for wx.PyGridTableBase

Hi,

I was just trying to extend the Grid_MegaExample from the wxpython demo with some cell 'metadata' and got stuck on how PyGridTableBase handles the delivered data. Can someone please explain how the given data is converted to a cell structure (wx.grid.Grid)? Why is it necessary to wrap the data like that:

colnames = ["Row", "This", "Is", "A", "Test"]

data = []

for row in range(1000):
    d = {}
    for name in ["This", "Test", "Is"]:
        d[name] = random.random()

    d["Row"] = len(data)
    # XXX
    # the "A" column can only be between one and 4
    d["A"] = random.choice(range(4))
    data.append((str(row), d))

And if this is the only way to represent the data, is there any possibility to add more information (e.g. cell background or text colours)? I'd like to use the PyGridTableBase to implement a fast undo/redo algorithm.. This works fine with the cell data itself but I have no idea how to undo/redo the cell colours.

Thanks in advance,
Tim

Tim,

Tim Kraemer wrote:

Hi,

I was just trying to extend the Grid_MegaExample from the wxpython demo with some cell 'metadata' and got stuck on how PyGridTableBase handles the delivered data. Can someone please explain how the given data is converted to a cell structure (wx.grid.Grid)? Why is it necessary to wrap the data like that:

colnames = ["Row", "This", "Is", "A", "Test"]

data =

for row in range(1000):
    d = {}
    for name in ["This", "Test", "Is"]:
        d[name] = random.random()

    d["Row"] = len(data)
    # XXX
    # the "A" column can only be between one and 4
    d["A"] = random.choice(range(4))
    data.append((str(row), d))

And if this is the only way to represent the data, is there any possibility to add more information (e.g. cell background or text colours)? I'd like to use the PyGridTableBase to implement a fast undo/redo algorithm.. This works fine with the cell data itself but I have no idea how to undo/redo the cell colours.
  

Have you seen the wiki entry?
http://wiki.wxpython.org/wxPyGridTableBase

Werner

Hi Werner,

thank you for the link. I haven't seen this wiki entry before and now I am in the know.

Tim

----- Ursprüngliche Mail ----

···

Von: Werner F. Bruhin <werner.bruhin@free.fr>
An: wxpython-users@lists.wxwidgets.org
Gesendet: Dienstag, den 20. Januar 2009, 13:25:51 Uhr
Betreff: Re: [wxpython-users] Setting data for wx.PyGridTableBase

Tim,

Tim Kraemer wrote:
> Hi,
>
> I was just trying to extend the Grid_MegaExample from the wxpython demo with
some cell 'metadata' and got stuck on how PyGridTableBase handles the delivered
data. Can someone please explain how the given data is converted to a cell
structure (wx.grid.Grid)? Why is it necessary to wrap the data like that:
>
> colnames = ["Row", "This", "Is", "A", "Test"]
>
> data =
>
> for row in range(1000):
> d = {}
> for name in ["This", "Test", "Is"]:
> d[name] = random.random()
>
> d["Row"] = len(data)
> # XXX
> # the "A" column can only be between one and 4
> d["A"] = random.choice(range(4))
> data.append((str(row), d))
>
> And if this is the only way to represent the data, is there any possibility to
add more information (e.g. cell background or text colours)? I'd like to use the
PyGridTableBase to implement a fast undo/redo algorithm.. This works fine with
the cell data itself but I have no idea how to undo/redo the cell colours.
>
Have you seen the wiki entry?
wxPyGridTableBase - wxPyWiki

Werner
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users