瀏覽代碼

封装了UIAPI类

Huan 5 年之前
父節點
當前提交
bf2f694ae5
共有 11 個文件被更改,包括 2293 次插入2178 次删除
  1. 2 0
      Hello.py
  2. 422 420
      algebraicfactory/gui.py
  3. 279 277
      crawler/gui.py
  4. 383 386
      datascience/gui.py
  5. 17 9
      draftboard/customfunctions.py
  6. 192 184
      draftboard/drawingfunction.py
  7. 148 140
      draftboard/toolbox.py
  8. 0 1
      funcsystem/map.py
  9. 504 507
      gitrepo/gui.py
  10. 231 229
      machinelearning/gui.py
  11. 115 25
      system/gui.py

+ 2 - 0
Hello.py

@@ -81,6 +81,7 @@ def functionmapping_run():
 
 def functionfactory_main():
     from funcsystem.factory import function_factory_main
+    print('函数工厂加载完毕')
     function_factory_main()
 
 
@@ -88,6 +89,7 @@ def functionfactory_main():
 def functionfactory_run():
     global SCREEN, functionfactory_start
     functionfactory_start = Process(target=functionfactory_main)
+    print('函数工厂加载完毕')
     functionfactory_start.start()
 
 

文件差異過大導致無法顯示
+ 422 - 420
algebraicfactory/gui.py


+ 279 - 277
crawler/gui.py

@@ -69,241 +69,234 @@ page_parser = None
 database = None
 
 
-def get_db_index_gui(object_index):
-    try:
-        index = eval(object_index.get(), {})
-    except BaseException:
-        index = slice(None, None)
-    return index
-
-
-def get_datadase_name_gui():
-    global database_box, database_list
-    try:
-        return database_list[database_box.curselection()[0]]
-    except BaseException:
+class UIAPI:
+    @staticmethod
+    def get_db_index_gui(object_index):
         try:
-            return database_list[0]
+            index = eval(object_index.get(), {})
         except BaseException:
-            return None
-
-
-def update_database_box_gui():
-    global database_box, database_list
-    database_list = database.return_database()
-    database_box.delete(0, tkinter.END)
-    database_box.insert(tkinter.END, *database_list)
-
-
-def update_run_status_gui(now_func, status, value_box):
-    global now_running, status_output, variable_box
-    now_running.set(now_func)
-    status_output.set(status)
-    variable_box.delete(0, tkinter.END)
-    variable_box.insert(0, *value_box)
-
-
-def get_attributes_box_index_gui():
-    return attributes_box.curselection()[0]
-
-
-def add_attributes_gui():
-    name = attributes_name.get()
-    value = attributes_value.get()
-    if name == "" or value == "":
-        raise Exception
-    value = re.compile(value) if bool(attribute_regex.get()) else value
-    return name, value
-
-
-def update_attributes_box_gui():
-    global attributes_box, attributes_dict
-    show = []
-    for i in attributes_dict:
-        show.append(f"{i} -> {attributes_dict[i]}")
-    attributes_box.delete(0, tkinter.END)
-    attributes_box.insert(tkinter.END, *show)
-
-
-def third_func_args_gui():  # 方法args统一转换(第三栏目)
-    global is_special_keys, chains, drag_element, drag_element_index, run_time, operation_object, object_index
-    global type_value
-    try:
-        index = int(object_index.get())
-    except BaseException:
-        index = 0
-    try:
-        index2 = int(drag_element_index.get())
-    except BaseException:
-        index2 = 0
-    try:
-        time = int(run_time.get())
-    except BaseException:
-        time = 1
-    return dict(
-        Chains=chains.get(),
-        element_value=operation_object.get(),
-        index=index,
-        element_value2=drag_element.get(),
-        index2=index2,
-        run_time=time,
-        is_special_keys=bool(is_special_keys.get()),
-        key=type_value.get(),
-    )
-
-
-def second_func_args_gui():  # 方法args统一转换(第二栏目)
-    global cookies_name_input, new_cookies, element_name, attributes_dict, operation_object, object_index
-    global find_text, text_regex, limit, is_recursive, find_path
-    try:
-        index = eval(object_index.get(), {})
-    except BaseException:
-        index = slice(None, None)
-    try:
-        cookies = eval(new_cookies.get(), {})
-    except BaseException:
-        cookies = {}
-    return dict(
-        element_value=operation_object.get(),
-        index=index,
-        cookies_name=cookies_name_input.get(),
-        cookies=cookies,
-        tag=element_name.get().split(","),
-        attribute=attributes_dict,
-        text=re.compile(find_text.get()) if bool(text_regex.get()) else find_text.get(),
-        limit=limit.get(),
-        recursive=bool(is_recursive.get()),
-        path=find_path.get(),
-    )
-
-
-def first_func_args_gui():  # 方法args统一转换(不支持Frame)
-    global operation_object, object_index, send_text, password, select_object, js_code, wait_time
-    try:
-        time = int(wait_time.get())
-    except BaseException:
-        time = 2
-    try:
-        index = int(object_index.get())
-    except BaseException:
-        index = 0
-    return dict(
-        element_value=operation_object.get(),
-        index=index,
-        text=send_text.get(),
-        User=password.get(),
-        Passwd=password.get(),
-        deselect=select_object.get(),
-        JS=js_code.get(),
-        time=time,
-    )
-
-
-def get_parser_func_box_index_gui():
-    return parser_func_box.curselection()[0]
-
-
-def update_parser_func_box_gui():
-    global parser_func_box, page_parser
-    parser_func_box.delete(0, tkinter.END)
-    parser_func_box.insert(tkinter.END, *page_parser.return_func(False)[::-1])
-
-
-def get_new_cookies_gui():
-    return eval(new_cookies.get(), {})
-
-
-def get_cookies_fix_gui():
-    return bool(cookies_fixed.get())
-
-
-def get_cookies_box_index_gui():
-    return cookies_BOX.curselection()[0]
-
-
-def update_cookies_box_gui(cookies):
-    global cookies_BOX, cookies_list
-    if get_cookies_fix_gui():
-        cookies_list = cookies
-        cookies_BOX.delete(0, tkinter.END)
-        cookies_BOX.insert(0, *cookies)
-
-
-def get_filter_func_box_index_gui():
-    return filter_func_box.curselection()[0]
-
-
-def update_filter_func_box_gui():
-    global url, filter_func_box
-    filter_func_box.delete(0, tkinter.END)
-    filter_func_box.insert(tkinter.END, *url.return_filter_func())
-
-
-def get_url_box_index_gui():
-    return url_box.curselection()[0]
-
-
-def get_url_parameter_gui():
-    try:
-        data = eval(requests_data.get(), {})
-    except BaseException:
-        data = {}
-    try:
-        the_time_out = int(time_out.get())
-    except BaseException:
-        the_time_out = 5
-    re = dict(
-        func=mode_input.get(),
-        UA=user_agent_input.get(),
-        cookies=applied_cookies.get(),
-        data=data,
-        time_out=the_time_out,
-    )
-    name = ["no_js", "no_java", "no_plugins", "first_run", "head", "no_img", "new"]
-    for i in range(len(name)):
-        re[name[i]] = bool(url_parameter[i].get())
-    return re
-
-
-def get_new_url_name_gui():
-    return url_input.get()
+            index = slice(None, None)
+        return index
 
+    @staticmethod
+    def get_datadase_name_gui():
+        global database_box, database_list
+        try:
+            return database_list[database_box.curselection()[0]]
+        except BaseException:
+            try:
+                return database_list[0]
+            except BaseException:
+                return None
 
-def add_url_from_tag_gui():
-    try:
-        index = eval(object_index.get(), {})
-    except BaseException:
-        index = slice(None, None)
-    return dict(
-        element_value=operation_object.get(),
-        index=index,
-        url_name=url_tag.get(),
-        update_func=update_url_box_gui,
-        url_args=get_url_parameter_gui(),
-    )
+    @staticmethod
+    def update_database_box_gui():
+        global database_box, database_list
+        database_list = database.return_database()
+        database_box.delete(0, tkinter.END)
+        database_box.insert(tkinter.END, *database_list)
 
+    @staticmethod
+    def update_run_status_gui(now_func, status, value_box):
+        global now_running, status_output, variable_box
+        now_running.set(now_func)
+        status_output.set(status)
+        variable_box.delete(0, tkinter.END)
+        variable_box.insert(0, *value_box)
 
-def update_url_box_gui():
-    global url, url_box
-    url_box.delete(0, tkinter.END)
-    url_box.insert(tkinter.END, *url.return_url())
+    @staticmethod
+    def get_attributes_box_index_gui():
+        return attributes_box.curselection()[0]
 
+    @staticmethod
+    def add_attributes_gui():
+        name = attributes_name.get()
+        value = attributes_value.get()
+        if name == "" or value == "":
+            raise Exception
+        value = re.compile(value) if bool(attribute_regex.get()) else value
+        return name, value
 
-def to_database_gui():
-    index = get_db_index_gui(object_index)
-    return dict(element_value=operation_object.get(),
-                index=index,
-                data=data_format.get(),
-                dataBase_name=get_datadase_name_gui(),)
+    @staticmethod
+    def update_attributes_box_gui():
+        global attributes_box, attributes_dict
+        show = []
+        for i in attributes_dict:
+            show.append(f"{i} -> {attributes_dict[i]}")
+        attributes_box.delete(0, tkinter.END)
+        attributes_box.insert(tkinter.END, *show)
 
+    @staticmethod
+    def third_func_args_gui():  # 方法args统一转换(第三栏目)
+        global is_special_keys, chains, drag_element, drag_element_index, run_time, operation_object, object_index
+        global type_value
+        try:
+            index = int(object_index.get())
+        except BaseException:
+            index = 0
+        try:
+            index2 = int(drag_element_index.get())
+        except BaseException:
+            index2 = 0
+        try:
+            time = int(run_time.get())
+        except BaseException:
+            time = 1
+        return dict(
+            Chains=chains.get(),
+            element_value=operation_object.get(),
+            index=index,
+            element_value2=drag_element.get(),
+            index2=index2,
+            run_time=time,
+            is_special_keys=bool(is_special_keys.get()),
+            key=type_value.get(),
+        )
 
