Browse Source

feat: 新增help和about程序

SongZihuan 3 years ago
parent
commit
0db811d18f
6 changed files with 121 additions and 50 deletions
  1. 7 0
      conf/__init__.py
  2. 7 2
      control/admin.py
  3. 70 14
      control/admin_program.py
  4. 6 6
      control/ranking.py
  5. 23 22
      control/station.py
  6. 8 6
      control/station_event.py

+ 7 - 0
conf/__init__.py

@@ -45,3 +45,10 @@ ranking_tk_show_uid_len = tk_show_uid_len  # tk ranking 界面上展示uid的长
 
 tk_win_bg = "#fffffb"  # tkinter manager 窗口 按钮标准颜色
 tk_btn_bg = "#dcdcdc"  # tkinter 按钮 按钮标准颜色
+
+about_info = f'''
+HGSSystem (c) SuperHuan
+From github
+HGSSystem is Garbage Sorting System
+Author: SongZihuan[SuperHuan]
+'''.strip()

+ 7 - 2
control/admin.py

@@ -273,6 +273,7 @@ class AdminStation(AdminStationBase):
                                                                         tk.Button(self._window)]
 
         self._msg_frame = tk.Frame(self._window)
+        self._msg_line = tk.Label(self._msg_frame)
         self._msg_label = tk.Label(self._msg_frame), tk.Label(self._msg_frame), tk.StringVar(), tk.StringVar()
         self._msg_hide = tk.Button(self._msg_frame)
 
@@ -322,10 +323,12 @@ class AdminStation(AdminStationBase):
         rely = 0.02
         bt_help: tk.Button = self._win_ctrl_button[2]
         bt_help['text'] = 'Help'
+        bt_help['command'] = lambda: self.to_program()
         bt_help.place(relx=0.81, rely=rely, relwidth=0.05, relheight=0.05)
 
         bt_about: tk.Button = self._win_ctrl_button[3]
         bt_about['text'] = 'About'
+        bt_about['command'] = lambda: self.to_program("About")
         bt_about.place(relx=0.87, rely=rely, relwidth=0.05, relheight=0.05)
 
         bt_exit: tk.Button = self._win_ctrl_button[4]
@@ -342,7 +345,6 @@ class AdminStation(AdminStationBase):
     def __to_main_menu(self):
         self._menu_list = []
         self.to_menu()
-        self.to_program()
 
     def __to_back_menu(self):
         assert len(self._menu_list) > 1
@@ -483,6 +485,8 @@ class AdminStation(AdminStationBase):
         self._msg_label[0]['anchor'] = 'w'
         self._msg_label[0]['textvariable'] = self._msg_label[2]
 
+        self._msg_line['bg'] = '#000000'
+
         self._msg_label[1]['font'] = info_font
         self._msg_label[1]['bg'] = conf.tk_win_bg
         self._msg_label[1]['anchor'] = 'nw'
@@ -490,13 +494,14 @@ class AdminStation(AdminStationBase):
         self._msg_label[1]['justify'] = 'left'
 
         self._msg_label[0].place(relx=0.05, rely=0.05, relwidth=0.9, relheight=0.1)
+        self._msg_line.place(relx=0.05, rely=0.15, relwidth=0.9, height=1)  # 一个像素的高度即可
         self._msg_label[1].place(relx=0.075, rely=0.2, relwidth=0.85, relheight=0.58)
 
         self._msg_hide['font'] = info_font
         self._msg_hide['text'] = 'close'
         self._msg_hide['bg'] = conf.tk_btn_bg
         self._msg_hide['command'] = lambda: self.hide_msg()
-        self._msg_hide.place(relx=0.375, rely=0.80, relwidth=0.25, relheight=0.13)
+        self._msg_hide.place(relx=0.375, rely=0.80, relwidth=0.25, relheight=0.10)
 
     def show_msg(self, title, info, msg_type='info'):
         assert not self._is_loading  # loading 时不显示msg

+ 70 - 14
control/admin_program.py

