Added ui.py to make everything a little more oop.
This commit is contained in:
parent
fdd83c204e
commit
4cf77ac631
4 changed files with 42 additions and 28 deletions
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
def connect_gui(app):
|
def connect_gui(app):
|
||||||
app.main_window.openFile.triggered.connect(app.file_actions.open_files)
|
app.gui.main_window.openFile.triggered.connect(app.file_actions.open_files)
|
||||||
app.main_window.saveFile.triggered.connect(app.file_actions.save_current_file)
|
app.gui.main_window.saveFile.triggered.connect(app.file_actions.save_current_file)
|
||||||
app.main_window.openFileTabs.tabCloseRequested.connect(app.file_actions.close_current_file)
|
app.gui.main_window.openFileTabs.tabCloseRequested.connect(app.file_actions.close_current_file)
|
||||||
app.QTMainWindow.closeEvent = app.utils.on_close
|
app.gui.QTMainWindow.closeEvent = app.utils.on_close
|
||||||
app.main_window.menuSettings.triggered.connect(app.utils.open_settings)
|
app.gui.main_window.menuSettings.triggered.connect(app.utils.open_settings)
|
||||||
|
|
14
file.py
14
file.py
|
@ -11,7 +11,7 @@ class FileActions:
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
def open_files(self):
|
def open_files(self):
|
||||||
dialog = QFileDialog(self.app.QTMainWindow)
|
dialog = QFileDialog(self.app.gui.QTMainWindow)
|
||||||
dialog.setDirectory(self.app.utils.home_path)
|
dialog.setDirectory(self.app.utils.home_path)
|
||||||
dialog.setFileMode(QFileDialog.FileMode.ExistingFiles)
|
dialog.setFileMode(QFileDialog.FileMode.ExistingFiles)
|
||||||
dialog.setNameFilters(["Binary (*.bin)", "Any (*)"])
|
dialog.setNameFilters(["Binary (*.bin)", "Any (*)"])
|
||||||
|
@ -33,18 +33,18 @@ class FileActions:
|
||||||
self.app.open_files[path].not_saved = False
|
self.app.open_files[path].not_saved = False
|
||||||
|
|
||||||
def save_current_file(self):
|
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()
|
current_file_path = current_tab.objectName()
|
||||||
|
|
||||||
self.save_file(current_file_path)
|
self.save_file(current_file_path)
|
||||||
|
|
||||||
def close_file(self, path, tab_index):
|
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]
|
del self.app.open_files[path]
|
||||||
|
|
||||||
def close_current_file(self):
|
def close_current_file(self):
|
||||||
tab_index = self.app.main_window.openFileTabs.currentIndex()
|
tab_index = self.app.gui.main_window.openFileTabs.currentIndex()
|
||||||
current_file_path = self.app.main_window.openFileTabs.currentWidget().objectName()#
|
current_file_path = self.app.gui.main_window.openFileTabs.currentWidget().objectName()#
|
||||||
|
|
||||||
if self.app.open_files[current_file_path].not_saved:
|
if self.app.open_files[current_file_path].not_saved:
|
||||||
save_or_not = self.app.utils.unsaved_changes_popup()
|
save_or_not = self.app.utils.unsaved_changes_popup()
|
||||||
|
@ -80,7 +80,7 @@ class File:
|
||||||
self.content = file_content
|
self.content = file_content
|
||||||
|
|
||||||
# the widget that contains all the 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_widget_layout = QVBoxLayout()
|
||||||
|
|
||||||
self.content_binary_input = BinaryTextEdit()
|
self.content_binary_input = BinaryTextEdit()
|
||||||
|
@ -102,7 +102,7 @@ class File:
|
||||||
|
|
||||||
self.content_widget.setLayout(self.content_widget_layout)
|
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.content_widget,
|
||||||
self.name
|
self.name
|
||||||
)
|
)
|
||||||
|
|
22
main.py
22
main.py
|
@ -1,36 +1,26 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from PyQt6.QtWidgets import QApplication, QMainWindow
|
|
||||||
from utils import Utils
|
from utils import Utils
|
||||||
from file import FileActions
|
from file import FileActions
|
||||||
from connect_gui import connect_gui
|
from ui import GUI
|
||||||
from gui.main_window import Ui_MainWindow
|
|
||||||
|
|
||||||
|
|
||||||
class BreadEditor:
|
class BreadEditor:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.utils = Utils(self)
|
self.utils = Utils(self)
|
||||||
self.file_actions = FileActions(self)
|
self.file_actions = FileActions(self)
|
||||||
|
self.gui = GUI(self)
|
||||||
|
|
||||||
|
self.gui.connect_gui(self)
|
||||||
|
|
||||||
self.open_files = {}
|
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):
|
def run(self):
|
||||||
self.utils.popup_init()
|
self.utils.popup_init()
|
||||||
|
|
||||||
self.QTMainWindow.show()
|
self.gui.QTMainWindow.show()
|
||||||
sys.exit(self.qt_app.exec())
|
sys.exit(self.gui.qt_app.exec())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
24
ui.py
Normal file
24
ui.py
Normal file
|
@ -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()
|
Loading…
Reference in a new issue