-def crawler_main():
-    global SCREEN
-    SCREEN.mainloop()
-    loader.stop()
-    database.close_all()
-    url.close()
-    loader.close()
+    @staticmethod
+    def second_func_args_gui():  # 方法args统一转换(第二栏目)
+        global cookies_name_input, new_cookies, element_name, attributes_dict, operation_object, object_index
+        global find_text, text_regex, limit, is_recursive, find_path
+        try:
+            index = eval(object_index.get(), {})
+        except BaseException:
+            index = slice(None, None)
+        try:
+            cookies = eval(new_cookies.get(), {})
+        except BaseException:
+            cookies = {}
+        return dict(
+            element_value=operation_object.get(),
+            index=index,
+            cookies_name=cookies_name_input.get(),
+            cookies=cookies,
+            tag=element_name.get().split(","),
+            attribute=attributes_dict,
+            text=re.compile(find_text.get()) if bool(text_regex.get()) else find_text.get(),
+            limit=limit.get(),
+            recursive=bool(is_recursive.get()),
+            path=find_path.get(),
+        )
+
+    @staticmethod
+    def first_func_args_gui():  # 方法args统一转换(不支持Frame)
+        global operation_object, object_index, send_text, password, select_object, js_code, wait_time
+        try:
+            time = int(wait_time.get())
+        except BaseException:
+            time = 2
+        try:
+            index = int(object_index.get())
+        except BaseException:
+            index = 0
+        return dict(
+            element_value=operation_object.get(),
+            index=index,
+            text=send_text.get(),
+            User=password.get(),
+            Passwd=password.get(),
+            deselect=select_object.get(),
+            JS=js_code.get(),
+            time=time,
+        )
+
+    @staticmethod
+    def get_parser_func_box_index_gui():
+        return parser_func_box.curselection()[0]
+
+    @staticmethod
+    def update_parser_func_box_gui():
+        global parser_func_box, page_parser
+        parser_func_box.delete(0, tkinter.END)
+        parser_func_box.insert(tkinter.END, *page_parser.return_func(False)[::-1])
+
+    @staticmethod
+    def get_new_cookies_gui():
+        return eval(new_cookies.get(), {})
+
+    @staticmethod
+    def get_cookies_fix_gui():
+        return bool(cookies_fixed.get())
+
+    @staticmethod
+    def get_cookies_box_index_gui():
+        return cookies_BOX.curselection()[0]
+
+    @staticmethod
+    def update_cookies_box_gui(cookies):
+        global cookies_BOX, cookies_list
+        if UIAPI.get_cookies_fix_gui():
+            cookies_list = cookies
+            cookies_BOX.delete(0, tkinter.END)
+            cookies_BOX.insert(0, *cookies)
+
+    @staticmethod
+    def get_filter_func_box_index_gui():
+        return filter_func_box.curselection()[0]
+
+    @staticmethod
+    def update_filter_func_box_gui():
+        global url, filter_func_box
+        filter_func_box.delete(0, tkinter.END)
+        filter_func_box.insert(tkinter.END, *url.return_filter_func())
+
+    @staticmethod
+    def get_url_box_index_gui():
+        return url_box.curselection()[0]
+
+    @staticmethod
+    def get_url_parameter_gui():
+        try:
+            data = eval(requests_data.get(), {})
+        except BaseException:
+            data = {}
+        try:
+            the_time_out = int(time_out.get())
+        except BaseException:
+            the_time_out = 5
+        re = dict(
+            func=mode_input.get(),
+            UA=user_agent_input.get(),
+            cookies=applied_cookies.get(),
+            data=data,
+            time_out=the_time_out,
+        )
+        name = ["no_js", "no_java", "no_plugins", "first_run", "head", "no_img", "new"]
+        for i in range(len(name)):
+            re[name[i]] = bool(url_parameter[i].get())
+        return re
+
+    @staticmethod
+    def get_new_url_name_gui():
+        return url_input.get()
+
+    @staticmethod
+    def add_url_from_tag_gui():
+        try:
+            index = eval(object_index.get(), {})
+        except BaseException:
+            index = slice(None, None)
+        return dict(
+            element_value=operation_object.get(),
+            index=index,
+            url_name=url_tag.get(),
+            update_func=UIAPI.update_url_box_gui,
+            url_args=UIAPI.get_url_parameter_gui(),
+        )
+
+    @staticmethod
+    def update_url_box_gui():
+        global url, url_box
+        url_box.delete(0, tkinter.END)
+        url_box.insert(tkinter.END, *url.return_url())
+
+    @staticmethod
+    def to_database_gui():
+        index = UIAPI.get_db_index_gui(object_index)
+        return dict(element_value=operation_object.get(),
+                    index=index,
+                    data=data_format.get(),
+                    dataBase_name=UIAPI.get_datadase_name_gui(),)
 
 
 class API:
@@ -314,56 +307,56 @@ class API:
             func = page_parser.to_database
         else:
             func = page_parser.to_database_by_re
-        func(**to_database_gui())
-        update_parser_func_box_gui()
+        func(**UIAPI.to_database_gui())
+        UIAPI.update_parser_func_box_gui()
 
     @staticmethod
     def close():
-        name = get_datadase_name_gui()
+        name = UIAPI.get_datadase_name_gui()
         database.close(name)
-        update_database_box_gui()
+        UIAPI.update_database_box_gui()
 
     @staticmethod
     def out():
-        name = get_datadase_name_gui()
+        name = UIAPI.get_datadase_name_gui()
         database.out(name, save_dir)
-        update_database_box_gui()
+        UIAPI.update_database_box_gui()
 
     @staticmethod
     def remove_database():
-        name = get_datadase_name_gui()
+        name = UIAPI.get_datadase_name_gui()
         database.rm_database(name)
-        update_database_box_gui()
+        UIAPI.update_database_box_gui()
 
     @staticmethod
     def add_database():
         name = database_name.get()
         database.add_database(name)
-        update_database_box_gui()
+        UIAPI.update_database_box_gui()
 
     @staticmethod
     def clean_attributes():
         global attributes_dict
         attributes_dict = {}
-        update_attributes_box_gui()
+        UIAPI.update_attributes_box_gui()
 
     @staticmethod
     def del_attributes():
-        del attributes_dict[list(attributes_dict.keys())[get_attributes_box_index_gui()]]
-        update_attributes_box_gui()
+        del attributes_dict[list(attributes_dict.keys())[UIAPI.get_attributes_box_index_gui()]]
+        UIAPI.update_attributes_box_gui()
 
     @staticmethod
     def add_attributes():
         try:
-            name, value = add_attributes_gui()
+            name, value = UIAPI.add_attributes_gui()
         except BaseException:
             return False
         attributes_dict[name] = value
-        update_attributes_box_gui()
+        UIAPI.update_attributes_box_gui()
 
     @staticmethod
     def third_add_action_func(func):
-        args = third_func_args_gui()
+        args = UIAPI.third_func_args_gui()
         func = {
             "make_ActionChains": page_parser.make_action_chains,
             "click": page_parser.action_click,
@@ -380,11 +373,11 @@ class API:
             "ActionChains_run": page_parser.action_run,
         }.get(func, page_parser.make_action_chains)
         func(**args)
-        update_parser_func_box_gui()
+        UIAPI.update_parser_func_box_gui()
 
     @staticmethod
     def second_add_action_func(func):
-        args = second_func_args_gui()
+        args = UIAPI.second_func_args_gui()
         func = {
             "del_all_cookies": page_parser.del_all_cookies,
             "del_cookies": page_parser.del_cookies,
@@ -405,11 +398,11 @@ class API:
             "to_json": page_parser.to_json,
         }.get(func, page_parser.make_bs)
         func(**args)
-        update_parser_func_box_gui()
+        UIAPI.update_parser_func_box_gui()
 
     @staticmethod
     def first_add_action_func(func):
-        args = first_func_args_gui()
+        args = UIAPI.first_func_args_gui()
         func = {
             "send_keys": page_parser.send_keys,
             "clear": page_parser.clear,
@@ -437,19 +430,19 @@ class API:
             "switch_to_windwos": page_parser.switch_to_windwos,
         }.get(func, page_parser.send_keys)
         func(**args)
-        update_parser_func_box_gui()
+        UIAPI.update_parser_func_box_gui()
 
     @staticmethod
     def add_frame_func_father(is_main=True):
         search = None if is_main else ""
         page_parser.find_switch_to_frame(search, True)
-        update_parser_func_box_gui()
+        UIAPI.update_parser_func_box_gui()
 
     @staticmethod
     def add_frame_func_id():
         search = API.get_search_key()
         page_parser.find_switch_to_frame(search, True)
-        update_parser_func_box_gui()
+        UIAPI.update_parser_func_box_gui()
 
     @staticmethod
     def add_find_func(func):
@@ -469,7 +462,7 @@ class API:
             "frame": page_parser.find_switch_to_frame,
         }.get(func, page_parser.find_id)
         func(search, not_all=not_all)
-        update_parser_func_box_gui()
+        UIAPI.update_parser_func_box_gui()
 
     @staticmethod
     def get_search_key():
@@ -479,9 +472,9 @@ class API:
     @staticmethod
     def del_parser_func():
         try:
-            index = get_parser_func_box_index_gui()
+            index = UIAPI.get_parser_func_box_index_gui()
             page_parser.del_func(index, True)
-            update_parser_func_box_gui()
+            UIAPI.update_parser_func_box_gui()
         except BaseException:
             pass
 
@@ -489,17 +482,17 @@ class API:
     def clean_parser_func():
         try:
             page_parser.tra_func()
-            update_parser_func_box_gui()
+            UIAPI.update_parser_func_box_gui()
         except BaseException:
             pass
 
     @staticmethod
     def update_cookies():
-        cookies = get_new_cookies_gui()
-        if get_cookies_fix_gui():
+        cookies = UIAPI.get_new_cookies_gui()
+        if UIAPI.get_cookies_fix_gui():
             return False
         try:
-            name = cookies_list[get_cookies_box_index_gui()].get("name")
+            name = cookies_list[UIAPI.get_cookies_box_index_gui()].get("name")
             loader.monitoring_update_cookies(name, cookies)
             API.set_cookies_fix()
         except BaseException:
@@ -507,8 +500,8 @@ class API:
 
     @staticmethod
     def add_cookies():
-        cookies = get_new_cookies_gui()
-        if get_cookies_fix_gui():
+        cookies = UIAPI.get_new_cookies_gui()
+        if UIAPI.get_cookies_fix_gui():
             return False
         try:
             loader.monitoring_add_cookies(cookies)
@@ -518,7 +511,7 @@ class API:
 
     @staticmethod
     def clean_cookies():
-        if get_cookies_fix_gui():
+        if UIAPI.get_cookies_fix_gui():
             return False
         try:
             loader.monitoring_clear_cookier()
@@ -532,10 +525,10 @@ class API:
 
     @staticmethod
     def del_cookies():
-        if get_cookies_fix_gui():
+        if UIAPI.get_cookies_fix_gui():
             return False
         try:
-            name = cookies_list[get_cookies_box_index_gui()].get("name")
+            name = cookies_list[UIAPI.get_cookies_box_index_gui()].get("name")
             loader.monitoring_del_cookies(name)
             API.set_cookies_fix()
         except BaseException:
@@ -556,14 +549,14 @@ class API:
             while start_loader_stop:
                 if url.is_finish():
                     break
-                loader.start_to_run(func_cookie=update_cookies_box_gui)
-                update_url_box_gui()
-                page_parser.element_interaction(update_run_status_gui)
+                loader.start_to_run(func_cookie=UIAPI.update_cookies_box_gui)
+                UIAPI.update_url_box_gui()
+                page_parser.element_interaction(UIAPI.update_run_status_gui)
             loader.stop()
 
         new = threading.Thread(target=start_loader)
         new.start()
-        update_url_box_gui()
+        UIAPI.update_url_box_gui()
 
     @staticmethod
     def crawler_run_one():
@@ -571,9 +564,9 @@ class API:
             global loader, page_parser
             if url.is_finish():
                 return
-            loader.start_to_run(func_cookie=update_cookies_box_gui)
-            update_url_box_gui()
-            page_parser.element_interaction(update_run_status_gui)
+            loader.start_to_run(func_cookie=UIAPI.update_cookies_box_gui)
+            UIAPI.update_url_box_gui()
+            page_parser.element_interaction(UIAPI.update_run_status_gui)
             loader.stop()
 
         new = threading.Thread(target=start_loader)
@@ -582,38 +575,47 @@ class API:
     @staticmethod
     def add_filter_func_https():
         url.add_filter_func(lambda url: re.match(re.compile("^https://"), url), "HTTPS过滤")
-        update_filter_func_box_gui()
+        UIAPI.update_filter_func_box_gui()
 
     @staticmethod
     def add_filter_func_www():
         url.add_filter_func(lambda url: re.match(re.compile(r".*www\."), url), "www过滤")
-        update_filter_func_box_gui()
+        UIAPI.update_filter_func_box_gui()
 
     @staticmethod
     def del_filter_func():
-        index = get_filter_func_box_index_gui()
+        index = UIAPI.get_filter_func_box_index_gui()
         url.del_filter_func(index)
-        update_filter_func_box_gui()
+        UIAPI.update_filter_func_box_gui()
 
     @staticmethod
     def del_url():
-        index = get_url_box_index_gui()
+        index = UIAPI.get_url_box_index_gui()
         url.del_url(index)
-        update_url_box_gui()
+        UIAPI.update_url_box_gui()
 
     @staticmethod
     def add_url():
-        args = get_url_parameter_gui()
-        new_url = get_new_url_name_gui()
+        args = UIAPI.get_url_parameter_gui()
+        new_url = UIAPI.get_new_url_name_gui()
         if new_url == "":
             return
         url.add_url(new_url, **args)
-        update_url_box_gui()
+        UIAPI.update_url_box_gui()
 
     @staticmethod
     def add_url_from_tag():
-        page_parser.add_url(**add_url_from_tag_gui())
-        update_parser_func_box_gui()
+        page_parser.add_url(**UIAPI.add_url_from_tag_gui())
+        UIAPI.update_parser_func_box_gui()
+
+
+def crawler_main():
+    global SCREEN
+    SCREEN.mainloop()
+    loader.stop()
+    database.close_all()
+    url.close()
+    loader.close()
 
 
 SCREEN.title("CoTan自动化网页")

文件差異過大導致無法顯示
+ 383 - 386
datascience/gui.py


+ 17 - 9
draftboard/customfunctions.py

@@ -63,22 +63,30 @@ class FunctionExpression:
 
 
 def custom():
-    global func_input, help_doc, logger
-    func_str = func_input.get().replace(" ", "")
+    global help_doc, logger
+    func_str = UIAPI.get_func_str_gui()
     if func_str:
-        if tkinter.messagebox.askokcancel(
-            "提示", f"是否确认生成自定义函数:\n{func_input.get()}\n(点击取消可撤销未执行的制造函数)"
-        ):
+        if UIAPI.askok_gui(f"是否确认生成自定义函数:\n{func_input.get()}\n(点击取消可撤销未执行的制造函数)"):
             logger.set(FunctionExpression(func_input.get()))
         else:
             logger.set(None)
     else:
-        if tkinter.messagebox.askokcancel("提示", f"点击确定撤销为执行的制造函数"):
+        if UIAPI.askok_gui(f"点击确定撤销为执行的制造函数"):
             logger.set(None)
 
 
-def get_help():
-    tkinter.messagebox.showinfo(title="帮助", message=help_doc)
+class UIAPI:
+    @staticmethod
+    def get_help_gui():
+        tkinter.messagebox.showinfo(title="帮助", message=help_doc)
+
+    @staticmethod
+    def get_func_str_gui():
+        return func_input.get().replace(" ", "")
+
+    @staticmethod
+    def askok_gui(message):
+        return tkinter.messagebox.askokcancel("提示", message)
 
 
 def make_func():
@@ -99,7 +107,7 @@ def make_func():
     help = tkinter.Button(
         SCREEN,
         text="帮助",
-        command=get_help,
+        command=UIAPI.get_help_gui,
         width=28,
         height=1,
         bg=bg_color,

+ 192 - 184
draftboard/drawingfunction.py

@@ -22,169 +22,177 @@ class Logger:
         return func_dict
 
 
-def linear_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制1次函数(点击取消可撤销未执行的函数)"):
-        func_dict[1] = lambda x: x
-    else:
-        func_dict[1] = None
-
-
-def quadratic_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制2次函数(点击取消可撤销未执行的函数)"):
-        func_dict[2] = lambda x: x ** 2
-    else:
-        func_dict[2] = None
-
-
-def cubic_function():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制3次函数(点击取消可撤销未执行的函数)"):
-        func_dict[4] = lambda x: x ** 3
-    else:
-        func_dict[4] = None
-
-
-def inverse_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制-1次函数(点击取消可撤销未执行的函数)"):
-        func_dict[3] = lambda x: 1 / x
-    else:
-        func_dict[3] = None
-
-
-def radical_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制根号函数(点击取消可撤销未执行的函数)"):
-        func_dict[5] = lambda x: x ** (1 / 2)
-    else:
-        func_dict[5] = None
-
-
-def exp_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制指数函数(点击取消可撤销未执行的函数)"):
-        func_dict[6] = lambda x: 10 ** x
-    else:
-        func_dict[6] = None
-
-
-def log_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制对数函数(点击取消可撤销未执行的函数)"):
-        func_dict[7] = lambda x: math.log(x, 2)
-    else:
-        func_dict[7] = None
-
-
-def log2_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制对数函数2(点击取消可撤销未执行的函数)"):
-        func_dict[8] = lambda x: math.log(2, x)
-    else:
-        func_dict[8] = None
-
-
-def sin_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制正弦函数(点击取消可撤销未执行的函数)"):
-        func_dict[9] = lambda x: math.sin(x)
-    else:
-        func_dict[9] = None
-
-
-def cos_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制余弦函数(点击取消可撤销未执行的函数)"):
-        func_dict[10] = lambda x: math.cos(x)
-    else:
-        func_dict[10] = None
-
-
-def tan_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制正切函数(点击取消可撤销未执行的函数)"):
-        func_dict[11] = lambda x: math.tan(x)
-    else:
-        func_dict[11] = None
-
-
-def cot_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制余切函数(点击取消可撤销未执行的函数)"):
-        func_dict[12] = lambda x: 1 / math.tan(x)
-    else:
-        func_dict[12] = None
-
-
-def sec_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制正割函数(点击取消可撤销未执行的函数)"):
-        func_dict[13] = lambda x: 1 / math.cos(x)
-    else:
-        func_dict[13] = None
-
-
-def csc_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制余割函数(点击取消可撤销未执行的函数)"):
-        func_dict[11] = lambda x: 1 / math.sin(x)
-    else:
-        func_dict[11] = None
-
-
-def arcsin_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制反正弦函数(点击取消可撤销未执行的函数)"):
-        func_dict[12] = lambda x: math.asin(x)
-    else:
-        func_dict[12] = None
-
-
-def arccos_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制反余弦函数(点击取消可撤销未执行的函数)"):
-        func_dict[13] = lambda x: math.acos(x)
-    else:
-        func_dict[13] = None
-
-
-def arctan_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制反正切函数(点击取消可撤销未执行的函数)"):
-        func_dict[14] = lambda x: math.atan(x)
-    else:
-        func_dict[14] = None
-
-
-def arccot_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制反余切函数(点击取消可撤销未执行的函数)"):
-        func_dict[15] = lambda x: 1 / math.atan(x)
-    else:
-        func_dict[15] = None
-
-
-def arcsec_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制反正割函数(点击取消可撤销未执行的函数)"):
-        func_dict[16] = lambda x: 1 / math.acos(x)
-    else:
-        func_dict[16] = None
-
-
-def arccsc_func():
-    global func_dict
-    if tkinter.messagebox.askokcancel("提示", "是否绘制反余割函数(点击取消可撤销未执行的函数)"):
-        func_dict[17] = lambda x: 1 / math.asin(x)
-    else:
-        func_dict[17] = None
-
-
-def custom_func():
-    global func_dict, custom_function_index, custom_func_dict
-    custom_func_dict[custom_function_index] = customfunctions.make_func()
+class UIAPI:
+    @staticmethod
+    def askok_gui(message):
+        return tkinter.messagebox.askokcancel('提示', message)
+
+
+class API:
+    @staticmethod
+    def linear_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制1次函数(点击取消可撤销未执行的函数)"):
+            func_dict[1] = lambda x: x
+        else:
+            func_dict[1] = None
+
+    @staticmethod
+    def quadratic_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制2次函数(点击取消可撤销未执行的函数)"):
+            func_dict[2] = lambda x: x ** 2
+        else:
+            func_dict[2] = None
+
+    @staticmethod
+    def cubic_function():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制3次函数(点击取消可撤销未执行的函数)"):
+            func_dict[4] = lambda x: x ** 3
+        else:
+            func_dict[4] = None
+
+    @staticmethod
+    def inverse_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制-1次函数(点击取消可撤销未执行的函数)"):
+            func_dict[3] = lambda x: 1 / x
+        else:
+            func_dict[3] = None
+
+    @staticmethod
+    def radical_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制根号函数(点击取消可撤销未执行的函数)"):
+            func_dict[5] = lambda x: x ** (1 / 2)
+        else:
+            func_dict[5] = None
+
+    @staticmethod
+    def exp_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制指数函数(点击取消可撤销未执行的函数)"):
+            func_dict[6] = lambda x: 10 ** x
+        else:
+            func_dict[6] = None
+
+    @staticmethod
+    def log_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制对数函数(点击取消可撤销未执行的函数)"):
+            func_dict[7] = lambda x: math.log(x, 2)
+        else:
+            func_dict[7] = None
+
+    @staticmethod
+    def log2_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制对数函数2(点击取消可撤销未执行的函数)"):
+            func_dict[8] = lambda x: math.log(2, x)
+        else:
+            func_dict[8] = None
+
+    @staticmethod
+    def sin_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制正弦函数(点击取消可撤销未执行的函数)"):
+            func_dict[9] = lambda x: math.sin(x)
+        else:
+            func_dict[9] = None
+
+    @staticmethod
+    def cos_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制余弦函数(点击取消可撤销未执行的函数)"):
+            func_dict[10] = lambda x: math.cos(x)
+        else:
+            func_dict[10] = None
+
+    @staticmethod
+    def tan_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制正切函数(点击取消可撤销未执行的函数)"):
+            func_dict[11] = lambda x: math.tan(x)
+        else:
+            func_dict[11] = None
+
+    @staticmethod
+    def cot_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制余切函数(点击取消可撤销未执行的函数)"):
+            func_dict[12] = lambda x: 1 / math.tan(x)
+        else:
+            func_dict[12] = None
+
+    @staticmethod
+    def sec_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制正割函数(点击取消可撤销未执行的函数)"):
+            func_dict[13] = lambda x: 1 / math.cos(x)
+        else:
+            func_dict[13] = None
+
+    @staticmethod
+    def csc_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制余割函数(点击取消可撤销未执行的函数)"):
+            func_dict[11] = lambda x: 1 / math.sin(x)
+        else:
+            func_dict[11] = None
+
+    @staticmethod
+    def arcsin_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制反正弦函数(点击取消可撤销未执行的函数)"):
+            func_dict[12] = lambda x: math.asin(x)
+        else:
+            func_dict[12] = None
+
+    @staticmethod
+    def arccos_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制反余弦函数(点击取消可撤销未执行的函数)"):
+            func_dict[13] = lambda x: math.acos(x)
+        else:
+            func_dict[13] = None
+
+    @staticmethod
+    def arctan_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制反正切函数(点击取消可撤销未执行的函数)"):
+            func_dict[14] = lambda x: math.atan(x)
+        else:
+            func_dict[14] = None
+
+    @staticmethod
+    def arccot_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制反余切函数(点击取消可撤销未执行的函数)"):
+            func_dict[15] = lambda x: 1 / math.atan(x)
+        else:
+            func_dict[15] = None
+
+    @staticmethod
+    def arcsec_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制反正割函数(点击取消可撤销未执行的函数)"):
+            func_dict[16] = lambda x: 1 / math.acos(x)
+        else:
+            func_dict[16] = None
+
+    @staticmethod
+    def arccsc_func():
+        global func_dict
+        if UIAPI.askok_gui("是否绘制反余割函数(点击取消可撤销未执行的函数)"):
+            func_dict[17] = lambda x: 1 / math.asin(x)
+        else:
+            func_dict[17] = None
+
+    @staticmethod
+    def custom_func():
+        global func_dict, custom_function_index, custom_func_dict
+        custom_func_dict[custom_function_index] = customfunctions.make_func()
 
 
 def func_box():
@@ -199,7 +207,7 @@ def func_box():
         text="1次函数",
         bg=bg_color,
         fg=word_color,
-        command=linear_func,
+        command=API.linear_func,
         width=width,
         height=1,
     ).pack()
