I want to create a small tool, that will read all the python tools in the folder, put them in a QListWidget and every time I double-click on one of the tools, it will run.
ToolList.py
That's the main window with the tools
import sys
import glob
from PySide import QtGui
class List(QtGui.QListWidget):
def __init__(self, parent=None):
super(List, self).__init__(parent)
# Add tools
for f in glob.glob("tool_*.py"):
self.addItem(f)
self.itemDoubleClicked.connect(self.execute_python)
def execute_python(self):
for itm in self.selectedItems():
execfile(itm.text())
if __name__ == '__main__':
app = QtGui.QApplication([])
form = List()
form.show()
sys.exit(app.exec_())
tool_test1.py
When I double click this one, it disappears automatically
import sys
from PySide import QtGui
if __name__ == '__main__':
app = QtGui.QApplication.instance()
but = QtGui.QPushButton()
but.show()
tool_test2.py
And when I double click this one, it crashes saying QCoreApplication::exec: The event loop is already running
import sys
from PySide import QtGui
if __name__ == '__main__':
app = QtGui.QApplication.instance()
but = QtGui.QPushButton()
but.show()
sys.exit(app.exec_())
Any ideas?
Thanks, Nick