473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 6021
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(); $this->arrayOfAllTheObjectsSoFarLoaded = &...
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 like ...
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 call a method that is defined in its parent...
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 control B and web form A? If yes, How? The mthods...
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 the invoke button gone. Anyway, the XML...
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 control. It seems that there should be a way to do...
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 method? In this method: /// <summary> ///...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.