@@ -208,7 +216,7 @@ def func_box():
         text="2次函数",
         bg=bg_color,
         fg=word_color,
-        command=quadratic_func,
+        command=API.quadratic_func,
         width=width,
         height=1,
     ).pack()
@@ -217,7 +225,7 @@ def func_box():
         text="-1次函数",
         bg=bg_color,
         fg=word_color,
-        command=inverse_func,
+        command=API.inverse_func,
         width=width,
         height=1,
     ).pack()
@@ -226,7 +234,7 @@ def func_box():
         text="3次函数",
         bg=bg_color,
         fg=word_color,
-        command=cubic_function,
+        command=API.cubic_function,
         width=width,
         height=1,
     ).pack()
@@ -235,7 +243,7 @@ def func_box():
         text="根号函数",
         bg=bg_color,
         fg=word_color,
-        command=radical_func,
+        command=API.radical_func,
         width=width,
         height=1,
     ).pack()
@@ -244,7 +252,7 @@ def func_box():
         text="对数函数",
         bg=bg_color,
         fg=word_color,
-        command=log_func,
+        command=API.log_func,
         width=width,
         height=1,
     ).pack()
@@ -253,7 +261,7 @@ def func_box():
         text="指数函数",
         bg=bg_color,
         fg=word_color,
-        command=exp_func,
+        command=API.exp_func,
         width=width,
         height=1,
     ).pack()
@@ -262,7 +270,7 @@ def func_box():
         text="对数底函数",
         bg=bg_color,
         fg=word_color,
-        command=log2_func,
+        command=API.log2_func,
         width=width,
         height=1,
     ).pack()
@@ -271,7 +279,7 @@ def func_box():
         text="sin函数",
         bg=bg_color,
         fg=word_color,
-        command=sin_func,
+        command=API.sin_func,
         width=width,
         height=1,
     ).pack()
@@ -280,7 +288,7 @@ def func_box():
         text="cos函数",
         bg=bg_color,
         fg=word_color,
-        command=cos_func,
+        command=API.cos_func,
         width=width,
         height=1,
     ).pack()
@@ -289,7 +297,7 @@ def func_box():
         text="tan函数",
         bg=bg_color,
         fg=word_color,
-        command=tan_func,
+        command=API.tan_func,
         width=width,
         height=1,
     ).pack()
@@ -298,7 +306,7 @@ def func_box():
         text="cot函数",
         bg=bg_color,
         fg=word_color,
-        command=tan_func,
+        command=API.tan_func,
         width=width,
         height=1,
     ).pack()
@@ -307,7 +315,7 @@ def func_box():
         text="csc函数",
         bg=bg_color,
         fg=word_color,
-        command=csc_func,
+        command=API.csc_func,
         width=width,
         height=1,
     ).pack()
@@ -316,7 +324,7 @@ def func_box():
         text="sec函数",
         bg=bg_color,
         fg=word_color,
-        command=sec_func,
+        command=API.sec_func,
         width=width,
         height=1,
     ).pack()
@@ -325,7 +333,7 @@ def func_box():
         text="arcsin函数",
         bg=bg_color,
         fg=word_color,
-        command=arcsin_func,
+        command=API.arcsin_func,
         width=width,
         height=1,
     ).pack()
@@ -334,7 +342,7 @@ def func_box():
         text="arccos函数",
         bg=bg_color,
         fg=word_color,
-        command=arccos_func,
+        command=API.arccos_func,
         width=width,
         height=1,
     ).pack()
@@ -343,7 +351,7 @@ def func_box():
         text="arctan函数",
         bg=bg_color,
         fg=word_color,
-        command=arctan_func,
+        command=API.arctan_func,
         width=width,
         height=1,
     ).pack()
@@ -352,7 +360,7 @@ def func_box():
         text="arccot函数",
         bg=bg_color,
         fg=word_color,
-        command=arccot_func,
+        command=API.arccot_func,
         width=width,
         height=1,
     ).pack()
@@ -361,7 +369,7 @@ def func_box():
         text="arccsc函数",
         bg=bg_color,
         fg=word_color,
-        command=arccsc_func,
+        command=API.arccsc_func,
         width=width,
         height=1,
     ).pack()
@@ -370,7 +378,7 @@ def func_box():
         text="arcsec函数",
         bg=bg_color,
         fg=word_color,
-        command=arcsec_func,
+        command=API.arcsec_func,
         width=width,
         height=1,
     ).pack()
@@ -379,7 +387,7 @@ def func_box():
         text="自定义函数",
         bg=bg_color,
         fg=word_color,
-        command=custom_func,
+        command=API.custom_func,
         width=width,
         height=3,
     ).pack()

+ 148 - 140
draftboard/toolbox.py

@@ -66,122 +66,107 @@ help_doc = """
 """
 
 
-def increasing_func_color():
-    global increasing_color
-    increasing_color = askcolor(title="选择颜色")[0]
-
-
-def subtraction_func_color():
-    global subtraction_color
-    subtraction_color = askcolor(title="选择颜色")[0]
-
-
-def select_color():
-    global pen_color
-    pen_color = askcolor(title="选择颜色")[0]
-
-
-def choose_save():
-    global save_dir
-    save_dir = asksaveasfilename(
-        title="选择保存位置", filetypes=[("PNG", ".png")]
-    )
-    if not save_dir:
-        save_dir = None
-    else:
-        save_dir += ".png"
-
-
-def choose_open():
-    global background_image
-    background_image = askopenfilename(
-        title="选择载入图片", filetypes=[("PNG", ".png"), ("JPG", ".jpg")]
-    )
-    if not background_image:
-        background_image = None
-
-
-def switch_brush():
-    global pen_weight
-    if tkinter.messagebox.askokcancel("提示", "要切换到刷子吗(可当橡皮使用)"):
-        pen_weight = 10
-
-
-def switch_big():
-    global pen_weight
-    if tkinter.messagebox.askokcancel("提示", "要切换到大笔吗"):
-        pen_weight = 3
-
-
-def set_pen():
-    global pen_weight, pen_weight_input
-    pen = pen_weight_input.get().replace(" ", "")
-    try:
-        pen = int(pen)
-        if tkinter.messagebox.askokcancel("提示", f"是否设定大小为{pen}(系统默认大小为:2)"):
-            pen_weight = pen
-    except BaseException:
-        if tkinter.messagebox.askokcancel("提示", "设置失败,是否要切换到中笔吗"):
+class UIAPI:
+    @staticmethod
+    def askok_gui(message):
+        return tkinter.messagebox.askokcancel('提示', message)
+
+
+class API:
+    @staticmethod
+    def increasing_func_color():
+        global increasing_color
+        increasing_color = askcolor(title="选择颜色")[0]
+
+    @staticmethod
+    def subtraction_func_color():
+        global subtraction_color
+        subtraction_color = askcolor(title="选择颜色")[0]
+
+    @staticmethod
+    def select_color():
+        global pen_color
+        pen_color = askcolor(title="选择颜色")[0]
+
+    @staticmethod
+    def choose_save():
+        global save_dir
+        save_dir = asksaveasfilename(
+            title="选择保存位置", filetypes=[("PNG", ".png")]
+        )
+        if not save_dir:
+            save_dir = None
+        else:
+            save_dir += ".png"
+
+    @staticmethod
+    def choose_open():
+        global background_image
+        background_image = askopenfilename(
+            title="选择载入图片", filetypes=[("PNG", ".png"), ("JPG", ".jpg")]
+        )
+        if not background_image:
+            background_image = None
+
+    @staticmethod
+    def switch_brush():
+        global pen_weight
+        if UIAPI.askok_gui("要切换到刷子吗(可当橡皮使用)"):
+            pen_weight = 10
+
+    @staticmethod
+    def switch_big():
+        global pen_weight
+        if UIAPI.askok_gui("要切换到大笔吗"):
+            pen_weight = 3
+
+    @staticmethod
+    def set_pen():
+        global pen_weight, pen_weight_input
+        pen = pen_weight_input.get().replace(" ", "")
+        try:
+            pen = int(pen)
+            if UIAPI.askok_gui(f"是否设定大小为{pen}(系统默认大小为:2)"):
+                pen_weight = pen
+        except BaseException:
+            if UIAPI.askok_gui("设置失败,是否要切换到中笔吗"):
+                pen_weight = 2
+
+    @staticmethod
+    def switch_stroke():
+        global pen_weight
+        if UIAPI.askok_gui("要切换到中笔吗"):
             pen_weight = 2
 
+    @staticmethod
+    def switch_small():
+        global pen_weight
+        if UIAPI.askok_gui("要切换到小笔吗?"):
+            pen_weight = 1
 
-def switch_stroke():
-    global pen_weight
-    if tkinter.messagebox.askokcancel("提示", "要切换到中笔吗"):
-        pen_weight = 2
-
-
-def switch_small():
-    global pen_weight
-    if tkinter.messagebox.askokcancel("提示", "要切换到小笔吗?"):
-        pen_weight = 1
-
-
-def plot_coordinate():
-    global coordinate_system_drawing_method
-    if tkinter.messagebox.askokcancel(
-        "提示", "是否绘制坐标系,确定后返回草图界面任一点三点开始绘制(点击取消可撤销未执行的清空)"
-    ):
-        coordinate_system_drawing_method = 1
-    else:
-        coordinate_system_drawing_method = None
-
-
-def plot_coordinate_small():
-    global coordinate_system_drawing_method
-    if tkinter.messagebox.askokcancel(
-        "提示", "是否绘制小跨度的坐标系,确定后返回草图界面任一点三点开始绘制(点击取消可撤销未执行的清空)"
-    ):
-        coordinate_system_drawing_method = 2
-    else:
-        coordinate_system_drawing_method = None
-
-
-def plot_coordinate_big_span():
-    global coordinate_system_drawing_method
-    if tkinter.messagebox.askokcancel(
-        "提示", "是否绘制大跨度的坐标系,确定后返回草图界面任一点三点开始绘制(点击取消可撤销未执行的清空)"
-    ):
-        coordinate_system_drawing_method = 3
-    else:
-        coordinate_system_drawing_method = None
-
-
-def set_span():
-    global coordinate_system_drawing_method, span, span_input
-    span_input_str = span_input.get().replace(" ", "")
-    try:
-        span_input_str = int(span_input_str)
+    @staticmethod
+    def plot_coordinate():
+        global coordinate_system_drawing_method
         if tkinter.messagebox.askokcancel(
-            "提示", f"是否设定跨度为{span_input_str}(跨度代表坐标系一个单位大小的实际像素,系统默认大跨度为:120)"
+            "提示", "是否绘制坐标系,确定后返回草图界面任一点三点开始绘制(点击取消可撤销未执行的清空)"
         ):
-            span = span_input_str
             coordinate_system_drawing_method = 1
         else:
             coordinate_system_drawing_method = None
-            span = None
-    except BaseException:
-        span = None
+
+    @staticmethod
+    def plot_coordinate_small():
+        global coordinate_system_drawing_method
+        if tkinter.messagebox.askokcancel(
+            "提示", "是否绘制小跨度的坐标系,确定后返回草图界面任一点三点开始绘制(点击取消可撤销未执行的清空)"
+        ):
+            coordinate_system_drawing_method = 2
+        else:
+            coordinate_system_drawing_method = None
+
+    @staticmethod
+    def plot_coordinate_big_span():
+        global coordinate_system_drawing_method
         if tkinter.messagebox.askokcancel(
             "提示", "是否绘制大跨度的坐标系,确定后返回草图界面任一点三点开始绘制(点击取消可撤销未执行的清空)"
         ):
@@ -189,23 +174,46 @@ def set_span():
         else:
             coordinate_system_drawing_method = None
 
+    @staticmethod
+    def set_span():
+        global coordinate_system_drawing_method, span, span_input
+        span_input_str = span_input.get().replace(" ", "")
+        try:
+            span_input_str = int(span_input_str)
+            if tkinter.messagebox.askokcancel(
+                "提示", f"是否设定跨度为{span_input_str}(跨度代表坐标系一个单位大小的实际像素,系统默认大跨度为:120)"
+            ):
+                span = span_input_str
+                coordinate_system_drawing_method = 1
+            else:
+                coordinate_system_drawing_method = None
+                span = None
+        except BaseException:
+            span = None
+            if tkinter.messagebox.askokcancel(
+                "提示", "是否绘制大跨度的坐标系,确定后返回草图界面任一点三点开始绘制(点击取消可撤销未执行的清空)"
+            ):
+                coordinate_system_drawing_method = 3
+            else:
+                coordinate_system_drawing_method = None
+
+    @staticmethod
+    def empty():
+        global background_color
+        if UIAPI.askok_gui("是否清空草稿(点击取消可撤销未执行的清空)"):
+            background_color = askcolor(title="选择背景颜色")[0]
+        else:
+            background_color = None
 
-def empty():
-    global background_color
-    if tkinter.messagebox.askokcancel("提示", "是否清空草稿(点击取消可撤销未执行的清空)"):
-        background_color = askcolor(title="选择背景颜色")[0]
-    else:
-        background_color = None
-
-
-def open_func_box():
-    global func_logger
-    func_logger = drawingfunction.func_box()
-
+    @staticmethod
+    def open_func_box():
+        global func_logger
+        func_logger = drawingfunction.func_box()
 
-def _help():
-    global help_doc
-    tkinter.messagebox.showinfo(title="帮助", message=help_doc)
+    @staticmethod
+    def show_help():
+        global help_doc
+        tkinter.messagebox.showinfo(title="帮助", message=help_doc)
 
 
 def tool_box():
@@ -220,7 +228,7 @@ def tool_box():
         text="选择颜色",
         bg=bg_color,
         fg=word_color,
-        command=select_color,
+        command=API.select_color,
         width=gui_width,
         height=gui_height,
     ).pack()
@@ -229,7 +237,7 @@ def tool_box():
         text="选择增函数颜色",
         bg=bg_color,
         fg=word_color,
-        command=increasing_func_color,
+        command=API.increasing_func_color,
         width=gui_width,
         height=1,
     ).pack()
@@ -238,7 +246,7 @@ def tool_box():
         text="选择减函数颜色",
         bg=bg_color,
         fg=word_color,
-        command=subtraction_func_color,
+        command=API.subtraction_func_color,
         width=gui_width,
         height=1,
     ).pack()
@@ -247,7 +255,7 @@ def tool_box():
         text="使用中笔(默认笔)",
         bg=bg_color,
         fg=word_color,
-        command=switch_stroke,
+        command=API.switch_stroke,
         width=gui_width,
         height=gui_height,
     ).pack()
@@ -256,7 +264,7 @@ def tool_box():
         text="使用大笔",
         bg=bg_color,
         fg=word_color,
-        command=switch_big,
+        command=API.switch_big,
         width=gui_width,
         height=1,
     ).pack()  # 切换到大笔
@@ -265,7 +273,7 @@ def tool_box():
         text="使用小笔",
         bg=bg_color,
         fg=word_color,
-        command=switch_small,
+        command=API.switch_small,
         width=gui_width,
         height=1,
     ).pack()  # 切换笔
@@ -274,7 +282,7 @@ def tool_box():
         text="使用刷子",
         bg=bg_color,
         fg=word_color,
-        command=switch_brush,
+        command=API.switch_brush,
         width=gui_width,
         height=1,
     ).pack()  # 切换笔
@@ -285,7 +293,7 @@ def tool_box():
         text="使用自定义大小",
         bg=bg_color,
         fg=word_color,
-        command=set_pen,
+        command=API.set_pen,
         width=gui_width,
         height=1,
     ).pack()  # 切换笔
@@ -294,7 +302,7 @@ def tool_box():
         text="清空草稿",
         bg=bg_color,
         fg=word_color,
-        command=empty,
+        command=API.empty,
         width=gui_width,
         height=gui_height,
     ).pack()  # 填充背景
@@ -303,7 +311,7 @@ def tool_box():
         text="绘制坐标系",
         bg=bg_color,
         fg=word_color,
-        command=plot_coordinate,
+        command=API.plot_coordinate,
         width=gui_width,
         height=gui_height,
     ).pack()
@@ -312,14 +320,14 @@ def tool_box():
         text="绘制坐标系(小跨度)",
         bg=bg_color,
         fg=word_color,
