2012-04-06 03:04:26 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-04-12 16:44:31 +00:00
|
|
|
"""
|
2013-02-25 04:09:03 +00:00
|
|
|
JoystickButton is a button with x/y values. When the button is depressed and the
|
|
|
|
mouse dragged, the x/y values change to follow the mouse.
|
|
|
|
When the mouse button is released, the x/y values change to 0,0 (rather like
|
|
|
|
letting go of the joystick).
|
2012-04-12 16:44:31 +00:00
|
|
|
"""
|
2012-04-06 03:04:26 +00:00
|
|
|
|
|
|
|
import initExample ## Add path to library (just for examples; you do not need this)
|
|
|
|
|
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
|
|
|
import pyqtgraph as pg
|
|
|
|
|
|
|
|
|
2021-01-27 18:59:07 +00:00
|
|
|
app = pg.mkQApp("Joystick Button Example")
|
2012-04-06 03:04:26 +00:00
|
|
|
mw = QtGui.QMainWindow()
|
|
|
|
mw.resize(300,50)
|
2013-02-25 04:09:03 +00:00
|
|
|
mw.setWindowTitle('pyqtgraph example: JoystickButton')
|
2012-04-06 03:04:26 +00:00
|
|
|
cw = QtGui.QWidget()
|
|
|
|
mw.setCentralWidget(cw)
|
|
|
|
layout = QtGui.QGridLayout()
|
|
|
|
cw.setLayout(layout)
|
|
|
|
mw.show()
|
|
|
|
|
|
|
|
l1 = pg.ValueLabel(siPrefix=True, suffix='m')
|
|
|
|
l2 = pg.ValueLabel(siPrefix=True, suffix='m')
|
|
|
|
jb = pg.JoystickButton()
|
|
|
|
jb.setFixedWidth(30)
|
|
|
|
jb.setFixedHeight(30)
|
|
|
|
|
|
|
|
|
|
|
|
layout.addWidget(l1, 0, 0)
|
|
|
|
layout.addWidget(l2, 0, 1)
|
|
|
|
layout.addWidget(jb, 0, 2)
|
|
|
|
|
|
|
|
x = 0
|
|
|
|
y = 0
|
|
|
|
def update():
|
|
|
|
global x, y, l1, l2, jb
|
|
|
|
dx, dy = jb.getState()
|
|
|
|
x += dx * 1e-3
|
|
|
|
y += dy * 1e-3
|
|
|
|
l1.setValue(x)
|
|
|
|
l2.setValue(y)
|
|
|
|
timer = QtCore.QTimer()
|
|
|
|
timer.timeout.connect(update)
|
|
|
|
timer.start(30)
|
|
|
|
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
2021-03-22 18:17:12 +00:00
|
|
|
pg.mkQApp().exec_()
|