123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <class name="DSLToolbar">
- <relationships>
- <inheritance class="Toolbar"/>
- <association name="buttons" class="Button"/>
- <association name="parent" class="A"/>
- </relationships>
- <constructor>
- <parameter name="parent"/>
- <parameter name="elements"/>
- <super class="Toolbar">
- <parameter expr="parent"/>
- </super>
- <body>
- self.to_create = [i[0] for i in elements if i[1] == "Class"]
- self.buttons = {}
- tk.Label(self, text="Domain-Specific").pack(side=tk.LEFT)
- self.currently_active = None
- </body>
- </constructor>
- <destructor>
- <super class="Toolbar"/>
- </destructor>
- <scxml initial="init">
- <state id="init" initial="next_button">
- <onexit>
- <raise event="tk_widget" scope="narrow" target="'parent'">
- <parameter expr="self"/>
- </raise>
- </onexit>
- <state id="init_buttons">
- <onentry>
- <raise event="mv_request" scope="broad">
- <parameter expr="'read_attrs'"/>
- <parameter expr="[current_metamodel, self.to_create[0]]"/>
- </raise>
- </onentry>
- <transition event="mv_response" cond="'name' in result and result['name'] is not None and result['abstract'] != True" target="../create_buttons">
- <parameter name="result"/>
- <script>
- self.button_text = result["name"]
- print("Got attrs: " + str(result))
- </script>
- </transition>
- <transition event="mv_response" cond="ELSE" target="../next_button">
- <parameter name="result"/>
- <script>
- print("Skipping button for %s as it has no name attribute defined" % self.to_create[0])
- self.to_create.pop(0)
- </script>
- </transition>
- </state>
-
- <state id="create_buttons">
- <onentry>
- <raise event="create_instance" scope="cd">
- <parameter expr="'buttons'"/>
- <parameter expr="'Button'"/>
- <parameter expr="{'parent': self, 'visual': TextVisual(self.button_text), 'tooltip_text': 'Instantiate element %s' % self.button_text, 'event_parameters': self.to_create[0]}"/>
- </raise>
- </onentry>
- <transition event="instance_created" target="../pack_button">
- <parameter name="association_name"/>
- <raise event="start_instance" scope="cd">
- <parameter expr="association_name"/>
- </raise>
- <script>
- self.buttons[self.to_create[0]] = association_name
- self.to_create.pop(0)
- </script>
- </transition>
- </state>
- <state id="pack_button">
- <transition event="tk_widget" target="../next_button">
- <parameter name="tk_elem"/>
- <script>
- tk_elem.pack(side=tk.LEFT)
- </script>
- </transition>
- </state>
- <state id="next_button">
- <transition cond="len(self.to_create) == 0" target="../../root"/>
- <transition cond="len(self.to_create) > 0" target="../init_buttons"/>
- </state>
- </state>
- <state id="root">
- <transition event="button_pressed" cond="event_name != self.currently_active" target=".">
- <parameter name="event_name"/>
- <!-- Fake conditional raise: if no button pressed, we don't want to raise an event, but we have to :(
- As such, we send the event to the parent, which we HOPE doesn't catch this event. -->
- <raise event="deactivate" scope="narrow" target="self.buttons[self.currently_active] if self.currently_active is not None else 'parent'"/>
- <raise event="activate" scope="narrow" target="self.buttons[event_name]"/>
- <raise event="select_for_creation" scope="narrow" target="'parent'">
- <parameter expr="event_name"/>
- </raise>
- <script>
- self.currently_active = event_name
- </script>
- </transition>
- <transition event="close" cond="self.buttons" target="../closing"/>
- <transition event="close" cond="not self.buttons" target="../close"/>
- </state>
- <state id="closing">
- <onentry>
- <raise event="delete_instance" scope="cd">
- <parameter expr="self.buttons.popitem()[1]"/>
- </raise>
- </onentry>
- <transition event="instance_deleted" cond="len(self.buttons) > 0" target="../closing"/>
- <transition event="instance_deleted" cond="len(self.buttons) == 0" target="../close"/>
- </state>
-
- <state id="close">
- <onentry>
- <raise event="close_window" scope="narrow" target="'parent'"/>
- </onentry>
- </state>
- </scxml>
- </class>
|