示例#1
0
文件: qt_ui_node.py 项目: z25/pyZOCP
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
示例#2
0
class QTZOCPNode(QtWidgets.QWidget):

    def __init__(self):
        super(QTZOCPNode, self).__init__()
        self.qle = QtWidgets.QTextEdit(self)
        self.qle.move(1, 1)
        self.qle.resize(640,480)
        self.init_zocp()
        self.show()

    def init_zocp(self):
        self.z = ZOCP()
        self.z.set_node_name("QT UI TEST")
        self.z.register_float("myFloat", 2.3, 'rw', 0, 5.0, 0.1)
        self.notifier = QtCore.QSocketNotifier(
                self.z.inbox.getsockopt(zmq.FD), 
                QtCore.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()
示例#3
0
#!/usr/bin/python

from zocp import ZOCP
import logging

if __name__ == '__main__':
    zl = logging.getLogger("zocp")
    zl.setLevel(logging.DEBUG)

    z = ZOCP()
    z.set_name("ZOCP-Test")
    z.register_bool("myBool", True, 'rwe')
    z.register_float("myFloat", 2.3, 'rws', 0, 5.0, 0.1)
    z.register_int('myInt', 10, access='rwes', min=-10, max=10, step=1)
    z.register_percent('myPercent', 12, access='rw')
    z.register_vec2f('myVec2', [0,0], access='rwes')
    z.start()
    z.run()
    print("FINISH")
示例#4
0
文件: simple_node.py 项目: z25/pyZOCP
#!/usr/bin/python

from zocp import ZOCP
import logging

if __name__ == '__main__':
    zl = logging.getLogger("zocp")
    zl.setLevel(logging.DEBUG)

    z = ZOCP("ZOCP-Test")
    z.register_bool("myBool", True, 'rwe')
    z.register_float("myFloat", 2.3, 'rws', 0, 5.0, 0.1)
    z.register_int('myInt', 10, access='rwes', min=-10, max=10, step=1)
    z.register_percent('myPercent', 12, access='rw')
    z.register_vec2f('myVec2', [0, 0], access='rwes')
    z.start()
    z.run()
    print("FINISH")
示例#5
0
class QTZOCPNode(QtGui.QWidget):

    def __init__(self):
        super(QTZOCPNode, self).__init__()

        # Set name of Node
        self.nodename = "QT Sliders@%s" % socket.gethostname()
        
        self.init_zocp()
        self.initUI()
 
    def init_zocp(self):
        self.z = ZOCP()
        self.z.set_name(self.nodename)
        
        self.notifier = QtCore.QSocketNotifier(
                self.z.inbox.getsockopt(zmq.FD), 
                QtCore.QSocketNotifier.Read
                )
        self.notifier.setEnabled(True)
        self.notifier.activated.connect(self.zocp_event)
        self.z.start()

    def initUI(self):      

        # Create Sliders
        sld1 = self.createSlider("slider1",0,100)
        sld2 = self.createSlider("slider2",0,100)
        sld3 = self.createSlider("slider3",0,100)

        # Create Layout Grid
        grid = QtGui.QGridLayout()
        grid.setSpacing(10)

        # add all the widgets to the grid
        grid.addWidget(sld1, 1, 1)
        grid.addWidget(sld1.label, 2, 1)
        grid.addWidget(sld2, 1, 2)
        grid.addWidget(sld2.label, 2, 2)
        grid.addWidget(sld3, 1, 3)
        grid.addWidget(sld3.label, 2, 3)
        
        # set layout of window
        self.setLayout(grid) 
        self.setGeometry(300, 300, 280, 170)
        self.setWindowTitle(self.nodename)
        self.show()

    def createSlider(self, _id, _min, _max):

        sld = QtGui.QSlider(QtCore.Qt.Vertical, self)
        sld.setAccessibleName(_id)
        sld.setFocusPolicy(QtCore.Qt.NoFocus)
        sld.valueChanged[int].connect(self.changeValue)
        sld.setMinimum(_min)
        sld.setMaximum(_max)
        
        sld.label = QtGui.QLabel(self)
        sld.label.setText(_id)

        # Register the ZOCP variable
        self.z.register_float(_id, 0, access='rwe', min=_min, max=_max, step=1)

        return sld

    def changeValue(self, value):
        sender = self.sender().accessibleName()
        zl.debug("value ",value," id ",sender)

        # ZOCP: HANDLE VALUE CHANGE  
        self.z.emit_signal(sender, value)

    
    # HANDLE INCOMING ZOCP MESSAGES 
    def zocp_event(self):
        self.z.run_once(0)
         
    def closeEvent(self, *args):
        zl.debug(args)
        self.z.stop()