CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
JoystickButton.py47 linesDownload Raw Back to examples
1"""2JoystickButton is a button with x/y values. When the button is depressed and the3mouse dragged, the x/y values change to follow the mouse.4When the mouse button is released, the x/y values change to 0,0 (rather like 5letting go of the joystick).6"""7 8import pyqtgraph as pg9from pyqtgraph.Qt import QtCore, QtWidgets10 11app = pg.mkQApp("Joystick Button Example")12mw = QtWidgets.QMainWindow()13mw.resize(300,50)14mw.setWindowTitle('pyqtgraph example: JoystickButton')15cw = QtWidgets.QWidget()16mw.setCentralWidget(cw)17layout = QtWidgets.QGridLayout()18cw.setLayout(layout)19mw.show()20 21l1 = pg.ValueLabel(siPrefix=True, suffix='m')22l2 = pg.ValueLabel(siPrefix=True, suffix='m')23jb = pg.JoystickButton()24jb.setFixedWidth(30)25jb.setFixedHeight(30)26 27 28layout.addWidget(l1, 0, 0)29layout.addWidget(l2, 0, 1)30layout.addWidget(jb, 0, 2)31 32x = 033y = 034def update():35    global x, y, l1, l2, jb36    dx, dy = jb.getState()37    x += dx * 1e-338    y += dy * 1e-339    l1.setValue(x)40    l2.setValue(y)41timer = QtCore.QTimer()42timer.timeout.connect(update)43timer.start(30)44    45if __name__ == '__main__':46    pg.exec()47 
Aluode/PerceptionLabPortable · CoolFace