in method 'new_panel' expected argument 1 of type wxWindow*

Hi There:

I have a class A (wx.Panel) which I believe is its parent class and this panel has been created using automatically generated wxGlade code and it has the init as

wx.Panel.init(self, *args, **kwds)

now Class B inherits class A. Class B(class A) and the init for class B is

def init(self, *args, **kw):

   A.__init__(self, *args, **kw)

When I try to create an object of class B, how should i instantiate it?

obj = B(). I know I cannot have a None because a parent is definitely needed. Why do I land in the error “in method ‘new_panel’ expected argument 1 of type wxWindow*”

-B

parent, which needs to be type wxWindow.

If this isn't the issue, try posting more code:

http://wiki.wxpython.org/MakingSampleApps

-Chris

···

On Thu, Oct 31, 2013 at 4:37 PM, kb <kukki.kanchana@gmail.com> wrote:

When I try to create an object of class B, how should i instantiate it?

obj = B(). I know I cannot have a None because a parent is definitely
needed. Why do I land in the error "in method 'new_panel' expected argument
1 of type wxWindow*"

umm, you just answered your own question -- argument 1 needs to be the

--

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

I tried that and I get an error saying wxWindow is not globally defined. I m missing something trivial… Any suggestions?

···

On Thursday, October 31, 2013 4:45:56 PM UTC-7, Chris Barker wrote:

When I try to create an object of class B, how should i instantiate it?

obj = B(). I know I cannot have a None because a parent is definitely needed. Why do I land in the error “in method ‘new_panel’ expected argument 1 of type wxWindow*”

umm, you just answered your own question – argument 1 needs to be the parent, which needs to be type wxWindow.

If this isn’t the issue, try posting more code:

http://wiki.wxpython.org/MakingSampleApps

-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....@noaa.gov

wx.Panels.init(parent=[wx.Frame | wx.Panel | wx.Window])
Panels need another wx widget as its parent. The wx.Frame class can set “parent” to None in its init() method.

Doing obj=B() sets the panel class B’s init(parent) argument to “None” which is not a valid value.

Try

mysubdPanel = B(self)

where self is assigned to the “parent” keyword or more explicitly if you changed your panel class’ init keyword argument names then try

mysubdPanel = B(parent=self) or

mysubdPanel = B(parent=self.parentPanel) or the like

···

The following code works fine for me.

import wx

class AppBasePanel(wx.Panel):

def init(self, *args, **kwargs):

wx.Panel.init(self, *args, **kwargs)

self.SetBackgroundColour(‘Blue’)

st = wx.StaticText(self, label=str(self))

class SubclassedPanel(AppBasePanel):

def init(self, *args, **kwargs):

AppBasePanel.init(self, *args, **kwargs)

self.SetBackgroundColour(‘Green’)

class Frame(wx.Frame):

def init(self, *args, **kwargs):

wx.Frame.init(self, *args, **kwargs)

basePanel = AppBasePanel(parent=self)

subclassedPanel = SubclassedPanel(parent=self)

sizer=wx.BoxSizer(wx.VERTICAL)

sizer.Add(basePanel, 1, wx.EXPAND|wx.ALL, 5)

sizer.Add(subclassedPanel, 1, wx.EXPAND|wx.ALL, 5)

self.SetSizer(sizer)

if name == “main”:

app = wx.App()

frame = Frame(parent=None, title=‘Test Subclassed Panels’)

frame.Show()

app.MainLoop()

I tried that and I get an error saying wxWindow is not globally defined. I
m missing something trivial.. Any suggestions?

in python, it's called "wx.Window", but you dont want to be using that
anyway, you want to pass in a wxWindow subclass into the constructor as the
first argument -- the "parent" of the Window you are creating. It can be a
Frame, Dialog, Panel or Window subclass. Usually it's "self" -- i.e. the
instance object of the class you are creating the new Window to go on...

-Chris

···

On Thu, Oct 31, 2013 at 5:02 PM, kb <kukki.kanchana@gmail.com> wrote:

On Thursday, October 31, 2013 4:45:56 PM UTC-7, Chris Barker wrote:

When I try to create an object of class B, how should i instantiate it?

obj = B(). I know I cannot have a None because a parent is definitely
needed. Why do I land in the error "in method 'new_panel' expected argument
1 of type wxWindow*"

umm, you just answered your own question -- argument 1 needs to be the

parent, which needs to be type wxWindow.

If this isn't the issue, try posting more code:

http://wiki.wxpython.org/**MakingSampleApps&lt;http://wiki.wxpython.org/MakingSampleApps&gt;

-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....@noaa.gov

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--

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

I changed a few things around.I have a “class
A(wx.ScrolledWindow)” and “class B” is the child inherited from “Class A”. “Class B” has init → “def init(self, parent, *args, **kw):” and " A.init(self, parent, *args, **kw)". If I want to instantiate “Class B” inside a global function, like obj = class B() – what parameters would i pass to it?

···

On Friday, November 1, 2013 9:52:22 AM UTC-7, Chris Barker wrote:

