123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <class name="Canvas">
- <relationships>
- <association name="parent" class="A" min="1" max="1" />
- <inheritance class="SCCDWidget" priority='0'/>
- <inheritance class="tk.Canvas" priority='1'/>
- <association name="elements" class="CanvasElement"/>
- <association name="connecting_lines" class="ConnectingLines"/>
- </relationships>
- <constructor>
- <parameter name="parent" />
- <super class="SCCDWidget"/>
- <super class="tk.Canvas">
- <parameter expr="parent" />
- <parameter expr="**{'scrollregion': (0, 0, parent.winfo_screenwidth()*2, parent.winfo_screenheight() * 2)}"/>
- </super>
- <body>
- vbar = tk.Scrollbar(self, orient=tk.VERTICAL)
- vbar.config(command=self.yview)
- vbar.pack(side=tk.RIGHT, fill=tk.Y, pady=(0, 16))
- hbar = tk.Scrollbar(self, orient=tk.HORIZONTAL)
- hbar.config(command=self.xview)
- hbar.pack(side=tk.BOTTOM, fill=tk.X)
- self.config(background='white', yscrollcommand=vbar.set, xscrollcommand=hbar.set)
- self.focus_set()
- self.assoc_links = {}
- self.element_group = {}
- self.group_location = {}
- self.connecting_lines = {}
- self.lines = set()
- self.layers = []
- print("RESET CANVAS")
- self.to_move = {}
- self.elems = []
- self.currently_selected = None
- self.loading = [tk.PhotoImage(file="icons/loading.gif", format="gif -index %i" % i) for i in range(8)]
- </body>
- </constructor>
- <destructor>
- <body>
- print("CANVAS DESTROYED")
- self.destroy()
- </body>
- </destructor>
- <scxml initial="main">
- <state id="main">
- <transition target="../ready">
- <raise event="tk_widget" scope="narrow" target="'parent'">
- <parameter expr="self"/>
- </raise>
- </transition>
- </state>
- <parallel id="ready">
- <state id="process_events" initial="ready">
- <state id="ready">
- <transition event="clear_canvas" target=".">
- <raise event="delete_instance" scope="cd">
- <parameter expr="'elements'"/>
- </raise>
- <raise event="delete_instance" scope="cd">
- <parameter expr="'connecting_lines'"/>
- </raise>
- <script>
- self.group_location = {}
- self.layers = []
- </script>
- </transition>
- <transition event="select_for_creation" target=".">
- <parameter name="element_name"/>
- <script>
- self.currently_selected = element_name
- </script>
- </transition>
- <transition event="right-click" cond="self.currently_selected is not None" target="../creating_element">
- <script>
- self.create_location = (self.last_x, self.last_y)
- </script>
- </transition>
- <transition event="define_group" target="../creating_group">
- <parameter name="element"/>
- <script>
- self.creating_id = element["id"]
- self.group_location[element['id']] = (element['x'], element['y'])
- </script>
- <raise event="create_instance" scope="cd">
- <parameter expr="'elements'"/>
- <parameter expr="'CanvasElement'"/>
- <parameter expr="self"/>
- <parameter expr="(element['x'], element['y'])"/>
- <parameter expr="element['id']"/>
- <parameter expr="element['__asid']"/>
- </raise>
- </transition>
- <transition event="define_contains" target=".">
- <parameter name="element"/>
- <script>
- self.element_group[element["__target"]] = element["__source"]
- </script>
- </transition>
- <transition event="draw_canvas" cond="element['type'] != 'ConnectingLine'" target=".">
- <parameter name="element"/>
- <raise event="draw_element" scope="narrow" target="self.assoc_links[self.element_group[element['id']]]">
- <parameter expr="element"/>
- </raise>
- </transition>
- <transition event="draw_canvas" cond="element['type'] == 'ConnectingLine'" target=".">
- <parameter name="element"/>
- <raise event="create_instance" scope="cd">
- <parameter expr="'connecting_lines'"/>
- <parameter expr="'ConnectingLine'"/>
- <parameter expr="self"/>
- <parameter expr="element"/>
- </raise>
- </transition>
- <transition event="instance_created" target=".">
- <parameter name="result"/>
- <raise event="start_instance" scope="cd">
- <parameter expr="result"/>
- </raise>
- </transition>
- <transition event="moved_group" target=".">
- <parameter name="group_element"/>
- <parameter name="new_location"/>
- <script>
- self.group_location[group_element] = new_location
- </script>
- <raise event="moved_element" scope="narrow" target="'connecting_lines'">
- <parameter expr="group_element"/>
- <parameter expr="new_location"/>
- </raise>
- </transition>
- </state>
- <state id="creating_group">
- <transition event="instance_created" target="../wait_canvas_element_ready">
- <parameter name="assoc_name"/>
- <raise event="start_instance" scope="cd">
- <parameter expr="assoc_name"/>
- </raise>
- <script>
- self.assoc_links[self.creating_id] = assoc_name
- </script>
- </transition>
- </state>
- <state id="wait_canvas_element_ready">
- <transition event="moved_group" target=".">
- <parameter name="group_element"/>
- <parameter name="new_location"/>
- <script>
- self.group_location[group_element] = new_location
- </script>
- <raise event="moved_element" scope="narrow" target="'connecting_lines'">
- <parameter expr="group_element"/>
- <parameter expr="new_location"/>
- </raise>
- </transition>
- <transition event="canvas_element_ready" target="../ready">
- <raise event="group_ready" scope="narrow" target="'parent'"/>
- </transition>
- </state>
- <state id="creating_element">
- <onentry>
- <raise event="mv_request" scope="broad">
- <parameter expr="'instantiate'"/>
- <parameter expr="[current_model, self.currently_selected, None, '']"/>
- </raise>
- <script>
- self.elems.append([0, self.create_image(self.last_x, self.last_y, image=self.loading[0])])
- </script>
- </onentry>
- <transition event="mv_response" target="../waiting_for_clear">
- <parameter name="ID"/>
- <script>
- self.to_move[ID] = self.create_location
- </script>
- <raise event="rerender_model" scope="narrow" target="'parent'"/>
- </transition>
- </state>
- <state id="waiting_for_clear">
- <transition event="clear_canvas" target="../ready">
- <raise event="delete_instance" scope="cd">
- <parameter expr="'elements'"/>
- </raise>
- <raise event="delete_instance" scope="cd">
- <parameter expr="'connecting_lines'"/>
- </raise>
- <script>
- self.group_location = {}
- self.layers = []
- </script>
- </transition>
- </state>
- </state>
- <state id="update_loading">
- <state id="updating">
- <transition after="self.sccd_yield() + 0.1" target=".">
- <script>
- for i in self.elems:
- self.itemconfigure(i[1], image=self.loading[i[0]])
- i[0] = (i[0] + 1) % 8
- </script>
- </transition>
- </state>
- </state>
- </parallel>
- </scxml>
- </class>
|