-
-
Save thirstydevil/d9d185a11f65a8a16a0a6ba13c87abe1 to your computer and use it in GitHub Desktop.
mGear settingsUI base class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### component/guide.py | |
class guideSettingsDialog(QtWidgets.QDialog): | |
def __getattribute__(self, attr): | |
""" | |
Always try to get properties from the internal ui file after the parent object | |
Now this basically gets over the error (Internal c++ Object Already Deleted) when you don't save the | |
objects on the widget stack by adding them to a layout or setting their parent. | |
so : QtCompat.loadUi(path + "/{}".format(ui_file), self) works but causes the error Internal c++ Object Already Deleted | |
but : self.ui = QtCompat.loadUi(path + "/{}".format(ui_file)) is stable but incompatible with the way | |
widgets are being used from mgear as they are accessed directly on the parent object | |
""" | |
# return any functions straight away | |
try: | |
attr_ = object.__getattribute__(self, attr) | |
return attr_ | |
except Exception: | |
try: | |
ui = object.__getattribute__(self, "ui") | |
if ui: | |
try: | |
return object.__getattribute__(ui, attr) | |
except Exception as e: | |
return object.__getattribute__(self, attr) | |
else: | |
return object.__getattribute__(self, attr) | |
except Exception as e: | |
return object.__getattribute__(self, attr) | |
def set_ui_file(self, ui_file=None): | |
if ui_file is None: | |
ui_file = "settingsUI.ui" | |
path = os.path.dirname(sys.modules[self.__module__].__file__) | |
self.ui = QtCompat.loadUi(path + "/{}".format(ui_file)) | |
self.layout().addWidget(self.ui) | |
def __init__(self, parent=None): | |
super(guideSettingsDialog, self).__init__(parent) | |
self.ui = None | |
self.setLayout(QtWidgets.QVBoxLayout()) | |
self.layout().setContentsMargins(0, 0, 0, 0) | |
### your guide file | |
class settingsTab(guide.guideSettingsDialog): | |
"""The Component settings UI""" | |
def __init__(self, parent=None): | |
super(settingsTab, self).__init__(parent) | |
self.set_ui_file() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment