gui_helpers.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. from tkinter import *
  2. from lib.chain import Chain, Block
  3. from lib.transaction import Transaction
  4. from lib.contract import Contract
  5. from lib.block import CURRENT
  6. def add_contract():
  7. # add contract to the blockchain
  8. def add():
  9. contract1 = Contract()
  10. contract1.create(title=title.get(),
  11. desc=description.get(),
  12. deadline=int(deadline.get()),
  13. price=float(price.get()))
  14. add_term(contract1)
  15. def add_term(contract1):
  16. def process_term():
  17. term1 = Contract.Term()
  18. term1.create(title=title2.get(),
  19. desc=description2.get(),
  20. deadline=int(deadline2.get()))
  21. contract1.add_term(term=term1)
  22. term_window.destroy()
  23. add_term(contract1)
  24. def complete():
  25. # Bind contract to transaction
  26. transaction1 = Transaction()
  27. transaction1.set_contract(contract=contract1)
  28. r = recipient.get()
  29. transaction1.hash(recipient=r)
  30. # get the contract with transaction1.data
  31. # add reciever and sender keys and data
  32. # maybe the intital block value and modyfied by and state values
  33. # hash it with the public key of the reciever
  34. # send to push_transaction(hashed:str)
  35. # hashed has the format: {’sender’:..,’receiver’:…, ‘data’:encrypted contract} (see github readme)
  36. # deamon does the rest
  37. print(transaction1.hash_value)
  38. term_window.destroy()
  39. newWindow.destroy()
  40. term_window = Toplevel(newWindow)
  41. term_window.title('Add term')
  42. Label(term_window, text='Title: ').grid(row=0, column=0)
  43. title2 = Entry(term_window, width=35, borderwidth=5)
  44. title2.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  45. Label(term_window, text='Description: ').grid(row=1, column=0)
  46. description2 = Entry(term_window, width=35, borderwidth=5)
  47. description2.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  48. Label(term_window, text='Deadline: ').grid(row=2, column=0)
  49. deadline2 = Entry(term_window, width=35, borderwidth=5)
  50. deadline2.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  51. Label(term_window, text='Recipient: ').grid(row=3, column=0)
  52. recipient1 = Entry(term_window, width=35, borderwidth=5)
  53. recipient1.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  54. Button(term_window, text='Add term', command=process_term).grid(row=4,column=0)
  55. Button(term_window, text='Done', command=complete).grid(row=4,column=1)
  56. # make new window for adding the information for the contract
  57. newWindow = Tk()
  58. newWindow.title('Add contract')
  59. # create all text boxes
  60. Label(newWindow, text='Title: ').grid(row=0, column=0)
  61. title = Entry(newWindow, width=35, borderwidth=5)
  62. title.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  63. Label(newWindow, text='Description: ').grid(row=1, column=0)
  64. description = Entry(newWindow, width=35, borderwidth=5)
  65. description.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  66. Label(newWindow, text='Deadline: ').grid(row=2, column=0)
  67. deadline = Entry(newWindow, width=35, borderwidth=5)
  68. deadline.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  69. Label(newWindow, text='Price: ').grid(row=3, column=0)
  70. price = Entry(newWindow, width=35, borderwidth=5)
  71. price.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  72. Label(newWindow, text='Recipient: ').grid(row=4, column=0)
  73. recipient = Entry(newWindow, width=35, borderwidth=5)
  74. recipient.grid(row=4, column=1, columnspan=3, padx=10, pady=10)
  75. # create the add contract button
  76. Button(newWindow, text = "Create contract", command=add).grid(row=5, column=1)
  77. ## old code used for checking sytax of Tkinter
  78. # def update():
  79. # def up():
  80. # chain.update_contract(int(iden.get()), term.get(), update_value.get(), name.get())
  81. # newWindow.destroy()
  82. # print('update pending approval')
  83. # newWindow = Toplevel(root)
  84. # newWindow.title('Update terms')
  85. # Label(newWindow, text='Contract id: ').grid(row=0, column=0)
  86. # iden = Entry(newWindow, width=35, borderwidth=5)
  87. # iden.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  88. # Label(newWindow, text='Term: ').grid(row=1, column=0)
  89. # term = Entry(newWindow, width=35, borderwidth=5)
  90. # term.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  91. # Label(newWindow, text='New value: ').grid(row=2, column=0)
  92. # update_value = Entry(newWindow, width=35, borderwidth=5)
  93. # update_value.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  94. # Label(newWindow, text='Name: ').grid(row=3, column=0)
  95. # name = Entry(newWindow, width=35, borderwidth=5)
  96. # name.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  97. # Button(newWindow, text='Update', command=up).grid(row=4, column=0)
  98. # def accept_update():
  99. # def accept_up():
  100. # c = comment.get()
  101. # ans = awnser.get()
  102. # if ans == 'False':
  103. # ans = False
  104. # else: ans = True
  105. # if c == '':
  106. # chain.accept_update(int(iden.get()), int(update_id.get()), ans, name.get())
  107. # else:
  108. # chain.accept_update(int(iden.get()), int(update_id.get()), ans, name.get(), c)
  109. # newWindow.destroy()
  110. # newWindow = Toplevel(root)
  111. # newWindow.title('Update terms')
  112. # Label(newWindow, text='Contract id: ').grid(row=0, column=0)
  113. # iden = Entry(newWindow, width=35, borderwidth=5)
  114. # iden.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  115. # Label(newWindow, text='Update id: ').grid(row=1, column=0)
  116. # update_id = Entry(newWindow, width=35, borderwidth=5)
  117. # update_id.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  118. # Label(newWindow, text='Awnser ').grid(row=2, column=0)
  119. # awnser = Entry(newWindow, width=35, borderwidth=5)
  120. # awnser.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  121. # Label(newWindow, text='Name: ').grid(row=3, column=0)
  122. # name = Entry(newWindow, width=35, borderwidth=5)
  123. # name.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  124. # Label(newWindow, text='Comment optional: ').grid(row=3, column=0)
  125. # comment = Entry(newWindow, width=35, borderwidth=5)
  126. # comment.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  127. # Button(newWindow, text='Update', command=accept_up).grid(row=4, column=0)
  128. # def view_updates():
  129. # status =accept_status.get()
  130. # if status == 'False':
  131. # status = False
  132. # else: status = True
  133. # iden = int(accept_id.get())
  134. # if status == None:
  135. # pprint.pprint(chain.retrieve_updates(iden))
  136. # else:
  137. # pprint.pprint(chain.retrieve_updates(iden, status))