So I'm working on getting a popup working in multiple imported files, and come upon many answers and they all have the same format(see: Displaying pop-up windows in Python (PyQt4) )
They use this(summary):
class MyForm(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
# Usual setup stuff
self.ui = Ui_Dialog()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp= MyForm()
myapp.show()
sys.exit(app.exec_())
This is crucial because to open the popup you need to keep a reference to it, like myapp is doing here.
In QTDesigner, it sets it up something like this in the if (__name__ == '__main__')
app = QtGui.QApplication(sys.argv)
m = Ui_Frame()
Frame = QtGui.QWidget()
m.setupUi(Frame)
Frame.show()
With the actual class/ui setup like this:
class Ui_Frame(object):
def setupUi(self, Frame):
I tried to merge the two, but I am just getting a blank popup window like the setupUi isn't running. My code:
Edit: The new code with the disappearing window problem:
importedfile.py
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Frame(QtGui.QWidget):
def __init__(self, xlist, y, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setupUi(xlist,y)
def setupUi(self, xlist, y):
self.setObjectName(_fromUtf8("Frame"))
self.resize(800, 400)
self.tableWidget = QtGui.QTableWidget(self)
...
def startup(xlist, y):
myapp= Ui_Frame(xlist, y)
myapp.show()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp= Ui_Frame()
myapp.show()
sys.exit(app.exec_())
other.py is just a simple:
import importedfile
#app = QtGui.QApplication(sys.argv) and sys.exit are somewhere up here for the other frame
...code...
tempholder = importedfile.startup(xlist,y)
#Using a var for the startup() or not using has the same results
I'm obviously missing something simple. setupUi is actually running, as everything in it is printing and such, but just nothing is showing up in the main window, just a blank frame