smartpi 0.1.28__py3-none-any.whl → 0.1.30__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smartpi/__init__.py +4 -2
- smartpi/_gui.py +66 -0
- smartpi/base_driver.py +1 -1
- {smartpi-0.1.28.dist-info → smartpi-0.1.30.dist-info}/METADATA +1 -1
- {smartpi-0.1.28.dist-info → smartpi-0.1.30.dist-info}/RECORD +7 -7
- smartpi/gui.py +0 -87
- {smartpi-0.1.28.dist-info → smartpi-0.1.30.dist-info}/WHEEL +0 -0
- {smartpi-0.1.28.dist-info → smartpi-0.1.30.dist-info}/top_level.txt +0 -0
smartpi/__init__.py
CHANGED
smartpi/_gui.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import socket
|
|
4
|
+
import json
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
class gui_client:
|
|
8
|
+
def __init__(self, host="127.0.0.1", port=65167, timeout=2.0):
|
|
9
|
+
self.sock = None
|
|
10
|
+
try:
|
|
11
|
+
self.sock = socket.create_connection((host, port), timeout=timeout)
|
|
12
|
+
self.clear()
|
|
13
|
+
except :
|
|
14
|
+
self.sock = None
|
|
15
|
+
|
|
16
|
+
def is_connected(self):
|
|
17
|
+
result = False
|
|
18
|
+
if self.sock is not None:
|
|
19
|
+
result = True
|
|
20
|
+
return result
|
|
21
|
+
|
|
22
|
+
def _send(self, cmd):
|
|
23
|
+
if self.sock is None:
|
|
24
|
+
return
|
|
25
|
+
try:
|
|
26
|
+
self.sock.sendall((json.dumps(cmd) + "\n").encode())
|
|
27
|
+
time.sleep(0.1)
|
|
28
|
+
except :
|
|
29
|
+
self.sock = None
|
|
30
|
+
|
|
31
|
+
def show_text(self, x, y, text, color="black", size=16):
|
|
32
|
+
self._send({"type": "text", "x": x, "y": y, "text": text, "color": color, "size": size})
|
|
33
|
+
|
|
34
|
+
def print(self, text):
|
|
35
|
+
self._send({"type": "print", "text": text})
|
|
36
|
+
|
|
37
|
+
def println(self, text):
|
|
38
|
+
self._send({"type": "println", "text": text})
|
|
39
|
+
|
|
40
|
+
def show_image(self, x, y, path, width, height):
|
|
41
|
+
self._send({"type": "image", "x": x, "y": y, "path": path, "width": width, "height": height})
|
|
42
|
+
|
|
43
|
+
def draw_line(self, x1, y1, x2, y2, color="black", width=1):
|
|
44
|
+
self._send({"type": "line", "x1": x1, "y1": y1, "x2": x2, "y2": y2, "color": color, "width": width})
|
|
45
|
+
|
|
46
|
+
def fill_rect(self, x, y, w, h, color="black"):
|
|
47
|
+
self._send({"type": "fill_rect", "x": x, "y": y, "w": w, "h": h, "color": color})
|
|
48
|
+
|
|
49
|
+
def draw_rect(self, x, y, w, h, width, color="black"):
|
|
50
|
+
self._send({"type": "draw_rect", "x": x, "y": y, "w": w, "h": h, "width": width, "color": color})
|
|
51
|
+
|
|
52
|
+
def fill_circle(self, cx, cy, r, color="black"):
|
|
53
|
+
self._send({"type": "fill_circle", "cx": cx, "cy": cy, "r": r, "color": color})
|
|
54
|
+
|
|
55
|
+
def draw_circle(self, cx, cy, r, width, color="black"):
|
|
56
|
+
self._send({"type": "draw_circle", "cx": cx, "cy": cy, "r": r, "width": width, "color": color})
|
|
57
|
+
|
|
58
|
+
def clear(self):
|
|
59
|
+
self._send({"type": "clear"})
|
|
60
|
+
|
|
61
|
+
def finish(self):
|
|
62
|
+
self.sock.close()
|
|
63
|
+
|
|
64
|
+
# 外部调用
|
|
65
|
+
gui = gui_client()
|
|
66
|
+
|
smartpi/base_driver.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
smartpi/__init__.py,sha256=
|
|
2
|
-
smartpi/
|
|
1
|
+
smartpi/__init__.py,sha256=KxiHhAK2d08nDxhs_Me1ZQHnYHBUfjBfIwCDNy0nF3s,199
|
|
2
|
+
smartpi/_gui.py,sha256=ij-6HZAEIwdy_hvU7f0NkyQjx_-eephijlKbGUhf8Uo,2177
|
|
3
|
+
smartpi/base_driver.py,sha256=hJ5_Rph1BT-riYiW1pgw685WAgEMjpqDF264BLSP6hk,24392
|
|
3
4
|
smartpi/color_sensor.py,sha256=YXJjknYjp7teTZsHYZRAWgi73CH0MhBp1go9y0Inxyo,498
|
|
4
5
|
smartpi/cw2015.py,sha256=1lAF-pi_ye_ya1AZQS1sjbgsDf7MThO5IAskKsNGBzA,5695
|
|
5
6
|
smartpi/flash.py,sha256=-pUqg6FSVoBiLFKqrG9B4dFqn8lICnQsSPJr_MtZLIU,4132
|
|
6
|
-
smartpi/gui.py,sha256=HaupXWg5cWw_n86ge8IxARrvL3gpcDCNRwATK9irwH8,2960
|
|
7
7
|
smartpi/humidity.py,sha256=nZwiBtMWKNipVM83ymajZACPHxkC2vUJjDMmCOPN9lw,499
|
|
8
8
|
smartpi/led.py,sha256=flvN7EJfP6VDTSiC93w1uR8pRxcZD9w2vLXA1GbJTo8,538
|
|
9
9
|
smartpi/light_sensor.py,sha256=MayyVikWcXQfjeZrtYRnwYgHBDzu2g-mfJLpdd29EG8,1852
|
|
@@ -14,7 +14,7 @@ smartpi/temperature.py,sha256=VT79CYA41q1d_4AM-Y0eIMeIw7AtCkSXjWVws6Yx5yE,462
|
|
|
14
14
|
smartpi/touch_sensor.py,sha256=P57RRQlqY0KexpMi-ydqwF5albOKCBOGb0Rb6zeVTqk,440
|
|
15
15
|
smartpi/trace.py,sha256=tut7BMbq87ShaR5eNuv7PZtAEz9DS5_BDf0_muIZ-tQ,4577
|
|
16
16
|
smartpi/ultrasonic.py,sha256=kmVpUfvE1oHoqgv92ZU6Fi-sO6DSwm10ssKsImNeOkY,624
|
|
17
|
-
smartpi-0.1.
|
|
18
|
-
smartpi-0.1.
|
|
19
|
-
smartpi-0.1.
|
|
20
|
-
smartpi-0.1.
|
|
17
|
+
smartpi-0.1.30.dist-info/METADATA,sha256=HdapesvaqrPYL7dI86CO7s1gZ01ws0MbCfVdOIqByF8,311
|
|
18
|
+
smartpi-0.1.30.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
19
|
+
smartpi-0.1.30.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
|
|
20
|
+
smartpi-0.1.30.dist-info/RECORD,,
|
smartpi/gui.py
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import socket
|
|
2
|
-
import json
|
|
3
|
-
import time
|
|
4
|
-
|
|
5
|
-
class _gui_client:
|
|
6
|
-
def __init__(self, host="127.0.0.1", port=65167):
|
|
7
|
-
self.sock = socket.create_connection((host, port))
|
|
8
|
-
self.clear()
|
|
9
|
-
|
|
10
|
-
def _send(self, cmd):
|
|
11
|
-
self.sock.sendall((json.dumps(cmd) + "\n").encode())
|
|
12
|
-
time.sleep(0.1)
|
|
13
|
-
|
|
14
|
-
def show_text(self, x, y, text, color="black", size=16):
|
|
15
|
-
self._send({"type": "text", "x": x, "y": y, "text": text, "color": color, "size": size})
|
|
16
|
-
|
|
17
|
-
def print(self, text):
|
|
18
|
-
self._send({"type": "print", "text": text})
|
|
19
|
-
|
|
20
|
-
def println(self, text):
|
|
21
|
-
self._send({"type": "println", "text": text})
|
|
22
|
-
|
|
23
|
-
def show_image(self, x, y, path, width, height):
|
|
24
|
-
self._send({"type": "image", "x": x, "y": y, "path": path, "width": width, "height": height})
|
|
25
|
-
|
|
26
|
-
def draw_line(self, x1, y1, x2, y2, color="black", width=1):
|
|
27
|
-
self._send({"type": "line", "x1": x1, "y1": y1, "x2": x2, "y2": y2, "color": color, "width": width})
|
|
28
|
-
|
|
29
|
-
def fill_rect(self, x, y, w, h, color="black"):
|
|
30
|
-
self._send({"type": "fill_rect", "x": x, "y": y, "w": w, "h": h, "color": color})
|
|
31
|
-
|
|
32
|
-
def draw_rect(self, x, y, w, h, width, color="black"):
|
|
33
|
-
self._send({"type": "draw_rect", "x": x, "y": y, "w": w, "h": h, "width": width, "color": color})
|
|
34
|
-
|
|
35
|
-
def fill_circle(self, cx, cy, r, color="black"):
|
|
36
|
-
self._send({"type": "fill_circle", "cx": cx, "cy": cy, "r": r, "color": color})
|
|
37
|
-
|
|
38
|
-
def draw_circle(self, cx, cy, r, width, color="black"):
|
|
39
|
-
self._send({"type": "draw_circle", "cx": cx, "cy": cy, "r": r, "width": width, "color": color})
|
|
40
|
-
|
|
41
|
-
def clear(self):
|
|
42
|
-
self._send({"type": "clear"})
|
|
43
|
-
|
|
44
|
-
def finish(self):
|
|
45
|
-
self.sock.close()
|
|
46
|
-
|
|
47
|
-
# 创建全局实例
|
|
48
|
-
_client_instance = _gui_client()
|
|
49
|
-
|
|
50
|
-
# 将类方法提升为模块级别的函数
|
|
51
|
-
def show_text(x, y, text, color="black", size=16):
|
|
52
|
-
_client_instance.show_text(x, y, text, color, size)
|
|
53
|
-
|
|
54
|
-
def print(text):
|
|
55
|
-
_client_instance.print(text)
|
|
56
|
-
|
|
57
|
-
def println(text):
|
|
58
|
-
_client_instance.println(text)
|
|
59
|
-
|
|
60
|
-
def show_image(x, y, path, width, height):
|
|
61
|
-
_client_instance.show_image(x, y, path, width, height)
|
|
62
|
-
|
|
63
|
-
def draw_line(x1, y1, x2, y2, color="black", width=1):
|
|
64
|
-
_client_instance.draw_line(x1, y1, x2, y2, color, width)
|
|
65
|
-
|
|
66
|
-
def fill_rect(x, y, w, h, color="black"):
|
|
67
|
-
_client_instance.fill_rect(x, y, w, h, color)
|
|
68
|
-
|
|
69
|
-
def draw_rect(x, y, w, h, width, color="black"):
|
|
70
|
-
_client_instance.draw_rect(x, y, w, h, width, color)
|
|
71
|
-
|
|
72
|
-
def fill_circle(cx, cy, r, color="black"):
|
|
73
|
-
_client_instance.fill_circle(cx, cy, r, color)
|
|
74
|
-
|
|
75
|
-
def draw_circle(cx, cy, r, width, color="black"):
|
|
76
|
-
_client_instance.draw_circle(cx, cy, r, width, color)
|
|
77
|
-
|
|
78
|
-
def clear():
|
|
79
|
-
_client_instance.clear()
|
|
80
|
-
|
|
81
|
-
def finish():
|
|
82
|
-
_client_instance.finish()
|
|
83
|
-
|
|
84
|
-
# 可选:如果希望仍然可以使用类创建新实例
|
|
85
|
-
def create_client(host="127.0.0.1", port=65167):
|
|
86
|
-
return _gui_client(host, port)
|
|
87
|
-
|
|
File without changes
|
|
File without changes
|