-        command=plot_coordinate_small,
+        command=API.plot_coordinate_small,
         width=gui_width,
         height=1,
     ).pack()
     tkinter.Button(
         SCREEN,
         text="绘制坐标系(大跨度)",
-        command=plot_coordinate_big_span,
+        command=API.plot_coordinate_big_span,
         width=gui_width,
         height=1,
         bg=bg_color,
@@ -332,7 +340,7 @@ def tool_box():
         text="使用自定义跨度",
         bg=bg_color,
         fg=word_color,
-        command=set_span,
+        command=API.set_span,
         width=gui_width,
         height=1,
     ).pack()  # 切换笔
@@ -341,7 +349,7 @@ def tool_box():
         text="绘制函数",
         bg=bg_color,
         fg=word_color,
-        command=open_func_box,
+        command=API.open_func_box,
         width=gui_width,
         height=gui_height,
     ).pack()
@@ -350,7 +358,7 @@ def tool_box():
         text="保存",
         bg=bg_color,
         fg=word_color,
-        command=choose_save,
+        command=API.choose_save,
         width=gui_width,
         height=1,
     ).pack()
@@ -359,7 +367,7 @@ def tool_box():
         text="载入",
         bg=bg_color,
         fg=word_color,
-        command=choose_open,
+        command=API.choose_open,
         width=gui_width,
         height=1,
     ).pack()
@@ -368,7 +376,7 @@ def tool_box():
         text="帮助",
         bg=bg_color,
         fg=word_color,
-        command=_help,
+        command=API.show_help,
         width=gui_width,
         height=1,
     ).pack()  # help是系统保留关键词,用_help代替

+ 0 - 1
funcsystem/map.py

@@ -545,7 +545,6 @@ class API:
 
 def function_mapping():
     global SCREEN
-
     SCREEN.mainloop()
 
 

文件差異過大導致無法顯示
+ 504 - 507
gitrepo/gui.py


+ 231 - 229
machinelearning/gui.py

@@ -28,187 +28,184 @@ FONT = ("黑体", 11)  # 设置字体
 learn_dict = {}
 
 
-def get_split_shape_list_gui():
-    try:
-        split_shape_list = eval(f"[{shape.get()}]", {})[0]
-    except BaseException:
-        split_shape_list = 2
-    return split_shape_list
-
-
-def get_reval_type_gui():
-    return processing_type.get()
-
-
-def update_sheet_box_gui():
-    global SCREEN, sheet_box, sheet_list
-    sheet_list = list(learner_controller.get_form().keys())
-    sheet_box.delete(0, tkinter.END)
-    sheet_box.insert(tkinter.END, *sheet_list)
-
-
-def creat_text_sheet_gui(data, name):
-    global bg_color
-    new_top = tkinter.Toplevel(bg=bg_color)
-    new_top.title(name)
-    new_top.geometry("+10+10")  # 设置所在位置
-    text = ScrolledText(new_top, font=("黑体", 13), height=50)
-    text.pack(fill=tkinter.BOTH)
-    text.insert("0.0", data)
-    text.config(state=tkinter.DISABLED)
-    new_top.resizable(width=False, height=False)
-
-
-def add_python_gui():
-    python_dir = askopenfilename(
-        title="选择载入的py", filetypes=[("Python", ".py"), ("Txt", ".txt")]
-    )
-    name = sheet_name.get().replace(" ", "")
-    if name == "":
-        name = os.path.splitext(os.path.split(python_dir)[1])[0]
-    with open(python_dir, "r") as f:
-        code = f.read()
-    return code, name
-
-
-def get_data_name_gui(get_from_box=True, is_x_data=True):  # 获得名字统一接口
-    global sheet_list, sheet_box, x_data
-    if get_from_box:
-        try:
-            return sheet_list[sheet_box.curselection()[0]]
-        except BaseException:
-            try:
-                return sheet_list[0]
-            except BaseException:
-                return None
-    else:
+class UIAPI:
+    @staticmethod
+    def get_split_shape_list_gui():
         try:
-            if is_x_data:
-                return x_data.get()
-            else:
-                return y_data.get()
+            split_shape_list = eval(f"[{shape.get()}]", {})[0]
         except BaseException:
-            return None
-
-
-def add_csv_gui():
-    csv_dir = askopenfilename(title="选择载入的CSV", filetypes=[("CSV", ".csv")])
-    the_sep = sep.get()
-    the_encoding = encoding.get()
-    must_str = bool(dtype_str.get())
-    name = sheet_name.get().replace(" ", "")
-    if name == "":
-        name = os.path.splitext(os.path.split(csv_dir)[1])[0]
-    if the_encoding == "":
-        with open(csv_dir, "rb") as f:
-            the_encoding = chardet.detect(f.read())["encoding"]
-    if the_sep == "":
-        the_sep = ","
-    return csv_dir, name, the_encoding, must_str, the_sep
+            split_shape_list = 2
+        return split_shape_list
 
+    @staticmethod
+    def get_reval_type_gui():
+        return processing_type.get()
 
-def to_csv_gui():
-    save_dir = asksaveasfilename(title="选择保存的CSV", filetypes=[("CSV", ".csv")])
-    csv_sep = sep.get()
-    name = get_data_name_gui()
-    return save_dir, name, csv_sep
-
-
-def update_leaner_gui():
-    global learn_dict, learner_box
-    learn_dict = learner_controller.return_learner()
-    learner_box.delete(0, tkinter.END)
-    learner_box.insert(tkinter.END, *learn_dict.keys())
-
-
-def set_x_data_gui():
-    global x_data
-    x_data.set(get_data_name_gui())
-
-
-def set_y_data_gui():
-    global y_data
-    y_data.set(get_data_name_gui())
-
+    @staticmethod
+    def update_sheet_box_gui():
+        global SCREEN, sheet_box, sheet_list
+        sheet_list = list(learner_controller.get_form().keys())
+        sheet_box.delete(0, tkinter.END)
+        sheet_box.insert(tkinter.END, *sheet_list)
 
-def set_learner_gui():
-    global learner_output
-    learner_output.set(get_learner_gui(True))
+    @staticmethod
+    def creat_text_sheet_gui(data, name):
+        global bg_color
+        new_top = tkinter.Toplevel(bg=bg_color)
+        new_top.title(name)
+        new_top.geometry("+10+10")  # 设置所在位置
+        text = ScrolledText(new_top, font=("黑体", 13), height=50)
+        text.pack(fill=tkinter.BOTH)
+        text.insert("0.0", data)
+        text.config(state=tkinter.DISABLED)
+        new_top.resizable(width=False, height=False)
 
+    @staticmethod
+    def add_python_gui():
+        python_dir = askopenfilename(
+            title="选择载入的py", filetypes=[("Python", ".py"), ("Txt", ".txt")]
+        )
+        name = sheet_name.get().replace(" ", "")
+        if name == "":
+            name = os.path.splitext(os.path.split(python_dir)[1])[0]
+        with open(python_dir, "r") as f:
+            code = f.read()
+        return code, name
 
-def get_learner_gui(return_box=False):
-    global learn_dict, learner_box, learner_output
-    if return_box:
-        try:
-            return list(learn_dict.keys())[learner_box.curselection()[0]]
-        except BaseException:
+    @staticmethod
+    def get_data_name_gui(get_from_box=True, is_x_data=True):  # 获得名字统一接口
+        global sheet_list, sheet_box, x_data
+        if get_from_box:
             try:
-                return list(learn_dict.keys)[0]
+                return sheet_list[sheet_box.curselection()[0]]
             except BaseException:
-                return get_learner_gui(False)
-    else:
-        try:
-            return learner_output.get()
-        except BaseException:
-            return None
-
-
-def show_score_gui(message):
-    tkinter.messagebox.showinfo("完成", message)
-
-
-def get_learner_parameters_gui():
-    global learner_parameters
-    return learner_parameters.get("0.0", tkinter.END)
-
+                try:
+                    return sheet_list[0]
+                except BaseException:
+                    return None
+        else:
+            try:
+                if is_x_data:
+                    return x_data.get()
+                else:
+                    return y_data.get()
+            except BaseException:
+                return None
 
-def get_merge_box_index_gui():
-    return merge_box.curselection()[0]
+    @staticmethod
+    def add_csv_gui():
+        csv_dir = askopenfilename(title="选择载入的CSV", filetypes=[("CSV", ".csv")])
+        the_sep = sep.get()
+        the_encoding = encoding.get()
+        must_str = bool(dtype_str.get())
+        name = sheet_name.get().replace(" ", "")
+        if name == "":
+            name = os.path.splitext(os.path.split(csv_dir)[1])[0]
+        if the_encoding == "":
+            with open(csv_dir, "rb") as f:
+                the_encoding = chardet.detect(f.read())["encoding"]
+        if the_sep == "":
+            the_sep = ","
+        return csv_dir, name, the_encoding, must_str, the_sep
 
+    @staticmethod
+    def to_csv_gui():
+        save_dir = asksaveasfilename(title="选择保存的CSV", filetypes=[("CSV", ".csv")])
+        csv_sep = sep.get()
+        name = UIAPI.get_data_name_gui()
+        return save_dir, name, csv_sep
 
-def update_merge_box_gui():
-    global merge_list, merge_box
-    merge_box.delete(0, tkinter.END)
-    merge_box.insert(tkinter.END, *merge_list)
+    @staticmethod
+    def update_leaner_gui():
+        global learn_dict, learner_box
+        learn_dict = learner_controller.return_learner()
+        learner_box.delete(0, tkinter.END)
+        learner_box.insert(tkinter.END, *learn_dict.keys())
 
+    @staticmethod
+    def set_x_data_gui():
+        global x_data
+        x_data.set(UIAPI.get_data_name_gui())
 
-def get_merge_split_type_gui():
-    return processing_type.get()
+    @staticmethod
+    def set_y_data_gui():
+        global y_data
+        y_data.set(UIAPI.get_data_name_gui())
 
+    @staticmethod
+    def set_learner_gui():
+        global learner_output
+        learner_output.set(UIAPI.get_learner_gui(True))
 
-def get_shape_gui():
-    return eval(f"[{shape.get()}]")[0]
+    @staticmethod
+    def get_learner_gui(return_box=False):
+        global learn_dict, learner_box, learner_output
+        if return_box:
+            try:
+                return list(learn_dict.keys())[learner_box.curselection()[0]]
+            except BaseException:
+                try:
+                    return list(learn_dict.keys)[0]
+                except BaseException:
+                    return UIAPI.get_learner_gui(False)
+        else:
+            try:
+                return learner_output.get()
+            except BaseException:
+                return None
 
+    @staticmethod
+    def show_score_gui(message):
+        tkinter.messagebox.showinfo("完成", message)
 
