I am trying to create a UI that will act as a hub to launch all the other tools that have been created. The problem is that if i try to launch the UI from the toolshub UI, it won't let me because the event loop is already running. I know that I cannot do this APP = QtGui.QApplication(sys.argv) and APP.exec_() when launching the new window because the event loop is already running when I did that for the toolshub UI. But I can't figure out how to do it another way.
Here is an example code for one of the tools, works launching on its own.
global APP
APP = None
class toolwindow(QtGui.QDialog):
def __init__(self, parent=None):
init_app()
super(toolwindow, self).__init__(parent)
self.setWindowTitle('tool')
self.setMinimumSize(QtCore.QSize(500, 600))
self.setMaximumSize(QtCore.QSize(500, 600))
self.create_ui()
def create_ui(self):
code goes here
def closeEvent(self, event):
QtGui.QDialog.closeEvent(self, event)
return
def init_app():
global APP
APP = QtGui.QApplication.instance()
if not APP:
APP = QtGui.QApplication(sys.argv)
return
def start_ui():
win= toolwindow()
win.show()
APP.exec_()
if __name__ == '__main__':
start_ui()
global APP
APP = None
Now here is the code for the toolshub ui. These are both separate scripts. In toolshub i am importing the tool above.
import tool
LOGGER = logging.getLogger(__name__)
global APP
APP = None
class toolsHub(QtGui.QDialog):
def __init__(self, parent=None):
init_app()
super(toolsHub, self).__init__(parent)
self.setWindowTitle('Tools Launcher')
self.setSizeGripEnabled(False)
self.setMinimumSize(QtCore.QSize(300, 200))
self.setMaximumSize(QtCore.QSize(300, 200))
self.create_layouts()
def create_layouts(self):
master_layout = QtGui.QVBoxLayout()
self.setLayout(master_layout)
self.input_widgets()
grid_layout = QtGui.QGridLayout()
grid_layout.addWidget(self.env_creator, 0, 0)
grid_layout.addWidget(self.p4dl, 1, 0)
master_layout.addLayout(grid_layout)
def input_widgets(self):
self.tool_button= QtGui.QPushButton('launch tool')
self.tool_button.clicked.connect(self.launch_tool)
def launch_tool(self):
tool.start_ui()
def closeEvent(self, event):
QtGui.QDialog.closeEvent(self, event)
return
def init_app():
global APP
APP = QtGui.QApplication.instance()
if not APP:
APP = QtGui.QApplication(sys.argv)
return
def start_ui():
toolui = toolsHub()
toolui.show()
APP.exec_()
if __name__ == '__main__':
start_ui()
So how do write and structure these so that I can open the tool UI from the toolshub UI? I am guessing the code i have to change is the tool UI, I know i have to take out APP = QtGui.QApplication(sys.argv) and APP.exec_(), but not sure what to do to launch it.
Thanks