Advertisement
lorenapop

ui

Mar 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import os
  2. from Graph import Graph
  3. from EdgesPropriety import Edges
  4.  
  5.  
  6. class UI:
  7.  
  8. def main_menu(self):
  9. menu = "1. Show the number of vertices.\n"
  10. menu += "2. Check if there is an edge between two vertices.\n"
  11. menu += "3. Show the in and out degree of a vertex.\n"
  12. menu += "4. Outbound edges of a specified vertex.\n"
  13. menu += "5. Inbound edges of a specified vertex.\n"
  14. menu += "6. Retrieve the value attached to an edge.\n"
  15. menu += "7. Modify the value attached to an edge.\n"
  16. menu += "8. BONUS: Add an edge.\n"
  17. menu += "9. BONUS: Remove an edge.\n"
  18. menu += "10. BONUS: Add a vertex.\n"
  19. menu += "11. BONUS: Remove a vertex.\n"
  20. menu += "12. BONUS: Show the initial graph.\n"
  21. menu += "13. BONUS: Show the initial value map.\n"
  22. menu += "14. Show graph.\n"
  23. menu += "15. Show the value map.\n"
  24. menu += "0. EXIT\n"
  25. print(menu)
  26.  
  27. option = input("Enter option: ").strip()
  28. return int(option)
  29.  
  30. def read_new_vertex(self, msg, keys):
  31. x = input(msg).strip()
  32. while x in str(keys) or to_int(x):
  33. print("That was not a positive integer or vertex already exists!")
  34. x = input(msg).strip()
  35. return x
  36.  
  37. def read_vertex(self, msg, keys):
  38. x = input(msg).strip()
  39. while x not in str(keys):
  40. print("That vertex does not exist!")
  41. x = input(msg).strip()
  42. return x
  43.  
  44. def number_vertices(self, nrVertices):
  45. print("Number of vertices:", str(nrVertices))
  46.  
  47. def show(self, obj):
  48. self.clear()
  49. print(obj)
  50.  
  51. def clear(self):
  52. if os.name == "nt":
  53. os.system("cls")
  54. elif os.name == "posix":
  55. os.system("clear")
  56.  
  57.  
  58. def to_int(x):
  59. try:
  60. x = int(x)
  61. if x > 0:
  62. return False
  63. return True
  64. except:
  65. return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement