admin_menu.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. import abc
  2. import tkinter as tk
  3. from tool.typing import *
  4. from tool.tk import make_font, set_tk_disable_from_list
  5. from . 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_title(self) -> str:
  35. return self.menu_title
  36. def get_menu_frame(self) -> Tuple[str, tk.Frame]:
  37. return self.menu_title, self.frame
  38. class MainMenu(AdminMenu):
  39. def __init__(self, station, win, color):
  40. super().__init__(station, win, color, "主页")
  41. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(6)]
  42. self.btn_name = ["创建", "删除", "搜索", "更新", "数据分析", "退出登录"]
  43. def conf_gui(self, color: str, n: int = 1):
  44. super().conf_gui(color, n)
  45. self.btn[0]['command'] = lambda: self.create_command()
  46. self.btn[1]['command'] = lambda: self.delete_command()
  47. self.btn[2]['command'] = lambda: self.search_command()
  48. self.btn[3]['command'] = lambda: self.update_command()
  49. self.btn[4]['command'] = lambda: self.statistics_command()
  50. self.btn[5]['command'] = lambda: self.logout_command()
  51. def create_command(self):
  52. self.station.to_menu("创建")
  53. def delete_command(self):
  54. self.station.to_menu("删除")
  55. def search_command(self):
  56. self.station.to_menu("搜索")
  57. def update_command(self):
  58. self.station.to_menu("更新")
  59. def statistics_command(self):
  60. self.station.to_menu("数据分析")
  61. def logout_command(self):
  62. self.station.logout()
  63. class CreateMenu(AdminMenu):
  64. def __init__(self, station, win, color):
  65. super().__init__(station, win, color, "创建")
  66. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(7)]
  67. self.btn_name = ["普通用户", "自动创建", "管理员用户", "垃圾袋",
  68. "导出用户二维码", "导出垃圾袋二维码", "从CSV导入用户"]
  69. def conf_gui(self, color: str, n: int = 1):
  70. super().conf_gui(color, n)
  71. self.btn[0]['command'] = lambda: self.create_normal_user()
  72. self.btn[1]['command'] = lambda: self.create_auto_user()
  73. self.btn[2]['command'] = lambda: self.create_manager_user()
  74. self.btn[3]['command'] = lambda: self.create_garbage()
  75. self.btn[4]['command'] = lambda: self.export_user()
  76. self.btn[5]['command'] = lambda: self.export_garbage()
  77. self.btn[6]['command'] = lambda: self.create_user_from_csv()
  78. def create_normal_user(self):
  79. self.station.to_program("创建普通用户")
  80. def create_auto_user(self):
  81. self.station.to_program("创建自动用户")
  82. def create_manager_user(self):
  83. self.station.to_program("创建管理员")
  84. def create_garbage(self):
  85. self.station.to_program("创建垃圾袋")
  86. def export_user(self):
  87. self.station.to_program("导出用户二维码")
  88. def export_garbage(self):
  89. self.station.to_program("导出垃圾袋二维码")
  90. def create_user_from_csv(self):
  91. self.station.to_program("从CSV导入用户")
  92. class DeleteMenu(AdminMenu):
  93. def __init__(self, station, win, color):
  94. super().__init__(station, win, color, "删除")
  95. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(5)]
  96. self.btn_name = ["用户", "多个用户", "垃圾袋", "多个垃圾袋", "所有垃圾袋"]
  97. def conf_gui(self, color: str, n: int = 1):
  98. super().conf_gui(color, n)
  99. self.btn[0]['command'] = lambda: self.del_user()
  100. self.btn[1]['command'] = lambda: self.del_users()
  101. self.btn[2]['command'] = lambda: self.del_garbage()
  102. self.btn[3]['command'] = lambda: self.del_garbage_more()
  103. self.btn[4]['command'] = lambda: self.del_all_garbage()
  104. def del_user(self):
  105. self.station.to_program("删除用户")
  106. def del_users(self):
  107. self.station.to_program("删除多个用户")
  108. def del_garbage(self):
  109. self.station.to_program("删除垃圾袋")
  110. def del_garbage_more(self):
  111. self.station.to_program("删除多个垃圾袋")
  112. def del_all_garbage(self):
  113. self.station.to_program("删除所有垃圾袋")
  114. class SearchMenu(AdminMenu):
  115. def __init__(self, station, win, color):
  116. super().__init__(station, win, color, "搜索")
  117. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(6)]
  118. self.btn_name = ["用户", "高级搜索-用户", "垃圾袋", "高级搜索-垃圾袋", "高级搜索"]
  119. def conf_gui(self, color: str, n: int = 1):
  120. super().conf_gui(color, n)
  121. self.btn[0]['command'] = lambda: self.user_command()
  122. self.btn[1]['command'] = lambda: self.user_advanced_command()
  123. self.btn[2]['command'] = lambda: self.garbage_command()
  124. self.btn[3]['command'] = lambda: self.garbage_advanced_command()
  125. self.btn[4]['command'] = lambda: self.advanced_command()
  126. def user_command(self):
  127. self.station.to_program("搜索用户")
  128. def user_advanced_command(self):
  129. self.station.to_program("高级搜索-用户")
  130. def garbage_command(self):
  131. self.station.to_program("搜索垃圾袋")
  132. def garbage_advanced_command(self):
  133. self.station.to_program("高级搜索-垃圾袋")
  134. def advanced_command(self):
  135. self.station.to_program("高级搜索")
  136. class UpdateMenu(AdminMenu):
  137. def __init__(self, station, win, color):
  138. super().__init__(station, win, color, "更新")
  139. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(4)]
  140. self.btn_name = ["用户-积分", "用户-累计分类信用", "垃圾袋-垃圾类型", "垃圾袋-检测结果"]
  141. def conf_gui(self, color: str, n: int = 1):
  142. super().conf_gui(color, n)
  143. self.btn[0]['command'] = lambda: self.update_score_command()
  144. self.btn[1]['command'] = lambda: self.update_reputation_command()
  145. self.btn[2]['command'] = lambda: self.update_garbage_type_command()
  146. self.btn[3]['command'] = lambda: self.update_garbage_result_command()
  147. def update_reputation_command(self):
  148. self.station.to_program("更新用户-垃圾分类信用")
  149. def update_score_command(self):
  150. self.station.to_program("更新用户-积分")
  151. def update_garbage_type_command(self):
  152. self.station.to_program("更新垃圾袋-垃圾类型")
  153. def update_garbage_result_command(self):
  154. self.station.to_program("更新垃圾袋-检测结果")
  155. class StatisticsMenu(AdminMenu):
  156. def __init__(self, station, win, color):
  157. super().__init__(station, win, color, "数据分析")
  158. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(4)]
  159. self.btn_name = ["时段分析", "日期分析", "积分信用分析", "通过率"]
  160. def conf_gui(self, color: str, n: int = 1):
  161. super().conf_gui(color, n)
  162. self.btn[0]['command'] = self.statistics_time_command
  163. self.btn[1]['command'] = self.statistics_date_command
  164. self.btn[2]['command'] = self.statistics_user_command
  165. self.btn[3]['command'] = self.statistics_pass_command
  166. def statistics_time_command(self):
  167. self.station.to_menu("时段分析")
  168. def statistics_date_command(self):
  169. self.station.to_menu("日期分析")
  170. def statistics_user_command(self):
  171. self.station.to_menu("积分信用分析")
  172. def statistics_pass_command(self):
  173. self.station.to_menu("通过率")
  174. class StatisticsTimeMenu(AdminMenu):
  175. def __init__(self, station, win, color):
  176. super().__init__(station, win, color, "时段分析")
  177. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(7)]
  178. self.btn_name = ["按投放区域", "按投放类型", "投放类型和区域", "按检查结果", "按检查结果和类型", "按检查结果和区域",
  179. "详细分类"]
  180. def conf_gui(self, color: str, n: int = 1):
  181. super().conf_gui(color, n)
  182. self.btn[0]['command'] = self.by_loc
  183. self.btn[1]['command'] = self.by_type
  184. self.btn[2]['command'] = self.by_type_and_type
  185. self.btn[3]['command'] = self.by_result
  186. self.btn[4]['command'] = self.by_result_and_type
  187. self.btn[5]['command'] = self.by_result_and_loc
  188. self.btn[6]['command'] = self.by_detail
  189. def by_loc(self):
  190. self.station.to_program("时段分析-按投放区域")
  191. def by_type(self):
  192. self.station.to_program("时段分析-按投放类型")
  193. def by_type_and_type(self):
  194. self.station.to_program("时段分析-按投放类型和区域")
  195. def by_result(self):
  196. self.station.to_program("时段分析-按检查结果")
  197. def by_result_and_type(self):
  198. self.station.to_program("时段分析-按检查结果和类型")
  199. def by_result_and_loc(self):
  200. self.station.to_program("时段分析-按检查结果和区域")
  201. def by_detail(self):
  202. self.station.to_program("时段分析-详细分类")
  203. class StatisticsDateMenu(AdminMenu):
  204. def __init__(self, station, win, color):
  205. super().__init__(station, win, color, "日期分析")
  206. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(2)]
  207. self.btn_name = ["最近7日", "最近30日"]
  208. def conf_gui(self, color: str, n: int = 1):
  209. super().conf_gui(color, n)
  210. self.btn[0]['command'] = self.by_7
  211. self.btn[1]['command'] = self.by_30
  212. def by_7(self):
  213. self.station.to_menu("日期分析-最近7日")
  214. def by_30(self):
  215. self.station.to_menu("日期分析-最近30日")
  216. class StatisticsDate7Menu(AdminMenu):
  217. def __init__(self, station, win, color):
  218. super().__init__(station, win, color, "日期分析-最近7日")
  219. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(7)]
  220. self.btn_name = ["按投放区域", "按投放类型", "投放类型和区域", "按检查结果", "按检查结果和类型", "按检查结果和区域",
  221. "详细分类"]
  222. def conf_gui(self, color: str, n: int = 1):
  223. super().conf_gui(color, n)
  224. self.btn[0]['command'] = self.by_loc
  225. self.btn[1]['command'] = self.by_type
  226. self.btn[2]['command'] = self.by_type_and_type
  227. self.btn[3]['command'] = self.by_result
  228. self.btn[4]['command'] = self.by_result_and_type
  229. self.btn[5]['command'] = self.by_result_and_loc
  230. self.btn[6]['command'] = self.by_detail
  231. def by_loc(self):
  232. self.station.to_program("最近7日-按投放区域")
  233. def by_type(self):
  234. self.station.to_program("最近7日-按投放类型")
  235. def by_type_and_type(self):
  236. self.station.to_program("最近7日-按投放类型和区域")
  237. def by_result(self):
  238. self.station.to_program("最近7日-按检查结果")
  239. def by_result_and_type(self):
  240. self.station.to_program("最近7日-按检查结果和类型")
  241. def by_result_and_loc(self):
  242. self.station.to_program("最近7日-按检查结果和区域")
  243. def by_detail(self):
  244. self.station.to_program("最近7日-详细分类")
  245. class StatisticsDate30Menu(AdminMenu):
  246. def __init__(self, station, win, color):
  247. super().__init__(station, win, color, "日期分析-最近30日")
  248. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(7)]
  249. self.btn_name = ["按投放区域", "按投放类型", "投放类型和区域", "按检查结果", "按检查结果和类型", "按检查结果和区域",
  250. "详细分类"]
  251. def conf_gui(self, color: str, n: int = 1):
  252. super().conf_gui(color, n)
  253. self.btn[0]['command'] = self.by_loc
  254. self.btn[1]['command'] = self.by_type
  255. self.btn[2]['command'] = self.by_type_and_type
  256. self.btn[3]['command'] = self.by_result
  257. self.btn[4]['command'] = self.by_result_and_type
  258. self.btn[5]['command'] = self.by_result_and_loc
  259. self.btn[6]['command'] = self.by_detail
  260. def by_loc(self):
  261. self.station.to_program("最近30日-按投放区域")
  262. def by_type(self):
  263. self.station.to_program("最近30日-按投放类型")
  264. def by_type_and_type(self):
  265. self.station.to_program("最近30日-按投放类型和区域")
  266. def by_result(self):
  267. self.station.to_program("最近30日-按检查结果")
  268. def by_result_and_type(self):
  269. self.station.to_program("最近30日-按检查结果和类型")
  270. def by_result_and_loc(self):
  271. self.station.to_program("最近30日-按检查结果和区域")
  272. def by_detail(self):
  273. self.station.to_program("最近30日-详细分类")
  274. class StatisticsUserMenu(AdminMenu):
  275. def __init__(self, station, win, color):
  276. super().__init__(station, win, color, "积分信用分析")
  277. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(6)]
  278. self.btn_name = ["积分,信用-细致", "积分,信用-大致", "积分分布", "信用分布"]
  279. def conf_gui(self, color: str, n: int = 1):
  280. super().conf_gui(color, n)
  281. self.btn[0]['command'] = self.by_tiny
  282. self.btn[1]['command'] = self.by_large
  283. self.btn[2]['command'] = self.score
  284. self.btn[3]['command'] = self.reputation
  285. def by_tiny(self):
  286. self.station.to_program("积分信用分析-细致")
  287. def by_large(self):
  288. self.station.to_program("积分信用分析-大致")
  289. def score(self):
  290. self.station.to_program("积分分布")
  291. def reputation(self):
  292. self.station.to_program("垃圾分类信用分布")
  293. class StatisticsPassMenu(AdminMenu):
  294. def __init__(self, station, win, color):
  295. super().__init__(station, win, color, "通过率")
  296. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(4)]
  297. self.btn_name = ["全局", "按类型", "按区域", "按类型和区域"]
  298. def conf_gui(self, color: str, n: int = 1):
  299. super().conf_gui(color, n)
  300. self.btn[0]['command'] = self.by_global
  301. self.btn[1]['command'] = self.by_type
  302. self.btn[2]['command'] = self.by_loc
  303. self.btn[3]['command'] = self.by_type_loc
  304. def by_global(self):
  305. self.station.to_program("通过率-全局")
  306. def by_type(self):
  307. self.station.to_program("通过率-按类型")
  308. def by_loc(self):
  309. self.station.to_program("通过率-按区域")
  310. def by_type_loc(self):
  311. self.station.to_program("通过率-按类型和区域")
  312. all_menu = [MainMenu, CreateMenu, DeleteMenu, SearchMenu, UpdateMenu, StatisticsMenu, StatisticsTimeMenu,
  313. StatisticsUserMenu, StatisticsPassMenu, StatisticsDateMenu, StatisticsDate7Menu, StatisticsDate30Menu]