473,659 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6040
many_years_afte r 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 "Cooperativ e 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(sel f)
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_afte r 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 "Cooperativ e 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(sel f)
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(b illy)
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_afte r 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.Fram e):
def __init__(self, parent, id, title):
wx.Frame.__init __(self, parent, id, title)
MyPanel(self)

class MyPanel(wx.Pane l):
def __init__(self,f rame):
wx.Panel.__init __(self,frame,-1)
self.frame = frame
b = wx.Button(self,-1,'Close')
b.Bind(wx.EVT_B UTTON,self.onCl ose,id=b.GetId( ))

def onClose(self,ev t):
self.frame.Clos e()
evt.Skip()

class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, "Test")
frame.Show(True )
self.SetTopWind ow(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
3869
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 = & $object; if (method_exists($object, "setCallingCode")) $object->setCallingCode($nameOfFunctionOrClassCalling); return $object; } else {
4
1417
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
1345
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
3775
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 gridView.GetType().InvokeMember("RaiseKeyDown",BindingFlags.Instance|Bin
1
2342
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 class (guiClass). Specifically, when guiClassA or guiClassB calls a method from the sharedClass, the sharedClass needs to log its actions by sending strings to the guiClass (via guiClass method calls), which in turn display or record this log...
1
2702
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 are declared as public, of course. TIA
0
1685
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 description still there. As I can see the invoke button if I logon locally to the webservice PC, I suspect that the invoke button hided by permissions/authentications. After checked with web.config file, portion list here, with not changes from 1.0...
1
1773
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 this! Thanks in advance for your help. Steve
5
9715
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> /// Invokes the wrapped delegate synchronously /// </summary> static void InvokeWrappedDelegate (Delegate d, object args)
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.