<?xml version="1.0" ?>
<diagram author="Sam Pieters" name="Timer (Eventloop Version)">
    <top>
        from sccd.runtime.libs.ui import ui
        import time

        CANVAS_WIDTH = 350
        CANVAS_HEIGHT = 300
    </top>
    
    <inport name="ui" />    
    <class name="MainApp" default="true">
        <attribute name="window_id" />
        <attribute name="canvas_id" />
        <attribute name="clock_id" />
        <attribute name="actual_clock_id" />
        <attribute name="button_id" />
        <attribute name="starting_time" />
        <inport name="field_ui"/>
        <scxml initial="creating_window">
            <state id="creating_window">
                <onentry>
                    <raise port="ui" event="create_window">
                        <parameter expr="CANVAS_WIDTH"/><!-- width -->
                        <parameter expr="CANVAS_HEIGHT"/><!-- height -->
                        <parameter expr='"Fixed Timer"'/><!-- title -->
                        <parameter expr="self.inports['field_ui']"/><!-- inport for response -->
                    </raise>
                </onentry>
                <transition event="window_created" target="../creating_canvas">
                    <parameter name="window_id" type="int" />
                    <script>
                        <![CDATA[
                        self.window_id = window_id
                        self.starting_time = time.time()
                        ]]>
                    </script>
                    <raise port="ui" event="bind_event">
                        <parameter expr="window_id"/><!-- widget_id -->
                        <parameter expr="ui.EVENTS.WINDOW_CLOSE"/><!-- tk_event -->
                        <parameter expr="'window_close'"/><!-- sccd_event_name -->
                        <parameter expr="self.inports['field_ui']"/><!-- inport for response -->
                    </raise>
                    <raise port="ui" event="bind_event">
                        <parameter expr="window_id"/><!-- widget_id -->
                        <parameter expr="ui.EVENTS.KEY_PRESS"/><!-- tk_event -->
                        <parameter expr="'key_press'"/><!-- sccd_event_name -->
                        <parameter expr="self.inports['field_ui']"/><!-- inport for response -->
                    </raise>
                </transition>
            </state>
            <state id="creating_canvas">
                <onentry>
                    <raise port="ui" event="create_canvas">
                        <parameter expr="self.window_id"/><!-- window_id -->
                        <parameter expr="CANVAS_WIDTH"/><!-- width -->
                        <parameter expr="CANVAS_HEIGHT - 200"/><!-- height -->
                        <parameter expr="{'background':'#222222'}"/><!-- style -->
                        <parameter expr="self.inports['field_ui']"/><!-- inport for response -->
                    </raise>
                </onentry>
                <transition event="canvas_created" target="../creating_clock_text">
                    <parameter name="canvas_id" type="int"/>
                    <script>
                        <![CDATA[
                        self.canvas_id = canvas_id
                        ]]>
                    </script>
                    <raise scope="narrow" event="set_association_name" target="association_name">
                        <parameter expr="association_name" />
                    </raise>
                </transition>
            </state>
            <state id="running">
            </state>
        </scxml>
    </class>

    <class name="Elevator">
        <attribute name="canvas_id" />
        <atrribute name="circle_id" />
        <attribute name="pos" />
        <inport name="elevator_ui"/>
        <relationships>
            <association name="parent" class="MainApp" min="1" max="1" />
        </relationships>
        <scxml initial="root">
            <state id="root" initial="waiting">
                <state id="waiting">
                    <transition event="set_association_name" target="../creating_elevator">
                        <parameter name="association_name" type="str" />
                        <script>
                            self.association_name = association_name
                        </script>
                    </transition>
                </state>
                <state id="creating_elevator">
                    <onentry>
                        <raise port="ui" event="create_rectangle">
                            canvas_id, x, y, r, style, res_port
                            <parameter expr="self.canvas_id"/><!-- canvas_id -->
                            <parameter expr="self.pos['x']"/><!-- x -->
                            <parameter expr="self.pos['y']"/><!-- y -->
                            <parameter expr="self.r"/><!-- r -->
                            <parameter expr="{'fill':'#000'}"/><!-- style -->
                            <parameter expr="self.inports['ball_ui']"/><!-- inport for response -->
                        </raise>
                    </onentry>
                </state>
            </state>
        </scxml>
    </class>
</diagram>