Explorar o código

Allow changing attributes

Yentl Van Tendeloo %!s(int64=8) %!d(string=hai) anos
pai
achega
6e2c4e20f7
Modificáronse 1 ficheiros con 11 adicións e 3 borrados
  1. 11 3
      interface/graphical/main.py

+ 11 - 3
interface/graphical/main.py

@@ -127,6 +127,7 @@ class Window(object):
         # Read available attrs and their values
         as_id = self.find_AS(x, y)
         attrs = read_attrs(as_id)
+        attrs = {k: json.dumps(attrs[k]) for k in attrs}
         print("Got attrs: " + str(attrs))
 
         # Prompt for new values
@@ -136,6 +137,12 @@ class Window(object):
             # TODO
             #TODO think about type checking
             print("New attributes: " + str(d.result))
+            for k, v in d.result.items():
+                v = json.loads(v)
+                if v is None:
+                    attr_delete(as_id, k)
+                else:
+                    attr_assign(as_id, k, v)
 
     def right_clicked(self, evt):
         # Right clicked means we are creating something
@@ -296,7 +303,7 @@ class Window(object):
             self.mm_buttons.append(Button(root, text=t, command=lambda : self.create_element(t)))
             self.mm_buttons[-1].grid(row=1, column=i)
 
-    def instantiate_model():
+    def instantiate_model(self):
         try:
             model_exit()
         except InvalidMode:
@@ -308,14 +315,15 @@ class Window(object):
             model_add(name, self.selected_model.get())
             self.reset_optionmenu(self.available_models, model_list())
             self.selected_model.set(name)
-            open_model()
+            self.open_model()
 
-    def verify_model():
+    def verify_model(self):
         try:
             # Exit if necessary
             model_exit()
         except InvalidMode:
             pass
+
         print(verify(self.selected_model.get()))
 
 class PromptDialog(tkSimpleDialog.Dialog):