Reputation: 1095
I'm currently porting a small application from PyGTK to PySide which sits in your systray and periodically checks a server for updates.
When I initially wrote this, I used a custom state model to represent its behaviour:
I since discovered that Qt has QStateMachine, which seems perfect for this type of structure. However, I was not able to apply the examples satisfyingly to my problem!
In particular:
Any pointers are appreciated muchly!
Upvotes: 3
Views: 1091
Reputation: 6162
Ok. Pyside.QtCore.Signal
is Signals & Slots derivative.
As for your questions
I'd say there is no difference in QEvent
and Signal
in context of QStateMachine (although QEvent
and Signals & Slots are totally different concepts). Depending on your needs you can trigger transition with QEvent
or Signal
. See QAbstactTransition
for the list of out of the box transitions:
Inherited by: QSignalTransition, QEventTransition, QMouseEventTransition, QKeyEventTransition
Again depending on what happens inside your application your error may be either signal from QObject
or you can send (post) custom QEvent
. You'll need to implement your custom QEvent
and/or custom QEventTransition
to trigger transition only on your events.
And again it depends:) Transition is the glue. It has knowledge about source and destination states. So I'd put only preparatory code inside onTransition()
and state initialization code inside onEnter()
. Also it seems wrong for me to put code that changes state inside onTransition()
like in example you've shown:
def onTransition(self, e):
x = e.arguments()[0]
fac = self.fact.fac
self.fact.fac = x * fac
self.fact.x = x - 1
but as you can see it works well.
NB: If you have iOS experience then UIStoryboardSegue
is analogue for transition. Mainly it is used to pass data between UIView
's i.e. UI states.
Upvotes: 4