From 4cf77ac6317116e7686ed9b7878eda4842390872 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Thu, 21 Nov 2024 16:56:08 +0100 Subject: [PATCH] Added ui.py to make everything a little more oop. --- connect_gui.py | 10 +++++----- file.py | 14 +++++++------- main.py | 22 ++++++---------------- ui.py | 24 ++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 ui.py diff --git a/connect_gui.py b/connect_gui.py index aebd04f..d9ebb66 100644 --- a/connect_gui.py +++ b/connect_gui.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 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) - app.main_window.openFileTabs.tabCloseRequested.connect(app.file_actions.close_current_file) - app.QTMainWindow.closeEvent = app.utils.on_close - app.main_window.menuSettings.triggered.connect(app.utils.open_settings) + app.gui.main_window.openFile.triggered.connect(app.file_actions.open_files) + app.gui.main_window.saveFile.triggered.connect(app.file_actions.save_current_file) + app.gui.main_window.openFileTabs.tabCloseRequested.connect(app.file_actions.close_current_file) + app.gui.QTMainWindow.closeEvent = app.utils.on_close + app.gui.main_window.menuSettings.triggered.connect(app.utils.open_settings) diff --git a/file.py b/file.py index fa4f2f5..b771a9f 100644 --- a/file.py +++ b/file.py @@ -11,7 +11,7 @@ class FileActions: self.app = app def open_files(self): - dialog = QFileDialog(self.app.QTMainWindow) + dialog = QFileDialog(self.app.gui.QTMainWindow) dialog.setDirectory(self.app.utils.home_path) dialog.setFileMode(QFileDialog.FileMode.ExistingFiles) dialog.setNameFilters(["Binary (*.bin)", "Any (*)"]) @@ -33,18 +33,18 @@ class FileActions: self.app.open_files[path].not_saved = False def save_current_file(self): - current_tab = self.app.main_window.openFileTabs.currentWidget() + current_tab = self.app.gui.main_window.openFileTabs.currentWidget() current_file_path = current_tab.objectName() self.save_file(current_file_path) def close_file(self, path, tab_index): - self.app.main_window.openFileTabs.removeTab(tab_index) + self.app.gui.main_window.openFileTabs.removeTab(tab_index) del self.app.open_files[path] def close_current_file(self): - tab_index = self.app.main_window.openFileTabs.currentIndex() - current_file_path = self.app.main_window.openFileTabs.currentWidget().objectName()# + tab_index = self.app.gui.main_window.openFileTabs.currentIndex() + current_file_path = self.app.gui.main_window.openFileTabs.currentWidget().objectName()# if self.app.open_files[current_file_path].not_saved: save_or_not = self.app.utils.unsaved_changes_popup() @@ -80,7 +80,7 @@ class File: self.content = file_content # the widget that contains all the file content - self.content_widget = QWidget(self.app.main_window.openFileTabs, objectName=path) + self.content_widget = QWidget(self.app.gui.main_window.openFileTabs, objectName=path) self.content_widget_layout = QVBoxLayout() self.content_binary_input = BinaryTextEdit() @@ -102,7 +102,7 @@ class File: 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.app.gui.main_window.openFileTabs.addTab( # add a tab for the file in the top files list self.content_widget, self.name ) diff --git a/main.py b/main.py index 75121ed..58a11bb 100755 --- a/main.py +++ b/main.py @@ -1,36 +1,26 @@ #!/usr/bin/python3 import sys -from PyQt6.QtWidgets import QApplication, QMainWindow from utils import Utils from file import FileActions -from connect_gui import connect_gui -from gui.main_window import Ui_MainWindow +from ui import GUI class BreadEditor: def __init__(self): self.utils = Utils(self) self.file_actions = FileActions(self) + self.gui = GUI(self) + + self.gui.connect_gui(self) self.open_files = {} - self.qt_app = QApplication(sys.argv) - - self.QTMainWindow = QMainWindow() - - self.main_window = Ui_MainWindow() - self.main_window.setupUi(self.QTMainWindow) - - connect_gui(self) - - self.main_window.settingsDock.hide() - def run(self): self.utils.popup_init() - self.QTMainWindow.show() - sys.exit(self.qt_app.exec()) + self.gui.QTMainWindow.show() + sys.exit(self.gui.qt_app.exec()) if __name__ == "__main__": diff --git a/ui.py b/ui.py new file mode 100644 index 0000000..e34e72c --- /dev/null +++ b/ui.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +import sys +from PyQt6.QtWidgets import QApplication, QMainWindow +from gui.main_window import Ui_MainWindow +from connect_gui import connect_gui + + +class GUI: + def __init__(self, app): + self.app = app + + self.qt_app = QApplication(sys.argv) + self.QTMainWindow = QMainWindow() + + self.main_window = Ui_MainWindow() + + self.setup_gui() + + self.connect_gui = connect_gui + + def setup_gui(self): + self.main_window.setupUi(self.QTMainWindow) + self.main_window.settingsDock.hide()