Fix newsigslot documentation. Use Signal/Slot instead of signal/slot.
This commit is contained in:
parent
ee6303819e
commit
c47802c503
1 changed files with 22 additions and 22 deletions
|
|
@ -25,7 +25,7 @@ The example below uses the well known *clicked* signal from a *QPushButton*. The
|
||||||
|
|
||||||
Next section shows how everything has changed to become more pythonic.
|
Next section shows how everything has changed to become more pythonic.
|
||||||
|
|
||||||
New way: signal() and slot()
|
New way: Signal() and Slot()
|
||||||
----------------------------
|
----------------------------
|
||||||
The new-style uses a different syntax to create and to connect signals/slots. The previous example could be rewritten as:
|
The new-style uses a different syntax to create and to connect signals/slots. The previous example could be rewritten as:
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ The new-style uses a different syntax to create and to connect signals/slots. Th
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
clicked = QtCore.signal()
|
clicked = QtCore.Signal()
|
||||||
|
|
||||||
button = QtGui.QPushButton("Call someFunc")
|
button = QtGui.QPushButton("Call someFunc")
|
||||||
button.clicked.connect(someFunc)
|
button.clicked.connect(someFunc)
|
||||||
|
|
@ -46,22 +46,22 @@ The new-style uses a different syntax to create and to connect signals/slots. Th
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
Using QtCore.signal()
|
Using QtCore.Signal()
|
||||||
---------------------
|
---------------------
|
||||||
Signals can be defined using the *QtCore.signal()* class. Python types and C types can be passed as parameters to it. If you need to overload it just pass the types as tuples or lists.
|
Signals can be defined using the *QtCore.Signal()* class. Python types and C types can be passed as parameters to it. If you need to overload it just pass the types as tuples or lists.
|
||||||
|
|
||||||
Besides that it can receive also a named argument *name* that defines the signal name. If nothing is passed as *name* then the new signal will have the same name as the variable that it is being assigned to.
|
Besides that it can receive also a named argument *name* that defines the signal name. If nothing is passed as *name* then the new signal will have the same name as the variable that it is being assigned to.
|
||||||
|
|
||||||
The section `Putting everything together`_ has a collection of examples that shows a bunch of situation using the *signal()* class.
|
The section `Putting everything together`_ has a collection of examples that shows a bunch of situation using the *Signal()* class.
|
||||||
|
|
||||||
**Note**: Signals should be defined only inside classes inheriting from QObject. This way the signal information is added to the class QMetaObject structure.
|
**Note**: Signals should be defined only inside classes inheriting from QObject. This way the signal information is added to the class QMetaObject structure.
|
||||||
|
|
||||||
|
|
||||||
Using QtCore.slot()
|
Using QtCore.Slot()
|
||||||
-------------------
|
-------------------
|
||||||
Slots are assigned and overloaded using the decorator *QtCore.slot()*. Again, to define a signature just pass the types like the *QtCore.signal()* class. Unlike the *signal()* class, to overload a function you don't pass every variation as tuple or list. Instead of that you have to define a new decorator for every different signature. The examples section below will make it clearer.
|
Slots are assigned and overloaded using the decorator *QtCore.Slot()*. Again, to define a signature just pass the types like the *QtCore.Signal()* class. Unlike the *Signal()* class, to overload a function you don't pass every variation as tuple or list. Instead of that you have to define a new decorator for every different signature. The examples section below will make it clearer.
|
||||||
|
|
||||||
Another difference is about its keywords. *slot()* accepts a *name* and a *result*. The *result* keyword defines the type that will be returned and can be a C or Python type. The *name* behaves the same way as in *signal()*. If nothing is passed as *name* then the new slot will have the same name as the function that is being decorated.
|
Another difference is about its keywords. *Slot()* accepts a *name* and a *result*. The *result* keyword defines the type that will be returned and can be a C or Python type. The *name* behaves the same way as in *Signal()*. If nothing is passed as *name* then the new slot will have the same name as the function that is being decorated.
|
||||||
|
|
||||||
Putting everything together
|
Putting everything together
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
@ -97,13 +97,13 @@ Nothing better than examples to show how to use the new-style. Here you can find
|
||||||
|
|
||||||
# define a new slot that receives a QString and has
|
# define a new slot that receives a QString and has
|
||||||
# 'saySomeWords' as its name
|
# 'saySomeWords' as its name
|
||||||
@QtCore.slot(QtCore.QString)
|
@QtCore.Slot(QtCore.QString)
|
||||||
def saySomeWords(words):
|
def saySomeWords(words):
|
||||||
print words
|
print words
|
||||||
|
|
||||||
class Communicate(QtCore.QObject):
|
class Communicate(QtCore.QObject):
|
||||||
# create a new signal on the fly and name it 'speak'
|
# create a new signal on the fly and name it 'speak'
|
||||||
speak = QtCore.signal(QtCore.QString)
|
speak = QtCore.Signal(QtCore.QString)
|
||||||
|
|
||||||
someone = Communicate()
|
someone = Communicate()
|
||||||
# connect signal and slot
|
# connect signal and slot
|
||||||
|
|
@ -120,16 +120,16 @@ Nothing better than examples to show how to use the new-style. Here you can find
|
||||||
|
|
||||||
# define a new slot that receives a C 'int' or a 'QString'
|
# define a new slot that receives a C 'int' or a 'QString'
|
||||||
# and has 'saySomething' as its name
|
# and has 'saySomething' as its name
|
||||||
@QtCore.slot(int)
|
@QtCore.Slot(int)
|
||||||
@QtCore.slot(QtCore.QString)
|
@QtCore.Slot(QtCore.QString)
|
||||||
def saySomething(stuff):
|
def saySomething(stuff):
|
||||||
print stuff
|
print stuff
|
||||||
|
|
||||||
class Communicate(QtCore.QObject):
|
class Communicate(QtCore.QObject):
|
||||||
# create two new signals on the fly: one will handle
|
# create two new signals on the fly: one will handle
|
||||||
# int type, the other will handle QStrings
|
# int type, the other will handle QStrings
|
||||||
speakNumber = QtCore.signal(int)
|
speakNumber = QtCore.Signal(int)
|
||||||
speakWord = QtCore.signal(QtCore.QString)
|
speakWord = QtCore.Signal(QtCore.QString)
|
||||||
|
|
||||||
someone = Communicate()
|
someone = Communicate()
|
||||||
# connect signal and slot properly
|
# connect signal and slot properly
|
||||||
|
|
@ -149,15 +149,15 @@ Nothing better than examples to show how to use the new-style. Here you can find
|
||||||
|
|
||||||
# define a new slot that receives an C 'int' or a 'QString'
|
# define a new slot that receives an C 'int' or a 'QString'
|
||||||
# and has 'saySomething' as its name
|
# and has 'saySomething' as its name
|
||||||
@QtCore.slot(int)
|
@QtCore.Slot(int)
|
||||||
@QtCore.slot(QtCore.QString)
|
@QtCore.Slot(QtCore.QString)
|
||||||
def saySomething(stuff):
|
def saySomething(stuff):
|
||||||
print stuff
|
print stuff
|
||||||
|
|
||||||
class Communicate(QtCore.QObject):
|
class Communicate(QtCore.QObject):
|
||||||
# create two new signals on the fly: one will handle
|
# create two new signals on the fly: one will handle
|
||||||
# int type, the other will handle QStrings
|
# int type, the other will handle QStrings
|
||||||
speak = QtCore.signal((int,), (QtCore.QString,))
|
speak = QtCore.Signal((int,), (QtCore.QString,))
|
||||||
|
|
||||||
someone = Communicate()
|
someone = Communicate()
|
||||||
# connect signal and slot. As 'int' is the default
|
# connect signal and slot. As 'int' is the default
|
||||||
|
|
@ -178,14 +178,14 @@ PyQt uses a different naming convention to its new signal/slot functions. In ord
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
from PySide.QtCore import signal as pyqtSignal
|
from PySide.QtCore import Signal as pyqtSignal
|
||||||
from PySide.QtCore import slot as pyqtSlot
|
from PySide.QtCore import Slot as pyqtSlot
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
QtCore.pyqtSignal = QtCore.signal
|
QtCore.pyqtSignal = QtCore.Signal
|
||||||
QtCore.pyqtSlot = QtCore.slot
|
QtCore.pyqtSlot = QtCore.Slot
|
||||||
|
|
||||||
This way any call to *pyqtSignal* or *pyqtSlot* will be translated to a *signal* or *slot* call.
|
This way any call to *pyqtSignal* or *pyqtSlot* will be translated to a *Signal* or *Slot* call.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue