This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
qt_ui_node.py
64 lines (52 loc) · 1.54 KB
/
qt_ui_node.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
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
"""
qt_ui_node.py
PyQt5 ZOCP UI Node example
"""
import sys
try:
from PyQt5.QtCore import QSocketNotifier
from PyQt5.QtWidgets import QWidget, QTextEdit, QApplication
except ImportError:
from PySide.QtCore import QSocketNotifier
from PySide.QtGui import QWidget, QTextEdit, QApplication
from zocp import ZOCP
import zmq
class QTZOCPNode(QWidget):
def __init__(self):
super(QTZOCPNode, self).__init__()
self.qle = QTextEdit(self)
self.qle.move(1, 1)
self.qle.resize(640,480)
self.init_zocp()
self.show()
def init_zocp(self):
self.z = ZOCP("QT UI TEST")
self.z.register_float("myFloat", 2.3, 'rw', 0, 5.0, 0.1)
self.notifier = QSocketNotifier(
self.z.inbox.getsockopt(zmq.FD),
QSocketNotifier.Read
)
self.notifier.setEnabled(True)
self.notifier.activated.connect(self.zocp_event)
self.z.on_modified = self.on_modified
self.z.start()
def zocp_event(self):
print("ZOCP EVENT START")
self.z.run_once(0)
print("ZOCP EVENT END")
def on_modified(self, peer, name, data, *args, **kwargs):
t = self.qle.toPlainText()
t = "{0}\n{1}".format(data, t)
self.qle.setPlainText(t)
def closeEvent(self, *args):
print(args)
self.z.stop()
del self.z
def main():
app = QApplication(sys.argv)
window = QTZOCPNode()
app.exec_()
if __name__ == '__main__':
main()