Forráskód Böngészése

added contract update functionality to gui

justtheboss97 4 éve
szülő
commit
f9ebfeb15b
2 módosított fájl, 101 hozzáadás és 6 törlés
  1. 101 5
      gui.py
  2. 0 1
      linked_data.py

+ 101 - 5
gui.py

@@ -11,9 +11,16 @@ root.title('dsp blockchain')
 view = Entry(root, width=35, borderwidth=5)
 view.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
 
+accept_id = Entry(root, width=35, borderwidth=5)
+accept_id.grid(row=4, column=1, columnspan=3, padx=10, pady=10)
+accept_id.insert(0, 'contract')
+
+accept_status = StringVar(root)
+accept_status.set('False') # default value
+OptionMenu(root, accept_status, 'False', 'True').grid(row=4, column=4)
+
 
 def myClick():
-    print(view.get())
     chain.current_contract_state(int(view.get()))
     pprint.pprint(chain.state)
 
@@ -67,12 +74,101 @@ def add_contract():
     # create the add contract button
     add_c = Button(newWindow, text = "Add contract", command=add)
     add_c.grid(row=8, column=0)
+
+def update():
+
+    def up():
+        chain.update_contract(int(iden.get()), term.get(), update_value.get(), name.get())
+
+        newWindow.destroy()
+        print('update pending approval')
+
+    newWindow = Toplevel(root)
+    newWindow.title('Update terms')
+
+    Label(newWindow, text='Contract id: ').grid(row=0, column=0)
+    iden =  Entry(newWindow, width=35, borderwidth=5)
+    iden.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
+
+    Label(newWindow, text='Term: ').grid(row=1, column=0)
+    term =  Entry(newWindow, width=35, borderwidth=5)
+    term.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
+
+    Label(newWindow, text='New value: ').grid(row=2, column=0)
+    update_value =  Entry(newWindow, width=35, borderwidth=5)
+    update_value.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
+
+    Label(newWindow, text='Name: ').grid(row=3, column=0)
+    name =  Entry(newWindow, width=35, borderwidth=5)
+    name.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
+    
+    Button(newWindow, text='Update', command=up).grid(row=4, column=0)
+
+
+def accept_update():
+    def accept_up():
+        c = comment.get()
+        ans = awnser.get()
+        if ans == 'False':
+            ans = False
+        else: ans = True
+
+        if c == '':
+            chain.accept_update(int(iden.get()), int(update_id.get()), ans, name.get())
+        else:
+            chain.accept_update(int(iden.get()), int(update_id.get()), ans, name.get(), c)
+
+        newWindow.destroy()
+
+
+    newWindow = Toplevel(root)
+    newWindow.title('Update terms')
+
+    Label(newWindow, text='Contract id: ').grid(row=0, column=0)
+    iden =  Entry(newWindow, width=35, borderwidth=5)
+    iden.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
+
+    Label(newWindow, text='Update id: ').grid(row=1, column=0)
+    update_id =  Entry(newWindow, width=35, borderwidth=5)
+    update_id.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
+
+    Label(newWindow, text='Awnser ').grid(row=2, column=0)
+    awnser =  Entry(newWindow, width=35, borderwidth=5)
+    awnser.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
+
+    Label(newWindow, text='Name: ').grid(row=3, column=0)
+    name =  Entry(newWindow, width=35, borderwidth=5)
+    name.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
+
+    Label(newWindow, text='Comment optional: ').grid(row=3, column=0)
+    comment =  Entry(newWindow, width=35, borderwidth=5)
+    comment.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
+    
+    Button(newWindow, text='Update', command=accept_up).grid(row=4, column=0)
+    
+def view_updates():
+    status =accept_status.get()
+    if status == 'False':
+        status = False
+    else: status = True
+    iden = int(accept_id.get())
+    if status == None:
+        pprint.pprint(chain.retrieve_updates(iden))
+    else:
+        pprint.pprint(chain.retrieve_updates(iden, status))
     
+    
+
+Button(root, text="View contract", command=myClick).grid(row=0, column=0)
+
+Button(root, text="New contract", command=add_contract).grid(row=1, column=0)
+
+Button(root, text="Update contract", command=update).grid(row=2, column=0)
+
+Button(root, text="Accept updates", command=accept_update).grid(row=3, column=0)
+
+Button(root, text="View pending updates", command=view_updates).grid(row=4, column=0)
 
-myButton = Button(root, text="View contract", command=myClick)
-myButton.grid(row=0, column=0)
 
-myButton = Button(root, text="New contract", command=add_contract)
-myButton.grid(row=1, column=0)
 
 root.mainloop()

+ 0 - 1
linked_data.py

@@ -293,7 +293,6 @@ class Chain():
     def retrieve_updates(self, iden, accepted=None):
     
         updates = {}
-        
         # get all updates for a contract
         all_updates = self.get_updates(iden = iden, accepted = accepted)