help with TypeError: in method 'new_Panel', expected argument 1 of type 'wxWindow *'

70 views
Skip to first unread message

pytho...@gmail.com

unread,
Sep 25, 2017, 3:40:46 AM9/25/17
to wxPython-users
Hi, can anyone help me with this error .
I'm trying to make an contact manager to help me in my work as a blind person. The idea is create
data base to store all the phone and fax number I
needed in my work, but I have problem with the update method in Dialogs() class
I can't get the row.name scop variable to get the function work and I get the following error:
Traceback (most recent call last):
  File "E:\projects\data manager\skeliton\data manager\contact_manager.py", line
 118, in Onupdate
    old_name = MainPanel(MainFrame).getValue()
  File "E:\projects\data manager\skeliton\data manager\contact_manager.py", line
 136, in __init__
    wx.Panel.__init__(self, parent)
  File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_windows.py", line 68, in __
init__
    _windows_.Panel_swiginit(self,_windows_.new_Panel(*args, **kwargs))
TypeError: in method 'new_Panel', expected argument 1 of type 'wxWindow *'


contact_manager.py

Tim Roberts

unread,
Sep 25, 2017, 12:11:59 PM9/25/17
to wxpytho...@googlegroups.com
I'm not sure what you're trying to do in Onupdate, but the code you have
is wrong:
    old_name = MainPanel(MainFrame).getValue()
That line will create a brand new MainPanel, passing the "MainFrame"
class (not an INSTANCE of that class) as the first parameter.  That's
clearly wrong.  I don't think you are storing the "old name" anywhere;
perhaps you need to save a copy of it in your "setValues" function.

In several places, you have a similar problem when you write
DataOperation().table_name.  That creates a brand new object each time. 
Instead of that, you should create a single DataOperation() object and
store it in a member variable.  You even do that inside the
DataOperation class in the "insert" method, where you should use "self"
instead.

The SQL in Onupdate is also wrong.  You need to use parameter
substitution, just like you did in the INSERT calls above.  As it is,
your UPDATE call merely replaces the name, tel, and fax fields with
copies of their existing values.

I have attached something that makes these changes.  I don't have
ObjectListView, so I'm not sure this is entirely right, but it should
get you started.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

contact_manager.py

pytho...@gmail.com

unread,
Sep 25, 2017, 2:51:22 PM9/25/17
to wxPython-users
Hi thanks you for your reply, I tryed your file and it didn't work
my original code shows the error message when I press the update button only,
but with your file the error appears when I start the script .
What I want from the following line
    old_name = MainPanel(MainFrame).getValue()
is to get the value stored in the name variable from the getValue() function
and give it to old_name to complete the sql function UPDATE

I hope I made myself clear

Rufus Smith

unread,
Sep 25, 2017, 3:58:24 PM9/25/17
to wxpytho...@googlegroups.com
One of the points you missed from that example was that this line:

> old_name = MainPanel(MainFrame).getValue()

is fundamentally flawed. You can't get an existing value that way, because you
are creating a brand new MainPanel object, and getting whatever the default value is.
you should have a line during init such as:

self.mainPanel = MainPanel(...)

then, later on, to get the value from it using:

old_name = self.mainPanel.getValue()

Do you understand object constructors versus object references?

It's crucial.


Tim Roberts

unread,
Sep 26, 2017, 12:38:01 PM9/26/17
to wxpytho...@googlegroups.com
pytho...@gmail.com wrote:
> Hi thanks you for your reply, I tryed your file and it didn't work
> my original code shows the error message when I press the update
> button only,
> but with your file the error appears when I start the script .

WHAT error?  The code I sent you works on my machine (after I commented
out the ObjectListView references), so the fundamentals are correct.  It
looks like you and I use different philosophies in tabs vs spaces , but
I would hope you could fix that.


> What I want from the following line
>     old_name = MainPanel(MainFrame).getValue()
> is to get the value stored in the name variable from the getValue()
> function
> and give it to old_name to complete the sql function UPDATE

But "MainPanel" and "MainFrame" are not variables, and they are not
objects.  They are types.  That statement is just like writing this:
    old_name = list(unicode).getValue()

It's nonsense.  If you want to access members of your main panel object
from the Dialogs code, then you need to have a variable that contains
that object.  Now, as it happens, you do pass an instance of the
MainPanel to the Dialogs constructor (the "parent"), but right now you
are throwing that away.  If you were to store "parent" in a member
variable in Dialogs.__init__, then you could refer to it in
Dialogs.Onupdate.

However, my code shows a more efficient way of handling that, by just
remembering the original name when it is first handed to us.

pytho...@gmail.com

unread,
Sep 27, 2017, 3:08:17 AM9/27/17
to wxPython-users
Hi thank you
First now my code work after reading your comments on my code and after review and correct some errors in the code
second after you saw my code and the mistakes I made on it, can you suggest any internet resources to improve my python oop.


pytho...@gmail.com

unread,
Sep 27, 2017, 3:13:47 AM9/27/17
to wxPython-users
Hi thank you for your comment.
First now my code works
Reply all
Reply to author
Forward
0 new messages