[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] simpler 'connect' function
From:       Ewald de Wit <erdewit () zonnet ! nl>
Date:       2008-01-17 22:35:16
Message-ID: 200801172335.16200.erdewit () zonnet ! nl
[Download RAW message or body]

On Thursday 17 January 2008 18:27:19 Peter Shinners wrote:
> > 	button.clicked.connect(self.onButtonClicked)
>
> Is there a clean way to handle signals with the same name that take
> different arguments? Here's an idea I can think of for QComboBox.
>
> combo.activated[int].connect(callback1)
> combo.activated[QString].connect(callback2)

A simpler way would be to just give the signal objects a different name,
like activatedInt and activatedString. It's the easiest way to uniquely
specify which signal you mean.

Btw, it would also be convenient to have an emit method on the signal
object, like for example

	combo.activatedInt.emit(1)
	combo.activatedString.emit('Pizza')
	canvas.mouseMoved.emit(dx, dy)

If __call__ is used instead of emit, then the syntax becomes even shorter:

	canvas.mouseMoved(dx, dy)

And once there is a signal object, other methods become possible as well.
For example a slots() method that returns a list of all connected
slots. One could then do lazy evaluation like

	if self.heavyJobFinished.slots():
		result = self.doHeavyJob()
		self.heavyJobFinished.emit(result)

This example skips doing the heavy job if there is no one listening for
the result. Just some ideas.

--
  -- Ewald


_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic