472,352 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 software developers and data experts.

How to invoke parent's method?

Hi, pythoners:

My wxPython program includes a panel whose parent is a frame. The
panel has a button. When I click the button , I want to let the frame
destroy. How to implement it? Could the panel invoke the frame's
method?
Thanks.

Jan 7 '07 #1
4 5976
many_years_after wrote:
Hi, pythoners:

My wxPython program includes a panel whose parent is a frame. The
panel has a button. When I click the button , I want to let the frame
destroy. How to implement it? Could the panel invoke the frame's
method?
Thanks.
I think it "could" if what I read recently in:
http://www.python.org/download/relea...o/#cooperation
Is applicable.

Look at the link "Cooperative methods and super"
Write a subclass of panel where the target method of it's parent
is targX (that parent method of Frame that you want to call)

class myPanel (Panel):
def dadsX (self):
Frame.targX(self)
I think you are forced to invoke this within a method of the Class
itself, as opposed to doing so with an instance.

Good luck!
Jan 7 '07 #2
rweth wrote:
many_years_after wrote:
>Hi, pythoners:

My wxPython program includes a panel whose parent is a frame. The
panel has a button. When I click the button , I want to let the frame
destroy. How to implement it? Could the panel invoke the frame's
method?
Thanks.
I think it "could" if what I read recently in:
http://www.python.org/download/relea...o/#cooperation
Is applicable.

Look at the link "Cooperative methods and super"
Write a subclass of panel where the target method of it's parent
is targX (that parent method of Frame that you want to call)

class myPanel (Panel):
def dadsX (self):
Frame.targX(self)
I think you are forced to invoke this within a method of the Class
itself, as opposed to doing so with an instance.

Good luck!

You know I just tried a code fragment and got the parent method to work
with an instance .. so maybe you don't have to subclass. Here is a
transcript illustrating the idea:
>>class DAD:
.... def methodx(self):
.... print "DAD-methodx"
....
>>class SON(DAD):
.... def methodx(self):
.... print "SON-methodx"
....
>>>

billy = SON()
billy.methodx()
SON-methodx
>>DAD.methodx(billy)
DAD-methodx
>>>
So you can invoke the DAD.methodx via the billy instance of the object
... without subclassing. Now I wonder if this will actually work?




Jan 7 '07 #3

many_years_after wrote:
Hi, pythoners:

My wxPython program includes a panel whose parent is a frame. The
panel has a button. When I click the button , I want to let the frame
destroy. How to implement it? Could the panel invoke the frame's
method?
Thanks.
Have a look at the following program -

----------------------------------------------------------------------

class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
MyPanel(self)

class MyPanel(wx.Panel):
def __init__(self,frame):
wx.Panel.__init__(self,frame,-1)
self.frame = frame
b = wx.Button(self,-1,'Close')
b.Bind(wx.EVT_BUTTON,self.onClose,id=b.GetId())

def onClose(self,evt):
self.frame.Close()
evt.Skip()

class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, "Test")
frame.Show(True)
self.SetTopWindow(frame)
return True

app = MyApp(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events

----------------------------------------------------------------------

The essential point is that you save a reference to the frame when you
create the panel. Then when the button is clicked you can use the
reference to call the frame's Close method.

HTH

Frank Millman

Jan 7 '07 #4
On 7 Jan 2007 01:33:32 -0800, Frank Millman <fr***@chagford.comwrote:
The essential point is that you save a reference to the frame when you
create the panel. Then when the button is clicked you can use the
reference to call the frame's Close method.
Or you could look into Dabo. This is one of those common needs that
has been built into the framework. Any object on a form (a wx.Frame)
can simple reference 'self.Form' to get a reference to the containing
frame. Controls that are contained within other controls (such as
inside panels or notebook pages) can always reference that container
with 'self.Parent'.

--

# p.d.
Jan 7 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lkrubner | last post by:
My code was dying on the line below where I use method_exists: if (class_exists($nameOfClassToBeUsed)) { $object = new $nameOfClassToBeUsed();...
4
by: FeOl | last post by:
Hi. How can I invoke the "Text1_LostFocus()" method within the "Button1_Clik()" method? Or wath parameters should I pass? Thanks in advance.
1
by: Mel | last post by:
I am in my class and I want to invoke a method on my form. I made my form method public. But I don't see it through intellisensing. Any ideas?
1
by: tolisss | last post by:
Hi there is a method at an external assembly that i want to invoke with signature internal void RaiseKeyUp(KeyEventArgs e) and i m trying...
1
by: - vhannak | last post by:
I have a class (sharedClass) that is instantiated (not derived) by two other classes (guiClassA and guiClassB). The sharedClass needs to be able to...
1
by: Danny Ni | last post by:
Hi, I have a web form A that contains an user control B, which contains an user control C. Inside user control C, can I call methods in user...
0
by: Joe | last post by:
Hi, I had a web service and all along able be invoked directly in IE within its asmx page. After someone upgrade the framework to 1.1 recently, all...
1
by: Steve Kershaw | last post by:
I have this web page that has on it a user control. I have a need to access a method that resides in the parent web page from within this user...
5
by: puzzlecracker | last post by:
I've just discovered DynamicInvoke methods while reading Jon's threading article. And my question is how it's different from a regular invoke...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.