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

List:       pykde
Subject:    [PyQt] bug or expected?
From:       oliver <oliver.schoenborn () gmail ! com>
Date:       2016-12-27 20:24:17
Message-ID: CAMb+DaXdUpm+H58z2KhXEU8aZP=mV=JSZuEF8i-bGNvqYxaAYQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


from PyQt5.QtCore import QObject, pyqtSlot, Qt, pyqtSignal

class MyObj(QObject):
    sig_test = pyqtSignal()

class Listener(QObject):
    @pyqtSlot()
    def meth(self):
        pass

    # @pyqtSlot()
    def meth2(self):
        pass

obj = MyObj()
obs = Listener()

def test_no_connections(slot):
    assert obj.receivers(obj.sig_test) == 0

    obj.sig_test.connect(slot, Qt.UniqueConnection)
    assert obj.receivers(obj.sig_test) == 1

    obj.sig_test.disconnect(slot)
    assert obj.receivers(obj.sig_test) == 0

test_no_connections(obs.meth)
test_no_connections(obs.meth)

test_no_connections(obs.meth2)
test_no_connections(obs.meth2)  # FAILS

Last line fails because meth2 was not decorated with pyqtSlot. Is this
expected or a bug?

Related to this, the exception on a unique connection is completely
different if the method is decorated. Using the same code as above (but
without the test_no_connections stuff):

def test_unique_connection(slot, str_exc):
    obj.sig_test.connect(slot, Qt.UniqueConnection)
    try:
        obj.sig_test.connect(slot, Qt.UniqueConnection)
    except TypeError as exc:
        assert str(exc) == str_exc

test_unique_connection(obs.meth, 'connect() failed between MyObj.sig_test[]
and meth()')
test_unique_connection(obs.meth2, 'connection is not unique')

Shouldn't both produce an exception that says 'connection is not unique'?
-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects

[Attachment #5 (text/html)]

<div dir="ltr"><div><div><font face="monospace" size="1">from PyQt5.QtCore import \
QObject, pyqtSlot, Qt, pyqtSignal</font></div><div><font face="monospace" \
size="1"><br></font></div><div><font face="monospace" size="1">class \
MyObj(QObject):</font></div><div><font face="monospace" size="1">      sig_test = \
pyqtSignal()</font></div><div><font face="monospace" \
size="1"><br></font></div><div><font face="monospace" size="1">class \
Listener(QObject):</font></div><div><font face="monospace" size="1">      \
@pyqtSlot()</font></div><div><font face="monospace" size="1">      def \
meth(self):</font></div><div><font face="monospace" size="1">            \
pass</font></div><div><font face="monospace" size="1"><br></font></div><div><font \
face="monospace" size="1">      # @pyqtSlot()</font></div><div><font face="monospace" \
size="1">      def meth2(self):</font></div><div><font face="monospace" size="1">     \
pass</font></div><div><font face="monospace" size="1"><br></font></div><div><font \
face="monospace" size="1">obj = MyObj()</font></div><div><font face="monospace" \
size="1">obs = Listener()</font></div><div><font face="monospace" \
size="1"><br></font></div><div><font face="monospace" size="1">def \
test_no_connections(slot):</font></div><div><font face="monospace" size="1">      \
assert obj.receivers(obj.sig_test) == 0</font></div><div><font face="monospace" \
size="1"><br></font></div><div><font face="monospace" size="1">      \
obj.sig_test.connect(slot, Qt.UniqueConnection)</font></div><div><font \
face="monospace" size="1">      assert obj.receivers(obj.sig_test) == \
1</font></div><div><font face="monospace" size="1"><br></font></div><div><font \
face="monospace" size="1">      obj.sig_test.disconnect(slot)</font></div><div><font \
face="monospace" size="1">      assert obj.receivers(obj.sig_test) == \
0</font></div><div><font face="monospace" size="1"><br></font></div><div><font \
face="monospace" size="1">test_no_connections(obs.meth)</font></div><div><font \
face="monospace" size="1">test_no_connections(obs.meth)</font></div><div><font \
face="monospace" size="1"><br></font></div><div><font face="monospace" \
size="1">test_no_connections(obs.meth2)</font></div><div><font face="monospace" \
size="1">test_no_connections(obs.meth2)   # FAILS  </font></div><div \
style="font-size:13px"><br></div><div>Last line fails because meth2 was not decorated \
with pyqtSlot. Is this expected or a bug?  </div><div><br></div><div>Related to this, \
the exception on a unique connection is completely different if the method is \
decorated. Using the same code as above (but without the test_no_connections stuff):  \
</div></div><div><br></div><div><div><font face="monospace" size="1">def \
test_unique_connection(slot, str_exc):</font></div><div><font face="monospace" \
size="1">      obj.sig_test.connect(slot, Qt.UniqueConnection)</font></div><div><font \
face="monospace" size="1">      try:</font></div><div><font face="monospace" \
size="1">            obj.sig_test.connect(slot, \
Qt.UniqueConnection)</font></div><div><font face="monospace" size="1">      except \
TypeError as exc:</font></div><div><font face="monospace" size="1">            assert \
str(exc) == str_exc</font></div><div><font face="monospace" \
size="1"><br></font></div><div><font face="monospace" \
size="1">test_unique_connection(obs.meth, &#39;connect() failed between \
MyObj.sig_test[] and meth()&#39;)</font></div><div><font face="monospace" \
size="1">test_unique_connection(obs.meth2, &#39;connection is not \
unique&#39;)</font></div></div><div><br></div><div>Shouldn&#39;t both produce an \
exception that says &#39;connection is not unique&#39;?</div></div><div dir="ltr">-- \
<br></div><div data-smartmail="gmail_signature"><div dir="ltr">Oliver<div>My \
StackOverflow contributions<br><div>My CodeProject articles</div></div><div>My Github \
projects</div><div>My SourceForget.net projects</div></div></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://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