Created
January 13, 2016 15:15
-
-
Save snorfalorpagus/589ce266fd500dc35719 to your computer and use it in GitHub Desktop.
Example of connecting a PyQt signal to a method with a decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from PySide import QtCore, QtGui | |
def wrapper(fn): | |
print('inside wrapper...') | |
def wrapped(*args, **kwargs): | |
print('inside wrapped!') | |
fn(*args, **kwargs) | |
return wrapped | |
class MyDialog(QtGui.QDialog): | |
def __init__(self): | |
super(MyDialog, self).__init__() | |
# add a button to the dialog | |
self.button = QtGui.QPushButton('Push Me!') | |
self.layout = QtGui.QVBoxLayout() | |
self.layout.addWidget(self.button) | |
self.setLayout(self.layout) | |
# when the button is clicked, hello is called | |
self.button.clicked.connect(self.hello) | |
@wrapper | |
def hello(self): | |
print('hello') | |
if __name__ == '__main__': | |
app = QtGui.QApplication([]) | |
dialog = MyDialog() | |
dialog.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment