Hello,

I was playing around with PySide and came across a strange behavior in the case 
if curried functions are used as slot.

The test code creates a form of six buttons. Each click to a button sets the 
label to a message which button was clicked. The clicked signals sent from 
buttons One, Five and Six behave as expected (no argument in signal call). The 
signals sent from the button Two, Three and Four contain an additional boolean 
argument.

Behavior:
 - a click on button One, Five and Six set the label to "You clicked button 
'BUTTON_NAME'" which is ok.
 - a click on button Two or Three sets the label prints "Additional arguments: 
(False,)" to the console.
 - a click on button Four sets the label to "You clicked button 'False'"

Summary:
If the button's "clicked()" signal is sent to a slot which is comprised of 
either a curried (partial) or lambda function then the slot is called with an 
additional boolean argument.

Is this a usage error on my side or a bug for which I should create a bug 
report?
I am using PySide version 1.0-beta1 @ Win32.

Code (modified from the book Rapid GUI Programming with Python and QT):

#!/usr/bin/env python
# Copyright (c) 2008 Qtrac Ltd. All rights reserved.
# This program or module is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 2 of the License, or
# version 3 of the License, or (at your option) any later version. It is
# provided for educational purposes and is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.

from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future_builtins import *

import functools
import sys
from PySide.QtGui import (QApplication, QDialog, QHBoxLayout, QLabel,
        QPushButton)


class Form(QDialog):

    def __init__(self, parent=None):
        super(Form, self).__init__(parent)

        button1 = QPushButton("One")
        button2 = QPushButton("Two")
        button3 = QPushButton("Three")
        button4 = QPushButton("Four")
        button5 = QPushButton("Five")
        button6 = QPushButton("Six")
        self.label = QLabel("Click a button...")

        layout = QHBoxLayout()
        layout.addWidget(button1)
        layout.addWidget(button2)
        layout.addWidget(button3)
        layout.addWidget(button4)
        layout.addWidget(button5)
        layout.addWidget(button6)
        layout.addStretch()
        layout.addWidget(self.label)
        self.setLayout(layout)

        button1.clicked.connect(self.one)
        self.button2callback = functools.partial(self.anyButton, "Two")
        button2.clicked.connect(self.button2callback)
        button3.clicked.connect(functools.partial(self.anyButton, "Three"))
        self.button4callback = lambda who="Four": self.anyButton(who)
        button4.clicked.connect(self.button4callback)
        button5.clicked.connect(self.clicked)
        button6.clicked.connect(self.clicked)

        self.setWindowTitle("Connections")

    def one(self):
        self.label.setText("You clicked button 'One'")

    def anyButton(self, who, *args):
        self.label.setText("You clicked button '{0}'".format(who))
        if len(args) > 0:
            print("Additional arguments: {0}".format(args))

    def clicked(self):
        button = self.sender()
        if button is None or not isinstance(button, QPushButton):
            return
        self.label.setText("You clicked button '{0}'".format(
                           button.text()))


app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()

Best Regards,
Christian
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to