admin_menu.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import abc
  2. import tkinter as tk
  3. from tool.type_ import *
  4. from tool.tk import make_font, set_tk_disable_from_list
  5. import admin
  6. class AdminMenu(metaclass=abc.ABCMeta):
  7. def __init__(self, station: admin.AdminStationBase, win: Union[tk.Frame, tk.Toplevel, tk.Tk], color: str,
  8. title: str):
  9. self.station = station
  10. self.win = win
  11. self.color = color
  12. self.frame = tk.Frame(self.win)
  13. self.frame['bg'] = color
  14. self.menu_title = title
  15. self.btn: List[tk.Button] = []
  16. self.btn_name: List[str] = []
  17. self.__conf_font()
  18. def __conf_font(self, n: int = 1):
  19. self.btn_font_size = int(16 * n)
  20. def set_disable(self):
  21. set_tk_disable_from_list(self.btn)
  22. def reset_disable(self):
  23. set_tk_disable_from_list(self.btn, flat='normal')
  24. def conf_gui(self, color: str, n: int = 1):
  25. self.__conf_font(n)
  26. btn_font = make_font(size=self.btn_font_size, weight="bold")
  27. height = 0.02
  28. for btn, text in zip(self.btn, self.btn_name):
  29. btn['font'] = btn_font
  30. btn['text'] = text
  31. btn['bg'] = color
  32. btn.place(relx=0.02, rely=height, relwidth=0.96, relheight=0.1)
  33. height += 0.1 + 0.02
  34. def get_menu_frame(self) -> Tuple[str, tk.Frame]:
  35. return self.menu_title, self.frame
  36. class MainMenu(AdminMenu):
  37. def __init__(self, station, win, color):
  38. super().__init__(station, win, color, "Main")
  39. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(5)]
  40. self.btn_name = ["Create", "Delete", "Search", "Update", "Logout"]
  41. def conf_gui(self, color: str, n: int = 1):
  42. super().conf_gui(color, n)
  43. self.btn[0]['command'] = lambda: self.create_command()
  44. self.btn[1]['command'] = lambda: self.delete_command()
  45. self.btn[2]['command'] = lambda: self.search_command()
  46. self.btn[3]['command'] = lambda: self.update_command()
  47. self.btn[4]['command'] = lambda: self.logout_command()
  48. def create_command(self):
  49. self.station.to_menu("Create")
  50. def delete_command(self):
  51. self.station.to_menu("Delete")
  52. def search_command(self):
  53. self.station.to_menu("Search")
  54. def update_command(self):
  55. self.station.to_menu("Update")
  56. def logout_command(self):
  57. self.station.logout()
  58. class CreateMenu(AdminMenu):
  59. def __init__(self, station, win, color):
  60. super().__init__(station, win, color, "Create")
  61. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(6)]
  62. self.btn_name = ["NormalUser", "AutoNormalUser", "ManagerUser", "Garbage", "ExportUser", "ExportGarbage"]
  63. def conf_gui(self, color: str, n: int = 1):
  64. super().conf_gui(color, n)
  65. self.btn[0]['command'] = lambda: self.create_normal_user()
  66. self.btn[1]['command'] = lambda: self.create_auto_user()
  67. self.btn[2]['command'] = lambda: self.create_manager_user()
  68. self.btn[3]['command'] = lambda: self.create_garbage()
  69. def create_normal_user(self):
  70. self.station.to_program("CreateNormalUser")
  71. def create_auto_user(self):
  72. self.station.to_program("CreateAutoNormalUser")
  73. def create_manager_user(self):
  74. self.station.to_program("CreateManagerUser")
  75. def create_garbage(self):
  76. self.station.to_program("CreateGarbage")
  77. class DeleteMenu(AdminMenu):
  78. def __init__(self, station, win, color):
  79. super().__init__(station, win, color, "Delete")
  80. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(5)]
  81. self.btn_name = ["User", "UserMore", "Garbage", "GarbageMore", "AllGarbage"]
  82. def conf_gui(self, color: str, n: int = 1):
  83. super().conf_gui(color, n)
  84. self.btn[0]['command'] = lambda: self.del_user()
  85. self.btn[1]['command'] = lambda: self.del_users()
  86. self.btn[2]['command'] = lambda: self.del_garbage()
  87. self.btn[3]['command'] = lambda: self.del_garbage_more()
  88. self.btn[4]['command'] = lambda: self.del_all_garbage()
  89. def del_user(self):
  90. self.station.to_program("DeleteUser")
  91. def del_users(self):
  92. self.station.to_program("DeleteUsers")
  93. def del_garbage(self):
  94. self.station.to_program("DeleteGarbage")
  95. def del_garbage_more(self):
  96. self.station.to_program("DeleteGarbageMore")
  97. def del_all_garbage(self):
  98. self.station.to_program("DeleteAllGarbage")
  99. class SearchMenu(AdminMenu):
  100. def __init__(self, station, win, color):
  101. super().__init__(station, win, color, "Search")
  102. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(6)]
  103. self.btn_name = ["User", "UserAdvanced", "Garbage", "GarbageAdvanced", "Advanced", "Statistics"]
  104. def conf_gui(self, color: str, n: int = 1):
  105. super().conf_gui(color, n)
  106. self.btn[0]['command'] = lambda: self.user_command()
  107. self.btn[1]['command'] = lambda: self.user_advanced_command()
  108. self.btn[2]['command'] = lambda: self.garbage_command()
  109. self.btn[3]['command'] = lambda: self.garbage_advanced_command()
  110. self.btn[4]['command'] = lambda: self.advanced_command()
  111. self.btn[5]['command'] = lambda: self.statistics_command()
  112. def user_command(self):
  113. self.station.to_program("SearchUser")
  114. def user_advanced_command(self):
  115. self.station.to_program("SearchUserAdvanced")
  116. def garbage_command(self):
  117. self.station.to_program("SearchGarbage")
  118. def garbage_advanced_command(self):
  119. self.station.to_program("SearchGarbageAdvanced")
  120. def advanced_command(self):
  121. self.station.to_program("SearchAdvanced")
  122. def statistics_command(self):
  123. self.station.to_menu("Statistics")
  124. class UpdateMenu(AdminMenu):
  125. def __init__(self, station, win, color):
  126. super().__init__(station, win, color, "Update")
  127. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(4)]
  128. self.btn_name = ["Score", "Reputation", "GarbageType", "GarbageCheck"]
  129. def conf_gui(self, color: str, n: int = 1):
  130. super().conf_gui(color, n)
  131. self.btn[0]['command'] = lambda: self.update_score_command()
  132. self.btn[1]['command'] = lambda: self.update_reputation_command()
  133. self.btn[2]['command'] = lambda: self.update_garbage_type_command()
  134. self.btn[3]['command'] = lambda: self.update_garbage_result_command()
  135. def update_reputation_command(self):
  136. self.station.to_program("UpdateReputation")
  137. def update_score_command(self):
  138. self.station.to_program("UpdateScore")
  139. def update_garbage_type_command(self):
  140. self.station.to_program("UpdateGarbageType")
  141. def update_garbage_result_command(self):
  142. self.station.to_program("UpdateGarbageCheckResult")
  143. class StatisticsMenu(AdminMenu):
  144. def __init__(self, station, win, color):
  145. super().__init__(station, win, color, "Statistics")
  146. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(5)]
  147. self.btn_name = ["Time", "Score", "Reputation", "BlackUser", "PassingRate"]
  148. def conf_gui(self, color: str, n: int = 1):
  149. super().conf_gui(color, n)
  150. all_menu = [MainMenu, CreateMenu, DeleteMenu, SearchMenu, UpdateMenu, StatisticsMenu]