diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 819e599..850a1d5 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,13 @@ - + + + + + + + - + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + @@ -29,18 +65,42 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -66,9 +126,12 @@ print( action base + current_dir + __file__ D:\programeCode\python\testCode\GUI\pyqt5\local_transfer_file + D:\programeCode\python\testCode\GUI\pyqt5\local_transfer_file\local_transfer_file @@ -97,14 +160,15 @@ @@ -139,23 +203,13 @@ - - - - - - - - - - - + @@ -237,7 +291,7 @@ - + @@ -246,15 +300,15 @@ - - + + - + @@ -290,31 +344,26 @@ file://$PROJECT_DIR$/local_transfer_file/service/request_handler.py - 180 + 186 file://$PROJECT_DIR$/local_transfer_file/service/request_handler.py - 170 + 176 file://$PROJECT_DIR$/local_transfer_file/service/request_handler.py - 163 + 169 - file://$PROJECT_DIR$/local_transfer_file/utils.py - 43 - - - file://$PROJECT_DIR$/local_transfer_file/utils.py - 45 - - @@ -513,16 +562,6 @@ - - - - - - - - - - @@ -537,24 +576,8 @@ - - - - - - - - - - - - - - - - - - + + @@ -579,16 +602,7 @@ - - - - - - - - - - + @@ -626,29 +640,25 @@ - - - - - - - - - - - + + + - - + + + + + + + + + - + - - - - - + + @@ -661,34 +671,41 @@ - - + + - - + + + + + + + + + - + - - + + - - - - - - - + + + + + + + diff --git a/local_transfer_file/file_select_dialog.py b/local_transfer_file/file_select_dialog.py index bd16100..8efd832 100644 --- a/local_transfer_file/file_select_dialog.py +++ b/local_transfer_file/file_select_dialog.py @@ -6,6 +6,7 @@ import json import traceback import logging +import sys from PyQt5.QtWidgets import QMainWindow, QMessageBox, QFileDialog import qrcode @@ -47,8 +48,13 @@ def init_menu_action(self): self.ui.action_3.triggered.connect(self.aboutMe) def set_config(self, code, file_path): - current_dir = os.path.dirname(os.path.abspath(__file__)) - config_file = os.path.join(current_dir, "service/config.json") + if getattr(sys, 'frozen', False): + bundle_dir = sys._MEIPASS + config_file = os.path.join(bundle_dir, "config.json") + else: + bundle_dir = os.path.dirname(os.path.abspath(__file__)) + + config_file = os.path.join(bundle_dir, "service/config.json") data = { "file_path": file_path, "code": code @@ -124,6 +130,7 @@ def selectFileMode(self): if self.file_mode == FileMode.DIRECTORMODE: QMessageBox.warning(self, "警告", "出于安全考虑,请尽量不要分享文件夹,可以打包后分享或者下载!") self.ui.showFilePath.clear() + self.ui.showUrlText.clear() def setShowAgain(self, isNotShowAgain): self.need_show_again = not isNotShowAgain diff --git a/local_transfer_file/main.py b/local_transfer_file/main.py index 358cef1..f94cf3d 100644 --- a/local_transfer_file/main.py +++ b/local_transfer_file/main.py @@ -8,6 +8,9 @@ from local_transfer_file.run_server_thread import CustomServerThread from local_transfer_file.utils import get_local_ip, setup_logging +# pyinstaller import +import local_transfer_file.service +import local_transfer_file.ui_files def main(): diff --git a/local_transfer_file/service/config.json b/local_transfer_file/service/config.json index 5913548..7804c0d 100644 --- a/local_transfer_file/service/config.json +++ b/local_transfer_file/service/config.json @@ -1,4 +1,4 @@ { - "code": "aafc92e61b8a11e9ae6b1831bfbd596c", + "code": "1e05da7e1bd311e9a64a1831bfbd596c", "file_path": "D:/programeCode/python/testCode/GUI/pyqt5/local_transfer_file/local_transfer_file/background.jpeg" } \ No newline at end of file diff --git a/local_transfer_file/service/request_handler.py b/local_transfer_file/service/request_handler.py index 5dbf66d..6e73d0d 100644 --- a/local_transfer_file/service/request_handler.py +++ b/local_transfer_file/service/request_handler.py @@ -13,8 +13,14 @@ from http.server import SimpleHTTPRequestHandler, HTTPStatus -current_dir = os.path.dirname(os.path.abspath(__file__)) -config_file = os.path.join(current_dir, "config.json") +if getattr(sys, 'frozen', False): + bundle_dir = sys._MEIPASS + config_file = os.path.join(bundle_dir, "config.json") +else: + bundle_dir = os.path.dirname(os.path.abspath(__file__)) + + config_file = os.path.join(bundle_dir, "config.json") + logger = logging.getLogger() @@ -178,7 +184,7 @@ def do_GET(self): if os.path.isdir(path): if not path.endswith("/"): path += "/" - f = self.list_directory(path) + f = self.list_directory(path) else: f = self.get_file(path) if f: diff --git a/local_transfer_file/utils.py b/local_transfer_file/utils.py index 7d189cf..050bed7 100644 --- a/local_transfer_file/utils.py +++ b/local_transfer_file/utils.py @@ -9,6 +9,7 @@ import logging import logging.config import json +import sys import psutil @@ -42,7 +43,14 @@ def setup_logging( """ if default_path is None: - default_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "logging.json") + if getattr(sys, 'frozen', False): + bundle_dir = sys._MEIPASS + default_path = os.path.join(bundle_dir, "logging.json") + else: + bundle_dir = os.path.dirname(os.path.abspath(__file__)) + + default_path = os.path.join(bundle_dir, "logging.json") + # default_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "logging.json") path = default_path value = os.getenv(env_key, None) if value: diff --git a/setup.py b/setup.py index 4f6fd86..548f4da 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,10 @@ packages=find_packages(), include_package_data=True, platforms="any", - install_requires=[], + install_requires=[ + "PyQt5", + "qrcode" + ], scripts=[], entry_points={