[PyKDE] Static member functions
Hihn, Jason
Jason.Hihn at verint.com
Tue Dec 14 14:31:07 GMT 2004
Ok, my problem is that I want to provide some function that is called by
the widget that generates the signal.
I have an On-Screen Keyboard. Each text-control gets assigned a
lostFocus handler. I need that handler to do one thing. I need it to
store that widget's id (or instance) so the OSK knows where to write the
characters to.
The issue I am having is in my previous environment, I could just say
the equivalent of:
Dlg.child('text1').lostFocusEvent=some_func()
#0 params passed
And some_func() would be given the 'this' object by the interpreter
(because it was then a member function of the class). This is not the
case for python. Assigning a global some_func() to an object does not
get the self object, even though it is now in the object's name space.
For connects, I tried:
Dlg.connect(dlg.child('text'), SIGNAL('lostFocus()'), setKeyboardDest)
#0 params passed
Dlg.connect(dlg.child('text'), SIGNAL('lostFocus()'),
self.setKeyboardDest)
# 1 param, self, passed, but this is the dialog instance
Furthermore, the dialogs that receive input are created from
QWidgetFactory, so I don't know if I can subclass the text controls at
runtime.
I am lost, lost, lost. I figure the ultimate way out is to assign each
slot to a separate function, but that is not elegant, since they would
all be of the form:
Def text1_lostfocus(self)
Globals.lastText=self.dlg.child('text1')
... repeat for each text box...
Then connect the signal to each indivisual slot. It is quite a waste
though. Also, adding text boxes would require recoding of the python
script, where the old method would not.
> -----Original Message-----
> From: pykde-bounces at mats.imk.fraunhofer.de [mailto:pykde-
> bounces at mats.imk.fraunhofer.de] On Behalf Of Sundance
> Sent: Monday, December 13, 2004 7:38 PM
> To: pykde at mats.imk.fraunhofer.de
> Subject: Re: [PyKDE] Static member functions
>
> I heard Hihn, Jason said:
>
> > How can I do this in python?
>
> It may be I'm not getting your question, but... What's the problem
> exactly? You can have global objects (which includes functions) all
you
> want, really.
>
> Example:
>
> ---[ globalstuff.py
]--------------------------------------------------
> data = None
>
-----------------------------------------------------------------------
>
> ---[ A.py
]------------------------------------------------------------
> import globalstuff
> def functionA():
> globalstuff.data = 42
>
-----------------------------------------------------------------------
>
> ---[ B.py
]------------------------------------------------------------
> import globalstuff
> def functionB():
> print "The global data contains:", globalstuff.data
>
-----------------------------------------------------------------------
>
> ---[ main.py
]---------------------------------------------------------
> import globalstuff
>
> from A import functionA
> from B import functionB
>
> # Set the global bit of data with functionA() from module A:
> functionA()
>
> # Print the global bit of data with functionB() from module B:
> functionB()
>
> # Set the global bit of data ourselves:
> globalstuff.data = "Nobody expects the Spanish Inquisition!"
>
> # Then print it with functionB() from module B:
> functionB()
>
> print "See, Jason? I don't understand what your problem is, exactly."
>
-----------------------------------------------------------------------
>
> Does this answer your question?
>
> -- S.
>
> _______________________________________________
> PyKDE mailing list PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
__________________________________________________________________________________________
This electronic message may contain proprietary and confidential information of Verint Systems Inc., its affiliates and/or subsidiaries.
The information is intended to be for the use of the individual(s) or
entity(ies) named above. If you are not the intended recipient (or authorized to receive this e-mail for the intended recipient), you may not use, copy, disclose or distribute to anyone this message or any information contained in this message. If you have received this electronic message in error, please notify us by replying to this e-mail. (1)
More information about the PyQt
mailing list