From 3c30e0cf94aef64bd08ce51be04b304225640982 Mon Sep 17 00:00:00 2001 From: louisyoungx <1462648167@qq.com> Date: Mon, 22 Nov 2021 14:35:37 +0800 Subject: [PATCH] feat(gui): package the gui file --- Config/config.ini | 4 ++++ GUI/gui.py | 21 +++++++++++++++++++++ TEST/pack.py | 1 + TEST/py2app_setup.py | 30 ++++++++++++++++++++++++++++++ runserver.py | 17 ++++++++++++----- 5 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 TEST/pack.py create mode 100644 TEST/py2app_setup.py diff --git a/Config/config.ini b/Config/config.ini index b9587a2..7cbcdb8 100755 --- a/Config/config.ini +++ b/Config/config.ini @@ -92,6 +92,10 @@ PORT = 12021 PROCESS_MODEL = False PROCESS_COUNT = 4 +[GUI] +# GUI Settings +START_USING = False + [Logger] # 记录设置 # FILE_NAME-记录文件名,AMOUNT-记录文件个数,MAX_BYTES-单个记录文件的大小 diff --git a/GUI/gui.py b/GUI/gui.py index e69de29..8cbba5e 100644 --- a/GUI/gui.py +++ b/GUI/gui.py @@ -0,0 +1,21 @@ +import webview + +from Config.settings import config + +PROJECT = config.settings("Information", "PROJECT") +SERVER_HOST = config.settings("Server", "SERVER_HOST") +PORT = config.settings("Server", "PORT") + +def gui(): + url = "http://{}:{}/".format(SERVER_HOST, PORT) + webview.create_window(PROJECT, + url=url, + js_api=None, + width=900, + height=800, + resizable=True, + fullscreen=False, + min_size=(200, 200), + background_color='#FFF', + text_select=False) + webview.start() diff --git a/TEST/pack.py b/TEST/pack.py new file mode 100644 index 0000000..1a0f082 --- /dev/null +++ b/TEST/pack.py @@ -0,0 +1 @@ +command = '' \ No newline at end of file diff --git a/TEST/py2app_setup.py b/TEST/py2app_setup.py new file mode 100644 index 0000000..e8e825e --- /dev/null +++ b/TEST/py2app_setup.py @@ -0,0 +1,30 @@ +""" +This is an example of py2app py2app_setup.py script for freezing your pywebview +application +Usage: + python py2app_setup.py py2app +""" + +import os +from setuptools import setup + + +def tree(src): + return [(root, map(lambda f: os.path.join(root, f), files)) + for (root, dirs, files) in os.walk(os.path.normpath(src))] + + +ENTRY_POINT = ['runserver.py'] + +DATA_FILES = tree('DATA_FILES_DIR') + tree('DATA_FILE_DIR2') +OPTIONS = {'argv_emulation': False, + 'strip': True, + #'iconfile': 'icon.icns', # uncomment to include an icon + 'includes': ['WebKit', 'Foundation', 'webview']} + +setup( + app=ENTRY_POINT, + data_files=DATA_FILES, + options={'py2app': OPTIONS}, + setup_requires=['py2app'], +) \ No newline at end of file diff --git a/runserver.py b/runserver.py index 3d25cb1..e51454c 100755 --- a/runserver.py +++ b/runserver.py @@ -4,16 +4,20 @@ from Scheduler.scheduler import Timer from Config.settings import config from Server.server import server from threading import Thread +from GUI.gui import gui from concurrent.futures import ProcessPoolExecutor +PROCESS_MODEL = config.settings("Server", "PROCESS_MODEL") +SCHEDULER = config.settings("Scheduler", "START_USING") +SERVER = config.settings("Server", "START_USING") +GUI = config.settings("GUI", "START_USING") + + def running(): - PROCESS_MODEL = config.settings("Server", "PROCESS_MODEL") - SCHEDULER = config.settings("Scheduler", "START_USING") - SERVER = config.settings("Server", "START_USING") if not SCHEDULER: thread_main = Thread(target=main) thread_main.start() - else: # 调度器开启后main函数将被scheduler调度器代理,开启定时执行main + else: # 调度器开启后main函数将被scheduler调度器代理,开启定时执行main startTime = config.settings("Scheduler", "START_TIME") skipWeekend = config.settings("Scheduler", "SKIP_WEEKEND") scheduler = Timer(task=main, startTime=startTime, skipWeekend=skipWeekend) @@ -26,12 +30,16 @@ def running(): else: thread_server = Thread(target=server) thread_server.start() + if GUI: + gui() + def server_process(work_count=4): with ProcessPoolExecutor(work_count) as pool: for i in range(work_count): pool.submit(server()) + if __name__ == "__main__": DEBUG = config.settings("Debug", "DEBUG") if DEBUG: @@ -39,4 +47,3 @@ if __name__ == "__main__": main() else: running() -