RE: [PyKDE] Static member functions

2004-12-15 Thread Phil Thompson
>
> Followup: I seem to have found sender(), but I get the usual 'you can't
> do this because it was not created in python' error.
>
> So I still don't know how to go about it. Here's a sample class that I
> just typed up:
>
> class testDlg:
>   def __init__(self):
>   self.dlg=QWidgetFactory.create('lineedit.ui') #just a
> dialog with 2 lineedit boxes named lineedit1 and lineedit2, clicking
> between them should print out different instances
>   self.dlg.connect(self.dlg.child('lineedit1'),
> SIGNAL('lostFocus()'), self.lostFocus)
>
>   def lostFocus(self):
>   print self.dlg.sender() # error here
>
>   def show(self):
>   self.dlg.show()
> if __name__=='__main__':
>   d=testDlg()
>   d.show()
>   qApp.exec_loop()

Like I said, the slot must be a member of a QObject derived class. Also,
sender() should be from the receiver - there's no point in asking the
sender who the sender is :)

So, testDlg should sub-class from QObject and the lostFocus() method
should be...

def lostFocus(self):
print self.sender()

Phil

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


RE: [PyKDE] Static member functions

2004-12-14 Thread Hihn, Jason

Followup: I seem to have found sender(), but I get the usual 'you can't
do this because it was not created in python' error.

So I still don't know how to go about it. Here's a sample class that I
just typed up:

class testDlg:
def __init__(self):
self.dlg=QWidgetFactory.create('lineedit.ui') #just a
dialog with 2 lineedit boxes named lineedit1 and lineedit2, clicking
between them should print out different instances
self.dlg.connect(self.dlg.child('lineedit1'),
SIGNAL('lostFocus()'), self.lostFocus)

def lostFocus(self):
print self.dlg.sender() # error here

def show(self):
self.dlg.show()
if __name__=='__main__':
d=testDlg()
d.show()
qApp.exec_loop()


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:pykde-
> [EMAIL PROTECTED] On Behalf Of Hihn, Jason
> Sent: Tuesday, December 14, 2004 3:20 PM
> To: Phil Thompson; Diez B. Roggisch
> Cc: [EMAIL PROTECTED]
> Subject: RE: [PyKDE] Static member functions
>
>
> I think this is exactly what I want, but I do not know how to use it.
>
> Can I get an example in PyQt?
>
> Thanks again!
>
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:pykde-
> > [EMAIL PROTECTED] On Behalf Of Phil Thompson
> > Sent: Tuesday, December 14, 2004 11:09 AM
> > To: Diez B. Roggisch
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: [PyKDE] Static member functions
> >
>
> > > Hi,
> > >
> > > I think I understand your problem as follows: You have a non-
> > parametrized
> > > signal, lostFocus, that you want to connect to one slot - but then
> > somehow
> > > "magically" there shall be a reference to the object the signal
came
> > from
> > > is
> > > passed.
> >
>
> > If that's the case then just use QObject.sender(). The slot must be
a
> > method of a QObject derived class - but that wouldn't seem to be a
> problem
> > in this case.
> >
>
> > Phil
> >
>
> > ___
> > PyKDE mailing list[EMAIL PROTECTED]
> > 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)
>
> ___
> PyKDE mailing list[EMAIL PROTECTED]
> 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)

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


RE: [PyKDE] Static member functions

2004-12-14 Thread Hihn, Jason

I think this is exactly what I want, but I do not know how to use it.

Can I get an example in PyQt?

Thanks again!

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:pykde-
> [EMAIL PROTECTED] On Behalf Of Phil Thompson
> Sent: Tuesday, December 14, 2004 11:09 AM
> To: Diez B. Roggisch
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PyKDE] Static member functions
>
> > Hi,
> >
> > I think I understand your problem as follows: You have a non-
> parametrized
> > signal, lostFocus, that you want to connect to one slot - but then
> somehow
> > "magically" there shall be a reference to the object the signal came
> from
> > is
> > passed.
>
> If that's the case then just use QObject.sender(). The slot must be a
> method of a QObject derived class - but that wouldn't seem to be a
problem
> in this case.
>
> Phil
>
> ___
> PyKDE mailing list[EMAIL PROTECTED]
> 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)

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Static member functions

2004-12-14 Thread Sundance
I heard Hihn, Jason said:

> Ok, my problem is that I want to provide some function that is called
> by the widget that generates the signal.

I'm not sure I fully get your problem, I'm afraid (I'm a bit slow like 
that), but:
  http://doc.trolltech.com/qq/qq10-signalmapper.html
Would this help?

-- S.

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Static member functions

2004-12-14 Thread Diez B. Roggisch
> If that's the case then just use QObject.sender(). The slot must be a
> method of a QObject derived class - but that wouldn't seem to be a problem
> in this case.


Nice. Didn't know that.

Diez

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Static member functions

2004-12-13 Thread Phil Thompson
> Hi,
>
> I think I understand your problem as follows: You have a non-parametrized
> signal, lostFocus, that you want to connect to one slot - but then somehow
> "magically" there shall be a reference to the object the signal came from
> is
> passed.

If that's the case then just use QObject.sender(). The slot must be a
method of a QObject derived class - but that wouldn't seem to be a problem
in this case.

Phil

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Static member functions

2004-12-13 Thread Diez B. Roggisch
Hi,

I think I understand your problem as follows: You have a non-parametrized 
signal, lostFocus, that you want to connect to one slot - but then somehow 
"magically" there shall be a reference to the object the signal came from is 
passed.

May be what could help is somthing like this:

class Magic(QObject):
 def __init__(self, dialog, key):
QObject.__init__(self)
self.dialog = dialog
self.key = key

def focusLost(self):
  self.dialog.keyLostFocus(self.key)


Now you connect your signals in a loop like this:

for key in keys:
 self.connect(key, SIGNAL("focusLost()"), Magic(self, key).focusLost)

That assumes that self is the dialog and keys the list of key-widgets.

HTH,

Diez

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


Re: [PyKDE] Static member functions

2004-12-13 Thread Sundance
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[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


RE: [PyKDE] Static member functions

2004-12-13 Thread Hihn, Jason

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: [EMAIL PROTECTED] [mailto:pykde-
> [EMAIL PROTECTED] On Behalf Of Sundance
> Sent: Monday, December 13, 2004 7:38 PM
> To: [EMAIL PROTECTED]
> 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[EMAIL PROTECTED]
> 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)

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde


[PyKDE] Static member functions

2004-12-13 Thread Hihn, Jason








I need to have a lostfocus event store the object that
created the event. In my previous language, I had a global function that could
do it, because I could bring it in to the class by setting it at run-time.  The
‘this’ object, would then be the object that generated the event.
It was then easy enough to say : global lostFicusObj=this

 

Then later, I could use this.whatever()

 

How can I do this in python? I’d really hate to have a
function for every possible widget.

 

Thanks.

 







__
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)
___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde