Skip to content

Commit ac91832

Browse files
committed
graphic plot add clear btn and update help
1 parent 90d382e commit ac91832

4 files changed

Lines changed: 55 additions & 4 deletions

File tree

COMTool/plugins/graph.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ class Plugin(Plugin_Base):
5050
enabled = False # user enabled this plugin
5151
active = False # using this plugin
5252

53-
help = '{}<br><br>{}<br>Python:<br><pre>{}</pre><br>C/C++:<br><pre>{}</pre>'.format(_("Double click graph item to add a graph widget"), _("line chart plot protocol:"),
53+
help = '{}<br><br>{}<br><h2>Python</h2><br><pre>{}</pre><p><p>{}<br>{}</p><p>{}</p></p><br><h2>C/C++</h2><br><pre>{}</pre>'.format(
54+
_("Double click graph item to add a graph widget"), _("line chart plot protocol:"),
5455
'''
55-
from COMTool.plugin import graph_protocol
56+
from COMTool.plugins import graph_protocol
5657
frame = graph_protocol.plot_pack(name, x, y, header= b'\\xAA\\xCC\\xEE\\xBB')
5758
''',
59+
_("Full demo see:"),
60+
'<a href="https://github.com/Neutree/COMTool/tree/master/tool/send_curve_demo.py">https://github.com/Neutree/COMTool/tree/master/tool/send_curve_demo.py</a>',
61+
_("Install comtool by <code>pip install comtool</code> first"),
5862
'''
5963
void plot_pack(uint8_t *buff, int buff_len,
6064
uint8_t *header, int header_len,

COMTool/plugins/graph_widgets.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(self, parent=None, hintSignal=lambda type, title, msg: None, rmCall
4747
self.plotWin.setMinimumHeight(200)
4848
pg.setConfigOptions(antialias=True)
4949
rmBtn = QPushButton(_("Remove"))
50+
clearBtn = QPushButton(_("Clear"))
5051
rangeLabel = QLabel(_("Range:"))
5152
rangeConf = QLineEdit(str(self.config["xRange"]))
5253
rangeEnable = QCheckBox(_("Enable"))
@@ -63,6 +64,7 @@ def __init__(self, parent=None, hintSignal=lambda type, title, msg: None, rmCall
6364
rangeConf.setValidator(validator)
6465
self.layout.addWidget(self.plotWin, 0, 0, 1, 3)
6566
self.layout.addWidget(rmBtn, 1, 0, 1, 1)
67+
self.layout.addWidget(clearBtn, 1, 2, 1, 1)
6668
self.layout.addWidget(rangeLabel, 2, 0, 1, 1)
6769
self.layout.addWidget(rangeConf, 2, 1, 1, 1)
6870
self.layout.addWidget(rangeEnable, 2, 2, 1, 1)
@@ -111,10 +113,18 @@ def __init__(self, parent=None, hintSignal=lambda type, title, msg: None, rmCall
111113
lambda: self.setHeader(headerConf.text()))
112114
rmBtn.clicked.connect(self.remove)
113115
headerConf.textChanged.connect(self.headerChanged)
116+
clearBtn.clicked.connect(self.clear)
114117

115118
def remove(self):
116119
self.rmCallback(self)
117120

121+
def clear(self):
122+
self.data = {}
123+
self.curves = {}
124+
self.notUsedColors = self.builtinColors.copy()
125+
self.colors = {}
126+
self.p.clear()
127+
118128
def setRange(self, text):
119129
if text:
120130
self.config["xRange"] = float(text)

COMTool/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
major = 3
3-
minor = 1
4-
dev = 4
3+
minor = 2
4+
dev = 0
55

66
__version__ = "{}.{}.{}".format(major, minor, dev)
77

tool/send_curve_demo.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'''
2+
execute `pip install comtool --upgrade` first
3+
Then run a TCP server on COMTool
4+
Finally run this script to connect the server and send data
5+
'''
6+
from COMTool.plugins import graph_protocol
7+
import math
8+
import socket
9+
import time
10+
11+
class Conn:
12+
def __init__(self, addr, port):
13+
self.addr = addr
14+
self.port = port
15+
self.sock = None
16+
# connect tcp server
17+
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
18+
self.sock.connect((self.addr, self.port))
19+
20+
def send(self, data):
21+
self.sock.send(data)
22+
23+
if __name__ == "__main__":
24+
conn = Conn("127.0.0.1", 2345)
25+
26+
count = 0
27+
while 1:
28+
# x belong to [0, 2pi]
29+
x = count * 2 * math.pi / 100
30+
y = math.sin(x)
31+
frame1 = graph_protocol.plot_pack("data1", x, y, header= b'\xAA\xCC\xEE\xBB')
32+
y = math.pow(math.cos(x), 2)
33+
frame2 = graph_protocol.plot_pack("data2", x, y, header= b'\xAA\xCC\xEE\xBB')
34+
conn.send(frame1)
35+
conn.send(frame2)
36+
count += 1
37+
time.sleep(0.1)

0 commit comments

Comments
 (0)