[PyKDE] slots and callables.

Yves BAILLY kafka.fr at netcourrier.com
Wed May 30 11:44:35 BST 2001


Hello toby,

On Wednesday 30 May 2001 10:46, Toby Sargeant wrote:
> -- of the four connects, only the last works, even though the three prior
> to it are functionally equivalent. being able to use lambdas at least would
> be very handy. As an example, say you wanted to synchronize the position of
> a group of tables. With lambdas, you could write:
>
> class TableManager(qt.QWidget):
>   def tableMoving(self,x,y,t):
>      for tablenum in range(len(self.tables)):
>         if tablenum==t:
>            continue
>         ...
>
>   def __init__(self,parent=None,name=None):
>      ...
>      for tablenum in range(len(self.tables)):
>         self.connect(self.tables[tablenum],
>                      qt.SIGNAL('contentsMoving(int,int)'),
>                      lambda
> x,y,self=self,t=tablenum:self.tableMoving(x,y,t))
>
> without them, I can't see how tableMoving can know which table is being
> moved by the user, and it seems that even though you can sort out the
> infinite recursion that can result from moving _all_ of the tables to the
> new location, the result seems to be that the update doesn't occur
> properly.

Have you tried using the "sender()" method ? It's very handy, you can
connect several signal to a single slot, and it gives you the signal
sender, i.e. in your example that could be the moved table...

class TableManager(qt.QWidget):
  def tableMoving(self,x,y):
     moved_table = self.sender()
     ....moved_table is of same type as self.tables[i]....

  def __init__(self,parent=None,name=None):
    ...
    for tablenum in range(len(self.tables)):
       self.connect(self.tables[tablenum],
                    qt.SIGNAL('contentsMoving(int,int)'),
                    self.tableMoving(x,y))

Maybe this works (I know that in PyQt 2.4, sender() was not working, but
it has been corrected since then - thanks Phil), I've not tested it
though.

Best regards,

-- 
   .~.          __________________________  
   /V\   Linux /                          \        ___ 
  // \\  Power |        Yves BAILLY       |      /"   "\
 /(   )\       | kafka.fr at netcourrier.com |     ( @ _ @ )
- ^^-^^ -------\__________________________/----oOO (_) OOo------
LUG Dijon : http://www.coagul.org




More information about the PyQt mailing list