{{{
#!python
dialog = wx.TextEntryDialog(self, *args)
try :
if dialog.ShowModal() == wx.ID_OK:
value = dialog.GetValue()
if value :
try :
self.grid.GetTable().add_value(value)
self.notify() <=====
********** ForceRefresh called in here **********
except ValueError, exc :
wx.MessageBox(exc.message, caption="Invalid value", style=wx.OK)
else :
wx.MessageBox("Cannot be empty", caption="Invalid value", style=wx.OK)
finally :
dialog.Destroy()
}}}
and the Grid doesn't display the new row . I have confirmed that the
model includes the recently created row and also tried grid.AppendRows
(the model's method always returns True ) but everything remains just
the same (IOW model.GetNumberRows returns e.g. 15 whereas
grid.GetNumberRows returns 14 ).
Why is this happening ? What can be done ?
Thnx in advance !
--
Regards,
Olemis.
Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/
Featured article:
There is an extra step you have to take, but I have never seen it in any
formal documentation. The only place I have seen it is in some of the Grid
examples in the demo.
After appending, inserting, or deleting rows (or columns) in the table, you
must notify the grid of the change, like this -
msg = wx.grid.GridTableMessage(self, # The table
wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it
1 # how many
)
or
msg = wx.grid.GridTableMessage(self, # The table
wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED, # what we did to it
5, # from which row
1 # how many
)
or
msg = wx.grid.GridTableMessage(self, # The table
wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, # what we did to it
5, # from which row
1 # how many
)
followed by
self.GetView().ProcessTableMessage(msg)
This assumes that it is called from the Table class.
If it is called from the Grid class, change self to self.GetTable(), and
self.GetView() to self.
HTH
Frank Millman
I'll try that ... I suppose that the same holds for ClearGrid (/me
experiencing similar problems :-/ )
> but I have never seen it in any
> formal documentation.
Undocumented thingies ... Hmmmm . IMO it should be documented somewhere .
> The only place I have seen it is in some of the Grid
> examples in the demo.
>
I c . And they are in cyberspace somewhere, isn't it ?
> After appending, inserting, or deleting rows (or columns) in the table, you
> must notify the grid of the change, like this -
>
>
Just to satisfy my curiosity : Shouldn't all these happen
transparently once ForceRefresh or (AppendRows | ... ) is called ? Is
there a (good) reason for sending an extra (non-intuitive IMO )
message to the grid ?
BTW : Thnx !
I see . Thnx !
BTW, if `BasePropertyTable` is a well known «patch» to workaround this
situation :
Q:
- Why not to include it in wxPython as a helper ?
Well , probably I was wrong (and | or) got the wrong (and premature )
impression about whether that was «well known "patch"» . You're right.
But I am really sure that, once those operations (append, delete,
clear ...) are performed , the human intuition makes programmers (like
me) think that those changes will be reflected in the grid. The use of
such events directly is just a «hack» (didn't find the right word ...
) that exposes the details of the underlying mechanisms available in
(wxPython | wxWiidgets ) to communicate with widgets . Considering
that I agree with those people ( e.g. Trygve Reenskaug and James O.
Coplien authors of MVC [1]_ and DCI [2]_ architectures ) that state
that «Object oriented programming grew out of Doug Englebart's vision
of the computer as an extension of the human mind» and therefore «the
goal of object-oriented programming pioneers was to capture end user
mental models in the code» and that's why the goal should be to
«provide the illusion of a direct connection from the end user brain
to the computer "brain"» ... then IMO they should be hidden somehow.
That's what encapsulation is for ;o)
If this is not possible directly in the base classes (e.g. due to the
fact that wxPython depends on wxWidgets and SWIG and ...) at least
IMHO it would be nice to have a ready-to-use shortcut somewhere to get
this done OOTB . It's just a suggestion ; but you know, probably I'm
wrong (anyway, I was born by mistake :P ...)
> It's really up to Robin Dunn or one
> of the other wx devs to decide if something is worth including with
> the distro.
>
Of course , that's why I am asking it here, it's just a suggestion .
I'm just pushing them a little to see if they fall . I keep waiting at
the bottom of the precipice ... ;o) ... but probably programmers will
be the real winners .
PS: ... just a funny way to say a serious thing
;o)
.. [1] Model–view–controller
(http://en.wikipedia.org/wiki/Model–view–controller)
.. [2] The DCI Architecture: A New Vision of Object-Oriented Programming
(http://www.artima.com/articles/dci_vision.html)
> Just to satisfy my curiosity : Shouldn't all these happen
> transparently once ForceRefresh or (AppendRows | ... ) is called ? Is
> there a (good) reason for sending an extra (non-intuitive IMO )
> message to the grid ?
It's just the way that the API was designed, and was probably meant to
help facilitate a looser coupling between the table and the grid. IOW,
to allow the grid and the table to be somewhat out of sync if there is a
need for it.
--
Robin Dunn
Software Craftsman
http://wxPython.org