admin_menu.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 = ["Creat", "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.creat_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 creat_command(self):
  49. self.station.to_menu("Creat")
  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 CreatMenu(AdminMenu):
  59. def __init__(self, station, win, color):
  60. super().__init__(station, win, color, "Creat")
  61. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(4)]
  62. self.btn_name = ["NormalUser", "AutoNormalUser", "ManagerUser", "Garbage"]
  63. def conf_gui(self, color: str, n: int = 1):
  64. super().conf_gui(color, n)
  65. self.btn[0]['command'] = lambda: self.creat_normal_user()
  66. self.btn[1]['command'] = lambda: self.creat_auto_user()
  67. self.btn[2]['command'] = lambda: self.creat_manager_user()
  68. self.btn[3]['command'] = lambda: self.creat_garbage()
  69. def creat_normal_user(self):
  70. self.station.to_program("CreatNormalUser")
  71. def creat_auto_user(self):
  72. self.station.to_program("CreatAutoNormalUser")
  73. def creat_manager_user(self):
  74. self.station.to_program("CreatManagerUser")
  75. def creat_garbage(self):
  76. self.station.to_program("CreatGarbage")
  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(4)]
  81. self.btn_name = ["User", "Users", "Garbage", "AllGarbage"]
  82. def conf_gui(self, color: str, n: int = 1):
  83. super().conf_gui(color, n)
  84. class SearchMenu(AdminMenu):
  85. def __init__(self, station, win, color):
  86. super().__init__(station, win, color, "Search")
  87. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(6)]
  88. self.btn_name = ["User", "User's phone", "Garbage", "User's garbage", "Checker's garbage", "Statistics"]
  89. def conf_gui(self, color: str, n: int = 1):
  90. super().conf_gui(color, n)
  91. self.btn[5]['command'] = lambda: self.statistics_command()
  92. def statistics_command(self):
  93. self.station.to_menu("Statistics")
  94. class UpdateMenu(AdminMenu):
  95. def __init__(self, station, win, color):
  96. super().__init__(station, win, color, "Update")
  97. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(5)]
  98. self.btn_name = ["User's score", "User's reputation", "Garbage's type", "Garbage's check"]
  99. def conf_gui(self, color: str, n: int = 1):
  100. super().conf_gui(color, n)
  101. class StatisticsMenu(AdminMenu):
  102. def __init__(self, station, win, color):
  103. super().__init__(station, win, color, "Statistics")
  104. self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(6)]
  105. self.btn_name = ["System", "Time", "Score", "Reputation", "BlackUser", "PassingRate"]
  106. def conf_gui(self, color: str, n: int = 1):
  107. super().conf_gui(color, n)
  108. all_menu = [MainMenu, CreatMenu, DeleteMenu, SearchMenu, UpdateMenu, StatisticsMenu]