Skip to content

Add pyqtBoundSignal.signal: str#51

Merged
stlehmann merged 2 commits intopython-qt-tools:masterfrom
altendky:pyqtBoundSignal.signal
Jul 30, 2020
Merged

Add pyqtBoundSignal.signal: str#51
stlehmann merged 2 commits intopython-qt-tools:masterfrom
altendky:pyqtBoundSignal.signal

Conversation

@altendky
Copy link
Collaborator

@altendky altendky commented Jul 8, 2020

No description provided.

@altendky altendky marked this pull request as draft July 8, 2020 23:28
@altendky altendky mentioned this pull request Jul 9, 2020
15 tasks
@altendky altendky marked this pull request as ready for review July 12, 2020 02:57
@stlehmann
Copy link
Collaborator

Could you please add a description to your PR to help others understand why you made the change. Thanks :)

@altendky
Copy link
Collaborator Author

Over in QTrio I am comparing bound signals against each other to see if they are 'the same signal'. While PySide2 already implements this, PyQt5 did not (though it will be in the next release). I wrote the workaround below which uses the .signal attribute which is a string. Given that I will not be using this attribute soon it could certainly be argued that this PR is not needed anymore. Or, it could be argued that being more complete is good. I don't know where the balance lies in this case.

https://www.riverbankcomputing.com/pipermail/pyqt/2020-July/043064.html

https://github.com/altendky/qtrio/blob/03742c3599b27645b81ce51f3f4776888400a259/qtrio/_core.py#L163-L185

    def is_from(self, signal: SignalInstance) -> bool:
        """Check if this emission came from `signal`.
        Args:
            signal: The signal instance to check for being the source.
        """

        # TODO: `repr()` here seems really bad.
        if qtpy.PYQT5:
            return self.signal.signal == signal.signal and repr(self.signal) == repr(
                signal
            )
        elif qtpy.PYSIDE2:
            # TODO: get this to work properly.
            return bool(self.signal == signal)

        raise qtrio.QTrioException()  # pragma: no cover

    def __eq__(self, other):
        if type(other) != type(self):
            return False

        return self.is_from(signal=other.signal) and self.args == other.args

@The-Compiler
Copy link
Collaborator

FWIW I also use .signal in the qutebrowser codebase (IIRC to log the name of a signal to the debug log).

@stlehmann
Copy link
Collaborator

I honestly didn't know about this attribute. Found a reference in here: https://www.riverbankcomputing.com/static/Docs/PyQt5/signals_slots.html. I think we can accept this PR to be more complete.

@stlehmann stlehmann merged commit c9c3002 into python-qt-tools:master Jul 30, 2020
@altendky altendky deleted the pyqtBoundSignal.signal branch July 30, 2020 15:43
bluebird75 pushed a commit to bluebird75/PyQt5-stubs that referenced this pull request Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants