1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 09:46:25 +00:00

Full UTF-8 awareness (close #74)

Tested only on Windows. But he had the biggest problems with it.
This commit is contained in:
Paweł Jastrzębski
2014-01-16 11:40:49 +01:00
parent d76a624a82
commit 921511dcf2
4 changed files with 24 additions and 23 deletions

11
kcc.py
View File

@@ -77,7 +77,7 @@ elif sys.platform.startswith('win'):
# Implementing detection of already running KCC instance and forwarding argv to it
class QApplicationMessaging(QtWidgets.QApplication):
messageFromOtherInstance = QtCore.pyqtSignal(str)
messageFromOtherInstance = QtCore.pyqtSignal(bytes)
def __init__(self, argv):
QtWidgets.QApplication.__init__(self, argv)
@@ -102,7 +102,7 @@ class QApplicationMessaging(QtWidgets.QApplication):
def handleMessage(self):
socket = self._server.nextPendingConnection()
if socket.waitForReadyRead(self._timeout):
self.messageFromOtherInstance.emit(socket.readAll().data().decode('utf8'))
self.messageFromOtherInstance.emit(socket.readAll().data())
def sendMessage(self, message):
if self.isRunning():
@@ -110,7 +110,8 @@ class QApplicationMessaging(QtWidgets.QApplication):
socket.connectToServer(self._key, QtCore.QIODevice.WriteOnly)
if not socket.waitForConnected(self._timeout):
return False
socket.write(message.encode('utf8'))
# noinspection PyArgumentList
socket.write(bytes(message, 'UTF-8'))
if not socket.waitForBytesWritten(self._timeout):
return False
socket.disconnectFromServer()
@@ -133,7 +134,7 @@ if __name__ == "__main__":
KCCAplication = QApplicationMessaging(sys.argv)
if KCCAplication.isRunning():
if len(sys.argv) > 1:
KCCAplication.sendMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
KCCAplication.sendMessage(sys.argv[1])
sys.exit(0)
else:
messageBox = QtWidgets.QMessageBox()
@@ -146,5 +147,5 @@ if __name__ == "__main__":
KCCWindow = QMainWindowKCC()
KCCUI = KCC_gui.KCCGUI(KCCAplication, KCCWindow)
if len(sys.argv) > 1:
KCCUI.handleMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
KCCUI.handleMessage(sys.argv[1])
sys.exit(KCCAplication.exec_())