admin_menu.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. self.btn[4]['command'] = lambda: self.export_user()
  70. self.btn[5]['command'] = lambda: self.export_garbage()
  71. def create_normal_user(self):
  72. self.station.to_program("CreateNormalUser")
  73. def create_auto_user(self):
  74. self.station.to_program("CreateAutoNormalUser")
  75. def create_manager_user(self):
  76. self.station.to_program("CreateManagerUser")
  77. def create_garbage(self):
  78. self.station.to_program("CreateGarbage")
  79. def export_user(self):
  80. self.station.to_program("ExportUser")
  81. def export_garbage(self):
  82. self.station.to_program("ExportGarbage")
  83. class DeleteMenu(AdminMenu):
  84. def __init__(self, station, win, color):
  85. super().__init__(station, win, color, "Delete")
  86. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(5)]
  87. self.btn_name = ["User", "UserMore", "Garbage", "GarbageMore", "AllGarbage"]
  88. def conf_gui(self, color: str, n: int = 1):
  89. super().conf_gui(color, n)
  90. self.btn[0]['command'] = lambda: self.del_user()
  91. self.btn[1]['command'] = lambda: self.del_users()
  92. self.btn[2]['command'] = lambda: self.del_garbage()
  93. self.btn[3]['command'] = lambda: self.del_garbage_more()
  94. self.btn[4]['command'] = lambda: self.del_all_garbage()
  95. def del_user(self):
  96. self.station.to_program("DeleteUser")
  97. def del_users(self):
  98. self.station.to_program("DeleteUsers")
  99. def del_garbage(self):
  100. self.station.to_program("DeleteGarbage")
  101. def del_garbage_more(self):
  102. self.station.to_program("DeleteGarbageMore")
  103. def del_all_garbage(self):
  104. self.station.to_program("DeleteAllGarbage")
  105. class SearchMenu(AdminMenu):
  106. def __init__(self, station, win, color):
  107. super().__init__(station, win, color, "Search")
  108. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(6)]
  109. self.btn_name = ["User", "UserAdvanced", "Garbage", "GarbageAdvanced", "Advanced", "Statistics"]
  110. def conf_gui(self, color: str, n: int = 1):
  111. super().conf_gui(color, n)
  112. self.btn[0]['command'] = lambda: self.user_command()
  113. self.btn[1]['command'] = lambda: self.user_advanced_command()
  114. self.btn[2]['command'] = lambda: self.garbage_command()
  115. self.btn[3]['command'] = lambda: self.garbage_advanced_command()
  116. self.btn[4]['command'] = lambda: self.advanced_command()
  117. self.btn[5]['command'] = lambda: self.statistics_command()
  118. def user_command(self):
  119. self.station.to_program("SearchUser")
  120. def user_advanced_command(self):
  121. self.station.to_program("SearchUserAdvanced")
  122. def garbage_command(self):
  123. self.station.to_program("SearchGarbage")
  124. def garbage_advanced_command(self):
  125. self.station.to_program("SearchGarbageAdvanced")
  126. def advanced_command(self):
  127. self.station.to_program("SearchAdvanced")
  128. def statistics_command(self):
  129. self.station.to_menu("Statistics")
  130. class UpdateMenu(AdminMenu):
  131. def __init__(self, station, win, color):
  132. super().__init__(station, win, color, "Update")
  133. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(4)]
  134. self.btn_name = ["Score", "Reputation", "GarbageType", "GarbageCheck"]
  135. def conf_gui(self, color: str, n: int = 1):
  136. super().conf_gui(color, n)
  137. self.btn[0]['command'] = lambda: self.update_score_command()
  138. self.btn[1]['command'] = lambda: self.update_reputation_command()
  139. self.btn[2]['command'] = lambda: self.update_garbage_type_command()
  140. self.btn[3]['command'] = lambda: self.update_garbage_result_command()
  141. def update_reputation_command(self):
  142. self.station.to_program("UpdateReputation")
  143. def update_score_command(self):
  144. self.station.to_program("UpdateScore")
  145. def update_garbage_type_command(self):
  146. self.station.to_program("UpdateGarbageType")
  147. def update_garbage_result_command(self):
  148. self.station.to_program("UpdateGarbageCheckResult")
  149. class StatisticsMenu(AdminMenu):
  150. def __init__(self, station, win, color):
  151. super().__init__(station, win, color, "Statistics")
  152. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(5)]
  153. self.btn_name = ["Time", "Score", "Reputation", "BlackUser", "PassingRate"]
  154. def conf_gui(self, color: str, n: int = 1):
  155. super().conf_gui(color, n)
  156. all_menu = [MainMenu, CreateMenu, DeleteMenu, SearchMenu, UpdateMenu, StatisticsMenu]