Some refactoring; now using QUiLoader to load the .uic file directly

This commit is contained in:
Blue Fox 2023-07-09 08:54:14 +02:00
parent 6da873d3d3
commit 07b42abdfd
4 changed files with 20 additions and 14 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
Scorganizr.pyproject.user
Scorganizr.pyproject.user*
__pycache__/

View File

@ -1,3 +1,3 @@
{
"files": ["main.py", "form.ui"]
"files": ["main.ui","main.py","utils.py"]
}

30
main.py
View File

@ -1,19 +1,25 @@
# This Python file uses the following encoding: utf-8
import sys
from PySide6.QtWidgets import QApplication, QMainWindow
from ui_form import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import QFile, QIODevice
from PySide6.QtUiTools import QUiLoader
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = MainWindow()
widget.show()
ui_file_name = "main.ui"
ui_file = QFile(ui_file_name)
if not ui_file.open(QIODevice.ReadOnly):
print(f"Cannot open {ui_file_name}: {ui_file.errorString()}")
sys.exit(-1)
loader = QUiLoader()
window = loader.load(ui_file)
ui_file.close()
if not window:
print(loader.errorString())
sys.exit(-1)
window.show()
sys.exit(app.exec())

View File