Skip to content

Instantly share code, notes, and snippets.

@snorfalorpagus
Created January 13, 2016 15:15
Show Gist options
  • Save snorfalorpagus/589ce266fd500dc35719 to your computer and use it in GitHub Desktop.
Save snorfalorpagus/589ce266fd500dc35719 to your computer and use it in GitHub Desktop.
Example of connecting a PyQt signal to a method with a decorator
# -*- 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