From ada2d1c7cf697e186ead19f580cc47b5e8d74289 Mon Sep 17 00:00:00 2001 From: megamichi Date: Sun, 8 Dec 2024 20:22:28 +0100 Subject: [PATCH 01/18] http link in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e6ada4..58d0203 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ install the requirements and make the file called "main.py" executable.\ You can do that using these commands: ```bash -git clone git@teapot.informationsanarchistik.de:Wobbl/Bread_Editor.git +git clone https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor.git cd Bread_Editor pip install -r requirements.txt chmod +x main.py From de64c08532a76e7697e40eaa4d78a629e5b149c1 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Mon, 9 Dec 2024 14:35:04 +0100 Subject: [PATCH 02/18] Added git http clone url to the README.md, as suggested by Megamichi. --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e6ada4..a4106f8 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,17 @@ install the requirements and make the file called "main.py" executable.\ You can do that using these commands: ```bash -git clone git@teapot.informationsanarchistik.de:Wobbl/Bread_Editor.git +git clone https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor.git cd Bread_Editor pip install -r requirements.txt chmod +x main.py ``` +If you have already set up git for ssh, you can also clone the repository like this: + +```bash +git clone git git@teapot.informationsanarchistik.de:Wobbl/Bread_Editor.git +``` + Now you can execute the program using `./main.py`. You can also create a desktop shortcut to the file. \ No newline at end of file From 7235736309e17f7c8299afdcdbd484bdcb743655 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Mon, 9 Dec 2024 14:41:14 +0100 Subject: [PATCH 03/18] Added instruction to convert the ui files to python files. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a4106f8..4df07cb 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,15 @@ So I just made one. This program was made for Linux.\ It may work on Windows or Mac too, but it was not tested on these systems.\ To be able to use this program, you have to clone the repository,\ -install the requirements and make the file called "main.py" executable.\ +install the requirements, convert the ui files to python files\ +and make the file called "main.py" executable.\ You can do that using these commands: ```bash git clone https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor.git cd Bread_Editor pip install -r requirements.txt +python3 gui/raw_ui/ui_to_py.py chmod +x main.py ``` From 46f49804a88da97221bad336b396314b98fb3e15 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Mon, 9 Dec 2024 16:24:15 +0100 Subject: [PATCH 04/18] Implemented size check for files opened via command line, simplified some code and added some comments. --- file.py | 18 +++++++++++------- main.py | 4 ++-- ui.py | 1 - utils.py | 27 ++++++++++++--------------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/file.py b/file.py index e2a881e..60c89e1 100644 --- a/file.py +++ b/file.py @@ -20,13 +20,7 @@ class FileActions: dialog.setViewMode(QFileDialog.ViewMode.List) if dialog.exec(): - for file_path in dialog.selectedFiles(): - if not file_path in self.app.open_files: # dont open file twice - if os.path.getsize(file_path) > MAX_FILE_SIZE: - self.app.utils.ftb_popup.exec() - return - - self.app.open_files[file_path] = File(self.app, file_path, file_path.split("/")[-1]) + self.open_multiple_files(dialog.selectedFiles()) def create_file(self, content: bin=b""): file_path, extension = QFileDialog.getSaveFileName( @@ -82,6 +76,16 @@ class FileActions: for file_path in self.app.open_files: self.app.open_files[file_path].save() + def open_multiple_files(self, file_paths): + for file_path in file_paths: + if not file_path in self.app.open_files and os.path.isfile(file_path): + if os.path.getsize(file_path) > MAX_FILE_SIZE: + self.app.utils.ftb_popup.exec() + return + + file = File(self.app, file_path, file_path.split("/")[-1]) + self.app.open_files[file_path] = file + class File: def __init__(self, app, path, name): diff --git a/main.py b/main.py index 52e3d64..c62dc3f 100755 --- a/main.py +++ b/main.py @@ -38,10 +38,10 @@ class BreadEditor: self.gui.post_setup() - self.utils.on_start() - self.utils.popup_init() + self.utils.on_start() + self.gui.QTMainWindow.show() sys.exit(self.gui.qt_app.exec()) diff --git a/ui.py b/ui.py index 8bda743..8dacb37 100644 --- a/ui.py +++ b/ui.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 from PyQt6.QtWidgets import QApplication, QMainWindow -from PyQt6.QtGui import QFont from gui.main_window import Ui_MainWindow from connect_gui import connect_gui diff --git a/utils.py b/utils.py index 0e7c8bd..265d016 100644 --- a/utils.py +++ b/utils.py @@ -33,7 +33,7 @@ class Utils: "https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor" ) - def unsaved_changes_popup(self): + def unsaved_changes_popup(self): # show popup and simplify return values button = self.usc_popup.exec() match button: @@ -69,14 +69,14 @@ class Utils: def on_close(self, event): changes = False - for file_path in self.app.open_files: + for file_path in self.app.open_files: # check for files that have unsaved changes file = self.app.open_files[file_path] if file.bit_editor.not_saved: changes = True break - if changes: + if changes: # show a popup that informs the user that there are unsaved changes and ask them what to do save_or_not = self.unsaved_changes_popup() match save_or_not: @@ -94,8 +94,7 @@ class Utils: self.close() def close(self): - print("Bye!") - + # get paths of open files and save them to the settings to reopen them automatically on next start file_keys = self.app.open_files.keys() open_files = [] @@ -106,7 +105,10 @@ class Utils: self.app.settings.save(f"{self.editor_path}/settings.json") + print("Bye!") + def update_style_in_all_bit_editors(self): + # update the highlighting and character spacing when a setting has changed self.app.settings.highlight_ones = self.app.gui.main_window.highlightOnesSetting.isChecked() self.app.settings.square_bits = self.app.gui.main_window.bitsAreSquaresSetting.isChecked() @@ -116,23 +118,18 @@ class Utils: editor.update_style() def on_start(self): + # either open the lastly opened files or open the files specified by the parameters if len(sys.argv) == 1: # if no parameters were passed to the editor - self.load_files(self.app.settings.last_opened_files) + file_paths = self.app.settings.last_opened_files else: file_paths = sys.argv[1:] - self.load_files(file_paths) - - def load_files(self, file_paths): - for file_path in file_paths: - if not file_path in self.app.open_files and os.path.isfile(file_path): - file = File(self.app, file_path, file_path.split("/")[-1]) - self.app.open_files[file_path] = file + self.app.file_actions.open_multiple_files(file_paths) def check_file_queue(self): - if not len(self.app.open_files_queue) == 0: + if not self.app.open_files_queue == []: # check for file paths in the queue that the ipc server put there filenames = self.app.open_files_queue self.app.open_files_queue = [] - self.load_files(filenames) + self.app.file_actions.open_multiple_files(filenames) From 409213585a066eeb45ddc70e132aa9ae7dcc372a Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Mon, 9 Dec 2024 16:53:33 +0100 Subject: [PATCH 05/18] I think I fixed the formatting issue when writing new data. --- binary_text_edit.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/binary_text_edit.py b/binary_text_edit.py index 39d40b3..337b0bb 100644 --- a/binary_text_edit.py +++ b/binary_text_edit.py @@ -16,12 +16,10 @@ class BinaryTextEdit(QPlainTextEdit): # rewrite QPlainTextEdit.keyPressEvent be if not (pos + 1) % 9 == 0 or event.text() in {"", None}: # dont overwrite the separator character super().keyPressEvent(event) - # skip over the separator character when the cursor is before it. + # skip over the separator character when the cursor is right before it. if (pos + 2) % 9 == 0 and not event.text() in {"", None}: - if pos == text_length: # append to the input if the cursor is at the end - self.insertPlainText(" ") - cursor = self.textCursor() - cursor.setPosition(pos + 2) + if pos == text_length - 1: # append to the input if the cursor is at the end + self.insertPlainText(" 00000000") cursor.setPosition(pos + 2) self.setTextCursor(cursor) From 93408e9a29ace47c80f88ad56e4ce86d194da78e Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Mon, 9 Dec 2024 17:26:28 +0100 Subject: [PATCH 06/18] Implemented deleting of bytes. --- binary_text_edit.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/binary_text_edit.py b/binary_text_edit.py index 337b0bb..90ef344 100644 --- a/binary_text_edit.py +++ b/binary_text_edit.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 from PyQt6.QtWidgets import QPlainTextEdit +from PyQt6.QtCore import Qt class BinaryTextEdit(QPlainTextEdit): # rewrite QPlainTextEdit.keyPressEvent because it has no .setValidator() @@ -9,19 +10,40 @@ class BinaryTextEdit(QPlainTextEdit): # rewrite QPlainTextEdit.keyPressEvent be if event.text() in allowed_keys: cursor = self.textCursor() - pos = cursor.position() + position = cursor.position() text = self.toPlainText() text_length = len(text) - if not (pos + 1) % 9 == 0 or event.text() in {"", None}: # dont overwrite the separator character + if not (position + 1) % 9 == 0 or event.text() in {"", None}: # dont overwrite the separator character super().keyPressEvent(event) # skip over the separator character when the cursor is right before it. - if (pos + 2) % 9 == 0 and not event.text() in {"", None}: - if pos == text_length - 1: # append to the input if the cursor is at the end + if (position + 2) % 9 == 0 and not event.text() in {"", None}: + if position == text_length - 1: # append to the input if the cursor is at the end self.insertPlainText(" 00000000") - cursor.setPosition(pos + 2) + cursor.setPosition(position + 2) + self.setTextCursor(cursor) + + elif event.key() == Qt.Key.Key_Backspace or event.key() == Qt.Key.Key_Delete: + # delete last byte when backspace or delete is pressed + text = self.toPlainText() + + if len(text) >= 9: + cursor = self.textCursor() + position = cursor.position() + + text = text[:-9] # delete last byte + + self.setPlainText(text) + + # calculate the new cursor position (by subtracting 9, we set the position to the same bit but one byte + # before and by floor dividing this by 9 we get the "byte index" and when we multiply this by 9, we get + # the character position of the first bit in that byte.) + position = (position - 9) // 9 * 9 + + cursor.setPosition(position) + self.setTextCursor(cursor) else: From b2afa06ee120a180dc147f55f0dcc40205e7223f Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Mon, 9 Dec 2024 17:49:25 +0100 Subject: [PATCH 07/18] Creating new files now actually works. Somehow PyQt passed something to the new_file()-function, and it crashed every time because the variable was the wrong type. --- connect_gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect_gui.py b/connect_gui.py index 086f55d..d9ee6c1 100644 --- a/connect_gui.py +++ b/connect_gui.py @@ -2,7 +2,7 @@ def connect_gui(app): app.gui.main_window.openFile.triggered.connect(app.file_actions.open_files) - app.gui.main_window.newFile.triggered.connect(app.file_actions.create_file) + app.gui.main_window.newFile.triggered.connect(lambda: app.file_actions.create_file()) app.gui.main_window.saveFile.triggered.connect(app.file_actions.save_current_file) app.gui.main_window.saveFileAs.triggered.connect(app.file_actions.save_current_file_as) From b1b442b23a432dfe4b3063d9e693f08fd9115697 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Mon, 9 Dec 2024 18:11:46 +0100 Subject: [PATCH 08/18] Set new file default content to a single byte full of zeros so that the cursor doesn't leave replace mode. --- file.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/file.py b/file.py index 60c89e1..073db5a 100644 --- a/file.py +++ b/file.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 import os.path -from PyQt6.QtWidgets import QFileDialog, QTabWidget +from PyQt6.QtWidgets import QFileDialog from editor import BitEditor MAX_FILE_SIZE = 262144 # 2^18 @@ -22,7 +22,10 @@ class FileActions: if dialog.exec(): self.open_multiple_files(dialog.selectedFiles()) - def create_file(self, content: bin=b""): + def create_file(self, content: bytes=(0).to_bytes(1)): + # open a dialog where the user can choose a new filepath and create an empty file at that path + # bytes=(0).to_bytes(1) creates a byte with only zeros in it + file_path, extension = QFileDialog.getSaveFileName( caption="New File", directory=self.app.utils.home_path, From b7a6ba567af7fe40711f7eba9a341cc18f86d8e8 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 14 Dec 2024 18:41:42 +0100 Subject: [PATCH 09/18] 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"], + } +) From ea8b7456cc4825bb630aba7b906d5f3058f11565 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 14 Dec 2024 18:50:49 +0100 Subject: [PATCH 10/18] Modified the README.md accordingly to the latest changes. (Explained how to install the editor using pip) --- README.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4df07cb..b6f4ca2 100644 --- a/README.md +++ b/README.md @@ -6,25 +6,23 @@ So I just made one. ### Features -| Feature | Description | State | -|-----------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------| -| Editing of basic image formats /
"Syntax Highlighting" | If u have a very simple black/white image format
where single bits control the color,
the editor can highlight the enabled bits. | Implemented | +| Feature | Description | State | +|-----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------| +| Editing of basic image formats /
"Syntax Highlighting" | If you have a very simple black/white image format
where single bits control the color,
the editor can highlight the enabled bits. | Implemented | ## Setup This program was made for Linux.\ It may work on Windows or Mac too, but it was not tested on these systems.\ -To be able to use this program, you have to clone the repository,\ -install the requirements, convert the ui files to python files\ -and make the file called "main.py" executable.\ +To install the editor, you just have to clone the repository,\ +convert the ui files to python files and install the editor using pip.\ You can do that using these commands: ```bash git clone https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor.git cd Bread_Editor -pip install -r requirements.txt python3 gui/raw_ui/ui_to_py.py -chmod +x main.py +pip install . ``` If you have already set up git for ssh, you can also clone the repository like this: @@ -33,5 +31,4 @@ If you have already set up git for ssh, you can also clone the repository like t git clone git git@teapot.informationsanarchistik.de:Wobbl/Bread_Editor.git ``` -Now you can execute the program using `./main.py`. -You can also create a desktop shortcut to the file. \ No newline at end of file +You can now start the editor by typing in the terminal: `bread_editor` \ No newline at end of file From 47ede1e6894e030861e15f3fd19b1519f172b10f Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 14 Dec 2024 19:19:29 +0100 Subject: [PATCH 11/18] setup.py now automatically executes the gui generation script. --- bread_editor/__init__.py | 2 -- bread_editor/gui/raw_ui/ui_to_py.py | 17 +++++++++++++---- setup.py | 7 +++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/bread_editor/__init__.py b/bread_editor/__init__.py index 23d4ce1..a93a4bf 100644 --- a/bread_editor/__init__.py +++ b/bread_editor/__init__.py @@ -1,3 +1 @@ #!/usr/bin/python3 - -from bread_editor.main import start_from_command_line diff --git a/bread_editor/gui/raw_ui/ui_to_py.py b/bread_editor/gui/raw_ui/ui_to_py.py index ac953c1..a28a93c 100644 --- a/bread_editor/gui/raw_ui/ui_to_py.py +++ b/bread_editor/gui/raw_ui/ui_to_py.py @@ -7,9 +7,13 @@ working_dir = os.getcwd() if not working_dir.split('/')[-1] == "raw_ui": # cd into the right directory if this gets executed from somewhere else os.chdir(os.path.dirname(os.path.abspath(__file__))) -input_debug = input("Do you want to debug the gui scripts? (Make gui scripts executable.) (y/n): ") +if __name__ == "__main__": # dont ask for debug on setup + input_debug = input("Do you want to debug the gui scripts? (Make gui scripts executable.) (y/n): ") -debug = input_debug == "y" + debug = input_debug == "y" + +else: + debug = False params = "-o" if debug: @@ -19,5 +23,10 @@ paths = { "main_window.ui": "main_window.py" } -for ui_file, script_out in paths.items(): - os.system(f"pyuic6 {ui_file} {params} ../{script_out}") + +def convert_ui(): + for ui_file, script_out in paths.items(): + os.system(f"pyuic6 {ui_file} {params} ../{script_out}") + + +os.chdir(working_dir) # switch back to the working directory from which the script was executed diff --git a/setup.py b/setup.py index cf18162..bf7f6c7 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,11 @@ #!/usr/bin/python3 import setuptools +from bread_editor.gui.raw_ui import ui_to_py from pathlib import Path +ui_to_py.convert_ui() # convert the .ui files to .py files before setup + this_directory = Path(__file__).parent # use readme file as long description long_description = (this_directory / "README.md").read_text() @@ -15,13 +18,13 @@ setuptools.setup( url="https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor", author="The Wobbler", author_email="emil@i21k.de", - packages=["bread_editor"], + packages=["bread_editor", "bread_editor.gui"], 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"], + "console_scripts": ["bread_editor=bread_editor.main:start_from_command_line"], } ) From fb7a160d00116957e0bf59567ae7c1afd75c27a1 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 14 Dec 2024 19:23:30 +0100 Subject: [PATCH 12/18] Simplified installation instructions because a manual conversion of the ui files is no longer needed. --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index b6f4ca2..9dcf9c7 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,12 @@ So I just made one. This program was made for Linux.\ It may work on Windows or Mac too, but it was not tested on these systems.\ -To install the editor, you just have to clone the repository,\ -convert the ui files to python files and install the editor using pip.\ +To install the editor, you just have to clone the repository and install it using pip.\ You can do that using these commands: ```bash git clone https://teapot.informationsanarchistik.de/Wobbl/Bread_Editor.git cd Bread_Editor -python3 gui/raw_ui/ui_to_py.py pip install . ``` From 5cf5885d4b1bc053b16d48dd62ab76c6ab63f439 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 14 Dec 2024 19:40:31 +0100 Subject: [PATCH 13/18] Set default parameter for int.to_bytes() so that the editor is compatible with Python<3.12 The parameter is only standard since Python3.12. --- bread_editor/file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bread_editor/file.py b/bread_editor/file.py index 4b8a8fd..0802f5d 100644 --- a/bread_editor/file.py +++ b/bread_editor/file.py @@ -22,7 +22,7 @@ class FileActions: if dialog.exec(): self.open_multiple_files(dialog.selectedFiles()) - def create_file(self, content: bytes=(0).to_bytes(1)): + def create_file(self, content: bytes=(0).to_bytes(1, "big")): # open a dialog where the user can choose a new filepath and create an empty file at that path # bytes=(0).to_bytes(1) creates a byte with only zeros in it From d3b3dbc754d8d11c1ce3818c32881fad667cfb1a Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 14 Dec 2024 22:01:41 +0100 Subject: [PATCH 14/18] Fixed some bugs in the ui conversion script. --- bread_editor/gui/raw_ui/ui_to_py.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/bread_editor/gui/raw_ui/ui_to_py.py b/bread_editor/gui/raw_ui/ui_to_py.py index a28a93c..abf5012 100644 --- a/bread_editor/gui/raw_ui/ui_to_py.py +++ b/bread_editor/gui/raw_ui/ui_to_py.py @@ -2,31 +2,35 @@ import os -working_dir = os.getcwd() -if not working_dir.split('/')[-1] == "raw_ui": # cd into the right directory if this gets executed from somewhere else - os.chdir(os.path.dirname(os.path.abspath(__file__))) +def convert_ui(): + working_dir = os.getcwd() + + if not working_dir.split('/')[ + -1] == "raw_ui": # cd into the right directory if this gets executed from somewhere else + os.chdir(os.path.dirname(os.path.abspath(__file__))) + + for ui_file, script_out in paths.items(): + os.system(f"pyuic6 {ui_file} {params} ../{script_out}") + + os.chdir(working_dir) # switch back to the working directory from which the script was executed + if __name__ == "__main__": # dont ask for debug on setup input_debug = input("Do you want to debug the gui scripts? (Make gui scripts executable.) (y/n): ") debug = input_debug == "y" + convert_ui() + else: debug = False params = "-o" + if debug: params = "-xo" paths = { "main_window.ui": "main_window.py" } - - -def convert_ui(): - for ui_file, script_out in paths.items(): - os.system(f"pyuic6 {ui_file} {params} ../{script_out}") - - -os.chdir(working_dir) # switch back to the working directory from which the script was executed From 9a3789a99b7342316cb4a3477f0027c1cc0398b0 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 14 Dec 2024 22:15:34 +0100 Subject: [PATCH 15/18] Included necessary libraries in the README.md --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9dcf9c7..35ce065 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,14 @@ So I just made one. ## Setup -This program was made for Linux.\ -It may work on Windows or Mac too, but it was not tested on these systems.\ -To install the editor, you just have to clone the repository and install it using pip.\ +This program was made for Linux. It may work on Windows or Mac too, but it was not tested on these systems.\ +Before you can install the editor, you first have to install the requirements. That can be done using: + +```bash +sudo apt install pyqt6-dev-tools xcb libxcb-curser0 +``` + +And to install the editor, you just have to clone the repository and install it using pip.\ You can do that using these commands: ```bash From e863815b412e25dffb6d3f148868a67d8dae849c Mon Sep 17 00:00:00 2001 From: Megamichi Date: Sat, 14 Dec 2024 23:42:33 +0100 Subject: [PATCH 16/18] Typo in README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit schon wieder n problem 😅 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 35ce065..3b2ced4 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This program was made for Linux. It may work on Windows or Mac too, but it was n Before you can install the editor, you first have to install the requirements. That can be done using: ```bash -sudo apt install pyqt6-dev-tools xcb libxcb-curser0 +sudo apt install pyqt6-dev-tools xcb libxcb-cursor0 ``` And to install the editor, you just have to clone the repository and install it using pip.\ From 2cb7b80cb8475c523d808af98f518527b9f27fca Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sun, 15 Dec 2024 15:43:09 +0100 Subject: [PATCH 17/18] Moved function connect_gui() from own file to GUI class for better OOP and less complicated file structure. --- bread_editor/connect_gui.py | 15 --------------- bread_editor/main.py | 1 - bread_editor/ui.py | 18 +++++++++++++++--- 3 files changed, 15 insertions(+), 19 deletions(-) delete mode 100644 bread_editor/connect_gui.py diff --git a/bread_editor/connect_gui.py b/bread_editor/connect_gui.py deleted file mode 100644 index d9ee6c1..0000000 --- a/bread_editor/connect_gui.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/python3 - -def connect_gui(app): - app.gui.main_window.openFile.triggered.connect(app.file_actions.open_files) - app.gui.main_window.newFile.triggered.connect(lambda: app.file_actions.create_file()) - app.gui.main_window.saveFile.triggered.connect(app.file_actions.save_current_file) - app.gui.main_window.saveFileAs.triggered.connect(app.file_actions.save_current_file_as) - - app.gui.main_window.menuSettings.triggered.connect(app.gui.main_window.settingsDock.show) - - app.gui.main_window.bitsAreSquaresSetting.stateChanged.connect(app.utils.update_style_in_all_bit_editors) - app.gui.main_window.highlightOnesSetting.stateChanged.connect(app.utils.update_style_in_all_bit_editors) - - app.gui.main_window.openFileTabs.tabCloseRequested.connect(app.file_actions.close_current_file) - app.gui.QTMainWindow.closeEvent = app.utils.on_close diff --git a/bread_editor/main.py b/bread_editor/main.py index 5cb0d5d..fc11e69 100755 --- a/bread_editor/main.py +++ b/bread_editor/main.py @@ -24,7 +24,6 @@ class BreadEditor: self.gui = GUI(self) - self.gui.connect_gui(self) self.open_files: dict[str, File] = {} self.open_files_queue = [] diff --git a/bread_editor/ui.py b/bread_editor/ui.py index ec6862c..a866707 100644 --- a/bread_editor/ui.py +++ b/bread_editor/ui.py @@ -2,7 +2,6 @@ from PyQt6.QtWidgets import QApplication, QMainWindow from bread_editor.gui.main_window import Ui_MainWindow -from bread_editor.connect_gui import connect_gui class GUI: @@ -15,8 +14,7 @@ class GUI: self.main_window = Ui_MainWindow() self.setup_gui() - - self.connect_gui = connect_gui + self.connect_gui() def setup_gui(self): self.main_window.setupUi(self.QTMainWindow) @@ -30,3 +28,17 @@ class GUI: self.main_window.highlightOnesSetting.setChecked(self.app.settings.highlight_ones) self.app.utils.update_style_in_all_bit_editors() + + def connect_gui(self): + self.main_window.openFile.triggered.connect(self.app.file_actions.open_files) + self.main_window.newFile.triggered.connect(lambda: self.app.file_actions.create_file()) + self.main_window.saveFile.triggered.connect(self.app.file_actions.save_current_file) + self.main_window.saveFileAs.triggered.connect(self.app.file_actions.save_current_file_as) + + self.main_window.menuSettings.triggered.connect(self.main_window.settingsDock.show) + + self.main_window.bitsAreSquaresSetting.stateChanged.connect(self.app.utils.update_style_in_all_bit_editors) + self.main_window.highlightOnesSetting.stateChanged.connect(self.app.utils.update_style_in_all_bit_editors) + + self.main_window.openFileTabs.tabCloseRequested.connect(self.app.file_actions.close_current_file) + self.QTMainWindow.closeEvent = self.app.utils.on_close From 436cb3018cadeef633ff29ecd9962b443fa698fd Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sun, 15 Dec 2024 16:07:47 +0100 Subject: [PATCH 18/18] Made the cursor also be a square when square bits is enabled. --- bread_editor/editor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bread_editor/editor.py b/bread_editor/editor.py index f5e5c87..64d99f9 100644 --- a/bread_editor/editor.py +++ b/bread_editor/editor.py @@ -55,6 +55,11 @@ class BitEditor: self.font.setLetterSpacing(QFont.SpacingType.PercentageSpacing, spacing) self.input.setFont(self.font) + self.cursor_width = self.input.fontMetrics().averageCharWidth() + + # set the cursor with to match the letter spacing + self.input.setCursorWidth(self.cursor_width + 1) # + 1 because else it somehow draws a 1px wide vertical line + highlight_ones = self.app.settings.highlight_ones highlighter_document = self.input.document() if highlight_ones else None