コード例 #1
0
def concurrent_statechart():
    def composite(name, context):
        composite = CompositeState(name=name, context=context)
        composite.init = InitialState(composite)
        composite.state = State(name='state', context=composite)
        composite.final = FinalState(composite)

        Transition(start=composite.init, end=composite.state)
        Transition(start=composite.state,
                   end=composite.final,
                   event=Event('finish'))

        return composite

    sc = Statechart('simple')
    sc.init = InitialState(sc)

    sc.concurrent = ConcurrentState(name='compound', context=sc)

    sc.concurrent.composite_a = composite(name='a', context=sc.concurrent)
    sc.concurrent.composite_b = composite(name='b', context=sc.concurrent)
    sc.concurrent.composite_c = composite(name='c', context=sc.concurrent)

    sc.final = FinalState(sc)

    Transition(start=sc.init, end=sc.concurrent)
    Transition(start=sc.concurrent, end=sc.final, event=Event('finish'))

    return sc
コード例 #2
0
def simple_statechart():
    sc = Statechart('simple')
    sc.init = InitialState(sc)
    sc.state = State(name='state', context=sc)
    sc.final = FinalState(sc)

    Transition(start=sc.init, end=sc.state)
    Transition(start=sc.state, end=sc.final, event=Event('finish'))

    return sc