From b7a6ba567af7fe40711f7eba9a341cc18f86d8e8 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 14 Dec 2024 18:41:42 +0100 Subject: [PATCH] Changed folder structure to match the python package standards more and created setup.py for an easy installation. --- bread_editor/__init__.py | 3 +++ .../binary_text_edit.py | 0 connect_gui.py => bread_editor/connect_gui.py | 0 editor.py => bread_editor/editor.py | 4 +-- example.txt => bread_editor/example.txt | 0 file.py => bread_editor/file.py | 2 +- bread_editor/gui/__init__.py | 1 + bread_editor/gui/raw_ui/__init__.py | 1 + .../gui}/raw_ui/main_window.ui | 0 {gui => bread_editor/gui}/raw_ui/ui_to_py.py | 0 .../highlighting.py | 0 ipc.py => bread_editor/ipc.py | 0 main.py => bread_editor/main.py | 15 +++++++---- settings.py => bread_editor/settings.py | 2 +- ui.py => bread_editor/ui.py | 4 +-- utils.py => bread_editor/utils.py | 1 - setup.py | 27 +++++++++++++++++++ 17 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 bread_editor/__init__.py rename binary_text_edit.py => bread_editor/binary_text_edit.py (100%) rename connect_gui.py => bread_editor/connect_gui.py (100%) rename editor.py => bread_editor/editor.py (94%) rename example.txt => bread_editor/example.txt (100%) rename file.py => bread_editor/file.py (98%) create mode 100644 bread_editor/gui/__init__.py create mode 100644 bread_editor/gui/raw_ui/__init__.py rename {gui => bread_editor/gui}/raw_ui/main_window.ui (100%) rename {gui => bread_editor/gui}/raw_ui/ui_to_py.py (100%) rename highlighting.py => bread_editor/highlighting.py (100%) rename ipc.py => bread_editor/ipc.py (100%) rename main.py => bread_editor/main.py (80%) rename settings.py => bread_editor/settings.py (87%) rename ui.py => bread_editor/ui.py (89%) rename utils.py => bread_editor/utils.py (99%) create mode 100644 setup.py diff --git a/bread_editor/__init__.py b/bread_editor/__init__.py new file mode 100644 index 0000000..23d4ce1 --- /dev/null +++ b/bread_editor/__init__.py @@ -0,0 +1,3 @@ +#!/usr/bin/python3 + +from bread_editor.main import start_from_command_line diff --git a/binary_text_edit.py b/bread_editor/binary_text_edit.py similarity index 100% rename from binary_text_edit.py rename to bread_editor/binary_text_edit.py diff --git a/connect_gui.py b/bread_editor/connect_gui.py similarity index 100% rename from connect_gui.py rename to bread_editor/connect_gui.py diff --git a/editor.py b/bread_editor/editor.py similarity index 94% rename from editor.py rename to bread_editor/editor.py index 62e56b7..f5e5c87 100644 --- a/editor.py +++ b/bread_editor/editor.py @@ -2,8 +2,8 @@ from PyQt6.QtWidgets import QWidget, QVBoxLayout from PyQt6.QtGui import QFont, QTextCharFormat, QColor -from binary_text_edit import BinaryTextEdit -from highlighting import Higlighter +from bread_editor.binary_text_edit import BinaryTextEdit +from bread_editor.highlighting import Higlighter class BitEditor: diff --git a/example.txt b/bread_editor/example.txt similarity index 100% rename from example.txt rename to bread_editor/example.txt diff --git a/file.py b/bread_editor/file.py similarity index 98% rename from file.py rename to bread_editor/file.py index 073db5a..4b8a8fd 100644 --- a/file.py +++ b/bread_editor/file.py @@ -2,7 +2,7 @@ import os.path from PyQt6.QtWidgets import QFileDialog -from editor import BitEditor +from bread_editor.editor import BitEditor MAX_FILE_SIZE = 262144 # 2^18 diff --git a/bread_editor/gui/__init__.py b/bread_editor/gui/__init__.py new file mode 100644 index 0000000..a93a4bf --- /dev/null +++ b/bread_editor/gui/__init__.py @@ -0,0 +1 @@ +#!/usr/bin/python3 diff --git a/bread_editor/gui/raw_ui/__init__.py b/bread_editor/gui/raw_ui/__init__.py new file mode 100644 index 0000000..a93a4bf --- /dev/null +++ b/bread_editor/gui/raw_ui/__init__.py @@ -0,0 +1 @@ +#!/usr/bin/python3 diff --git a/gui/raw_ui/main_window.ui b/bread_editor/gui/raw_ui/main_window.ui similarity index 100% rename from gui/raw_ui/main_window.ui rename to bread_editor/gui/raw_ui/main_window.ui diff --git a/gui/raw_ui/ui_to_py.py b/bread_editor/gui/raw_ui/ui_to_py.py similarity index 100% rename from gui/raw_ui/ui_to_py.py rename to bread_editor/gui/raw_ui/ui_to_py.py diff --git a/highlighting.py b/bread_editor/highlighting.py similarity index 100% rename from highlighting.py rename to bread_editor/highlighting.py diff --git a/ipc.py b/bread_editor/ipc.py similarity index 100% rename from ipc.py rename to bread_editor/ipc.py diff --git a/main.py b/bread_editor/main.py similarity index 80% rename from main.py rename to bread_editor/main.py index c62dc3f..5cb0d5d 100755 --- a/main.py +++ b/bread_editor/main.py @@ -3,11 +3,11 @@ import sys from PyQt6.QtCore import QTimer from wobbl_tools.data_file import load_dataclass_json -from utils import Utils -from file import File, FileActions -from ui import GUI -from settings import Settings -from ipc import IPC +from bread_editor.utils import Utils +from bread_editor.file import File, FileActions +from bread_editor.ui import GUI +from bread_editor.settings import Settings +from bread_editor.ipc import IPC class BreadEditor: @@ -46,6 +46,11 @@ class BreadEditor: sys.exit(self.gui.qt_app.exec()) +def start_from_command_line(): + editor = BreadEditor() + editor.run() + + if __name__ == "__main__": editor = BreadEditor() editor.run() diff --git a/settings.py b/bread_editor/settings.py similarity index 87% rename from settings.py rename to bread_editor/settings.py index ba339d0..1fa47e1 100644 --- a/settings.py +++ b/bread_editor/settings.py @@ -2,7 +2,7 @@ from dataclasses import dataclass, field from typing import List -from utils import Utils +from bread_editor.utils import Utils @dataclass diff --git a/ui.py b/bread_editor/ui.py similarity index 89% rename from ui.py rename to bread_editor/ui.py index 8dacb37..ec6862c 100644 --- a/ui.py +++ b/bread_editor/ui.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 from PyQt6.QtWidgets import QApplication, QMainWindow -from gui.main_window import Ui_MainWindow -from connect_gui import connect_gui +from bread_editor.gui.main_window import Ui_MainWindow +from bread_editor.connect_gui import connect_gui class GUI: diff --git a/utils.py b/bread_editor/utils.py similarity index 99% rename from utils.py rename to bread_editor/utils.py index 265d016..b655727 100644 --- a/utils.py +++ b/bread_editor/utils.py @@ -4,7 +4,6 @@ import os import sys from pathlib import Path from PyQt6.QtWidgets import QMessageBox -from file import File class Utils: diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..cf18162 --- /dev/null +++ b/setup.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 + +import setuptools +from pathlib import Path + +this_directory = Path(__file__).parent # use readme file as long description +long_description = (this_directory / "README.md").read_text() + +setuptools.setup( + name="Bread Editor", + version="0.0", + description="A binary editor with that you can edit single bits.", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor", + author="The Wobbler", + author_email="emil@i21k.de", + packages=["bread_editor"], + package_data={"": ["*.ui", "*.txt"]}, + install_requires=[ + "PyQt6", + "wobbl_tools @ git+https://teapot.informationsanarchistik.de/Wobbl/wobbl_tools@main#egg=wobbl_tools" + ], + entry_points={ + "console_scripts": ["bread_editor=bread_editor:start_from_command_line"], + } +)