[wxPython-users] Bound Methods
António Barbosa (GN/dpi)
ab at jn.pt
Mon Feb 26 12:34:08 PST 2007
Hi Murat,
Excuse me but I was too synthetic ;)
I will try to explain it better:
Sometimes I have to modify or debug a program made by me (or by someone els=
e) and I would like, for instance, to change the behavior of pressing a par=
ticular button.
In a small program it is very easy to do it: I only have to read a hand-ful=
l of code lines. =
But in large programs with several script files, with several classes an se=
veral dialogs, that task is not so easy!
Particularly if I am not the author or if my memory not helps me as it shou=
ld ;)
Suppose that at near the end of main script, I put something like this:
#--------------------------------------------------
class MyApp(wx.App):
def OnInit(self):
(...)
self.Bind(wx.EVT_RIGHT_UP , self.OnRightClick) #only for debug!
def OnRightClick(self, event):
import inspect
obj =3D wx.FindWindowAtPointer()
name=3Dobj.GetName()+' '+obj.GetLabel()
A=3D[name]
parent=3Dobj.GetParent()
bases=3D parent.__class__.__bases__[0]
methodList =3D [ method for method in dir (parent) if method not in di=
r (bases) and callable(getattr(parent, method)) ]
for method in methodList:
A.append('Method: '+method)
method=3DmyPopUp(self.dialog_1,A) #myPopup gives a popup menu, and return=
s the choice
myattr=3Dmethod.split()
if len(myattr)>1:
s=3Dgetattr(parent,myattr[1])
script=3Dinspect.getsourcefile(s)
line=3Dinspect.getsourcelines(s)[1]
print 'TRACE ---->[%s] %s Script: "%s" line %d' %(name,method,script, =
line)
else:
print 'TRACE ----> [%s]' %(name)
#--------------------------------------------------
With this, I get the name of object that I am inspecting, and a list of met=
hods of parent's class.
What I would like is to show only the relevant methods: - the ones that are=
BOUND to it!
It is possible?
I know that I can parse the class code and search for lines that have =AB.b=
ind=BB, but it is not a good solution, don't you agree?
I hope to have been more clear.
Thanks for your attention.
Antonio Barbosa
-----Mensagem original-----
De: Murat Erten [mailto:murerten at gmail.com]
Enviada: seg 26-02-2007 19:01
Para: wxPython-users at lists.wxwidgets.org
Assunto: Re: [wxPython-users] Bound Methods
=
2007/2/26, Ant=F3nio Barbosa (GN/dpi) <ab at jn.pt>:
>
>
>
>
> Hi,
>
>
>
> I am playing with =ABintrospection=BB and I would like to know if it is p=
ossible
> to know which method is bound to a particular object.
>
> Or putting the problem in another form: It's possible to know which object
> is bound to a particular method?
>
>
>
> Suppose a window with 2 buttons (bt1 + bt2)
>
> And:
>
> bt1.Bind(wx.EVT_BUTTON, self.onButton1)
>
> bt2.Bind(wx.EVT_BUTTON, self.onButton2)
>
>
>
> I can easily identify the two objects, the two methods of their parent and
> the source line where they are defined.
>
> But:
>
> How can I know that onButton1 is bound to bt1 and onButton2 is bound to b=
t2?
>
> Or:
>
> How can I know that bt1 is bound to onButton1 and bt2 is bound to
> onButton2?
>
>
>
> Any help would be appreciated.
>
> Antonio Barbosa
>
>
I think you already know that by saying:
bt1.Bind(wx.EVT_BUTTON, self.onButton1)
bt2.Bind(wx.EVT_BUTTON, self.onButton2)
What are you trying to do ? What is your purpose ? Can you be more specific=
?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 4311 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20070=
226/144888d5/attachment.bin
More information about the wxpython-users
mailing list