Understanding class instantiation

While I thought I understood class instatiation with wxPython I've
discovered that I still lack complete understanding. I've read the Python3
doc, Chapter 9 (Classes), Sections 9.3.3--9.3.5 and cannot find my error. I
want to learn to properly initialize and instantiate wxPython4 classes so
pointers to other references will be appreciated.

   The current issue is adding panels to a notebook. Both the wx.Frame and
wx.Notebook are in the same module and the notebook panels are imported at
the top of this module; e.g.,

   from sitePage import SiteGrid

and the notebook class is attached to the frame at the end of the wx.Frame
class:

         # Attach notebook
         self.theNB = MainNB(self, id=wx.ID_ANY)

   The notebook class:

class MainNB(wx.Notebook):
     def __init__(self, parent, id):
         wx.Notebook.__init__(self, parent, id, style=wx.NB_TOP)

         self.panel1 = SiteGrid(self,wx.ID_ANY)
   # plus the other panels.

         self.AddPage(self.panel1, "Sites")
   # plus the other panels.

   When I run the main module there's a type error:

$ ./openEDMS.py Traceback (most recent call last):
   File "./openEDMS.py", line 320, in <module>
     top = MainFrame(None, 'openEDMS')
   File "./openEDMS.py", line 161, in __init__
     self.theNB = MainNB(self, id=wx.ID_ANY)
   File "./openEDMS.py", line 283, in __init__
     self.panel1 = SiteGrid(self,wx.ID_ANY)
TypeError: __init__() takes 1 positional argument but 3 were given

   My readings haven't shown me where this inconsistency arises and I do need
to learn how to avoid these TypeErrors in the future.

TIA,

Rich

        self.panel1 = SiteGrid(self,wx.ID_ANY)

...

$ ./openEDMS.py Traceback (most recent call last):
  File "./openEDMS.py", line 320, in <module>
    top = MainFrame(None, 'openEDMS')
  File "./openEDMS.py", line 161, in __init__
    self.theNB = MainNB(self, id=wx.ID_ANY)
  File "./openEDMS.py", line 283, in __init__
    self.panel1 = SiteGrid(self,wx.ID_ANY)
TypeError: __init__() takes 1 positional argument but 3 were given

SiteGrid wants 1 non-keyword argument but you hand it 3:

  self.panel1 = SiteGrid(self,wx.ID_ANY)

non-keyword args:

  #1: self, auto-added by Python, = class-of-SiteGrid
  #2: self, again, given by you, = likely the MainNB instance
  #3: wx.ID_ANY, = -1

Look at

  SiteGrid.__init__

which is where the problem occurs, as the traceback says.

Karsten

···

On Sun, Apr 29, 2018 at 11:04:21AM -0700, Rich Shepard wrote:
--

Karsten,

   Thank you. These imported modules were generated by wxFormBuilder and I
assumed -- incorrectly -- they worked as provided.

   I referenced the wx.Panel inits from a project written a dozen years ago
and that syntax works:

     def __init__(self, parent, id):
         wx.Panel.__init__(self, parent, id)

         self.SetClientSize(wx.Size(800, 600))

         self.Fit()

Much appreciated,

Rich

···

On Sun, 29 Apr 2018, Karsten Hilbert wrote:

Look at
  SiteGrid.__init__
which is where the problem occurs, as the traceback says.

They do, as long as they are used the way they are defined.

There is no magic (except for the "self" auto-added by
Python).

Karsten

···

On Sun, Apr 29, 2018 at 12:51:46PM -0700, Rich Shepard wrote:

  SiteGrid.__init__

  Thank you. These imported modules were generated by wxFormBuilder and I
assumed -- incorrectly -- they worked as provided.

--
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346