Class/Method Instance Not Correctly Written

I fixed the "unbound method needs class instance as first attribute" after
extensive Google searching. But, my function is still broken; almost
certainly a fundamental python error over which I tripped in ignorance.

   Here's the function:

   def OnVarAdd(self, event):
     newVar = varDlg().varEnterDlg("Add a Variable")
     if (newVar.ShowModal() == wx.ID_OK):
       values = newVar.GetValues()
       DBtools.cur.execute("insert into variable (variable_name, \
                            variable_description, policy_name, \
                            sub_policy_name) values (?,?,?,?)", values)
       self.con.commit()
     newVar.Destroy()

varDlg() is a class in which the dialog box, varEnterDlg, is defined. All
this is in the same module.

   The error message tossed by python is:

Traceback (most recent call last):
   File "/data1/eikos/variablePage.py", line 233, in OnVarAdd
     if (newVar.ShowModal() == wx.ID_OK):
AttributeError: 'NoneType' object has no attribute 'ShowModal'

   What naive mistake have I made here?

Rich

···

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc.(TM) | Accelerator
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Well, varDlg().varEnterDlg("Add a Variable") is returning None, so you need to look there. Without knowing what's going on there, I can't say, but I'd guess that you meant to say varDlg(); I would debug this with
   def OnVarAdd(self, event):
     vardlg = varDlg()
     print 'vardlg',vardlg,type(vardlg)
     newvar = vardlg.varEnterDlg("Add a Variable")
     print 'newvar',newvar,type(newvar)
     if (newVar.ShowModal() == wx.ID_OK):
       values = newVar.GetValues()
       DBtools.cur.execute("insert into variable (variable_name, \
                            variable_description, policy_name, \
                            sub_policy_name) values (?,?,?,?)", values)
       self.con.commit()
     newVar.Destroy()

HTH, Phil

···

At 09:15 AM 11/10/2006, you wrote:

  I fixed the "unbound method needs class instance as first attribute" after
extensive Google searching. But, my function is still broken; almost
certainly a fundamental python error over which I tripped in ignorance.

  Here's the function:

  def OnVarAdd(self, event):
    newVar = varDlg().varEnterDlg("Add a Variable")
    if (newVar.ShowModal() == wx.ID_OK):
      values = newVar.GetValues()
      DBtools.cur.execute("insert into variable (variable_name, \
                           variable_description, policy_name, \
                           sub_policy_name) values (?,?,?,?)", values)
      self.con.commit()
    newVar.Destroy()

varDlg() is a class in which the dialog box, varEnterDlg, is defined. All
this is in the same module.

  The error message tossed by python is:

Traceback (most recent call last):
  File "/data1/eikos/variablePage.py", line 233, in OnVarAdd
    if (newVar.ShowModal() == wx.ID_OK):
AttributeError: 'NoneType' object has no attribute 'ShowModal'

  What naive mistake have I made here?

Rich

Phil,

   Yes, that was exactly my problem. Some more reading in the wPIA book
re-taught me that the dialog box should be defined as a class, not a
function. As soon as I cleaned that up, it displays properly.

   Each wx.TextCtrl() is assigned to a variable name. I believe that the
values assigned to those names are retained after the dialog box is closed,
so 'if results == wx.OK', I can write those values to the appropriate
database table.

Thanks very much,

Rich

···

On Fri, 10 Nov 2006, Phil Mayes wrote:

Well, varDlg().varEnterDlg("Add a Variable") is returning None, so you
need to look there. Without knowing what's going on there, I can't say,
but I'd guess that you meant to say varDlg();

HTH

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc.(TM) | Accelerator
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863