Here is my own implementation. It has been tested with Python 2.7 and PySide 1.1.
It has essentially the same interface as the C ++ version of QtSingleApplication . The main difference is that you must provide a unique application identifier for the constructor. (By default, C ++ uses the path to the executable as a unique identifier that will not work here, since the executable will most likely be python.exe .)
from PySide.QtCore import * from PySide.QtGui import * from PySide.QtNetwork import * class QtSingleApplication(QApplication): messageReceived = Signal(unicode) def __init__(self, id, *argv): super(QtSingleApplication, self).__init__(*argv) self._id = id self._activationWindow = None self._activateOnMessage = False
Here is a simple test program:
import sys from PySide.QtGui import * from QtSingleApplication import QtSingleApplication appGuid = 'F3FF80BA-BA05-4277-8063-82A6DB9245A2' app = QtSingleApplication(appGuid, sys.argv) if app.isRunning(): sys.exit(0) w = QWidget() w.show() app.setActivationWindow(w) sys.exit(app.exec_())
source share