Grid Table GetValue() Called at Application Invocation

I'm using a grid table for the data in the embedded RDBMS and displaying
the cell values in the wx.grid.Grid. In class
dataTable(wx.grid.PyGridTableBase): I have the method GetValue(self, row,
col) overridden to use the extracted table values for display. The actual
function is:

   def GetValue(self, row, col):
     if self.appData.altData != None:
       value = self.appData.altData
       return value

   It's written this way bacause there will not initially be data in the
table, and the first three columns need to be explicitly set; hence the
'else' clause in the if statement.

   However, as soon as I click on the notebook tab holding the grid, it
attempts to load data into each cell, and throws errors because the list it
should use is still empty. If I don't comment out the entire function I get
errors. If it's commented out, each cell contains 'None'. I seem to be stuck
in an infinite loop here; I cannot leave GetValue() uncommented and not have
the grid try to display something in each cell as soon as it's visible.

   Cannot find anything appropriate in chapter 14 of the book.

Rich

···

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Rich Shepard wrote:

The grid wants to know what to show in the cells. I thought this should have happened at the point the grid is initially displayed, but maybe it makes a call when the grid is instantiated as well.

  That's apparently the case. Not nice ... for my application.

I don't know how to help you if you aren't willing to rearrange when the grid is instantiated and/or just making a grid.Refresh() call after your altData is filled in.

Your if block checks for appData.altData equalling None. It must not equal None at that point, but may still be an empty list.[1]

  Tried that with no better results.

Sorry... you tried what, exactly? I wasn't telling you what to do there, but noting what Python was doing.

All I can say is, you have near total control, but something isn't
clicking for you. Whatever you return from GetValue() is what will display
in the cell referenced by row, col.

  Well, I _should_ have complete control over this puppy. :slight_smile: After all,
it's only application code.

  Perhaps if I explain the context the most appropriate approach will be
more apparent to those more experienced than am I with wxPython grids.

  The application is a mathematical model. The grid is for entry,
modification, and display of the data fed to the modeling functions. The
rest of the notebook tabs are for the model parameters and conditions.
Therefore, there are no data to be displayed in the grid until all
parameters and conditions have been defined, and the grid should silently
display blank cells.

So for this case, GetValue() needs to return '' no matter what the row and col arguments are.

  Once the parameters and conditions have been defined, they become the
first three columns of the grid. I want to have them loaded into the grid
display by a method bound to a button.

So when the conditions are appropriate, have GetValue() return the right values for the row and col arguments.

  When these parameters and conditions have been used to initialize the
grid, they are saved to the appropriate database table in the method bound
to the "SAVE" button. Now, when that model's database is opened, there are
at least the parameters and conditions in self.appData.altData, so the grid
can load them into the appropriate cells.

  It is dealing with the empty grid when there are no tuples in the
self.appData.altData list that keeps eluding me.

??? I can't parse that last sentence. Sorry.

Paul

···

On Tue, 27 May 2008, Paul McNett wrote:

Walter,

   That's a clever idea.

   I've changed the code so that 'None' is loaded when the application is
invoked. That's OK with me. If there are no values in the appropriate
database table, then I can replace the 'None' with the appropriate values
for the first three columns (almost there with this!). And, when there are
values in the database table, those will automatically be loaded and replace
the default 'None' values.

   That the behavior is the opposite of other widgets -- which require
explicit setting of the values to display -- got me stuck for quite a while.

Many thanks,

Rich

···

On Tue, 27 May 2008, Walter Mario Gardella Sambeth wrote:

Rich, I am currently working on an application using a HTMLListBox, and
this control also seeks data before having it loaded. The issue is that
seemingly the "virtual" controls looks for data in the instantiation
phase. I solved (or maybe just hacked through :wink: ) the problem setting a
flag that is initially False and only changing the value to True when the
instantiation is done (in my __init__ generated by Boa, after init_ctrls).
In the data serving function, if the flag is false, I return nothing, else
return the available data. Maybe this can help you to tame the beast.

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Paul,

   Now that I better understand the behavior of the grid, and the difference
from that of other widgets when the application is invoked, the code is
working. I need to tune the function for loading initial values, and will
call grid.Refresh() when it's changed, and I need to explicitly set the
first three columns read-only when these data are loaded.

   Having each cell display 'None' is perfectly acceptable; there's really no
difference in application function between that and each cell being blank.

   Thank you very much for your comments and insights, they really helped me
understand what's going on and how to work with it.

Rich

···

On Tue, 27 May 2008, Paul McNett wrote:

I don't know how to help you if you aren't willing to rearrange when the
grid is instantiated and/or just making a grid.Refresh() call after your
altData is filled in.

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Paul McNett wrote:

Rich Shepard wrote:

  As soon as I invoke the application, many lines of "No existing data in
list" are printed to the console. That's the correct string, but why when
the application is invoked?

The grid wants to know what to show in the cells. I thought this should have happened at the point the grid is initially displayed, but maybe it makes a call when the grid is instantiated as well.

It's probably from trying to do a auto size of the columns, or perhaps from the DoGetBestSize.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!