main_app.xml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <class name="MainApp" default="true">
  2. <relationships>
  3. <association name="modelverse" class="Modelverse" min="1" max="1"/>
  4. <association name="windows" class="Window"/>
  5. </relationships>
  6. <constructor>
  7. <parameter name="root"/>
  8. <body>
  9. self.nr_of_windows = 0
  10. self.root = root
  11. self.splash_window = None
  12. self.address = "127.0.0.1:8001"
  13. self.timeout = 20.0
  14. self.username = "admin"
  15. self.password = "admin"
  16. </body>
  17. </constructor>
  18. <scxml initial="parallel">
  19. <parallel id="parallel">
  20. <state id="behaviour" initial="init_modelverse">
  21. <state id="init_modelverse" initial="splash">
  22. <state id="splash">
  23. <onentry>
  24. <raise event="create_instance" scope="cd">
  25. <parameter expr="'windows'"/>
  26. <parameter expr="'SplashWindow'"/>
  27. </raise>
  28. </onentry>
  29. <transition event="instance_created" target="../instantiate">
  30. <parameter name="association_name"/>
  31. <raise event="start_instance" scope="cd">
  32. <parameter expr="association_name"/>
  33. </raise>
  34. <script>
  35. self.splash_window = association_name
  36. </script>
  37. </transition>
  38. </state>
  39. <state id="instantiate">
  40. <onentry>
  41. <raise event="create_instance" scope="cd">
  42. <parameter expr="'modelverse'"/>
  43. <parameter expr="'Modelverse'"/>
  44. </raise>
  45. <raise event="update_status" scope="narrow" target="self.splash_window">
  46. <parameter expr="0"/>
  47. <parameter expr="'Waiting for Modelverse Instantiation...'"/>
  48. </raise>
  49. </onentry>
  50. <transition event="instance_created" target="../initializing_network">
  51. <parameter name="association_name"/>
  52. <raise event="start_instance" scope="cd">
  53. <parameter expr="association_name"/>
  54. </raise>
  55. <raise event="update_status" scope="narrow" target="self.splash_window">
  56. <parameter expr="15"/>
  57. <parameter expr="'Waiting for Modelverse Instantiation... OK'"/>
  58. </raise>
  59. </transition>
  60. </state>
  61. <state id="initializing_network">
  62. <onentry>
  63. <raise event="update_status" scope="narrow" target="self.splash_window">
  64. <parameter expr="30"/>
  65. <parameter expr="'Waiting for HTTP connection to Modelverse...'"/>
  66. </raise>
  67. </onentry>
  68. <transition event="mv_ready" target="../initializing_modelverse">
  69. <raise event="update_status" scope="narrow" target="self.splash_window">
  70. <parameter expr="40"/>
  71. <parameter expr="'Waiting for HTTP connection to Modelverse... OK'"/>
  72. </raise>
  73. </transition>
  74. </state>
  75. <state id="initializing_modelverse">
  76. <onentry>
  77. <raise event="mv_request">
  78. <parameter expr="'init'"/>
  79. <parameter expr="[self.address, self.timeout]"/>
  80. </raise>
  81. <raise event="update_status" scope="narrow" target="self.splash_window">
  82. <parameter expr="50"/>
  83. <parameter expr="'Waiting for Modelverse initialization...'"/>
  84. </raise>
  85. </onentry>
  86. <transition event="mv_response" target="../logging_in_modelverse">
  87. <raise event="update_status" scope="narrow" target="self.splash_window">
  88. <parameter expr="70"/>
  89. <parameter expr="'Waiting for Modelverse initialization... OK'"/>
  90. </raise>
  91. </transition>
  92. </state>
  93. <state id="logging_in_modelverse">
  94. <onentry>
  95. <raise event="mv_request">
  96. <parameter expr="'login'"/>
  97. <parameter expr="[self.username, self.password]"/>
  98. </raise>
  99. <raise event="update_status" scope="narrow" target="self.splash_window">
  100. <parameter expr="90"/>
  101. <parameter expr="'Logging in...'"/>
  102. </raise>
  103. </onentry>
  104. <transition event="mv_response" target="../../init_main_window">
  105. <raise event="update_status" scope="narrow" target="self.splash_window">
  106. <parameter expr="100"/>
  107. <parameter expr="'Logging in... OK'"/>
  108. </raise>
  109. </transition>
  110. </state>
  111. </state>
  112. <state id="init_main_window">
  113. <onentry>
  114. <raise event="create_instance" scope="cd">
  115. <parameter expr="'windows'"/>
  116. <parameter expr="'MainWindow'"/>
  117. </raise>
  118. <raise event="delete_instance" scope="cd">
  119. <parameter expr="self.splash_window"/>
  120. </raise>
  121. </onentry>
  122. <transition event="instance_created" target="../main_behaviour"/>
  123. </state>
  124. <state id="main_behaviour">
  125. <transition event="window_created" target=".">
  126. <script>
  127. self.nr_of_windows += 1
  128. </script>
  129. </transition>
  130. <transition event="window_deleted" target="." cond="self.nr_of_windows > 1">
  131. <script>
  132. self.nr_of_windows -= 1
  133. </script>
  134. </transition>
  135. <transition cond="self.nr_of_windows == 0" target="../stopped">
  136. <raise event="stop" scope="local" />
  137. </transition>
  138. </state>
  139. <state id="stopped">
  140. <onentry>
  141. <script>
  142. self.root.quit()
  143. </script>
  144. </onentry>
  145. </state>
  146. <transition event="mv_exception" target="stopped">
  147. <parameter name="ID"/>
  148. <parameter name="exception_name"/>
  149. <parameter name="exception"/>
  150. <script>
  151. print("Got uncaught exception from Modelverse: " + str(exception_name))
  152. print("Parameters: " + str(exception))
  153. </script>
  154. </transition>
  155. </state>
  156. <state id="forward_requests">
  157. <state id="forward">
  158. <transition event="mv_request" target=".">
  159. <parameter name="name"/>
  160. <parameter name="parameters"/>
  161. <raise event="action" scope="narrow" target="'modelverse'">
  162. <parameter expr="name"/>
  163. <parameter expr="None"/>
  164. <parameter expr="None"/>
  165. <parameter expr="parameters"/>
  166. </raise>
  167. </transition>
  168. <transition event="mv_result" target=".">
  169. <parameter name="ID"/>
  170. <parameter name="result"/>
  171. <raise event="mv_response">
  172. <parameter expr="result"/>
  173. </raise>
  174. </transition>
  175. </state>
  176. </state>
  177. </parallel>
  178. </scxml>
  179. </class>