Advertisement
citronova

Untitled

Dec 5th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. from data_analyzer import DataAnalyzer
  4. from graph import Graph
  5. from histogram import *
  6.  
  7.  
  8. class GUI:
  9.  
  10. def callTask2a(self):
  11. userTxt = self.str1.get()
  12. docTxt = self.str2.get()
  13. fileTxt = self.str3.get()
  14. if docTxt is None:
  15. return
  16. if fileTxt is None:
  17. return
  18. # Show the graph of countries using matplotlib
  19. p = DataAnalyzer(fileTxt)
  20. showCountries(p.getCountries(docTxt))
  21. return
  22.  
  23. def callTask2b(self):
  24. userTxt = self.str1.get()
  25. docTxt = self.str2.get()
  26. fileTxt = self.str3.get()
  27. if docTxt is None:
  28. return
  29. if fileTxt is None:
  30. return
  31. # Show the graph of continents using matplotlib
  32. p = DataAnalyzer(fileTxt)
  33. showContinent(p.getContinents(docTxt))
  34. return
  35.  
  36. def callTask3a(self):
  37. # Show the graph of all the users agents
  38. userTxt = self.str1.get()
  39. docTxt = self.str2.get()
  40. fileTxt = self.str3.get()
  41. if fileTxt is None:
  42. return
  43. p = DataAnalyzer(fileTxt)
  44. showUserAgents(p.getUserAgents())
  45. return
  46.  
  47. def callTask3b(self):
  48. userTxt = self.str1.get()
  49. docTxt = self.str2.get()
  50. fileTxt = self.str3.get()
  51. # Show the graph of views per browser
  52. if fileTxt is None:
  53. return
  54. p = DataAnalyzer(fileTxt)
  55. showBrowsers(p.getBrowsers())
  56. return
  57.  
  58. def callTask4d(self):
  59. userTxt = self.str1.get()
  60. docTxt = self.str2.get()
  61. fileTxt = self.str3.get()
  62.  
  63. if docTxt is None:
  64. return
  65. if fileTxt is None:
  66. return
  67. p = DataAnalyzer(fileTxt)
  68.  
  69. # Getting the top 10 files that this user may likes
  70. # The uuid remove the user from the list
  71. list = p.topTenDocumentsSeen(docTxt, userTxt)
  72.  
  73. # Check if documents has been found
  74. if list is None or len(list) == 0:
  75. print("No documents has been found")
  76. else:
  77. print("Here the top 10 documents this user may like")
  78. for i in range(len(list)):
  79. print("{0}: {1}".format(i + 1, list[i]))
  80. return
  81.  
  82. def callTask5(self):
  83. userTxt = self.str1.get()
  84. docTxt = self.str2.get()
  85. fileTxt = self.str3.get()
  86. # Creation of a graphviz Graph by calling our object Graph
  87. if docTxt is None:
  88. print("Missing document argument")
  89. exit(1)
  90. if fileTxt is None:
  91. print("Missing file argument")
  92. exit(1)
  93. p = DataAnalyzer(fileTxt)
  94. if userTxt is None:
  95. Graph(p, uuid=None, document=docTxt)
  96. else:
  97. Graph(p, uuid=userTxt, document=docTxt)
  98. return
  99.  
  100. def openGui(self):
  101.  
  102. ##creating tkinter window
  103. root = Tk()
  104. root.geometry('300x100')
  105. root.title('Coursework 2 - GUI')
  106.  
  107. ##generate frames (lines)
  108. frame1 = Frame(root)
  109. frame1.pack()
  110. frame2 = Frame(root)
  111. frame2.pack()
  112. frame3 = Frame(root)
  113. frame3.pack()
  114. frame4 = Frame(root)
  115. frame4.pack()
  116.  
  117. ##generate buttons
  118. Button(frame1, text='Task 2a', command=self.callTask2a).pack(side=LEFT)
  119. Button(frame1, text='Task 2b', command=self.callTask2b).pack(side=LEFT)
  120. Button(frame1, text='Task 3a', command=self.callTask3a).pack(side=LEFT)
  121. Button(frame1, text='Task 3b', command=self.callTask3b).pack(side=LEFT)
  122. Button(frame1, text='Task 4d', command=self.callTask4d).pack(side=LEFT)
  123. Button(frame1, text='Task 5', command=self.callTask5).pack(side=LEFT)
  124.  
  125. ##generate inputbox
  126. self.str1 = StringVar()
  127. self.str2 = StringVar()
  128. self.str3 = StringVar()
  129.  
  130. label1 = Label(frame2, text='User Uuid : ').pack(side=LEFT)
  131. Entry(frame2, textvariable=self.str1).pack(side=LEFT)
  132.  
  133. label2 = Label(frame3, text='Doc Uuid : ').pack(side=LEFT)
  134. Entry(frame3, textvariable=self.str2).pack(side=LEFT)
  135.  
  136. label3 = Label(frame4, text='File name : ').pack(side=LEFT)
  137. Entry(frame4, textvariable=self.str3).pack(side=LEFT)
  138.  
  139. ##
  140. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement