Grid Table Widget: GetValue()

Rich Shepard wrote:

  Where is the GetValue() method called using the grid table mechanism?

  In both the demo/GridCustTable.py and listing 14.2 in the wPIA book, the
GetValue(self, row, col) method is called to provide data to the grid widget
from the underlying table. The logic is in the grid table class rather than
in the grid class.

  In my application, the grid cells are populated by the string, 'Empty,' if
there are no project-specific data in the database table. The method in my
application is written thusly:

      def GetValue(self, row, col):
        if self.appData.altData != None:
          return self.data
        else: # no data for existing or alternative condx, but project exists
          return 'Empty'

  However, there exist data for the first three columns in the grid that I
would like to have loaded when the project data file is opened. However,
when I try to add an embedded SQL statement in the 'else:' clause, python
complains that the 'str' has no 'execute' method.

Well, apparently whatever you have on the left side of the '.execute()' is a string object, not a database cursor object. Backtrack from there to see what is causing your confusion.

  Trying to figure out why the SQL does not work in this location as it does
in many others (including two other locations in the same class), I looked
to see where GetValue() was being called. I cannot find the call in the
table or grid classes. So, why is it invoked and placing the string, 'Empty,'
in the grid?

It's called from the C++ code. In a nutshell there was a paint event and the Grid class is iterating through the cells that intersect the update region and asking each cell's renderer to paint itself, and the renderers are fetching the data from the table so they know what to draw.

···

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

Well, apparently whatever you have on the left side of the '.execute()' is
a string object, not a database cursor object. Backtrack from there to
see what is causing your confusion.

   Actually, it's the same pysqlite2 statement. That's what puzzles me.

It's called from the C++ code. In a nutshell there was a paint event and
the Grid class is iterating through the cells that intersect the update
region and asking each cell's renderer to paint itself, and the renderers
are fetching the data from the table so they know what to draw.

   Ah! OK. I was looking for a call within the two classes here.

Thanks,

Rich

···

On Thu, 27 Dec 2007, Robin Dunn wrote:

--
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

I must be missing something, but I can’t even see why the first SELECT would work.

I see this:
appData = config.appData
and then this:
if self.appData.projname != ’ ':
self.appData.cur.execute
(‘SELECT count(*) from Variable’)

When you cleaned this up to post it (removing BoxSizers, etc.) did you also remove a line where self.appData was associated with appData? Or am I just clueless?

···

On Dec 27, 2007 12:06 PM, Rich Shepard rshepard@appl-ecosys.com wrote:

Perhaps another set of eyes will see what I keep missing. Here’s the top
portion of the class (with BoxSizers and other extraneous code removed). The
first SELECT triggers no errors, the second one does. I’m just not seeing

the difference(s):

class modData(wx.Panel):

appData = config.appData

def init(self, prnt, ID):
wx.Panel.init(self, prnt, wx.ID_ANY, size=wx.Size(770,440))

 # Get number of rows

 if self.appData.projname != ' ':
   self.appData.cur.execute('SELECT count(*) from Variable')
   self.nRows = self.appData.cur.fetchall()
 else:
   self.nRows = 24


 self.nCols = 33

 # Set labels for columns
 self.colLabel = ['Component', 'Subcomponent', 'Variable', 'Current 1',
                  'Current 2', 'Current 3', 'Current 4', 'Current 5',

                  'Current 6', 'Current 7', 'Current 8', 'Current 9',
                  'Current 10', 'Current 11', 'Current 12', 'No Action',

                  'Alt 2', 'Alt 3', 'Alt 4', 'Alt 5', 'Alt 6', 'Alt 7',
                  'Alt 8', 'Alt 9', 'Alt 10', 'Alt 11', 'Alt 12', 'Alt 13',

                  'Alt 14', 'Alt 15', 'Alt 16', 'Alt 17', 'Alt 18']

 # Get components, subcomponents, variables for grid if it's not fully populated
 c = []

 s = []
 v = []
 self.appData.cur.execute('SELECT comp_name, subcomp_name, name from Variable')
 initData = self.appData.cur.fetchall()
 for i in initData:
   c.append(i,0)

   s.append(i,1)
   v.append(i,2)

 # Here's where the grid widget is defined.
 self.dataGrid = wx.grid.Grid(self)
 self.dataGrid.CreateGrid(self.nRows, self.nCols, selmode=wx.grid.Grid.SelectCells

)

I am not seeing why line 21 works while line 41 triggers the error:

File “/data1/eikos/dataPage.py”, line 61, in init
self.appData.cur.execute(‘SELECT comp_name, subcomp_name, name from Variable’)

AttributeError: ‘str’ object has no attribute ‘execute’

Both are called before the CreateGrid command is issued. A clue stick is
welcome.

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


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org



www.fsrtechnologies.com

Rich,

This points out that the best way to get help is to make a as-small-as-possible runnable sample that demonstrates the problem. You'll get more help, and you'll be more likely to figure out the problem yourself when you try to make the pieces work by themselves (and probably design better code too)

In this case it may not be strictly possible to make it runnable without your database, but if the code you post does run on your system, at least we can all see all the parts that are required.

And again, you may figure out out yourself when you try to build the little stand-alone.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris,

   If it was relatively simple to extract this code to a separate tiny app I
would gladly have done so.

   The error shows up when the application is invoked and only when the
pysqlite select statement is issued the second time in the grid module. I'm
confident the error is related to how the grid widget is invoked because
select statements are not an issue with any other wxPython module or widget
in the application.

   I'll re-read the docs on this widget and see if I can discern what I need
to do to get the data from the database table into the first three columns.
Think I'll try doing so indirectly via a function call where the function
lives in the application-specific-functions module.

Ciao,

Rich

···

On Thu, 27 Dec 2007, Christopher Barker wrote:

This points out that the best way to get help is to make a
as-small-as-possible runnable sample that demonstrates the problem.

In this case it may not be strictly possible to make it runnable without
your database, but if the code you post does run on your system, at least
we can all see all the parts that are required.

--
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