File opening working.

(Only the popup that sets the variable.)
This commit is contained in:
The Wobbler 2024-11-17 18:54:51 +01:00
commit 2797c3ca44
5 changed files with 129 additions and 0 deletions

4
connect_gui.py Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/python3
def connect_gui(app):
app.main_window.openFile.triggered.connect(app.utils.open_file)

55
gui/raw_ui/main_window.ui Normal file
View file

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="fileMenu">
<property name="title">
<string>File</string>
</property>
<addaction name="openFile"/>
</widget>
<addaction name="fileMenu"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="openFile">
<property name="checkable">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="text">
<string>Open</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
<property name="visible">
<bool>true</bool>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

18
gui/raw_ui/ui_to_py.py Normal file
View file

@ -0,0 +1,18 @@
#!/usr/bin/python3
import os
input_debug = input("Do you want to debug the gui scripts? (Make gui scripts executable.) (y/n): ")
debug = input_debug == "y"
params = "-o"
if debug:
params = "-xo"
paths = {
"main_window.ui": "main_window.py"
}
for ui_file, script_out in paths.items():
os.system(f"pyuic6 {ui_file} {params} ../{script_out}")

31
main.py Normal file
View file

@ -0,0 +1,31 @@
#!/usr/bin/python3
import sys
from PyQt6 import QtWidgets
from gui.main_window import Ui_MainWindow
from utils import Utils
from connect_gui import connect_gui
class BreadEditor:
def __init__(self):
self.utils = Utils(self)
self.open_files = []
self.qt_app = QtWidgets.QApplication(sys.argv)
self.QTMainWindow = QtWidgets.QMainWindow()
self.main_window = Ui_MainWindow()
self.main_window.setupUi(self.QTMainWindow)
connect_gui(self)
def run(self):
self.QTMainWindow.show()
sys.exit(self.qt_app.exec())
if __name__ == "__main__":
editor = BreadEditor()
editor.run()

21
utils.py Normal file
View file

@ -0,0 +1,21 @@
#!/usr/bin/python3
from pathlib import Path
from PyQt6.QtWidgets import QFileDialog
class Utils:
def __init__(self, app):
self.app = app
self.home_path = str(Path.home())
def open_file(self):
dialog = QFileDialog(self.app.QTMainWindow)
dialog.setDirectory(self.home_path)
dialog.setFileMode(QFileDialog.FileMode.ExistingFiles)
dialog.setNameFilters(["Binary (*.bin)", "Any (*)"])
dialog.setViewMode(QFileDialog.ViewMode.List)
if dialog.exec():
self.app.open_files += dialog.selectedFiles()