Przeglądaj źródła

Merge remote-tracking branch 'origin/main' into main

DebenOldert 4 lat temu
rodzic
commit
f05d99bdf1
2 zmienionych plików z 198 dodań i 154 usunięć
  1. 20 154
      gui.py
  2. 178 0
      gui/gui_helpers.py

+ 20 - 154
gui.py

@@ -1,173 +1,39 @@
 from tkinter import *
 from linked_data import Chain, format_dict
 import pprint
+from gui.gui_helpers import add_contract
 
-chain = Chain()
-chain.populate()
+from lib.transaction import Transaction
+from lib.contract import Contract
+
+# chain = Chain()
+# chain.populate()
 
 root = Tk()
 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():
-    chain.current_contract_state(int(view.get()))
-    pprint.pprint(chain.state)
-
-def add_contract():
-
-    # add contract to the blockchain
-    def add():
-        chain.new_contract(client.get(), contractor.get(), deadline.get(), description.get(), name.get(), int(price.get()), people.get().split(','), initiator.get())
-
-        # destroy add contract window, and print conformation
-        newWindow.destroy()
-        print('contract added')
-
-    # make new window for adding the information for the contract
-    newWindow = Toplevel(root)
-    newWindow.title('Add contract')
-
-    # create all text boxes
-    Label(newWindow, text='The client: ').grid(row=0, column=0)
-    client =  Entry(newWindow, width=35, borderwidth=5)
-    client.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
-
-    Label(newWindow, text='The contractor: ').grid(row=1, column=0)
-    contractor =  Entry(newWindow, width=35, borderwidth=5)
-    contractor.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
-
-    Label(newWindow, text='Deadline: ').grid(row=2, column=0)
-    deadline =  Entry(newWindow, width=35, borderwidth=5)
-    deadline.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
-
-    Label(newWindow, text='Description: ').grid(row=3, column=0)
-    description =  Entry(newWindow, width=35, borderwidth=5)
-    description.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
-
-    Label(newWindow, text='Project name: ').grid(row=4, column=0)
-    name =  Entry(newWindow, width=35, borderwidth=5)
-    name.grid(row=4, column=1, columnspan=3, padx=10, pady=10)
-
-    Label(newWindow, text='Price: ').grid(row=5, column=0)
-    price =  Entry(newWindow, width=35, borderwidth=5)
-    price.grid(row=5, column=1, columnspan=3, padx=10, pady=10)
-
-    Label(newWindow, text='People involved: ').grid(row=6, column=0)
-    people =  Entry(newWindow, width=35, borderwidth=5)
-    people.grid(row=6, column=1, columnspan=3, padx=10, pady=10)
-
-    Label(newWindow, text='Initiator').grid(row=7, column=0)
-    initiator =  Entry(newWindow, width=35, borderwidth=5)
-    initiator.grid(row=7, column=1, columnspan=3, padx=10, pady=10)
-
-    # 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')
+# view = Entry(root, width=35, borderwidth=5)
+# view.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
 
-    newWindow = Toplevel(root)
-    newWindow.title('Update terms')
+# 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')
 
-    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)
+# accept_status = StringVar(root)
+# accept_status.set('False') # default value
+# OptionMenu(root, accept_status, 'False', 'True').grid(row=4, column=4)
 
-    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="View contract", command=myClick).grid(row=0, 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="Accept updates", command=accept_update).grid(row=3, column=0)
 
-Button(root, text="View pending updates", command=view_updates).grid(row=4, column=0)
+# Button(root, text="View pending updates", command=view_updates).grid(row=4, column=0)
 
 
 

+ 178 - 0
gui/gui_helpers.py

@@ -0,0 +1,178 @@
+from tkinter import *
+from lib.chain import Chain, Block
+from lib.transaction import Transaction
+from lib.contract import Contract
+from lib.block import CURRENT
+
+
+def add_contract():
+
+    # add contract to the blockchain
+    def add():
+        contract1 = Contract()
+        contract1.create(title=title.get(),
+                         desc=description.get(),
+                         deadline=int(deadline.get()),
+                         price=float(price.get()))
+
+
+        add_term(contract1)
+
+    def add_term(contract1):
+
+        def process_term():
+            term1 = Contract.Term()
+            term1.create(title=title2.get(),
+                     desc=description2.get(),
+                     deadline=int(deadline2.get()))
+
+            contract1.add_term(term=term1)
+
+            term_window.destroy()
+            add_term(contract1)
+
+        def complete():
+            # Bind contract to transaction
+            transaction1 = Transaction()
+            transaction1.set_contract(contract=contract1)
+
+            # get the contract with transaction1.data
+            # add reciever and sender keys and data
+            # maybe the intital block value and modyfied by and state values
+            # hash it with the public key of the reciever
+            # send to push_transaction(hashed:str)
+            # hashed has the format: {’sender’:..,’receiver’:…, ‘data’:encrypted contract} (see github readme)
+            # deamon does the rest
+
+            term_window.destroy()
+            newWindow.destroy()
+
+        term_window = Toplevel(newWindow)
+        term_window.title('Add term')
+
+        Label(term_window, text='Title: ').grid(row=0, column=0)
+        title2 =  Entry(term_window, width=35, borderwidth=5)
+        title2.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
+
+        Label(term_window, text='Description: ').grid(row=1, column=0)
+        description2 =  Entry(term_window, width=35, borderwidth=5)
+        description2.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
+
+        Label(term_window, text='Deadline: ').grid(row=2, column=0)
+        deadline2 =  Entry(term_window, width=35, borderwidth=5)
+        deadline2.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
+
+        Button(term_window, text='Add term', command=process_term).grid(row=3,column=0)
+        Button(term_window, text='Add term', command=complete).grid(row=3,column=1)
+
+        
+
+    # make new window for adding the information for the contract
+    newWindow = Tk()
+    newWindow.title('Add contract')
+
+    # create all text boxes
+    Label(newWindow, text='Title: ').grid(row=0, column=0)
+    title =  Entry(newWindow, width=35, borderwidth=5)
+    title.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
+
+    Label(newWindow, text='Description: ').grid(row=1, column=0)
+    description =  Entry(newWindow, width=35, borderwidth=5)
+    description.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
+
+    Label(newWindow, text='Deadline: ').grid(row=2, column=0)
+    deadline =  Entry(newWindow, width=35, borderwidth=5)
+    deadline.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
+
+    Label(newWindow, text='Price: ').grid(row=3, column=0)
+    price =  Entry(newWindow, width=35, borderwidth=5)
+    price.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
+
+    # create the add contract button
+    Button(newWindow, text = "Create contract", command=add).grid(row=4, column=1)
+
+
+
+## old code used for checking sytax of Tkinter 
+
+# 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))