smartpi 0.1.22__py3-none-any.whl → 0.1.23__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 +1 -1
- smartpi/base_driver.py +0 -1
- smartpi/gui.py +63 -37
- {smartpi-0.1.22.dist-info → smartpi-0.1.23.dist-info}/METADATA +1 -1
- {smartpi-0.1.22.dist-info → smartpi-0.1.23.dist-info}/RECORD +7 -7
- {smartpi-0.1.22.dist-info → smartpi-0.1.23.dist-info}/WHEEL +0 -0
- {smartpi-0.1.22.dist-info → smartpi-0.1.23.dist-info}/top_level.txt +0 -0
smartpi/__init__.py
CHANGED
smartpi/base_driver.py
CHANGED
smartpi/gui.py
CHANGED
|
@@ -1,61 +1,87 @@
|
|
|
1
1
|
import socket
|
|
2
2
|
import json
|
|
3
|
-
import
|
|
3
|
+
import time
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
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()
|
|
7
9
|
|
|
8
|
-
def
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if _connection is None:
|
|
12
|
-
_connection = socket.create_connection((host, port))
|
|
13
|
-
_send({"type": "clear"})
|
|
10
|
+
def _send(self, cmd):
|
|
11
|
+
self.sock.sendall((json.dumps(cmd) + "\n").encode())
|
|
12
|
+
time.sleep(0.1)
|
|
14
13
|
|
|
15
|
-
def
|
|
16
|
-
|
|
17
|
-
if _connection is None and "pytest" not in sys.modules: # 允许测试环境不初始化
|
|
18
|
-
raise ConnectionError("GUI not initialized. Call gui.init() first.")
|
|
19
|
-
if _connection:
|
|
20
|
-
_connection.sendall((json.dumps(cmd) + "\n").encode())
|
|
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})
|
|
21
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
|
+
# 将类方法提升为模块级别的函数
|
|
22
51
|
def show_text(x, y, text, color="black", size=16):
|
|
23
|
-
|
|
52
|
+
_client_instance.show_text(x, y, text, color, size)
|
|
24
53
|
|
|
25
|
-
def print(text):
|
|
26
|
-
|
|
54
|
+
def print(text):
|
|
55
|
+
_client_instance.print(text)
|
|
27
56
|
|
|
28
57
|
def println(text):
|
|
29
|
-
|
|
58
|
+
_client_instance.println(text)
|
|
30
59
|
|
|
31
60
|
def show_image(x, y, path, width, height):
|
|
32
|
-
|
|
61
|
+
_client_instance.show_image(x, y, path, width, height)
|
|
33
62
|
|
|
34
63
|
def draw_line(x1, y1, x2, y2, color="black", width=1):
|
|
35
|
-
|
|
64
|
+
_client_instance.draw_line(x1, y1, x2, y2, color, width)
|
|
36
65
|
|
|
37
66
|
def fill_rect(x, y, w, h, color="black"):
|
|
38
|
-
|
|
67
|
+
_client_instance.fill_rect(x, y, w, h, color)
|
|
39
68
|
|
|
40
69
|
def draw_rect(x, y, w, h, width, color="black"):
|
|
41
|
-
|
|
70
|
+
_client_instance.draw_rect(x, y, w, h, width, color)
|
|
42
71
|
|
|
43
72
|
def fill_circle(cx, cy, r, color="black"):
|
|
44
|
-
|
|
73
|
+
_client_instance.fill_circle(cx, cy, r, color)
|
|
45
74
|
|
|
46
75
|
def draw_circle(cx, cy, r, width, color="black"):
|
|
47
|
-
|
|
76
|
+
_client_instance.draw_circle(cx, cy, r, width, color)
|
|
48
77
|
|
|
49
78
|
def clear():
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
# 注册程序退出时自动关闭连接
|
|
60
|
-
import atexit
|
|
61
|
-
atexit.register(close)
|
|
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
|
+
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
smartpi/__init__.py,sha256=
|
|
2
|
-
smartpi/base_driver.py,sha256=
|
|
1
|
+
smartpi/__init__.py,sha256=vHEaSuG4o0m17zvDoMBhn-lttaKYGct1k73F5y1orhk,55
|
|
2
|
+
smartpi/base_driver.py,sha256=jP8cuQ0LRfjMuVQ2I6tY7fxp3JsjcUH8fdWKooIogME,24188
|
|
3
3
|
smartpi/color_sensor.py,sha256=YXJjknYjp7teTZsHYZRAWgi73CH0MhBp1go9y0Inxyo,498
|
|
4
4
|
smartpi/cw2015.py,sha256=1lAF-pi_ye_ya1AZQS1sjbgsDf7MThO5IAskKsNGBzA,5695
|
|
5
5
|
smartpi/flash.py,sha256=-pUqg6FSVoBiLFKqrG9B4dFqn8lICnQsSPJr_MtZLIU,4132
|
|
6
|
-
smartpi/gui.py,sha256=
|
|
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.23.dist-info/METADATA,sha256=VFDRXlgYEsVNBbHmPcqcwQnuu5VUeoFE0G1VtTfe3Vw,311
|
|
18
|
+
smartpi-0.1.23.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
19
|
+
smartpi-0.1.23.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
|
|
20
|
+
smartpi-0.1.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|