From 64bb1fbf1522b6369bf1c6511a7770a7d20d0769 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Tue, 19 Nov 2024 17:52:08 +0100 Subject: [PATCH] Data is now represented in readable Binary. --- file.py | 13 +++++++++---- utils.py | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/file.py b/file.py index b7f9f27..31c6594 100644 --- a/file.py +++ b/file.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -from PyQt6.QtWidgets import QWidget, QLabel, QFileDialog +from PyQt6.QtWidgets import QWidget, QPlainTextEdit, QFileDialog, QVBoxLayout class FileActions: @@ -26,7 +26,7 @@ class File: self.path = path self.name = name - file = open(path, "r") + file = open(path, "rb") file_content = file.read() file.close() @@ -34,8 +34,13 @@ class File: # the widget that contains all the file content self.content_widget = QWidget(self.app.main_window.openFileTabs) - self.content_label = QLabel(self.content_widget) # the label for the text in the file - self.content_label.setText(file_content) + self.content_widget_layout = QVBoxLayout() + + self.content_binary_input = QPlainTextEdit(self.content_widget) + self.content_widget_layout.addWidget(self.content_binary_input) + self.content_binary_input.setPlainText(self.app.utils.bstring_to_oz(file_content)) + + self.content_widget.setLayout(self.content_widget_layout) self.app.main_window.openFileTabs.addTab( # add a tab for the file in the top files list self.content_widget, diff --git a/utils.py b/utils.py index ee7ea9b..2ce17a7 100644 --- a/utils.py +++ b/utils.py @@ -10,3 +10,8 @@ class Utils: self.app = app self.home_path = str(Path.home()) + + def bstring_to_oz(self, data): # convert binary data to a string of ones and zeros (oz) + oz_string = " ".join([format(byte, "08b") for byte in data]) + + return oz_string