[PyQt] signal/slot with parameter (QSignalTransition)

Philippe Crave philippe.crave at gmail.com
Thu Apr 15 07:22:32 BST 2010


is there a workaround ?
"triggered()" is the only signal available in QSignaltransition :/


actually, maybe I don't try to solve my issue the right way.
I have a stateMachine.
when I am in a State, I modify some properties, but I would like my state to
perform some things under some condition (event).
that's why I wanted to use a targetLess Transition.

imagine that I have state_1, 2, 3, and some sub_states under each.
They all do something different (or nothing) while the user scroll the mouse
wheel.

Of course, I could simply do:
def wheelEvent(self, e):
    and then, testing in which State I am, and so on.

but that was not so much the way I thought we should use a stateMachine.
I liked the fact that I could define all my stateMachine in one single
place, not mixing it with fonctions that emit events.


2010/4/14 Thiago Zanetti <thiago.project at gmail.com>

>
>
> 2010/4/14 Philippe Crave <philippe.crave at gmail.com>
>
>> Hi,
>>
>> in a class, I have a QStateMachine, with some QState.
>> I would like to make a targetless transition for one state.
>> I followed the documentation here
>> http://qt.nokia.com/doc/4.6/statemachine-api.html#targetless-transitions
>>
>> it works well if the initial event that launch the targetless transition
>> does not include any variables.
>> but now, I emit an event with an increment from a wheelEvent.
>> self.emit(SIGNAL("wheelEvent(int)"), inc)
>> I do not know how to propagate that value from that event to the target
>> slot function self.change_drive.
>>
>> actually, I get this error message:
>> TypeError: change_drive() takes exactly 2 arguments (1 given)
>>
>> here is a part of my class
>> ...
>> t = QSignalTransition(self, SIGNAL("wheelEvent(int)"))
>> self.state_in.addTransition(t)
>> self.connect(t, SIGNAL("triggered()"), self.change_drive)
>>
>> @pyqtSignature("int")
>> def change_drive(self, v):
>>     print 'change_drive', v
>>
>> def wheelEvent(self, e):
>>     inc = cmp(e.delta(), 0) * -1
>>     self.emit(SIGNAL("wheelEvent(int)"), inc)
>>
>> thank you
>>
>> _______________________________________________
>> PyQt mailing list    PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>
>
> I think this is happening because the "triggered()" signal doesn't emit any
> argument. So, the callback is not receiveing any argument but the "self"
> argument. Probably that is the reason.
>
> I hope this helps you.
>
> Regards,
> Thiago Zanetti
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100415/62cd6056/attachment.html>


More information about the PyQt mailing list