generic_toolbar.xml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <class name="GenericToolbar">
  2. <relationships>
  3. <inheritance class="Toolbar"/>
  4. <association name="buttons" class="Button"/>
  5. <association name="parent" class="A"/>
  6. </relationships>
  7. <constructor>
  8. <parameter name="parent"/>
  9. <super class="Toolbar">
  10. <parameter expr="parent"/>
  11. </super>
  12. <body>
  13. self.to_create = ["new", "open"]
  14. self.button_info = {"new": "Create a new model",
  15. "open": "Open an existing model"}
  16. self.buttons = {}
  17. </body>
  18. </constructor>
  19. <destructor>
  20. <super class="Toolbar"/>
  21. </destructor>
  22. <scxml initial="init">
  23. <state id="init" initial="init_buttons">
  24. <onexit>
  25. <raise event="tk_widget" scope="narrow" target="'parent'">
  26. <parameter expr="self"/>
  27. </raise>
  28. </onexit>
  29. <state id="init_buttons">
  30. <onentry>
  31. <raise event="create_instance" scope="cd">
  32. <parameter expr="'buttons'"/>
  33. <parameter expr="'Button'"/>
  34. <parameter expr="{'parent': self, 'visual': ImageVisual('icons/%s.png' % self.to_create[0]), 'tooltip_text': self.button_info[self.to_create[0]], 'event_parameters': self.to_create[0]}"/>
  35. </raise>
  36. </onentry>
  37. <transition event="instance_created" target="../pack_button">
  38. <parameter name="association_name"/>
  39. <raise event="start_instance" scope="cd">
  40. <parameter expr="association_name"/>
  41. </raise>
  42. <script>
  43. self.buttons[self.to_create[0]] = association_name
  44. self.to_create.pop(0)
  45. </script>
  46. </transition>
  47. </state>
  48. <state id="pack_button">
  49. <transition event="tk_widget" target="../next_button">
  50. <parameter name="tk_elem"/>
  51. <script>
  52. tk_elem.pack(side=tk.LEFT)
  53. </script>
  54. </transition>
  55. </state>
  56. <state id="next_button">
  57. <transition cond="len(self.to_create) == 0" target="../../root"/>
  58. <transition cond="len(self.to_create) > 0" target="../init_buttons"/>
  59. </state>
  60. </state>
  61. <state id="root">
  62. <transition event="button_pressed" cond="event_name == 'new'" target=".">
  63. <parameter name="event_name"/>
  64. <raise event="create_new_model" scope="narrow" target="'parent'"/>
  65. </transition>
  66. <transition event="button_pressed" cond="event_name == 'open'" target=".">
  67. <parameter name="event_name"/>
  68. <raise event="open_model" scope="narrow" target="'parent'"/>
  69. </transition>
  70. <transition event="close" target="../closing"/>
  71. </state>
  72. <state id="closing">
  73. <onentry>
  74. <raise event="delete_instance" scope="cd">
  75. <parameter expr="self.buttons.popitem()[1]"/>
  76. </raise>
  77. </onentry>
  78. <transition event="instance_deleted" cond="len(self.buttons) > 0" target="../closing"/>
  79. <transition event="instance_deleted" cond="len(self.buttons) == 0" target="../close"/>
  80. </state>
  81. <state id="close">
  82. <onentry>
  83. <raise event="close_window" scope="narrow" target="'parent'"/>
  84. </onentry>
  85. </state>
  86. </scxml>
  87. </class>