|
@@ -27,6 +27,7 @@ root = Tk()
|
|
|
names = {}
|
|
|
event_entry = StringVar()
|
|
|
setting_initial = False
|
|
|
+request_new_state = False
|
|
|
|
|
|
canvas = Canvas(root, width=MAX_WIDTH, height=MAX_HEIGHT, bg="white")
|
|
|
|
|
@@ -75,13 +76,22 @@ class FakeLayer():
|
|
|
def auto_sanitize(self, auto):
|
|
|
pass
|
|
|
|
|
|
+ def set_current(self, name):
|
|
|
+ pass
|
|
|
+
|
|
|
attribute = []
|
|
|
available_attrs = []
|
|
|
-simulation = []
|
|
|
+inp_evts = []
|
|
|
+state = []
|
|
|
+outp_evts = []
|
|
|
+
|
|
|
+#inp_evts = [(2, "arm"), (6, "detected")]
|
|
|
+#state = [(0, "idle"), (2, "armed"), (6, "detected"), (8, "idle")]
|
|
|
+#outp_evts = [(6, "soundAlarm"), ]
|
|
|
|
|
|
def poll(address):
|
|
|
+ simulation_time = None
|
|
|
working_available_attrs = []
|
|
|
- working_simulation = None
|
|
|
|
|
|
while 1:
|
|
|
returnvalue = json.loads(urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username}))).read())
|
|
@@ -101,19 +111,21 @@ def poll(address):
|
|
|
v = json.loads(v)
|
|
|
attribute.append(v)
|
|
|
elif (returnvalue.startswith("SIM_TIME")):
|
|
|
- working_simulation = (json.loads(returnvalue.split(" ", 1)[1]), {})
|
|
|
- elif (returnvalue.startswith("SIM_PROBE")):
|
|
|
- blockname, blockvalue = returnvalue.split(" ", 1)[1].rsplit(" ", 1)
|
|
|
- working_simulation[1][json.loads(blockname)] = json.loads(blockvalue)
|
|
|
- elif (returnvalue.startswith("SIM_END")):
|
|
|
- simulation.append(working_simulation)
|
|
|
- working_simulation = None
|
|
|
+ simulation_time = json.loads(returnvalue.split(" ", 1)[1])
|
|
|
+ elif (returnvalue.startswith("SIM_STATE")):
|
|
|
+ state.append((simulation_time, returnvalue.split(" ", 1)[1]))
|
|
|
+ elif (returnvalue.startswith("SIM_EVENT")):
|
|
|
+ inp_evts.append((simulation_time, returnvalue.split(" ", 1)[1]))
|
|
|
+ elif (returnvalue.startswith("SIM_RAISE")):
|
|
|
+ outp_evts.append((simulation_time, returnvalue.split(" ", 1)[1]))
|
|
|
elif (returnvalue.startswith("CONFORMANCE_OK")):
|
|
|
root.configure(background="grey")
|
|
|
elif (returnvalue.startswith("CONFORMANCE_FAIL")):
|
|
|
root.configure(background="red")
|
|
|
- elif (returnvalue.startswith("ALGEBRAIC_LOOP")):
|
|
|
+ elif (returnvalue.startswith("REQUEST_CURRENT_STATE"):
|
|
|
root.configure(background="blue")
|
|
|
+ global request_new_state
|
|
|
+ request_new_state = True
|
|
|
else:
|
|
|
print("Error: got unknown result: " + returnvalue)
|
|
|
|
|
@@ -184,6 +196,9 @@ class MvLayer():
|
|
|
urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"auto_sanitize"', "username": username}))).read()
|
|
|
urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": "true" if auto else "false", "username": username}))).read()
|
|
|
|
|
|
+ def set_current(self, name):
|
|
|
+ urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % (name), "username": username}))).read()
|
|
|
+
|
|
|
def lower(value):
|
|
|
return value / JUMP * JUMP
|
|
|
|
|
@@ -216,32 +231,37 @@ class InterfaceCore():
|
|
|
# Something already there, so don't add, but modify
|
|
|
lname = self.find((event.x, event.y))
|
|
|
|
|
|
- attrs = self.mv.read_available_attributes(lname)
|
|
|
-
|
|
|
- for attr, t in attrs:
|
|
|
- old_value = self.mv.read_attribute(lname, attr)
|
|
|
- if old_value == "None":
|
|
|
- old_value = None
|
|
|
-
|
|
|
- new_value = tkSimpleDialog.askstring("Attribute modification", attr, initialvalue=old_value)
|
|
|
- canvas.focus_set()
|
|
|
- if t == "Float":
|
|
|
- new_value = float(new_value)
|
|
|
- elif t == "String":
|
|
|
- new_value = str(new_value)
|
|
|
- elif t == "Natural":
|
|
|
- new_value = int(new_value)
|
|
|
- else:
|
|
|
- print("Got unknown type: " + str(t))
|
|
|
- self.mv.set_attribute(lname, attr, new_value)
|
|
|
-
|
|
|
- if attr == "name":
|
|
|
- if lname in names:
|
|
|
- self.canvas.delete(names[lname])
|
|
|
- del names[lname]
|
|
|
- entry = [x for x in self.drawn if str(x[4]) == str(lname)][0]
|
|
|
- xc, xy = avg(entry[0], entry[2]), avg(entry[1], entry[3])
|
|
|
- names[lname] = self.canvas.create_text(xc, xy, text=new_value)
|
|
|
+ if request_new_state:
|
|
|
+ global request_new_state
|
|
|
+ request_new_state = True
|
|
|
+ self.mv.set_current(lname)
|
|
|
+ else:
|
|
|
+ attrs = self.mv.read_available_attributes(lname)
|
|
|
+
|
|
|
+ for attr, t in attrs:
|
|
|
+ old_value = self.mv.read_attribute(lname, attr)
|
|
|
+ if old_value == "None":
|
|
|
+ old_value = None
|
|
|
+
|
|
|
+ new_value = tkSimpleDialog.askstring("Attribute modification", attr, initialvalue=old_value)
|
|
|
+ canvas.focus_set()
|
|
|
+ if t == "Float":
|
|
|
+ new_value = float(new_value)
|
|
|
+ elif t == "String":
|
|
|
+ new_value = str(new_value)
|
|
|
+ elif t == "Natural":
|
|
|
+ new_value = int(new_value)
|
|
|
+ else:
|
|
|
+ print("Got unknown type: " + str(t))
|
|
|
+ self.mv.set_attribute(lname, attr, new_value)
|
|
|
+
|
|
|
+ if attr == "name":
|
|
|
+ if lname in names:
|
|
|
+ self.canvas.delete(names[lname])
|
|
|
+ del names[lname]
|
|
|
+ entry = [x for x in self.drawn if str(x[4]) == str(lname)][0]
|
|
|
+ xc, xy = avg(entry[0], entry[2]), avg(entry[1], entry[3])
|
|
|
+ names[lname] = self.canvas.create_text(xc, xy, text=new_value)
|
|
|
|
|
|
else:
|
|
|
global name
|
|
@@ -331,12 +351,10 @@ def add_event():
|
|
|
core.add_event(event_entry.get())
|
|
|
|
|
|
def control_released(evt):
|
|
|
- print("Control released")
|
|
|
global setting_initial
|
|
|
setting_initial = False
|
|
|
|
|
|
def control_pressed(evt):
|
|
|
- print("Control pressed")
|
|
|
global setting_initial
|
|
|
setting_initial = True
|
|
|
|