admin_menu.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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, "主页")
  39. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(5)]
  40. self.btn_name = ["创建", "删除", "搜索", "更新", "退出登录"]
  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("创建")
  50. def delete_command(self):
  51. self.station.to_menu("删除")
  52. def search_command(self):
  53. self.station.to_menu("搜索")
  54. def update_command(self):
  55. self.station.to_menu("更新")
  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, "创建")
  61. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(7)]
  62. self.btn_name = ["普通用户", "自动创建", "管理员用户", "垃圾袋",
  63. "导出用户二维码", "导出垃圾袋二维码", "从CSV导入用户"]
  64. def conf_gui(self, color: str, n: int = 1):
  65. super().conf_gui(color, n)
  66. self.btn[0]['command'] = lambda: self.create_normal_user()
  67. self.btn[1]['command'] = lambda: self.create_auto_user()
  68. self.btn[2]['command'] = lambda: self.create_manager_user()
  69. self.btn[3]['command'] = lambda: self.create_garbage()
  70. self.btn[4]['command'] = lambda: self.export_user()
  71. self.btn[5]['command'] = lambda: self.export_garbage()
  72. self.btn[6]['command'] = lambda: self.create_user_from_csv()
  73. def create_normal_user(self):
  74. self.station.to_program("创建普通用户")
  75. def create_auto_user(self):
  76. self.station.to_program("创建自动用户")
  77. def create_manager_user(self):
  78. self.station.to_program("创建管理员")
  79. def create_garbage(self):
  80. self.station.to_program("创建垃圾袋")
  81. def export_user(self):
  82. self.station.to_program("导出用户二维码")
  83. def export_garbage(self):
  84. self.station.to_program("导出垃圾袋二维码")
  85. def create_user_from_csv(self):
  86. self.station.to_program("从CSV导入用户")
  87. class DeleteMenu(AdminMenu):
  88. def __init__(self, station, win, color):
  89. super().__init__(station, win, color, "删除")
  90. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(5)]
  91. self.btn_name = ["用户", "多个用户", "垃圾袋", "多个垃圾袋", "所有垃圾袋"]
  92. def conf_gui(self, color: str, n: int = 1):
  93. super().conf_gui(color, n)
  94. self.btn[0]['command'] = lambda: self.del_user()
  95. self.btn[1]['command'] = lambda: self.del_users()
  96. self.btn[2]['command'] = lambda: self.del_garbage()
  97. self.btn[3]['command'] = lambda: self.del_garbage_more()
  98. self.btn[4]['command'] = lambda: self.del_all_garbage()
  99. def del_user(self):
  100. self.station.to_program("删除用户")
  101. def del_users(self):
  102. self.station.to_program("删除多个用户")
  103. def del_garbage(self):
  104. self.station.to_program("删除垃圾袋")
  105. def del_garbage_more(self):
  106. self.station.to_program("删除多个垃圾袋")
  107. def del_all_garbage(self):
  108. self.station.to_program("删除所有垃圾袋")
  109. class SearchMenu(AdminMenu):
  110. def __init__(self, station, win, color):
  111. super().__init__(station, win, color, "搜索")
  112. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(6)]
  113. self.btn_name = ["用户", "高级搜索-用户", "垃圾袋", "高级搜索-垃圾袋", "高级搜索", "数据分析"]
  114. def conf_gui(self, color: str, n: int = 1):
  115. super().conf_gui(color, n)
  116. self.btn[0]['command'] = lambda: self.user_command()
  117. self.btn[1]['command'] = lambda: self.user_advanced_command()
  118. self.btn[2]['command'] = lambda: self.garbage_command()
  119. self.btn[3]['command'] = lambda: self.garbage_advanced_command()
  120. self.btn[4]['command'] = lambda: self.advanced_command()
  121. self.btn[5]['command'] = lambda: self.statistics_command()
  122. def user_command(self):
  123. self.station.to_program("搜索用户")
  124. def user_advanced_command(self):
  125. self.station.to_program("高级搜索-用户")
  126. def garbage_command(self):
  127. self.station.to_program("搜索垃圾袋")
  128. def garbage_advanced_command(self):
  129. self.station.to_program("高级搜索-垃圾袋")
  130. def advanced_command(self):
  131. self.station.to_program("高级搜索")
  132. def statistics_command(self):
  133. self.station.to_menu("数据分析")
  134. class UpdateMenu(AdminMenu):
  135. def __init__(self, station, win, color):
  136. super().__init__(station, win, color, "更新")
  137. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(4)]
  138. self.btn_name = ["用户-积分", "用户-累计分类信用", "垃圾袋-垃圾类型", "垃圾袋-检测结果"]
  139. def conf_gui(self, color: str, n: int = 1):
  140. super().conf_gui(color, n)
  141. self.btn[0]['command'] = lambda: self.update_score_command()
  142. self.btn[1]['command'] = lambda: self.update_reputation_command()
  143. self.btn[2]['command'] = lambda: self.update_garbage_type_command()
  144. self.btn[3]['command'] = lambda: self.update_garbage_result_command()
  145. def update_reputation_command(self):
  146. self.station.to_program("更新用户-垃圾分类信用")
  147. def update_score_command(self):
  148. self.station.to_program("更新用户-积分")
  149. def update_garbage_type_command(self):
  150. self.station.to_program("更新垃圾袋-垃圾类型")
  151. def update_garbage_result_command(self):
  152. self.station.to_program("更新垃圾袋-检测结果")
  153. class StatisticsMenu(AdminMenu):
  154. def __init__(self, station, win, color):
  155. super().__init__(station, win, color, "数据分析")
  156. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(5)]
  157. self.btn_name = ["时间分析", "积分分析", "信用分析", "失信用户", "通过率"]
  158. def conf_gui(self, color: str, n: int = 1):
  159. super().conf_gui(color, n)
  160. all_menu = [MainMenu, CreateMenu, DeleteMenu, SearchMenu, UpdateMenu, StatisticsMenu]