From 07d61a8690203003946ac8f726f1d1aff678cd9d Mon Sep 17 00:00:00 2001 From: Wulian233 <1055917385@qq.com> Date: Sat, 3 Aug 2024 19:53:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 2 ++ .gitignore | 1 - PyBuild/unix_build.sh | 6 ------ PyBuild/win_build.bat | 5 ----- README.md | 28 +++++++++++----------------- feedtheforge/i18n.py | 16 ++++++++++------ main.spec | 7 +++++-- 7 files changed, 28 insertions(+), 37 deletions(-) create mode 100644 .gitattributes delete mode 100644 PyBuild/unix_build.sh delete mode 100644 PyBuild/win_build.bat diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d0c0c4c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +* text eol=lf +*.png binary diff --git a/.gitignore b/.gitignore index c67069b..b585484 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ **/__pycache__ **/.vscode -*.exe **/.idea *.zip /__main__.build diff --git a/PyBuild/unix_build.sh b/PyBuild/unix_build.sh deleted file mode 100644 index b2db5ae..0000000 --- a/PyBuild/unix_build.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -cd .. -pip install -r requirements.txt -pip install pyinstaller -pyinstaller main.spec diff --git a/PyBuild/win_build.bat b/PyBuild/win_build.bat deleted file mode 100644 index 57b074e..0000000 --- a/PyBuild/win_build.bat +++ /dev/null @@ -1,5 +0,0 @@ -@echo off -cd.. -pip install -r requirements.txt -pip install pyinstaller -pyinstaller main.spec \ No newline at end of file diff --git a/README.md b/README.md index dbeb485..cca664b 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ WIP ## Develop and Build ### Requirements -- **Git**: 3.8+ +- **Git** - **Python Version**: 3.8+ - **Supported Operating Systems**: Windows 10 or later, macOS, Linux @@ -29,28 +29,22 @@ WIP pip install -r requirements.txt ``` -2. **Run**: - - After installing the dependencies, run `__main__.py` +2. **Run the Application**: + - **Windows**: Use the command `python __main__.py` + - **macOS and Linux**: Use the command `python3 __main__.py` -### Building Executable for Windows +### Building Executable 1. **Package as Executable**: - - To package the application as an executable for Windows, run the following script: - - Windows ```bash - cd PyBuild - win_build.bat + pip install pyinstaller + pyinstaller main.spec ``` - - Unix - ```bash - cd PyBuild - unix_build.sh - ``` -2. **Locate the Executable**: - - The resulting `.exe` file will be located in the `dist` folder. +3. **Locate the Executable**: + - For **Windows**, the executable will be a `.exe` file located in the `dist` folder. + - For **macOS**, the application will be packaged as a `.app` bundle, also found in the `dist` folder. + - For **Linux**, the executable will be a standalone file in the `dist` folder. -3. **Additional Steps**: - - Copy the `feedtheforge/lang` folder to the `dist` directory ## LICENSE [GNU General Public License v3.0](.LICENSE) \ No newline at end of file diff --git a/feedtheforge/i18n.py b/feedtheforge/i18n.py index 329ad01..bcb2718 100644 --- a/feedtheforge/i18n.py +++ b/feedtheforge/i18n.py @@ -1,12 +1,17 @@ -import json +import sys from pathlib import Path +import json from string import Template - class Locale: def __init__(self, lang: str): self.lang = lang - self.path = Path(f"./feedtheforge/lang/{lang}.json") + if getattr(sys, 'frozen', False): + # If running in a bundle + self.path = Path(sys._MEIPASS) / f"feedtheforge/lang/{lang}.json" + else: + # If running in a normal Python environment + self.path = Path(f"./feedtheforge/lang/{lang}.py") self.data = {} self.load() @@ -20,7 +25,6 @@ def load(self): with open(self.path, "r", encoding="utf-8") as f: d = f.read() self.data = json.loads(d) - f.close() def get_string(self, key: str, failed_prompt): n = self.data.get(key, None) @@ -36,5 +40,5 @@ def t(self, key: str, failed_prompt=True, *args, **kwargs): def get_language(self): return self.lang - -lang = Locale("zh_CN") \ No newline at end of file + +lang = Locale("zh_CN") diff --git a/main.spec b/main.spec index 646dfaf..035f837 100644 --- a/main.spec +++ b/main.spec @@ -5,8 +5,11 @@ a = Analysis( ['__main__.py'], pathex=[], binaries=[], - datas=[], - hiddenimports=['aiohttp','pick'], + datas=[ + ('feedtheforge/lang/zh_CN.json', 'feedtheforge/lang'), + ('feedtheforge/lang/en_US.json', 'feedtheforge/lang') + ], + hiddenimports=['aiohttp', 'pick'], hookspath=[], hooksconfig={}, runtime_hooks=[],