-def global_settings_gui():
-    return [bool(i.get()) for i in global_settings]
+    @staticmethod
+    def get_learner_parameters_gui():
+        global learner_parameters
+        return learner_parameters.get("0.0", tkinter.END)
 
+    @staticmethod
+    def get_merge_box_index_gui():
+        return merge_box.curselection()[0]
 
-def get_calculation_num_gui():
-    return eval(value.get(), {})
+    @staticmethod
+    def update_merge_box_gui():
+        global merge_list, merge_box
+        merge_box.delete(0, tkinter.END)
+        merge_box.insert(tkinter.END, *merge_list)
 
+    @staticmethod
+    def get_merge_split_type_gui():
+        return processing_type.get()
 
-def update_calculation_box_gui():
-    global calculation_list, calculation_method, calculation_box
-    calculation_box.delete(0, tkinter.END)
-    a = ["第一参数", "第二参数"]
-    b = ["参数", "矩阵"]
-    calculation_box.insert(
-        tkinter.END,
-        *[
-            f"{a[i]} {calculation_list[i]} {b[calculation_method[i]]}"
-            for i in range(len(calculation_list))
-        ],
-    )
+    @staticmethod
+    def get_shape_gui():
+        return eval(f"[{shape.get()}]")[0]
 
+    @staticmethod
+    def global_settings_gui():
+        return [bool(i.get()) for i in global_settings]
 
-def get_calculation_type_gui():
-    return calculation_type.get()
+    @staticmethod
+    def get_calculation_num_gui():
+        return eval(value.get(), {})
 
+    @staticmethod
+    def update_calculation_box_gui():
+        global calculation_list, calculation_method, calculation_box
+        calculation_box.delete(0, tkinter.END)
+        a = ["第一参数", "第二参数"]
+        b = ["参数", "矩阵"]
+        calculation_box.insert(
+            tkinter.END,
+            *[
+                f"{a[i]} {calculation_list[i]} {b[calculation_method[i]]}"
+                for i in range(len(calculation_list))
+            ],
+        )
 
-def machine_learning():
-    global SCREEN
-    SCREEN.mainloop()
+    @staticmethod
+    def get_calculation_type_gui():
+        return calculation_type.get()
 
 
 class API:
@@ -229,7 +226,7 @@ class API:
         file_dir = askopenfilename(title="导入参数")
         with open(file_dir, "r") as f:
             learner_controller.add_curve_fitting(f.read())
-            update_leaner_gui()
+            UIAPI.update_leaner_gui()
 
     @staticmethod
     def show_clustering_score():
@@ -245,28 +242,28 @@ class API:
 
     @staticmethod
     def show_score(func):
-        learner = get_learner_gui(True)
+        learner = UIAPI.get_learner_gui(True)
         save_dir = askdirectory(title="选择保存位置")
         data = learner_controller.model_evaluation(
             learner,
             save_dir,
-            get_data_name_gui(False, True),
-            get_data_name_gui(False, False),
+            UIAPI.get_data_name_gui(False, True),
+            UIAPI.get_data_name_gui(False, False),
             func,
         )
         webbrowser.open(data[0])
         webbrowser.open(data[1])  # 还可以打开文件管理器
-        update_sheet_box_gui()
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def calculation():
         global calculation_list, calculation_method
-        func = get_calculation_type_gui()
+        func = UIAPI.get_calculation_type_gui()
         if len(calculation_list) == 2 and 1 in calculation_method:
             learner_controller.calculation_matrix(
                 calculation_list, calculation_method, func
             )
-        update_sheet_box_gui()
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def add_calculation_core(num, type_):
@@ -278,115 +275,115 @@ class API:
 
     @staticmethod
     def add_calculation_number():
-        API.add_calculation_core(get_calculation_num_gui(), 0)
-        update_calculation_box_gui()
+        API.add_calculation_core(UIAPI.get_calculation_num_gui(), 0)
+        UIAPI.update_calculation_box_gui()
 
     @staticmethod
     def add_calculation_object():
-        name = get_data_name_gui()
+        name = UIAPI.get_data_name_gui()
         API.add_calculation_core(name, 1)
-        update_calculation_box_gui()
+        UIAPI.update_calculation_box_gui()
 
     @staticmethod
     def del_leaner():
-        learn = get_learner_gui(True)
-        set_learne = get_learner_gui(False)  # 获取学习器Learner
+        learn = UIAPI.get_learner_gui(True)
+        set_learne = UIAPI.get_learner_gui(False)  # 获取学习器Learner
         if set_learne != learn:
             learner_controller.del_leaner(learn)
-        update_leaner_gui()
+        UIAPI.update_leaner_gui()
 
     @staticmethod
     def global_seeting():
-        args = global_settings_gui()
+        args = UIAPI.global_settings_gui()
         machinelearning.template.set_global(*args)
 
     @staticmethod
     def reshape():
-        numpy_shape = get_shape_gui()
-        learner_controller.reshape(get_data_name_gui(), numpy_shape)
-        update_sheet_box_gui()
+        numpy_shape = UIAPI.get_shape_gui()
+        learner_controller.reshape(UIAPI.get_data_name_gui(), numpy_shape)
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def transpose():
         try:
-            func = get_shape_gui()
+            func = UIAPI.get_shape_gui()
         except BaseException:
             func = None
-        learner_controller.transpose(get_data_name_gui(), func)
-        update_sheet_box_gui()
+        learner_controller.transpose(UIAPI.get_data_name_gui(), func)
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def del_ndim():
-        learner_controller.del_ndim(get_data_name_gui())
-        update_sheet_box_gui()
+        learner_controller.del_ndim(UIAPI.get_data_name_gui())
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def reval():
         global learner_controller
-        reval_type = get_reval_type_gui()
-        learner_controller.reval(get_data_name_gui(), reval_type)
-        update_sheet_box_gui()
+        reval_type = UIAPI.get_reval_type_gui()
+        learner_controller.reval(UIAPI.get_data_name_gui(), reval_type)
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def two_split():
-        split_type = get_merge_split_type_gui()
-        learner_controller.two_split(get_data_name_gui(), shape.get(), split_type)
-        update_sheet_box_gui()
+        split_type = UIAPI.get_merge_split_type_gui()
+        learner_controller.two_split(UIAPI.get_data_name_gui(), shape.get(), split_type)
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def split():
         global learner_controller, shape
-        split_type = get_merge_split_type_gui()
-        split_shape_list = get_split_shape_list_gui()
-        learner_controller.split(get_data_name_gui(), split_shape_list, split_type)
-        update_sheet_box_gui()
+        split_type = UIAPI.get_merge_split_type_gui()
+        split_shape_list = UIAPI.get_split_shape_list_gui()
+        learner_controller.split(UIAPI.get_data_name_gui(), split_shape_list, split_type)
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def merge():
         if len(merge_list) < 1:
             return False
-        merge_type = get_merge_split_type_gui()
+        merge_type = UIAPI.get_merge_split_type_gui()
         learner_controller.merge(merge_list, merge_type)
-        update_sheet_box_gui()
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def merge_del():
-        del merge_list[get_merge_box_index_gui()]
-        update_merge_box_gui()
+        del merge_list[UIAPI.get_merge_box_index_gui()]
+        UIAPI.update_merge_box_gui()
 
     @staticmethod
     def merge_add():
-        merge_list.append(get_data_name_gui())
-        update_merge_box_gui()
+        merge_list.append(UIAPI.get_data_name_gui())
+        UIAPI.update_merge_box_gui()
 
     @staticmethod
     def visualization_results():
-        learner = get_learner_gui(True)
+        learner = UIAPI.get_learner_gui(True)
         save_dir = askdirectory(title="选择保存位置")
         data = learner_controller.model_visualization(learner, save_dir)
         webbrowser.open(data[0])
         webbrowser.open(data[1])  # 还可以打开文件管理器
-        update_sheet_box_gui()
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def score_learner():
-        learner = get_learner_gui()
+        learner = UIAPI.get_learner_gui()
         score = learner_controller.score(
-            get_data_name_gui(False, True), get_data_name_gui(False, False), learner
+            UIAPI.get_data_name_gui(False, True), UIAPI.get_data_name_gui(False, False), learner
         )
-        show_score_gui(f"针对测试数据评分结果为:{score}")
+        UIAPI.show_score_gui(f"针对测试数据评分结果为:{score}")
 
     @staticmethod
     def predict_learner():
-        learner = get_learner_gui()
-        data = learner_controller.predict(get_data_name_gui(False, True), learner)
+        learner = UIAPI.get_learner_gui()
+        data = learner_controller.predict(UIAPI.get_data_name_gui(False, True), learner)
         title = f"CoTan数据处理 学习器:{learner}"
-        creat_text_sheet_gui(data, title)
-        update_sheet_box_gui()
+        UIAPI.creat_text_sheet_gui(data, title)
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def fit_learner():
-        learner = get_learner_gui()
+        learner = UIAPI.get_learner_gui()
         try:
             split = float(data_split.get())
             if split < 0 or 1 < split:
@@ -394,13 +391,13 @@ class API:
         except BaseException:
             split = 0.3
         socore = learner_controller.fit_model(
-            get_data_name_gui(False, True),
-            get_data_name_gui(False, False),
+            UIAPI.get_data_name_gui(False, True),
+            UIAPI.get_data_name_gui(False, False),
             learner,
-            Text=get_learner_parameters_gui(),
+            Text=UIAPI.get_learner_parameters_gui(),
             split=split,
         )