On Thu, Oct 31, 2013 at 5:02 PM, kb wrote:

I tried that and I get an error saying wxWindow is not globally defined. I m missing something trivial… Any suggestions?

in python, it’s called “wx.Window”, but you dont want to be using that anyway, you want to pass in a wxWindow subclass into the constructor as the first argument – the “parent” of the Window you are creating. It can be a Frame, Dialog, Panel or Window subclass. Usually it’s “self” – i.e. the instance object of the class you are creating the new Window to go on…

-Chris

On Thursday, October 31, 2013 4:45:56 PM UTC-7, Chris Barker wrote:

When I try to create an object of class B, how should i instantiate it?

obj = B(). I know I cannot have a None because a parent is definitely needed. Why do I land in the error “in method ‘new_panel’ expected argument 1 of type wxWindow*”

umm, you just answered your own question – argument 1 needs to be the parent, which needs to be type wxWindow.

If this isn’t the issue, try posting more code:

http://wiki.wxpython.org/MakingSampleApps

-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....@noaa.gov

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

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....@noaa.gov

DevPlayer-

I follow your example and agree with you but in the specific case I am looking at where I am trying to instantiate inside a global function, i am having some issues understanding…

···

On Thursday, October 31, 2013 9:15:17 PM UTC-7, DevPlayer wrote:

Panels need another wx widget as its parent. The wx.Frame class can set “parent” to None in its init() method.

Doing obj=B() sets the panel class B’s init(parent) argument to “None” which is not a valid value.

Try

mysubdPanel = B(self)

where self is assigned to the “parent” keyword or more explicitly if you changed your panel class’ init keyword argument names then try

mysubdPanel = B(parent=self) or

mysubdPanel = B(parent=self.parentPanel) or the like

The following code works fine for me.

import wx

class AppBasePanel(wx.Panel):

def init(self, *args, **kwargs):

wx.Panel.init(self, *args, **kwargs)

self.SetBackgroundColour(‘Blue’)

st = wx.StaticText(self, label=str(self))

class SubclassedPanel(AppBasePanel):

def init(self, *args, **kwargs):

AppBasePanel.init(self, *args, **kwargs)

self.SetBackgroundColour(‘Green’)

class Frame(wx.Frame):

def init(self, *args, **kwargs):

wx.Frame.init(self, *args, **kwargs)

basePanel = AppBasePanel(parent=self)

subclassedPanel = SubclassedPanel(parent=self)

sizer=wx.BoxSizer(wx.VERTICAL)

sizer.Add(basePanel, 1, wx.EXPAND|wx.ALL, 5)

sizer.Add(subclassedPanel, 1, wx.EXPAND|wx.ALL, 5)

self.SetSizer(sizer)

if name == “main”:

app = wx.App()

frame = Frame(parent=None, title=‘Test Subclassed Panels’)

frame.Show()

app.MainLoop()

wx.Panels.init(parent=[wx.Frame | wx.Panel | wx.Window])

I - think - you are looking for:

import wx

module scope

def MyScrolledWindowFactory(parent, *args, **kwargs):
return B(parent, *args, **kwargs)

Hi,

···

On 02/11/2013 00:52, kb wrote:

Chris

I changed a few things around.I have a "class A(wx.ScrolledWindow)" and "class B" is the child inherited from "Class A". "Class B" has init -> "def __init__(self, parent, *args, **kw):" and " A.__init__(self, parent, *args, **kw)". If I want to instantiate "Class B" inside a global function, like obj = class B() -- what parameters would i pass to it?

I would say it does not matter where you instantiate your "Class B", or in other words the parameters depend on the class "B" definition and not where it gets initiated.

Maybe it is time for: MakingSampleApps - wxPyWiki

Werner

I still get the same error… I cant use “self” because i m instantiating inside another class and using “self” would mean I am using an all together different class.

···

On Saturday, November 2, 2013 12:06:15 AM UTC-7, werner wrote:

Hi,

On 02/11/2013 00:52, kb wrote:

Chris

I changed a few things around.I have a “class A(wx.ScrolledWindow)”
and “class B” is the child inherited from “Class A”. “Class B” has
init → “def init(self, parent, *args, **kw):” and "
A.init(self, parent, *args, **kw)". If I want to instantiate
“Class B” inside a global function, like obj = class B() – what
parameters would i pass to it?

I would say it does not matter where you instantiate your “Class B”, or
in other words the parameters depend on the class “B” definition and not
where it gets initiated.

Maybe it is time for: http://wiki.wxpython.org/MakingSampleApps

Werner

kb wrote:

I still get the same error.. I cant use "self" because i m
instantiating inside another class and using "self" would mean I am
using an all together different class.

Your question asked what parameters you should pass in "obj = B()" if
you want to instantiate a B object (derived from wx.ScrolledWindow)
inside a global function. The key is that the window has to have an
owner. You can't just instantiate a window from thin air. It has to
be owned by some other window, or by the app. It's an important
question, because the ownership tree determines how events propagate.

So, somewhere you have a window that needs to own this new B window.
That's the object you need to pass as the parent.

···

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