forked from Answeror/lit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
54 lines (41 loc) · 1.06 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from qt.QtCore import (
QObject,
Signal,
Slot,
QDataStream
)
from qt.QtNetwork import (
QTcpSocket,
QHostAddress
)
from service import (
set_version,
write,
PORT
)
class Client(QObject):
toggle = Signal()
def __init__(self, parent=None):
super(Client, self).__init__(parent)
self._make_socket()
def _make_socket(self):
self.con = QTcpSocket(self)
self.con.readyRead.connect(self._handle_read)
def _handle_read(self):
ins = QDataStream(self.con)
set_version(ins)
line = str(ins.readString(), encoding='ascii')
if line == 'toggle':
self.toggle.emit()
@Slot()
def start(self):
self.con.connectToHost(QHostAddress.LocalHost, PORT)
def stop(self):
self.con.disconnectFromHost()
def _write(self, callback):
assert self.con
write(self.con, callback)
def goto(self, hwnd):
self._write(lambda out: out.writeString(str(int(hwnd)).encode('ascii')))