I made a kind of tool for MAYA.
Once I call the class and make a instance, I don't have to call it anymore.
Instead I must check the window is existing or not.
In fact, when I press a button to call close() or "X" button, it doesn't call __del()__ method. I can't clear up my works.
So, I plan to check the instance is existing, and if it is, I don't call class, just call show().
But, I can't find the way.
_win = RigControlWindow()
_win.show()
How can RigControlWindow class find the instance is existing?
Keep a reference to the RigControlWindow instance as a private attribute of the main window.
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self._rcwin = None
def showRigControlWindow(self):
if self._rcwin is None:
self._rcwin = RigControlWindow()
self._rcwin.show()
Alternatively, you could use a property:
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self._rcwin = None
@property
def rcwin(self):
if self._rcwin is None:
self._rcwin = RigControlWindow()
return self._rcwin
def showRigControlWindow(self):
self.rcwin.show()
An alternative to ekhumoro's answer, is to have a function in a module like this:
def startGui():
if 'myWindows' in globals():
global myWindows
myWindows.show()
else:
global myWindows
myWindows = init_gui.MainWindow(parent=init_gui.MyMainWindow())
myWindows.show()
And then call startGui from a shelf script like this:
if __name__ == '__main__':
startGui()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With