|
@@ -0,0 +1,725 @@
|
|
|
+"""
|
|
|
+Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
|
|
|
+
|
|
|
+Date: Wed Nov 15 08:57:11 2017
|
|
|
+
|
|
|
+Model author: Yentl Van Tendeloo
|
|
|
+Model name: ChatWindow- Tkinter Version
|
|
|
+Model description:
|
|
|
+TkInter chatwindow over STDIN and STDOUT
|
|
|
+"""
|
|
|
+
|
|
|
+from sccd.runtime.statecharts_core import *
|
|
|
+import Tkinter as tk
|
|
|
+import ttk
|
|
|
+from sccd_widget import SCCDWidget, ImageVisual, TextVisual, ToolTip
|
|
|
+import uuid
|
|
|
+import json
|
|
|
+import urllib
|
|
|
+import subprocess
|
|
|
+import sys
|
|
|
+
|
|
|
+# package "ChatWindow- Tkinter Version "
|
|
|
+
|
|
|
+class ChatWindow(RuntimeClassBase, tk.Toplevel, SCCDWidget):
|
|
|
+ def __init__(self, controller):
|
|
|
+ RuntimeClassBase.__init__(self, controller)
|
|
|
+
|
|
|
+ self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
|
+ self.semantics.internal_event_lifeline = StatechartSemantics.Queue
|
|
|
+ self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
|
|
|
+ self.semantics.priority = StatechartSemantics.SourceParent
|
|
|
+ self.semantics.concurrency = StatechartSemantics.Single
|
|
|
+
|
|
|
+ # build Statechart structure
|
|
|
+ self.build_statechart_structure()
|
|
|
+
|
|
|
+ # call user defined constructor
|
|
|
+ ChatWindow.user_defined_constructor(self)
|
|
|
+
|
|
|
+ def user_defined_constructor(self):
|
|
|
+ tk.Toplevel.__init__(self)
|
|
|
+ SCCDWidget.__init__(self)
|
|
|
+ self.input_value = ""
|
|
|
+
|
|
|
+ def user_defined_destructor(self):
|
|
|
+ self.destroy()
|
|
|
+ # call super class destructors
|
|
|
+ if hasattr(tk.Toplevel, "__del__"):
|
|
|
+ tk.Toplevel.__del__(self)
|
|
|
+ if hasattr(SCCDWidget, "__del__"):
|
|
|
+ SCCDWidget.__del__(self)
|
|
|
+
|
|
|
+
|
|
|
+ # builds Statechart structure
|
|
|
+ def build_statechart_structure(self):
|
|
|
+
|
|
|
+ # state <root>
|
|
|
+ self.states[""] = State(0, "", self)
|
|
|
+
|
|
|
+ # state /init
|
|
|
+ self.states["/init"] = State(1, "/init", self)
|
|
|
+
|
|
|
+ # state /init/init_entry_log
|
|
|
+ self.states["/init/init_entry_log"] = State(2, "/init/init_entry_log", self)
|
|
|
+
|
|
|
+ # state /init/init_entry_log/create
|
|
|
+ self.states["/init/init_entry_log/create"] = State(3, "/init/init_entry_log/create", self)
|
|
|
+ self.states["/init/init_entry_log/create"].setEnter(self._init_init_entry_log_create_enter)
|
|
|
+
|
|
|
+ # state /init/init_entry_log/wait_for_packing
|
|
|
+ self.states["/init/init_entry_log/wait_for_packing"] = State(4, "/init/init_entry_log/wait_for_packing", self)
|
|
|
+
|
|
|
+ # state /init/init_entry_input
|
|
|
+ self.states["/init/init_entry_input"] = State(5, "/init/init_entry_input", self)
|
|
|
+
|
|
|
+ # state /init/init_entry_input/create
|
|
|
+ self.states["/init/init_entry_input/create"] = State(6, "/init/init_entry_input/create", self)
|
|
|
+ self.states["/init/init_entry_input/create"].setEnter(self._init_init_entry_input_create_enter)
|
|
|
+
|
|
|
+ # state /init/init_entry_input/wait_for_packing
|
|
|
+ self.states["/init/init_entry_input/wait_for_packing"] = State(7, "/init/init_entry_input/wait_for_packing", self)
|
|
|
+
|
|
|
+ # state /init/init_button_send
|
|
|
+ self.states["/init/init_button_send"] = State(8, "/init/init_button_send", self)
|
|
|
+
|
|
|
+ # state /init/init_button_send/create
|
|
|
+ self.states["/init/init_button_send/create"] = State(9, "/init/init_button_send/create", self)
|
|
|
+ self.states["/init/init_button_send/create"].setEnter(self._init_init_button_send_create_enter)
|
|
|
+
|
|
|
+ # state /init/init_button_send/wait_for_packing
|
|
|
+ self.states["/init/init_button_send/wait_for_packing"] = State(10, "/init/init_button_send/wait_for_packing", self)
|
|
|
+
|
|
|
+ # state /root
|
|
|
+ self.states["/root"] = State(11, "/root", self)
|
|
|
+
|
|
|
+ # state /closing
|
|
|
+ self.states["/closing"] = State(12, "/closing", self)
|
|
|
+ self.states["/closing"].setEnter(self._closing_enter)
|
|
|
+
|
|
|
+ # state /close
|
|
|
+ self.states["/close"] = State(13, "/close", self)
|
|
|
+
|
|
|
+ # add children
|
|
|
+ self.states[""].addChild(self.states["/init"])
|
|
|
+ self.states[""].addChild(self.states["/root"])
|
|
|
+ self.states[""].addChild(self.states["/closing"])
|
|
|
+ self.states[""].addChild(self.states["/close"])
|
|
|
+ self.states["/init"].addChild(self.states["/init/init_entry_log"])
|
|
|
+ self.states["/init"].addChild(self.states["/init/init_entry_input"])
|
|
|
+ self.states["/init"].addChild(self.states["/init/init_button_send"])
|
|
|
+ self.states["/init/init_entry_log"].addChild(self.states["/init/init_entry_log/create"])
|
|
|
+ self.states["/init/init_entry_log"].addChild(self.states["/init/init_entry_log/wait_for_packing"])
|
|
|
+ self.states["/init/init_entry_input"].addChild(self.states["/init/init_entry_input/create"])
|
|
|
+ self.states["/init/init_entry_input"].addChild(self.states["/init/init_entry_input/wait_for_packing"])
|
|
|
+ self.states["/init/init_button_send"].addChild(self.states["/init/init_button_send/create"])
|
|
|
+ self.states["/init/init_button_send"].addChild(self.states["/init/init_button_send/wait_for_packing"])
|
|
|
+ self.states[""].fixTree()
|
|
|
+ self.states[""].default_state = self.states["/init"]
|
|
|
+ self.states["/init"].default_state = self.states["/init/init_entry_log"]
|
|
|
+ self.states["/init/init_entry_log"].default_state = self.states["/init/init_entry_log/create"]
|
|
|
+ self.states["/init/init_entry_input"].default_state = self.states["/init/init_entry_input/create"]
|
|
|
+ self.states["/init/init_button_send"].default_state = self.states["/init/init_button_send/create"]
|
|
|
+
|
|
|
+ # transition /init/init_entry_log/create
|
|
|
+ _init_init_entry_log_create_0 = Transition(self, self.states["/init/init_entry_log/create"], [self.states["/init/init_entry_log/wait_for_packing"]])
|
|
|
+ _init_init_entry_log_create_0.setAction(self._init_init_entry_log_create_0_exec)
|
|
|
+ _init_init_entry_log_create_0.setTrigger(Event("instance_created", None))
|
|
|
+ self.states["/init/init_entry_log/create"].addTransition(_init_init_entry_log_create_0)
|
|
|
+
|
|
|
+ # transition /init/init_entry_log/wait_for_packing
|
|
|
+ _init_init_entry_log_wait_for_packing_0 = Transition(self, self.states["/init/init_entry_log/wait_for_packing"], [self.states["/init/init_entry_input"]])
|
|
|
+ _init_init_entry_log_wait_for_packing_0.setAction(self._init_init_entry_log_wait_for_packing_0_exec)
|
|
|
+ _init_init_entry_log_wait_for_packing_0.setTrigger(Event("tk_widget", None))
|
|
|
+ self.states["/init/init_entry_log/wait_for_packing"].addTransition(_init_init_entry_log_wait_for_packing_0)
|
|
|
+
|
|
|
+ # transition /init/init_entry_input/create
|
|
|
+ _init_init_entry_input_create_0 = Transition(self, self.states["/init/init_entry_input/create"], [self.states["/init/init_entry_input/wait_for_packing"]])
|
|
|
+ _init_init_entry_input_create_0.setAction(self._init_init_entry_input_create_0_exec)
|
|
|
+ _init_init_entry_input_create_0.setTrigger(Event("instance_created", None))
|
|
|
+ self.states["/init/init_entry_input/create"].addTransition(_init_init_entry_input_create_0)
|
|
|
+
|
|
|
+ # transition /init/init_entry_input/wait_for_packing
|
|
|
+ _init_init_entry_input_wait_for_packing_0 = Transition(self, self.states["/init/init_entry_input/wait_for_packing"], [self.states["/init/init_button_send"]])
|
|
|
+ _init_init_entry_input_wait_for_packing_0.setAction(self._init_init_entry_input_wait_for_packing_0_exec)
|
|
|
+ _init_init_entry_input_wait_for_packing_0.setTrigger(Event("tk_widget", None))
|
|
|
+ self.states["/init/init_entry_input/wait_for_packing"].addTransition(_init_init_entry_input_wait_for_packing_0)
|
|
|
+
|
|
|
+ # transition /init/init_button_send/create
|
|
|
+ _init_init_button_send_create_0 = Transition(self, self.states["/init/init_button_send/create"], [self.states["/init/init_button_send/wait_for_packing"]])
|
|
|
+ _init_init_button_send_create_0.setAction(self._init_init_button_send_create_0_exec)
|
|
|
+ _init_init_button_send_create_0.setTrigger(Event("instance_created", None))
|
|
|
+ self.states["/init/init_button_send/create"].addTransition(_init_init_button_send_create_0)
|
|
|
+
|
|
|
+ # transition /init/init_button_send/wait_for_packing
|
|
|
+ _init_init_button_send_wait_for_packing_0 = Transition(self, self.states["/init/init_button_send/wait_for_packing"], [self.states["/root"]])
|
|
|
+ _init_init_button_send_wait_for_packing_0.setAction(self._init_init_button_send_wait_for_packing_0_exec)
|
|
|
+ _init_init_button_send_wait_for_packing_0.setTrigger(Event("tk_widget", None))
|
|
|
+ self.states["/init/init_button_send/wait_for_packing"].addTransition(_init_init_button_send_wait_for_packing_0)
|
|
|
+
|
|
|
+ # transition /root
|
|
|
+ _root_0 = Transition(self, self.states["/root"], [self.states["/root"]])
|
|
|
+ _root_0.setAction(self._root_0_exec)
|
|
|
+ _root_0.setTrigger(Event("button_pressed", None))
|
|
|
+ _root_0.setGuard(self._root_0_guard)
|
|
|
+ self.states["/root"].addTransition(_root_0)
|
|
|
+ _root_1 = Transition(self, self.states["/root"], [self.states["/root"]])
|
|
|
+ _root_1.setAction(self._root_1_exec)
|
|
|
+ _root_1.setTrigger(Event("stdin_input", "stdin_port"))
|
|
|
+ self.states["/root"].addTransition(_root_1)
|
|
|
+ _root_2 = Transition(self, self.states["/root"], [self.states["/root"]])
|
|
|
+ _root_2.setAction(self._root_2_exec)
|
|
|
+ _root_2.setTrigger(Event("changed_entry", None))
|
|
|
+ _root_2.setGuard(self._root_2_guard)
|
|
|
+ self.states["/root"].addTransition(_root_2)
|
|
|
+ _root_3 = Transition(self, self.states["/root"], [self.states["/closing"]])
|
|
|
+ _root_3.setTrigger(Event("close_window", None))
|
|
|
+ self.states["/root"].addTransition(_root_3)
|
|
|
+
|
|
|
+ # transition /closing
|
|
|
+ _closing_0 = Transition(self, self.states["/closing"], [self.states["/close"]])
|
|
|
+ _closing_0.setTrigger(Event("instance_deleted", None))
|
|
|
+ self.states["/closing"].addTransition(_closing_0)
|
|
|
+
|
|
|
+ def _init_init_entry_log_create_enter(self):
|
|
|
+ self.big_step.outputEventOM(Event("create_instance", None, [self, 'entries', 'Text', {'parent': self, 'name': 'history'}]))
|
|
|
+
|
|
|
+ def _init_init_entry_input_create_enter(self):
|
|
|
+ self.big_step.outputEventOM(Event("create_instance", None, [self, 'entries', 'Entry', {'parent': self, 'value': self.input_value, 'name': 'input_value'}]))
|
|
|
+
|
|
|
+ def _init_init_button_send_create_enter(self):
|
|
|
+ self.big_step.outputEventOM(Event("create_instance", None, [self, 'buttons', 'Button', {'parent': self, 'visual': TextVisual('send'), 'tooltip_text': 'Send data to active activity.', 'event_parameters': 'send'}]))
|
|
|
+
|
|
|
+ def _closing_enter(self):
|
|
|
+ self.big_step.outputEventOM(Event("delete_instance", None, [self, 'buttons']))
|
|
|
+ self.big_step.outputEventOM(Event("delete_instance", None, [self, 'entries']))
|
|
|
+
|
|
|
+ def _init_init_entry_log_create_0_exec(self, parameters):
|
|
|
+ association_name = parameters[0]
|
|
|
+ self.big_step.outputEventOM(Event("start_instance", None, [self, association_name]))
|
|
|
+ self.entry_log = association_name
|
|
|
+
|
|
|
+ def _init_init_entry_log_wait_for_packing_0_exec(self, parameters):
|
|
|
+ tk_elem = parameters[0]
|
|
|
+ tk_elem.pack()
|
|
|
+
|
|
|
+ def _init_init_entry_input_create_0_exec(self, parameters):
|
|
|
+ association_name = parameters[0]
|
|
|
+ self.big_step.outputEventOM(Event("start_instance", None, [self, association_name]))
|
|
|
+ self.entry_input = association_name
|
|
|
+
|
|
|
+ def _init_init_entry_input_wait_for_packing_0_exec(self, parameters):
|
|
|
+ tk_elem = parameters[0]
|
|
|
+ tk_elem.pack()
|
|
|
+
|
|
|
+ def _init_init_button_send_create_0_exec(self, parameters):
|
|
|
+ association_name = parameters[0]
|
|
|
+ self.big_step.outputEventOM(Event("start_instance", None, [self, association_name]))
|
|
|
+ self.button = association_name
|
|
|
+
|
|
|
+ def _init_init_button_send_wait_for_packing_0_exec(self, parameters):
|
|
|
+ tk_elem = parameters[0]
|
|
|
+ tk_elem.pack()
|
|
|
+
|
|
|
+ def _root_0_exec(self, parameters):
|
|
|
+ event_name = parameters[0]
|
|
|
+ self.big_step.outputEvent(Event("stdout_output", "stdout_port", [self.input_value]))
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, self.entry_input, Event("change_value", None, [''])]))
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, self.entry_log, Event("append_value", None, ['< ' + self.input_value + '\n'])]))
|
|
|
+
|
|
|
+ def _root_0_guard(self, parameters):
|
|
|
+ event_name = parameters[0]
|
|
|
+ return event_name == 'send'
|
|
|
+
|
|
|
+ def _root_1_exec(self, parameters):
|
|
|
+ value = parameters[0]
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, self.entry_log, Event("append_value", None, ['> ' + value + '\n'])]))
|
|
|
+
|
|
|
+ def _root_2_exec(self, parameters):
|
|
|
+ name = parameters[0]
|
|
|
+ value = parameters[1]
|
|
|
+ self.input_value = value
|
|
|
+
|
|
|
+ def _root_2_guard(self, parameters):
|
|
|
+ name = parameters[0]
|
|
|
+ value = parameters[1]
|
|
|
+ return name == 'input_value'
|
|
|
+
|
|
|
+ def initializeStatechart(self):
|
|
|
+ # enter default state
|
|
|
+ self.default_targets = self.states["/init"].getEffectiveTargetStates()
|
|
|
+ RuntimeClassBase.initializeStatechart(self)
|
|
|
+
|
|
|
+class Text(RuntimeClassBase):
|
|
|
+ def __init__(self, controller, constructor_parameters = None):
|
|
|
+ if constructor_parameters == None: constructor_parameters = {}
|
|
|
+ RuntimeClassBase.__init__(self, controller)
|
|
|
+
|
|
|
+ self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
|
+ self.semantics.internal_event_lifeline = StatechartSemantics.Queue
|
|
|
+ self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
|
|
|
+ self.semantics.priority = StatechartSemantics.SourceParent
|
|
|
+ self.semantics.concurrency = StatechartSemantics.Single
|
|
|
+
|
|
|
+ # build Statechart structure
|
|
|
+ self.build_statechart_structure()
|
|
|
+
|
|
|
+ # call user defined constructor
|
|
|
+ Text.user_defined_constructor(self, constructor_parameters)
|
|
|
+
|
|
|
+ def user_defined_constructor(self, constructor_parameters = None):
|
|
|
+ if constructor_parameters == None: constructor_parameters = {}
|
|
|
+ self.name = constructor_parameters['name']
|
|
|
+ self.entry = tk.Text(constructor_parameters['parent'])
|
|
|
+ self.entry.config(state=tk.DISABLED)
|
|
|
+
|
|
|
+ def user_defined_destructor(self):
|
|
|
+ self.entry.destroy()
|
|
|
+
|
|
|
+
|
|
|
+ # builds Statechart structure
|
|
|
+ def build_statechart_structure(self):
|
|
|
+
|
|
|
+ # state <root>
|
|
|
+ self.states[""] = State(0, "", self)
|
|
|
+
|
|
|
+ # state /main
|
|
|
+ self.states["/main"] = State(1, "/main", self)
|
|
|
+
|
|
|
+ # state /main/initializing
|
|
|
+ self.states["/main/initializing"] = State(2, "/main/initializing", self)
|
|
|
+
|
|
|
+ # state /main/ready
|
|
|
+ self.states["/main/ready"] = State(3, "/main/ready", self)
|
|
|
+
|
|
|
+ # add children
|
|
|
+ self.states[""].addChild(self.states["/main"])
|
|
|
+ self.states["/main"].addChild(self.states["/main/initializing"])
|
|
|
+ self.states["/main"].addChild(self.states["/main/ready"])
|
|
|
+ self.states[""].fixTree()
|
|
|
+ self.states[""].default_state = self.states["/main"]
|
|
|
+ self.states["/main"].default_state = self.states["/main/initializing"]
|
|
|
+
|
|
|
+ # transition /main/initializing
|
|
|
+ _main_initializing_0 = Transition(self, self.states["/main/initializing"], [self.states["/main/ready"]])
|
|
|
+ _main_initializing_0.setAction(self._main_initializing_0_exec)
|
|
|
+ _main_initializing_0.setTrigger(None)
|
|
|
+ self.states["/main/initializing"].addTransition(_main_initializing_0)
|
|
|
+
|
|
|
+ # transition /main/ready
|
|
|
+ _main_ready_0 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_0.setAction(self._main_ready_0_exec)
|
|
|
+ _main_ready_0.setTrigger(Event("append_value", None))
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_0)
|
|
|
+
|
|
|
+ def _main_initializing_0_exec(self, parameters):
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("tk_widget", None, [self.entry])]))
|
|
|
+
|
|
|
+ def _main_ready_0_exec(self, parameters):
|
|
|
+ new_value = parameters[0]
|
|
|
+ self.entry.config(state=tk.NORMAL)
|
|
|
+ self.entry.insert(tk.END, new_value)
|
|
|
+ self.entry.config(state=tk.DISABLED)
|
|
|
+ self.entry.see(tk.END)
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("changed_value", None, [self.name, self.entry.get(1.0, tk.END)])]))
|
|
|
+
|
|
|
+ def initializeStatechart(self):
|
|
|
+ # enter default state
|
|
|
+ self.default_targets = self.states["/main"].getEffectiveTargetStates()
|
|
|
+ RuntimeClassBase.initializeStatechart(self)
|
|
|
+
|
|
|
+class Entry(RuntimeClassBase):
|
|
|
+ def __init__(self, controller, constructor_parameters = None):
|
|
|
+ if constructor_parameters == None: constructor_parameters = {}
|
|
|
+ RuntimeClassBase.__init__(self, controller)
|
|
|
+
|
|
|
+ self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
|
+ self.semantics.internal_event_lifeline = StatechartSemantics.Queue
|
|
|
+ self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
|
|
|
+ self.semantics.priority = StatechartSemantics.SourceParent
|
|
|
+ self.semantics.concurrency = StatechartSemantics.Single
|
|
|
+
|
|
|
+ # build Statechart structure
|
|
|
+ self.build_statechart_structure()
|
|
|
+
|
|
|
+ # call user defined constructor
|
|
|
+ Entry.user_defined_constructor(self, constructor_parameters)
|
|
|
+
|
|
|
+ def user_defined_constructor(self, constructor_parameters = None):
|
|
|
+ if constructor_parameters == None: constructor_parameters = {}
|
|
|
+ self.name = constructor_parameters['name']
|
|
|
+ self.entry = tk.Entry(constructor_parameters['parent'], textvariable=self.construct_strvar(constructor_parameters['parent'], constructor_parameters['value']))
|
|
|
+
|
|
|
+ if constructor_parameters.get('readonly', False):
|
|
|
+ self.entry.config(state=tk.DISABLED)
|
|
|
+
|
|
|
+ def user_defined_destructor(self):
|
|
|
+ self.entry.destroy()
|
|
|
+
|
|
|
+
|
|
|
+ # user defined method
|
|
|
+ def construct_strvar(self, parent, value):
|
|
|
+ self.strvar = tk.StringVar(parent)
|
|
|
+ self.strvar.set(value)
|
|
|
+ self.strvar.trace('w', lambda a, b, c: self.controller.addInput(Event("change_entry", "input", [id(self), self.strvar.get()])))
|
|
|
+ return self.strvar
|
|
|
+
|
|
|
+
|
|
|
+ # builds Statechart structure
|
|
|
+ def build_statechart_structure(self):
|
|
|
+
|
|
|
+ # state <root>
|
|
|
+ self.states[""] = State(0, "", self)
|
|
|
+
|
|
|
+ # state /main
|
|
|
+ self.states["/main"] = State(1, "/main", self)
|
|
|
+
|
|
|
+ # state /main/initializing
|
|
|
+ self.states["/main/initializing"] = State(2, "/main/initializing", self)
|
|
|
+
|
|
|
+ # state /main/ready
|
|
|
+ self.states["/main/ready"] = State(3, "/main/ready", self)
|
|
|
+
|
|
|
+ # add children
|
|
|
+ self.states[""].addChild(self.states["/main"])
|
|
|
+ self.states["/main"].addChild(self.states["/main/initializing"])
|
|
|
+ self.states["/main"].addChild(self.states["/main/ready"])
|
|
|
+ self.states[""].fixTree()
|
|
|
+ self.states[""].default_state = self.states["/main"]
|
|
|
+ self.states["/main"].default_state = self.states["/main/initializing"]
|
|
|
+
|
|
|
+ # transition /main/initializing
|
|
|
+ _main_initializing_0 = Transition(self, self.states["/main/initializing"], [self.states["/main/ready"]])
|
|
|
+ _main_initializing_0.setAction(self._main_initializing_0_exec)
|
|
|
+ _main_initializing_0.setTrigger(None)
|
|
|
+ self.states["/main/initializing"].addTransition(_main_initializing_0)
|
|
|
+
|
|
|
+ # transition /main/ready
|
|
|
+ _main_ready_0 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_0.setAction(self._main_ready_0_exec)
|
|
|
+ _main_ready_0.setTrigger(Event("change_entry", "input"))
|
|
|
+ _main_ready_0.setGuard(self._main_ready_0_guard)
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_0)
|
|
|
+ _main_ready_1 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_1.setAction(self._main_ready_1_exec)
|
|
|
+ _main_ready_1.setTrigger(Event("change_bg", None))
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_1)
|
|
|
+ _main_ready_2 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_2.setAction(self._main_ready_2_exec)
|
|
|
+ _main_ready_2.setTrigger(Event("change_event_name", None))
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_2)
|
|
|
+ _main_ready_3 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_3.setAction(self._main_ready_3_exec)
|
|
|
+ _main_ready_3.setTrigger(Event("change_value", None))
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_3)
|
|
|
+ _main_ready_4 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_4.setAction(self._main_ready_4_exec)
|
|
|
+ _main_ready_4.setTrigger(Event("disable", None))
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_4)
|
|
|
+
|
|
|
+ def _main_initializing_0_exec(self, parameters):
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("tk_widget", None, [self.entry])]))
|
|
|
+
|
|
|
+ def _main_ready_0_exec(self, parameters):
|
|
|
+ tagorid = parameters[0]
|
|
|
+ new_value = parameters[1]
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("changed_entry", None, [self.name, new_value])]))
|
|
|
+
|
|
|
+ def _main_ready_0_guard(self, parameters):
|
|
|
+ tagorid = parameters[0]
|
|
|
+ new_value = parameters[1]
|
|
|
+ return tagorid == id(self)
|
|
|
+
|
|
|
+ def _main_ready_1_exec(self, parameters):
|
|
|
+ colour = parameters[0]
|
|
|
+ self.entry.configure(bg=colour, disabledbackground=colour)
|
|
|
+
|
|
|
+ def _main_ready_2_exec(self, parameters):
|
|
|
+ new_name = parameters[0]
|
|
|
+ self.name = new_name
|
|
|
+
|
|
|
+ def _main_ready_3_exec(self, parameters):
|
|
|
+ new_value = parameters[0]
|
|
|
+ self.strvar.set(new_value)
|
|
|
+
|
|
|
+ def _main_ready_4_exec(self, parameters):
|
|
|
+ self.entry.config(state=tk.DISABLED)
|
|
|
+
|
|
|
+ def initializeStatechart(self):
|
|
|
+ # enter default state
|
|
|
+ self.default_targets = self.states["/main"].getEffectiveTargetStates()
|
|
|
+ RuntimeClassBase.initializeStatechart(self)
|
|
|
+
|
|
|
+class Button(RuntimeClassBase, tk.Button, SCCDWidget):
|
|
|
+ def __init__(self, controller, constructor_parameters = None):
|
|
|
+ if constructor_parameters == None: constructor_parameters = {}
|
|
|
+ RuntimeClassBase.__init__(self, controller)
|
|
|
+
|
|
|
+ self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
|
+ self.semantics.internal_event_lifeline = StatechartSemantics.Queue
|
|
|
+ self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
|
|
|
+ self.semantics.priority = StatechartSemantics.SourceParent
|
|
|
+ self.semantics.concurrency = StatechartSemantics.Single
|
|
|
+
|
|
|
+ # build Statechart structure
|
|
|
+ self.build_statechart_structure()
|
|
|
+
|
|
|
+ # call user defined constructor
|
|
|
+ Button.user_defined_constructor(self, constructor_parameters)
|
|
|
+
|
|
|
+ def user_defined_constructor(self, constructor_parameters = None):
|
|
|
+ if constructor_parameters == None: constructor_parameters = {}
|
|
|
+ tk.Button.__init__(self, constructor_parameters['parent'], **(constructor_parameters['visual'].get_params()))
|
|
|
+ SCCDWidget.__init__(self)
|
|
|
+ self.event_parameters = constructor_parameters["event_parameters"]
|
|
|
+ if "tooltip_text" in constructor_parameters:
|
|
|
+ self.tooltip = ToolTip(self, constructor_parameters["tooltip_text"])
|
|
|
+ else:
|
|
|
+ self.tooltip = None
|
|
|
+ self.visual = constructor_parameters["visual"]
|
|
|
+
|
|
|
+ def user_defined_destructor(self):
|
|
|
+ self.destroy()
|
|
|
+ # call super class destructors
|
|
|
+ if hasattr(tk.Button, "__del__"):
|
|
|
+ tk.Button.__del__(self)
|
|
|
+ if hasattr(SCCDWidget, "__del__"):
|
|
|
+ SCCDWidget.__del__(self)
|
|
|
+
|
|
|
+
|
|
|
+ # builds Statechart structure
|
|
|
+ def build_statechart_structure(self):
|
|
|
+
|
|
|
+ # state <root>
|
|
|
+ self.states[""] = State(0, "", self)
|
|
|
+
|
|
|
+ # state /main
|
|
|
+ self.states["/main"] = State(1, "/main", self)
|
|
|
+
|
|
|
+ # state /main/initializing
|
|
|
+ self.states["/main/initializing"] = State(2, "/main/initializing", self)
|
|
|
+
|
|
|
+ # state /main/ready
|
|
|
+ self.states["/main/ready"] = State(3, "/main/ready", self)
|
|
|
+
|
|
|
+ # add children
|
|
|
+ self.states[""].addChild(self.states["/main"])
|
|
|
+ self.states["/main"].addChild(self.states["/main/initializing"])
|
|
|
+ self.states["/main"].addChild(self.states["/main/ready"])
|
|
|
+ self.states[""].fixTree()
|
|
|
+ self.states[""].default_state = self.states["/main"]
|
|
|
+ self.states["/main"].default_state = self.states["/main/initializing"]
|
|
|
+
|
|
|
+ # transition /main/initializing
|
|
|
+ _main_initializing_0 = Transition(self, self.states["/main/initializing"], [self.states["/main/ready"]])
|
|
|
+ _main_initializing_0.setAction(self._main_initializing_0_exec)
|
|
|
+ _main_initializing_0.setTrigger(None)
|
|
|
+ self.states["/main/initializing"].addTransition(_main_initializing_0)
|
|
|
+
|
|
|
+ # transition /main/ready
|
|
|
+ _main_ready_0 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_0.setAction(self._main_ready_0_exec)
|
|
|
+ _main_ready_0.setTrigger(Event("left-click", "input"))
|
|
|
+ _main_ready_0.setGuard(self._main_ready_0_guard)
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_0)
|
|
|
+ _main_ready_1 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_1.setAction(self._main_ready_1_exec)
|
|
|
+ _main_ready_1.setTrigger(Event("enter", "input"))
|
|
|
+ _main_ready_1.setGuard(self._main_ready_1_guard)
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_1)
|
|
|
+ _main_ready_2 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_2.setAction(self._main_ready_2_exec)
|
|
|
+ _main_ready_2.setTrigger(Event("leave", "input"))
|
|
|
+ _main_ready_2.setGuard(self._main_ready_2_guard)
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_2)
|
|
|
+ _main_ready_3 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_3.setAction(self._main_ready_3_exec)
|
|
|
+ _main_ready_3.setTrigger(Event("activate", None))
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_3)
|
|
|
+ _main_ready_4 = Transition(self, self.states["/main/ready"], [self.states["/main/ready"]])
|
|
|
+ _main_ready_4.setAction(self._main_ready_4_exec)
|
|
|
+ _main_ready_4.setTrigger(Event("deactivate", None))
|
|
|
+ self.states["/main/ready"].addTransition(_main_ready_4)
|
|
|
+
|
|
|
+ def _main_initializing_0_exec(self, parameters):
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("tk_widget", None, [self])]))
|
|
|
+
|
|
|
+ def _main_ready_0_exec(self, parameters):
|
|
|
+ tagorid = parameters[0]
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("button_pressed", None, [self.event_parameters])]))
|
|
|
+
|
|
|
+ def _main_ready_0_guard(self, parameters):
|
|
|
+ tagorid = parameters[0]
|
|
|
+ return tagorid == id(self)
|
|
|
+
|
|
|
+ def _main_ready_1_exec(self, parameters):
|
|
|
+ tagorid = parameters[0]
|
|
|
+ self.tooltip.showtip()
|
|
|
+
|
|
|
+ def _main_ready_1_guard(self, parameters):
|
|
|
+ tagorid = parameters[0]
|
|
|
+ return tagorid == id(self) and self.tooltip is not None
|
|
|
+
|
|
|
+ def _main_ready_2_exec(self, parameters):
|
|
|
+ tagorid = parameters[0]
|
|
|
+ self.tooltip.hidetip()
|
|
|
+
|
|
|
+ def _main_ready_2_guard(self, parameters):
|
|
|
+ tagorid = parameters[0]
|
|
|
+ return tagorid == id(self) and self.tooltip is not None
|
|
|
+
|
|
|
+ def _main_ready_3_exec(self, parameters):
|
|
|
+ self.configure(state=tk.ACTIVE, relief=tk.SUNKEN)
|
|
|
+ print("Activate " + str(self.event_parameters))
|
|
|
+
|
|
|
+ def _main_ready_4_exec(self, parameters):
|
|
|
+ self.configure(state=tk.NORMAL, relief=tk.RAISED)
|
|
|
+ print("Deactivate " + str(self.event_parameters))
|
|
|
+
|
|
|
+ def initializeStatechart(self):
|
|
|
+ # enter default state
|
|
|
+ self.default_targets = self.states["/main"].getEffectiveTargetStates()
|
|
|
+ RuntimeClassBase.initializeStatechart(self)
|
|
|
+
|
|
|
+class Label(RuntimeClassBase, tk.Label, SCCDWidget):
|
|
|
+ def __init__(self, controller, constructor_parameters = None):
|
|
|
+ if constructor_parameters == None: constructor_parameters = {}
|
|
|
+ RuntimeClassBase.__init__(self, controller)
|
|
|
+
|
|
|
+ self.semantics.big_step_maximality = StatechartSemantics.TakeMany
|
|
|
+ self.semantics.internal_event_lifeline = StatechartSemantics.Queue
|
|
|
+ self.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep
|
|
|
+ self.semantics.priority = StatechartSemantics.SourceParent
|
|
|
+ self.semantics.concurrency = StatechartSemantics.Single
|
|
|
+
|
|
|
+ # build Statechart structure
|
|
|
+ self.build_statechart_structure()
|
|
|
+
|
|
|
+ # call user defined constructor
|
|
|
+ Label.user_defined_constructor(self, constructor_parameters)
|
|
|
+
|
|
|
+ def user_defined_constructor(self, constructor_parameters = None):
|
|
|
+ if constructor_parameters == None: constructor_parameters = {}
|
|
|
+ tk.Label.__init__(self, constructor_parameters['parent'], **({'text': constructor_parameters['text'], 'bg': 'white'}))
|
|
|
+ SCCDWidget.__init__(self)
|
|
|
+
|
|
|
+ def user_defined_destructor(self):
|
|
|
+ self.destroy()
|
|
|
+ # call super class destructors
|
|
|
+ if hasattr(tk.Label, "__del__"):
|
|
|
+ tk.Label.__del__(self)
|
|
|
+ if hasattr(SCCDWidget, "__del__"):
|
|
|
+ SCCDWidget.__del__(self)
|
|
|
+
|
|
|
+
|
|
|
+ # user defined method
|
|
|
+ def set_text(self, text):
|
|
|
+ self.config(text=text)
|
|
|
+
|
|
|
+
|
|
|
+ # builds Statechart structure
|
|
|
+ def build_statechart_structure(self):
|
|
|
+
|
|
|
+ # state <root>
|
|
|
+ self.states[""] = State(0, "", self)
|
|
|
+
|
|
|
+ # state /root
|
|
|
+ self.states["/root"] = State(1, "/root", self)
|
|
|
+
|
|
|
+ # state /root/initializing
|
|
|
+ self.states["/root/initializing"] = State(2, "/root/initializing", self)
|
|
|
+
|
|
|
+ # state /root/ready
|
|
|
+ self.states["/root/ready"] = State(3, "/root/ready", self)
|
|
|
+
|
|
|
+ # add children
|
|
|
+ self.states[""].addChild(self.states["/root"])
|
|
|
+ self.states["/root"].addChild(self.states["/root/initializing"])
|
|
|
+ self.states["/root"].addChild(self.states["/root/ready"])
|
|
|
+ self.states[""].fixTree()
|
|
|
+ self.states[""].default_state = self.states["/root"]
|
|
|
+ self.states["/root"].default_state = self.states["/root/initializing"]
|
|
|
+
|
|
|
+ # transition /root/initializing
|
|
|
+ _root_initializing_0 = Transition(self, self.states["/root/initializing"], [self.states["/root/ready"]])
|
|
|
+ _root_initializing_0.setAction(self._root_initializing_0_exec)
|
|
|
+ _root_initializing_0.setTrigger(None)
|
|
|
+ self.states["/root/initializing"].addTransition(_root_initializing_0)
|
|
|
+
|
|
|
+ # transition /root/ready
|
|
|
+ _root_ready_0 = Transition(self, self.states["/root/ready"], [self.states["/root/ready"]])
|
|
|
+ _root_ready_0.setAction(self._root_ready_0_exec)
|
|
|
+ _root_ready_0.setTrigger(Event("left-click", "input"))
|
|
|
+ _root_ready_0.setGuard(self._root_ready_0_guard)
|
|
|
+ self.states["/root/ready"].addTransition(_root_ready_0)
|
|
|
+ _root_ready_1 = Transition(self, self.states["/root/ready"], [self.states["/root/ready"]])
|
|
|
+ _root_ready_1.setAction(self._root_ready_1_exec)
|
|
|
+ _root_ready_1.setTrigger(Event("highlight", None))
|
|
|
+ self.states["/root/ready"].addTransition(_root_ready_1)
|
|
|
+ _root_ready_2 = Transition(self, self.states["/root/ready"], [self.states["/root/ready"]])
|
|
|
+ _root_ready_2.setAction(self._root_ready_2_exec)
|
|
|
+ _root_ready_2.setTrigger(Event("unhighlight", None))
|
|
|
+ self.states["/root/ready"].addTransition(_root_ready_2)
|
|
|
+
|
|
|
+ def _root_initializing_0_exec(self, parameters):
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("tk_widget", None, [self])]))
|
|
|
+
|
|
|
+ def _root_ready_0_exec(self, parameters):
|
|
|
+ tagorid = parameters[0]
|
|
|
+ self.big_step.outputEventOM(Event("narrow_cast", None, [self, 'parent', Event("label_pressed", None, [self.cget('text')])]))
|
|
|
+
|
|
|
+ def _root_ready_0_guard(self, parameters):
|
|
|
+ tagorid = parameters[0]
|
|
|
+ return tagorid == id(self)
|
|
|
+
|
|
|
+ def _root_ready_1_exec(self, parameters):
|
|
|
+ self.config(bg="yellow")
|
|
|
+
|
|
|
+ def _root_ready_2_exec(self, parameters):
|
|
|
+ self.config(bg="white")
|
|
|
+
|
|
|
+ def initializeStatechart(self):
|
|
|
+ # enter default state
|
|
|
+ self.default_targets = self.states["/root"].getEffectiveTargetStates()
|
|
|
+ RuntimeClassBase.initializeStatechart(self)
|
|
|
+
|
|
|
+class ObjectManager(ObjectManagerBase):
|
|
|
+ def __init__(self, controller):
|
|
|
+ ObjectManagerBase.__init__(self, controller)
|
|
|
+
|
|
|
+ def instantiate(self, class_name, construct_params):
|
|
|
+ if class_name == "ChatWindow":
|
|
|
+ instance = ChatWindow(self.controller)
|
|
|
+ instance.associations = {}
|
|
|
+ instance.associations["buttons"] = Association("Button", 0, -1)
|
|
|
+ instance.associations["entries"] = Association("Entry", 0, -1)
|
|
|
+ instance.associations["parent"] = Association("A", 0, -1)
|
|
|
+ elif class_name == "Text":
|
|
|
+ instance = Text(self.controller, construct_params[0])
|
|
|
+ instance.associations = {}
|
|
|
+ instance.associations["parent"] = Association("A", 0, -1)
|
|
|
+ elif class_name == "Entry":
|
|
|
+ instance = Entry(self.controller, construct_params[0])
|
|
|
+ instance.associations = {}
|
|
|
+ instance.associations["parent"] = Association("A", 0, -1)
|
|
|
+ elif class_name == "Button":
|
|
|
+ instance = Button(self.controller, construct_params[0])
|
|
|
+ instance.associations = {}
|
|
|
+ instance.associations["parent"] = Association("A", 0, -1)
|
|
|
+ elif class_name == "Label":
|
|
|
+ instance = Label(self.controller, construct_params[0])
|
|
|
+ instance.associations = {}
|
|
|
+ instance.associations["parent"] = Association("A", 1, 1)
|
|
|
+ else:
|
|
|
+ raise Exception("Cannot instantiate class " + class_name)
|
|
|
+ return instance
|
|
|
+
|
|
|
+class Controller(EventLoopControllerBase):
|
|
|
+ def __init__(self, event_loop_callbacks, finished_callback = None, behind_schedule_callback = None):
|
|
|
+ if finished_callback == None: finished_callback = None
|
|
|
+ if behind_schedule_callback == None: behind_schedule_callback = None
|
|
|
+ EventLoopControllerBase.__init__(self, ObjectManager(self), event_loop_callbacks, finished_callback, behind_schedule_callback)
|
|
|
+ self.addInputPort("input")
|
|
|
+ self.addInputPort("stdin_port")
|
|
|
+ self.addOutputPort("stdout_port")
|
|
|
+ self.object_manager.createInstance("ChatWindow", [])
|