@@ -45,34 +45,90 @@ class WelcomeProgram(AdminProgram):
         super().__init__(station, win, color, "Welcome")
 
         self.title = tk.Label(self.frame)
-        self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(2)]
+        self.info = tk.Label(self.frame)
         self.__conf_font()
 
     def __conf_font(self, n: int = 1):
         self.title_font_size = int(25 * n)
-        self.btn_font_size = int(14 * n)
+        self.info_font_size = int(14 * n)
 
     def conf_gui(self, n: int = 1):
         self.__conf_font(n)
 
         title_font = make_font(size=self.title_font_size, weight="bold")
-        btn_font = make_font(size=self.btn_font_size)
+        info_font = make_font(size=self.info_font_size)
 
-        for btn, text in zip(self.btn, ["TestMSG", "TestProgress"]):
-            btn['font'] = btn_font
-            btn['text'] = text
-            btn['bg'] = '#d3d7d4'
+        self.title['font'] = title_font
+        self.title['bg'] = self.color
+        self.title['text'] = 'Welcome to HGSSystem Manager\n[Help Page]'
+
+        self.info['bg'] = self.color
+        self.info['font'] = info_font
+        self.info['anchor'] = 'nw'
+        self.info['justify'] = 'left'
+        self.info['text'] = (f'''
+HGSSystem 管理者界面:
+  1) 点击菜单按钮进入子菜单或程序
+  2) Creat 菜单包含创建类的程序
+  3) Delete 菜单包含删除类的程序
+  4) Search 菜单包含数据分析类的程序
+  5) Update 菜单包含数据更新类的程序
+  6)当离开操作系统时请退出登录以确保安全
+  7)只能使用具有管理员权限的账号登陆系统
+  8)只有admin用户可以完成危险操作(例如删除所有垃圾袋数据)
+
+程序的运行:
+  1) 在菜单中选中程序后,根据程序界面提示完成操作
+  2) 操作过程通常会显示进度条,除非任务执行迅速
+  3) 结果通常会被反馈, 且不会自动消失
+
+系统登录:
+  1) 仅Manager用户可以登录
+
+关于彩蛋: 存在
+                '''.strip())
+
+        self.title.place(relx=0.1, rely=0.0, relwidth=0.8, relheight=0.2)
+        self.info.place(relx=0.05, rely=0.21, relwidth=0.90, relheight=0.75)
+
+    def set_disable(self):
+        pass
+
+    def reset_disable(self):
+        pass
+
+
+class AboutProgram(AdminProgram):
+    def __init__(self, station, win, color):
+        super().__init__(station, win, color, "About")
+
+        self.title = tk.Label(self.frame)
+        self.info = tk.Label(self.frame)
+        self.btn: List[tk.Button] = [tk.Button(self.frame) for _ in range(2)]
+        self.__conf_font()
+
+    def __conf_font(self, n: int = 1):
+        self.title_font_size = int(25 * n)
+        self.info_font_size = int(14 * n)
+
+    def conf_gui(self, n: int = 1):
+        self.__conf_font(n)
+
+        title_font = make_font(size=self.title_font_size, weight="bold")
+        info_font = make_font(size=self.info_font_size)
 
-        self.title['text'] = 'Welcome to HGSSystem Manager'
         self.title['font'] = title_font
         self.title['bg'] = self.color
+        self.title['text'] = 'About HGSSystem Manager\n[About Page]'
 
-        self.btn[0]['command'] = lambda: self.test_msg()
-        self.btn[1]['command'] = lambda: self.test_progress()
+        self.info['bg'] = self.color
+        self.info['font'] = info_font
+        self.info['anchor'] = 'nw'
+        self.info['justify'] = 'left'
+        self.info['text'] = conf.about_info
 
