Created
April 18, 2013 15:13
-
-
Save blaxter/5413516 to your computer and use it in GitHub Desktop.
PySide QSingleApplication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QSingleApplication(QApplication): | |
def single_start(self, widget): | |
self.widget = widget | |
self.local_socket = QLocalSocket() | |
self.local_socket.connected.connect(self.another_instance_started) | |
self.local_socket.error.connect(self.first_instance) | |
self.local_socket.connectToServer("foobar", QIODevice.WriteOnly) | |
def another_instance_started(self): | |
self.local_socket.write("foobar") | |
self.local_socket.bytesWritten.connect(self.quit) | |
def first_instance(self): | |
self.local_server = QLocalServer() | |
if self.local_server.listen("foobar"): | |
self.local_server.newConnection.connect(self.tried_to_start_another_instance) | |
self.widget.show() | |
def tried_to_start_another_instance(self): | |
def read(): | |
f = self.new_socket.readLine() | |
self.widget.getArgsFromOtherInstance(str(f)) | |
self.widget.activateWindow() | |
self.widget.show() | |
self.new_socket = self.local_server.nextPendingConnection() | |
self.new_socket.readyRead.connect(read) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment