2
0

gui_helpers.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. # get the contract with transaction1.data
  29. # add reciever and sender keys and data
  30. # maybe the intital block value and modyfied by and state values
  31. # hash it with the public key of the reciever
  32. # send to push_transaction(hashed:str)
  33. # hashed has the format: {’sender’:..,’receiver’:…, ‘data’:encrypted contract} (see github readme)
  34. # deamon does the rest
  35. term_window.destroy()
  36. newWindow.destroy()
  37. term_window = Toplevel(newWindow)
  38. term_window.title('Add term')
  39. Label(term_window, text='Title: ').grid(row=0, column=0)
  40. title2 = Entry(term_window, width=35, borderwidth=5)
  41. title2.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  42. Label(term_window, text='Description: ').grid(row=1, column=0)
  43. description2 = Entry(term_window, width=35, borderwidth=5)
  44. description2.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  45. Label(term_window, text='Deadline: ').grid(row=2, column=0)
  46. deadline2 = Entry(term_window, width=35, borderwidth=5)
  47. deadline2.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  48. Button(term_window, text='Add term', command=process_term).grid(row=3,column=0)
  49. Button(term_window, text='Add term', command=complete).grid(row=3,column=1)
  50. # make new window for adding the information for the contract
  51. newWindow = Tk()
  52. newWindow.title('Add contract')
  53. # create all text boxes
  54. Label(newWindow, text='Title: ').grid(row=0, column=0)
  55. title = Entry(newWindow, width=35, borderwidth=5)
  56. title.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  57. Label(newWindow, text='Description: ').grid(row=1, column=0)
  58. description = Entry(newWindow, width=35, borderwidth=5)
  59. description.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  60. Label(newWindow, text='Deadline: ').grid(row=2, column=0)
  61. deadline = Entry(newWindow, width=35, borderwidth=5)
  62. deadline.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  63. Label(newWindow, text='Price: ').grid(row=3, column=0)
  64. price = Entry(newWindow, width=35, borderwidth=5)
  65. price.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  66. # create the add contract button
  67. Button(newWindow, text = "Create contract", command=add).grid(row=4, column=1)
  68. ## old code used for checking sytax of Tkinter
  69. # def update():
  70. # def up():
  71. # chain.update_contract(int(iden.get()), term.get(), update_value.get(), name.get())
  72. # newWindow.destroy()
  73. # print('update pending approval')
  74. # newWindow = Toplevel(root)
  75. # newWindow.title('Update terms')
  76. # Label(newWindow, text='Contract id: ').grid(row=0, column=0)
  77. # iden = Entry(newWindow, width=35, borderwidth=5)
  78. # iden.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  79. # Label(newWindow, text='Term: ').grid(row=1, column=0)
  80. # term = Entry(newWindow, width=35, borderwidth=5)
  81. # term.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  82. # Label(newWindow, text='New value: ').grid(row=2, column=0)
  83. # update_value = Entry(newWindow, width=35, borderwidth=5)
  84. # update_value.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  85. # Label(newWindow, text='Name: ').grid(row=3, column=0)
  86. # name = Entry(newWindow, width=35, borderwidth=5)
  87. # name.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  88. # Button(newWindow, text='Update', command=up).grid(row=4, column=0)
  89. # def accept_update():
  90. # def accept_up():
  91. # c = comment.get()
  92. # ans = awnser.get()
  93. # if ans == 'False':
  94. # ans = False
  95. # else: ans = True
  96. # if c == '':
  97. # chain.accept_update(int(iden.get()), int(update_id.get()), ans, name.get())
  98. # else:
  99. # chain.accept_update(int(iden.get()), int(update_id.get()), ans, name.get(), c)
  100. # newWindow.destroy()
  101. # newWindow = Toplevel(root)
  102. # newWindow.title('Update terms')
  103. # Label(newWindow, text='Contract id: ').grid(row=0, column=0)
  104. # iden = Entry(newWindow, width=35, borderwidth=5)
  105. # iden.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  106. # Label(newWindow, text='Update id: ').grid(row=1, column=0)
  107. # update_id = Entry(newWindow, width=35, borderwidth=5)
  108. # update_id.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  109. # Label(newWindow, text='Awnser ').grid(row=2, column=0)
  110. # awnser = Entry(newWindow, width=35, borderwidth=5)
  111. # awnser.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  112. # Label(newWindow, text='Name: ').grid(row=3, column=0)
  113. # name = Entry(newWindow, width=35, borderwidth=5)
  114. # name.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  115. # Label(newWindow, text='Comment optional: ').grid(row=3, column=0)
  116. # comment = Entry(newWindow, width=35, borderwidth=5)
  117. # comment.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  118. # Button(newWindow, text='Update', command=accept_up).grid(row=4, column=0)
  119. # def view_updates():
  120. # status =accept_status.get()
  121. # if status == 'False':
  122. # status = False
  123. # else: status = True
  124. # iden = int(accept_id.get())
  125. # if status == None:
  126. # pprint.pprint(chain.retrieve_updates(iden))
  127. # else:
  128. # pprint.pprint(chain.retrieve_updates(iden, status))