main.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/python
  3. #
  4. # Copyright (c) Contributors to the Open 3D Engine Project.
  5. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. #
  7. # SPDX-License-Identifier: Apache-2.0 OR MIT
  8. #
  9. #
  10. # -------------------------------------------------------------------------
  11. import os
  12. import sys
  13. from PySide2.QtCore import QFile, QSize
  14. from PySide2.QtUiTools import QUiLoader
  15. from PySide2.QtWidgets import QApplication, QSizePolicy
  16. from PySide2.QtWidgets import QMainWindow, QWidget, QVBoxLayout, QHBoxLayout
  17. _MODULE_DIR_PATH = os.path.dirname(os.path.abspath(__file__))
  18. _UI_FILEPATH = "{0}\\\\sbs_builder_widget.ui".format(_MODULE_DIR_PATH)
  19. _PROGRAM_NAME_VERSION = 'Substance Builder'
  20. class UiLoader(QUiLoader):
  21. def __init__(self, baseInstance):
  22. super(UiLoader, self).__init__(baseInstance)
  23. self._baseInstance = baseInstance
  24. def createWidget(self, classname, parent=None, name=""):
  25. widget = super(UiLoader, self).createWidget(
  26. classname, parent, name)
  27. if parent is None:
  28. return self._baseInstance
  29. else:
  30. setattr(self._baseInstance, name, widget)
  31. return widget
  32. class MainWindow(QMainWindow):
  33. def __init__(self, ui_file=_UI_FILEPATH, parent=None):
  34. super().__init__(parent)
  35. # Setup central widget and layout
  36. self.central_widget = QWidget()
  37. self.central_layout = QVBoxLayout(self.central_widget)
  38. self.central_layout.setContentsMargins(8, 8, 8, 8)
  39. self.setCentralWidget(self.central_widget)
  40. self.setup_layout(ui_file)
  41. self.setMinimumSize(QSize(675, 825))
  42. def setup_layout(self, ui_file):
  43. self.layout = QHBoxLayout()
  44. self.widget = MyWidget(ui_file, self)
  45. self.widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
  46. self.layout.addWidget(self.widget)
  47. self.central_layout.addLayout(self.layout)
  48. class MyWidget(QWidget):
  49. def __init__(self, ui_file=_UI_FILEPATH, parent=None):
  50. super().__init__(parent)
  51. loader = UiLoader(parent)
  52. file = QFile(ui_file)
  53. file.open(QFile.ReadOnly)
  54. loader.load(file, self)
  55. file.close()
  56. if __name__ == "__main__":
  57. app = QApplication(sys.argv)
  58. mainWindow = MainWindow(_UI_FILEPATH)
  59. mainWindow.setWindowTitle(_PROGRAM_NAME_VERSION)
  60. mainWindow.show()
  61. sys.exit(app.exec_())