|
@@ -89,6 +89,8 @@ outp_evts = []
|
|
|
#state = [(0, "idle"), (2, "armed"), (6, "detected"), (8, "idle")]
|
|
|
#outp_evts = [(6, "soundAlarm"), ]
|
|
|
|
|
|
+do_color = "grey"
|
|
|
+
|
|
|
def poll(address):
|
|
|
simulation_time = None
|
|
|
working_available_attrs = []
|
|
@@ -119,12 +121,15 @@ def poll(address):
|
|
|
elif (returnvalue.startswith("SIM_RAISE")):
|
|
|
outp_evts.append((simulation_time, returnvalue.split(" ", 1)[1]))
|
|
|
elif (returnvalue.startswith("CONFORMANCE_OK")):
|
|
|
- root.configure(background="grey")
|
|
|
+ global do_color
|
|
|
+ do_color = "grey"
|
|
|
elif (returnvalue.startswith("CONFORMANCE_FAIL")):
|
|
|
- root.configure(background="red")
|
|
|
- elif (returnvalue.startswith("REQUEST_CURRENT_STATE"):
|
|
|
- root.configure(background="blue")
|
|
|
+ global do_color
|
|
|
+ do_color = "red"
|
|
|
+ elif (returnvalue.startswith("REQUEST_CURRENT_STATE")):
|
|
|
+ global do_color
|
|
|
global request_new_state
|
|
|
+ do_color = "blue"
|
|
|
request_new_state = True
|
|
|
else:
|
|
|
print("Error: got unknown result: " + returnvalue)
|
|
@@ -139,22 +144,40 @@ class MvLayer():
|
|
|
thrd.daemon = True
|
|
|
thrd.start()
|
|
|
|
|
|
+ def color():
|
|
|
+ while 1:
|
|
|
+ global do_color
|
|
|
+ root.configure(bg=do_color)
|
|
|
+ time.sleep(0.1)
|
|
|
+
|
|
|
+ thrd = threading.Thread(target=color)
|
|
|
+ thrd.daemon = True
|
|
|
+ thrd.start()
|
|
|
+
|
|
|
def read_available_attributes(self, name):
|
|
|
urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"read_available_attributes"', "username": username}))).read()
|
|
|
urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % name, "username": username}))).read()
|
|
|
|
|
|
- while not available_attrs:
|
|
|
- time.sleep(0.1)
|
|
|
- return available_attrs.pop(0)
|
|
|
+ while 1:
|
|
|
+ try:
|
|
|
+ print("Attribute: " + str(available_attrs))
|
|
|
+ return available_attrs.pop(0)
|
|
|
+ except IndexError:
|
|
|
+ time.sleep(0.1)
|
|
|
|
|
|
def read_attribute(self, name, attr):
|
|
|
+ print("Sending read_attribute")
|
|
|
urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"read_attribute"', "username": username}))).read()
|
|
|
urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % name, "username": username}))).read()
|
|
|
urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % attr, "username": username}))).read()
|
|
|
|
|
|
- while not attribute:
|
|
|
- time.sleep(0.1)
|
|
|
- return attribute.pop(0)
|
|
|
+ print("Waiting for attribute")
|
|
|
+ while 1:
|
|
|
+ try:
|
|
|
+ print("Attribute: " + str(attribute))
|
|
|
+ return attribute.pop(0)
|
|
|
+ except IndexError:
|
|
|
+ time.sleep(0.1)
|
|
|
|
|
|
def set_attribute(self, name, attr, value):
|
|
|
urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"set_attribute"', "username": username}))).read()
|
|
@@ -212,8 +235,8 @@ class InterfaceCore():
|
|
|
drawn = set()
|
|
|
refs = dict()
|
|
|
|
|
|
- #mv = MvLayer(address)
|
|
|
- mv = FakeLayer(address)
|
|
|
+ mv = MvLayer(address)
|
|
|
+ #mv = FakeLayer(address)
|
|
|
|
|
|
def delete(self, x, y):
|
|
|
lname = self.find((x, y))
|
|
@@ -231,15 +254,18 @@ class InterfaceCore():
|
|
|
# Something already there, so don't add, but modify
|
|
|
lname = self.find((event.x, event.y))
|
|
|
|
|
|
+ global request_new_state
|
|
|
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)
|
|
|
|
|
|
+ print("Processing attributes " + str(attrs))
|
|
|
for attr, t in attrs:
|
|
|
+ print("Reading attribute " + str(attr))
|
|
|
old_value = self.mv.read_attribute(lname, attr)
|
|
|
+ print("Got value " + str(old_value))
|
|
|
if old_value == "None":
|
|
|
old_value = None
|
|
|
|
|
@@ -254,8 +280,9 @@ class InterfaceCore():
|
|
|
else:
|
|
|
print("Got unknown type: " + str(t))
|
|
|
self.mv.set_attribute(lname, attr, new_value)
|
|
|
+ print("Set value")
|
|
|
|
|
|
- if attr == "name":
|
|
|
+ if attr in ["name", "event"]:
|
|
|
if lname in names:
|
|
|
self.canvas.delete(names[lname])
|
|
|
del names[lname]
|