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:

- init: initial state
- check: check server for updates
- disconnected: no connection to server (wait for some time to try again)
- error: server reported an error (user needs to check settings before proceeding)
- idle: wait for POLLING INTERVAL seconds before checking again
- quit
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:
- In the context of QStateMachine, what is the difference between Signal and QEvent?
- How do I define a conditional transition, i.e. on error go to... ?
- Should program logic happen in Transition.onTransition() or in QState.onEnter()?
Any pointers are appreciated muchly!
Ok.
Pyside.QtCore.Signalis Signals & Slots derivative.As for your questions
I'd say there is no difference in
QEventandSignalin context of QStateMachine (althoughQEventand Signals & Slots are totally different concepts). Depending on your needs you can trigger transition withQEventorSignal. SeeQAbstactTransitionfor the list of out of the box transitions:Again depending on what happens inside your application your error may be either signal from
QObjector you can send (post) customQEvent. You'll need to implement your customQEventand/or customQEventTransitionto 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 insideonEnter(). Also it seems wrong for me to put code that changes state insideonTransition()like in example you've shown:but as you can see it works well.
NB: If you have iOS experience then
UIStoryboardSegueis analogue for transition. Mainly it is used to pass data betweenUIView's i.e. UI states.