diff --git a/connect_gui.py b/connect_gui.py index 8c10c69..65990c5 100644 --- a/connect_gui.py +++ b/connect_gui.py @@ -2,3 +2,4 @@ def connect_gui(app): app.main_window.openFile.triggered.connect(app.file_actions.open_files) + app.main_window.saveFile.triggered.connect(app.file_actions.save_current_file) diff --git a/file.py b/file.py index 3182824..e456900 100644 --- a/file.py +++ b/file.py @@ -16,10 +16,23 @@ class FileActions: if dialog.exec(): for file_path in dialog.selectedFiles(): - self.app.open_files.append(File(self.app, file_path, file_path.split("/")[-1])) if not file_path in self.app.open_files: # dont open file twice self.app.open_files[file_path] = File(self.app, file_path, file_path.split("/")[-1]) + def save_file(self, path): + oz_string = self.app.open_files[path].content_binary_input.toPlainText() + data = self.app.utils.oz_string_to_bstring(oz_string) + + file = open(path, "wb") + file.write(data) + file.close() + + def save_current_file(self): + current_tab = self.app.main_window.openFileTabs.currentWidget() + current_file_path = current_tab.objectName() + + self.save_file(current_file_path) + class File: def __init__(self, app, path, name): @@ -35,7 +48,7 @@ class File: self.content = file_content # the widget that contains all the file content - self.content_widget = QWidget(self.app.main_window.openFileTabs) + self.content_widget = QWidget(self.app.main_window.openFileTabs, objectName=path) self.content_widget_layout = QVBoxLayout() self.content_binary_input = QPlainTextEdit(self.content_widget) diff --git a/gui/raw_ui/main_window.ui b/gui/raw_ui/main_window.ui index a765abd..821a9fd 100644 --- a/gui/raw_ui/main_window.ui +++ b/gui/raw_ui/main_window.ui @@ -38,6 +38,7 @@ File + @@ -59,6 +60,14 @@ true + + + Save + + + Ctrl+S + + diff --git a/utils.py b/utils.py index eb576ca..0a802f7 100644 --- a/utils.py +++ b/utils.py @@ -18,3 +18,15 @@ class Utils: oz_string = " ".join(oz_bytes) return oz_string + + def oz_string_to_bstring(self, oz_string): # convert a string of zeroes and ones to a binary string + oz_bytes = oz_string.split() + + bytes_int = [] + + for byte in oz_bytes: + bytes_int.append(int(byte, 2)) + + binary_string = bytes(bytes_int) + + return binary_string