-        show_score_gui(
+        UIAPI.show_score_gui(
             f"针对训练数据({(1 - split) * 100}%)评分结果为:{socore[0]}\n"
             f"针对测试数据评分({split * 100}%)结果为:{socore[1]}",
         )
@@ -420,9 +417,9 @@ class API:
     @staticmethod
     def add_view_data():
         learner_controller.add_view_data(
-            get_learner_gui(), parameters=get_learner_parameters_gui()
+            UIAPI.get_learner_gui(), parameters=UIAPI.get_learner_parameters_gui()
         )
-        update_leaner_gui()
+        UIAPI.update_leaner_gui()
 
     @staticmethod
     def add_cluster_tree():
@@ -439,16 +436,16 @@ class API:
     @staticmethod
     def add_predictive_heatmap_more():  # 添加Lenear的核心
         learner_controller.add_predictive_heat_map_more(
-            get_learner_gui(), parameters=get_learner_parameters_gui()
+            UIAPI.get_learner_gui(), parameters=UIAPI.get_learner_parameters_gui()
         )
-        update_leaner_gui()
+        UIAPI.update_leaner_gui()
 
     @staticmethod
     def add_predictive_heatmap():  # 添加Lenear的核心
         learner_controller.add_predictive_heat_map(
-            get_learner_gui(), parameters=get_learner_parameters_gui()
+            UIAPI.get_learner_gui(), parameters=UIAPI.get_learner_parameters_gui()
         )
-        update_leaner_gui()
+        UIAPI.update_leaner_gui()
 
     @staticmethod
     def add_feature_scatter_class_all():
@@ -637,22 +634,22 @@ class API:
     @staticmethod
     def add_select_from_model():  # 添加Lenear的核心
         learner_controller.add_select_from_model(
-            get_learner_gui(), parameters=get_learner_parameters_gui()
+            UIAPI.get_learner_gui(), parameters=UIAPI.get_learner_parameters_gui()
         )
-        update_leaner_gui()
+        UIAPI.update_leaner_gui()
 
     @staticmethod
     def add_leaner(learner_type):  # 添加Lenear的核心
         learner_controller.add_learner(
-            learner_type, parameters=get_learner_parameters_gui()
+            learner_type, parameters=UIAPI.get_learner_parameters_gui()
         )
-        update_leaner_gui()
+        UIAPI.update_leaner_gui()
 
     @staticmethod
     def to_html_one():
         html_dir = f"{PATH}/$Show_Sheet.html"
         try:
-            name = get_data_name_gui()
+            name = UIAPI.get_data_name_gui()
             if name is None:
                 raise Exception
             learner_controller.to_html_one(name, html_dir)
@@ -664,7 +661,7 @@ class API:
     def to_html():
         html_dir = f"{PATH}/$Show_Sheet.html"
         try:
-            name = get_data_name_gui()
+            name = UIAPI.get_data_name_gui()
             if name is None:
                 raise Exception
             learner_controller.to_html(name, html_dir, to_html_type.get())
@@ -674,19 +671,24 @@ class API:
 
     @staticmethod
     def to_csv():
-        learner_controller.to_csv(*to_csv_gui())
-        update_sheet_box_gui()
+        learner_controller.to_csv(*UIAPI.to_csv_gui())
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def add_csv():
-        learner_controller.read_csv(*add_csv_gui())
-        update_sheet_box_gui()
+        learner_controller.read_csv(*UIAPI.add_csv_gui())
+        UIAPI.update_sheet_box_gui()
 
     @staticmethod
     def add_python():
-        code, name = add_python_gui()
+        code, name = UIAPI.add_python_gui()
         learner_controller.add_python(code, name)
-        update_sheet_box_gui()
+        UIAPI.update_sheet_box_gui()
+
+
+def machine_learning():
+    global SCREEN
+    SCREEN.mainloop()
 
 
 SCREEN.title("CoTan机器学习")
@@ -1065,7 +1067,7 @@ tkinter.Button(
     bg=botton_color,
     fg=word_color,
     text="选用X集",
-    command=set_x_data_gui,
+    command=UIAPI.set_x_data_gui,
     font=FONT,
     width=gui_width,
     height=gui_height,
@@ -1081,7 +1083,7 @@ tkinter.Button(
     bg=botton_color,
     fg=word_color,
     text="选用Y集",
-    command=set_y_data_gui,
+    command=UIAPI.set_y_data_gui,
     font=FONT,
     width=gui_width,
     height=gui_height,
@@ -1097,7 +1099,7 @@ tkinter.Button(
     bg=botton_color,
     fg=word_color,
     text="选用学习器",
-    command=set_learner_gui,
+    command=UIAPI.set_learner_gui,
     font=FONT,
     width=gui_width,
     height=gui_height,

+ 115 - 25
system/gui.py

@@ -7,9 +7,9 @@ from system.controller import Plugin, NamingError, ConflictError
 
 SCREEN = tkinter.Tk()
 plugin = Plugin()
-SCREEN.title('插件管理')
+SCREEN.title("插件管理")
 SCREEN.resizable(width=False, height=False)
-SCREEN.geometry(f'+10+10')
+SCREEN.geometry(f"+10+10")
 bg_color = "#FFFAFA"  # 主颜色
 SCREEN["bg"] = bg_color
 botton_color = "#FFFAFA"  # 按钮颜色
@@ -24,7 +24,7 @@ column = 0
 def code_window(name):
     global bg_color
     cli_screen = tkinter.Toplevel(bg=bg_color)
-    cli_screen.title(f'插件查看器:{name}')
+    cli_screen.title(f"插件查看器:{name}")
     cli_screen.geometry("+10+10")  # 设置所在位置
     cli_screen.resizable(width=False, height=False)
 
@@ -70,16 +70,16 @@ def get_plugin():
 
 def add_plugin():
     index = plugin_dir_box.curselection()[0]
-    plugin_dir = askopenfilename(title='选择插件文件', filetypes=[("Python", ".py")])
+    plugin_dir = askopenfilename(title="选择插件文件", filetypes=[("Python", ".py")])
     try:
         plugin_list = plugin.add_plugin(index, plugin_dir)
     except NamingError:
-        showwarning('文件错误', '插件命名错误,命名规则:\ntemplate_[类\\方法名].py')
+        showwarning("文件错误", "插件命名错误,命名规则:\ntemplate_[类\\方法名].py")
     except ConflictError:
-        if askokcancel('提示', f'已经存在插件,是否需要尝试合并插件?\n[合并失败将产生不可逆的后果]'):
+        if askokcancel("提示", f"已经存在插件,是否需要尝试合并插件?\n[合并失败将产生不可逆的后果]"):
             plugin.merge_plugin(index, plugin_dir)
     except BaseException:
-        showwarning('文件错误', '插件导入遇到了未知错误')
+        showwarning("文件错误", "插件导入遇到了未知错误")
     else:
         plugin_box.delete(0, tkinter.END)
         plugin_box.insert(0, *plugin_list)
@@ -111,28 +111,118 @@ def system_main():
     SCREEN.mainloop()
 
 
-(tkinter.Label(SCREEN, text='【插件管理】', bg=bg_color, fg=word_color, font=FONT, width=gui_width*3, height=gui_height)
-    .grid(column=column, row=row, columnspan=3))
+(
+    tkinter.Label(
+        SCREEN,
+        text="【插件管理】",
+        bg=bg_color,
+        fg=word_color,
+        font=FONT,
+        width=gui_width * 3,
+        height=gui_height,
+    ).grid(column=column, row=row, columnspan=3)
+)
 row += 1
-(tkinter.Button(SCREEN, bg=botton_color, fg=word_color, command=get_dir, text='查看插件列表', font=FONT, width=gui_width, height=gui_height)
- .grid(column=column, row=row, sticky=tkinter.E + tkinter.W))
-(tkinter.Button(SCREEN, bg=botton_color, fg=word_color, command=get_all_plugin, text='查看所有插件', font=FONT, width=gui_width, height=gui_height)
- .grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W))
-(tkinter.Button(SCREEN, bg=botton_color, fg=word_color, command=get_plugin, text='查看仓库插件', font=FONT, width=gui_width, height=gui_height)
- .grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W))
+(
+    tkinter.Button(
+        SCREEN,
+        bg=botton_color,
+        fg=word_color,
+        command=get_dir,
+        text="查看插件列表",
+        font=FONT,
+        width=gui_width,
+        height=gui_height,
+    ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
+)
+(
+    tkinter.Button(
+        SCREEN,
+        bg=botton_color,
+        fg=word_color,
+        command=get_all_plugin,
+        text="查看所有插件",
+        font=FONT,
+        width=gui_width,
+        height=gui_height,
+    ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
+)
+(
+    tkinter.Button(
+        SCREEN,
+        bg=botton_color,
+        fg=word_color,
+        command=get_plugin,
+        text="查看仓库插件",
+        font=FONT,
+        width=gui_width,
+        height=gui_height,
+    ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
+)
 row += 1
 plugin_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 5)
-plugin_box.grid(column=column, row=row, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
+plugin_box.grid(
+    column=column,
+    row=row,
+    columnspan=3,
+    rowspan=5,
+    sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
+)
 row += 5
-(tkinter.Label(SCREEN, text='【插件仓库】', bg=bg_color, fg=word_color, font=FONT, width=gui_width*3, height=gui_height)
-    .grid(column=column, row=row, columnspan=3))
+(
+    tkinter.Label(
+        SCREEN,
+        text="【插件仓库】",
+        bg=bg_color,
+        fg=word_color,
+        font=FONT,
+        width=gui_width * 3,
+        height=gui_height,
+    ).grid(column=column, row=row, columnspan=3)
+)
 row += 1
 plugin_dir_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 5)
-plugin_dir_box.grid(column=column, row=row, columnspan=3, rowspan=5, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
+plugin_dir_box.grid(
+    column=column,
+    row=row,
+    columnspan=3,
+    rowspan=5,
+    sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
+)
 row += 5
-(tkinter.Button(SCREEN, bg=botton_color, fg=word_color, command=add_plugin, text='新增插件', font=FONT, width=gui_width, height=gui_height)
- .grid(column=column, row=row, sticky=tkinter.E + tkinter.W))
-(tkinter.Button(SCREEN, bg=botton_color, fg=word_color, command=del_plugin, text='删除插件', font=FONT, width=gui_width, height=gui_height)
- .grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W))
-(tkinter.Button(SCREEN, bg=botton_color, fg=word_color, command=show_plugin, text='查看插件', font=FONT, width=gui_width, height=gui_height)
- .grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W))
+(
+    tkinter.Button(
+        SCREEN,
+        bg=botton_color,
+        fg=word_color,
+        command=add_plugin,
+        text="新增插件",
+        font=FONT,
+        width=gui_width,
+        height=gui_height,
+    ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
+)
+(
+    tkinter.Button(
+        SCREEN,
+        bg=botton_color,
+        fg=word_color,
+        command=del_plugin,
+        text="删除插件",
+        font=FONT,
+        width=gui_width,
+        height=gui_height,
+    ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
+)
+(
+    tkinter.Button(
+        SCREEN,
+        bg=botton_color,
+        fg=word_color,
+        command=show_plugin,
+        text="查看插件",
+        font=FONT,
+        width=gui_width,
+        height=gui_height,
+    ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
+)

部分文件因文件數量過多而無法顯示