I'm trying to figure out why the window is closing after opening. I looked at examples of why this has happened for others but my application is set up a little differently (possibly a newer version of pyqt than the ones I was looking at or because I have it launching from within a tool bar menu).
Below is the main parts of the code that launch the first window of type Class1Base and which launch but lose the second window NewWindow (had to alter names for anonymity).
In ToolbarMenuSetup.py:
class ToolbarMenuSetup(object):
# only including call to the below for brevity
def clickOpenClass1(self):
self.config = self.toolbarConfig()
retval = Class1(self.class1_dlg, self.config)
In Class1.py:
class Class1(Class1Base):
def __init__(self, dlg, config):
self.dlg = dlg
self.iface = self.dlg.iface
self.config = config
self.dlg.ui.btnOpenWindow.clicked.connect(self.openNewWindow)
self.run()
In Class1Base.py:
class NewWindow(Qt.QDialog, UI_NewWindowBase):
def __init__(self, ToolbarMenuSetup):
QtGui.QDialog.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setupUi(self)
class Class1Base():
def __init__(self, dlg, config):
self.dlg = dlg
self.iface = self.dlg.iface
self.run()
def openNewWindow(self):
window = NewWindow(self)
window.show()
def run(self):
self.dlg.show()
result = self.dlg.exec_()
if(result):
performCalculations()
# this function not included for brevity
Any help is greatly appreciated!
Resolved by:
- added self.window = None
into run()
- added self.
in front of the lines in openNewWindow()