-        self.title.place(relx=0.1, rely=0.3, relwidth=0.8, relheight=0.2)
-        self.btn[0].place(relx=0.2, rely=0.7, relwidth=0.2, relheight=0.1)
-        self.btn[1].place(relx=0.6, rely=0.7, relwidth=0.2, relheight=0.1)
+        self.title.place(relx=0.1, rely=0.0, relwidth=0.8, relheight=0.2)
+        self.info.place(relx=0.05, rely=0.21, relwidth=0.90, relheight=0.75)
 
     def test_progress(self):
         event = tk_event.TestProgressEvent(self.station)
@@ -1668,4 +1724,4 @@ all_program = [WelcomeProgram, CreateNormalUserProgram, CreateManagerUserProgram
                DeleteGarbageMoreProgram, DeleteAllGarbageProgram, SearchUserProgram, SearchUserAdvancedProgram,
                SearchGarbageProgram, SearchGarbageAdvancedProgram, SearchAdvancedProgram, UpdateUserScoreBase,
                UpdateUserReputationBase, UpdateGarbageTypeProgram, UpdateGarbageCheckResultProgram,
-               ExportGarbageProgram, ExportUserProgram, CreateUserFromCSVProgram]
+               ExportGarbageProgram, ExportUserProgram, CreateUserFromCSVProgram, AboutProgram]

+ 6 - 6
control/ranking.py

@@ -38,9 +38,9 @@ class RankingStationBase(metaclass=abc.ABCMeta):
     def get_rank(self, offset: int = 0) -> Tuple[bool, list]:
         limit = self.rank_count * self.limit_n
         offset = self.offset + limit * offset  # offset为0表示不移动, 1表示向前, -1表示向后
-        cur = self._db.search((f"SELECT uid, name, score, reputation "
+        cur = self._db.search((f"SELECT UserID, Name, Score, Reputation "
                                f"FROM user "
-                               f"WHERE manager = 0 "
+                               f"WHERE IsManager = 0 "
                                f"ORDER BY reputation DESC, score DESC "
                                f"LIMIT {limit} OFFSET {offset};"))
         if cur is None or cur.rowcount == 0:
@@ -225,11 +225,11 @@ class RankingStation(RankingStationBase):
     def __conf_windows(self):
         self.window.title('HGSSystem: Ranking')
         self.window.geometry(f'{self.width}x{self.height}')
-        self.window['bg'] = "#F0FFF0"  # 蜜瓜绿
+        self.window['bg'] = conf.tk_win_bg
         self.window.resizable(False, False)
         self.bg_img = None
         self.bg_lb = tk.Label(self.window)
-        self.bg_lb['bg'] = "#F0FFF0"  # 蜜瓜绿
+        self.bg_lb['bg'] = conf.tk_win_bg
         self.bg_lb.place(relx=0, rely=0, relwidth=1, relheight=1)
 
         self.window.bind("<F11>", lambda _: self.__switch_full_screen())
@@ -274,11 +274,11 @@ class RankingStation(RankingStationBase):
 
         self.rank_frame['relief'] = "ridge"
         self.rank_frame['bd'] = 5
-        self.rank_frame['bg'] = "#F5F5DC"
+        self.rank_frame['bg'] = conf.tk_win_bg
         self.rank_frame.place(relx=relx, rely=rely, relwidth=relwidth, relheight=relheight)
 
         self.rank_title['font'] = title_font
-        self.rank_title['bg'] = "#F5F5DC"
+        self.rank_title['bg'] = conf.tk_win_bg
         self.rank_title['textvariable'] = self.rank_title_var
         self.rank_title.place(relx=0.02, rely=0.00, relwidth=0.96, relheight=0.1)
         self.rank_title_var.set("Ranking.loading...")

+ 23 - 22
control/station.py

@@ -177,10 +177,10 @@ class GarbageStationBase(TkEventMain, metaclass=abc.ABCMeta):
         if order_by != 'ASC' and order_by != 'DESC':
             order_by = 'DESC'
 
-        cur = self._db.search((f"SELECT uid, name, score, reputation "
+        cur = self._db.search((f"SELECT UserID, Name, Score, Reputation "
                                f"FROM user "
-                               f"WHERE manager = 0 "
-                               f"ORDER BY reputation {order_by}, score {order_by} "
+                               f"WHERE IsManager = 0 "
+                               f"ORDER BY Reputation {order_by}, Score {order_by} "
                                f"{limit}"))
         if cur is None:
             raise RankingUserError
@@ -290,13 +290,7 @@ HGSSystem:
 
     def show_about_info(self):
         self.update_user_time()
-        self.show_msg("About", f'''
-HGSSystem (c) SuperHuan
-From github
-HGSSystem is Garbage Sorting System
-Author: SongZihuan[SuperHuan]
-Run on python {sys.version}
-                '''.strip())
+        self.show_msg("About", conf.about_info)
 
     def show_exit(self):
         self.update_user_time()
@@ -515,6 +509,7 @@ class GarbageStation(GarbageStationBase):
                                            tk.Button(self._user_btn_frame)]
 
         self._msg_frame = tk.Frame(self._window)
+        self._msg_line = tk.Label(self._msg_frame)
         self._msg_label = tk.Label(self._msg_frame), tk.Label(self._msg_frame), tk.StringVar(), tk.StringVar()
         self._msg_hide = tk.Button(self._msg_frame)
 
@@ -534,6 +529,7 @@ class GarbageStation(GarbageStationBase):
         self._rank_btn = [tk.Button(self._rank_frame), tk.Button(self._rank_frame), tk.Button(self._rank_frame)]
 
         self._loading_frame = tk.Frame(self._window)
+        self._loading_line = tk.Label(self._loading_frame)
         self._loading_title: Tuple[tk.Label, tk.Variable] = tk.Label(self._loading_frame), tk.StringVar()
         self._loading_pro = ttk.Progressbar(self._loading_frame)
 
@@ -567,7 +563,7 @@ class GarbageStation(GarbageStationBase):
     def __conf_windows(self):
         self._window.title('HGSSystem: Garbage Station')
         self._window.geometry(f'{self._win_width}x{self._win_height}')
-        self._window['bg'] = "#F0FFF0"  # 蜜瓜绿
+        self._window['bg'] = conf.tk_win_bg
         self._window.attributes("-topmost", True)
         self._window.resizable(False, False)
         self._window.protocol("WM_DELETE_WINDOW", lambda: self.show_exit())
@@ -623,7 +619,7 @@ class GarbageStation(GarbageStationBase):
     def __conf_title_label(self):
         title_font = make_font(size=self._title_font_size, weight="bold")
         self._title_label['font'] = title_font
-        self._title_label['bg'] = "#F0FFF0"  # 蜜瓜绿
+        self._title_label['bg'] = conf.tk_win_bg  # 蜜瓜绿
         self._title_label['text'] = "HGSSystem: GarbageStation Control Center"
         self._title_label['anchor'] = 'w'
         self._title_label.place(relx=0.02, rely=0.0, relwidth=0.6, relheight=0.07)
@@ -784,12 +780,12 @@ class GarbageStation(GarbageStationBase):
 
     def __conf_user_btn(self):
         btn_font = make_font(size=self._user_btn_font_size, weight="bold")
-        btn_info: List[Tuple[str, str]] = [("Detail", "#b0a4e3"),
-                                           ("Ranking", "#b0a4e3"),
-                                           ("Search", "#b0a4e3")]
+        btn_info: List[Tuple[str, str]] = [("Detail", "#DDA0DD"),
+                                           ("Ranking", "#B0C4DE"),
+                                           ("Search", "#F4A460")]
 
         self._user_btn_frame.place(relx=0.02, rely=0.66, relwidth=0.19, relheight=0.32)
-        self._user_btn_frame['bg'] = "#F0FFF0"
+        self._user_btn_frame['bg'] = conf.tk_win_bg
 
         h_label = 5
         h_label_s = 1
@@ -826,6 +822,8 @@ class GarbageStation(GarbageStationBase):
         self._msg_label[0]['anchor'] = 'w'
         self._msg_label[0]['textvariable'] = self._msg_label[2]
 
+        self._msg_line['bg'] = '#000000'
+
         self._msg_label[1]['font'] = info_font
         self._msg_label[1]['bg'] = "#F5FFFA"
         self._msg_label[1]['anchor'] = 'nw'
@@ -833,13 +831,14 @@ class GarbageStation(GarbageStationBase):
         self._msg_label[1]['textvariable'] = self._msg_label[3]
 
         self._msg_label[0].place(relx=0.05, rely=0.05, relwidth=0.9, relheight=0.1)
+        self._msg_line.place(relx=0.05, rely=0.15, relwidth=0.9, height=1)  # 一个像素的高度即可
         self._msg_label[1].place(relx=0.075, rely=0.2, relwidth=0.85, relheight=0.64)
 
         self._msg_hide['font'] = info_font
-        self._msg_hide['bg'] = "#00CED1"
+        self._msg_hide['bg'] = conf.tk_btn_bg
         self._msg_hide['text'] = 'close'
         self._msg_hide['command'] = lambda: self.hide_msg_rank(True)
-        self._msg_hide.place(relx=0.375, rely=0.85, relwidth=0.25, relheight=0.1)
+        self._msg_hide.place(relx=0.375, rely=0.85, relwidth=0.25, relheight=0.08)
 
     def show_msg(self, title, info, msg_type='info', big: bool = True):
         if self._disable_all_btn:
@@ -965,17 +964,19 @@ class GarbageStation(GarbageStationBase):
     def __conf_loading(self):
         title_font = make_font(size=self._loading_tile_font, weight="bold")
 
-        self._loading_frame['bg'] = "#808080"
+        self._loading_frame['bg'] = conf.tk_win_bg
         self._loading_frame['bd'] = 5
         self._loading_frame['relief'] = "ridge"
         # frame 不会立即显示
 
         self._loading_title[0]['font'] = title_font
-        self._loading_title[0]['bg'] = "#808080"
-        self._loading_title[0]['fg'] = "#F8F8FF"
+        self._loading_title[0]['bg'] = conf.tk_win_bg
         self._loading_title[0]['anchor'] = 'w'
         self._loading_title[0]['textvariable'] = self._loading_title[1]
-        self._loading_title[0].place(relx=0.02, rely=0.00, relwidth=0.96, relheight=0.7)
+        self._loading_title[0].place(relx=0.02, rely=0.00, relwidth=0.96, relheight=0.6)
+
+        self._loading_line['bg'] = '#000000'
+        self._loading_line.place(relx=0.02, rely=0.6, relwidth=0.96, height=1)  # 一个像素的高度即可
 
         self._loading_pro['mode'] = 'indeterminate'
         self._loading_pro['orient'] = 'horizontal'

+ 8 - 6
control/station_event.py

@@ -92,10 +92,10 @@ class ScanGarbageEvent(StationEventBase):
 class RankingEvent(StationEventBase):
     @staticmethod
     def func(db: DB):
-        cur = db.search((f"SELECT uid, name, score, reputation "
+        cur = db.search((f"SELECT UserID, Name, Score, Reputation "
                          f"FROM user "
-                         f"WHERE manager = 0 "
-                         f"ORDER BY reputation DESC, score DESC "
+                         f"WHERE IsManager = 0 "
+                         f"ORDER BY Reputation DESC, Score DESC "
                          f"LIMIT 20;"))
         if cur is None:
             return []
@@ -109,9 +109,11 @@ class RankingEvent(StationEventBase):
         return not self.thread.is_alive()
 
     def done_after_event(self):
-        self.thread.join()
-        if self.thread.result is not None:
-            self.station.thread_show_rank(self.thread.result)
+        res = self.thread.wait_event()
+        if res is not None:
+            self.station.thread_show_rank(res)
+        else:
+            self.station.show_warning("RankError", f'Unable to get leaderboard data')
 
 
 class ThrowGarbageEvent(StationEventBase):