Advertisement
Guest User

Widget Control

a guest
Feb 10th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1.  
  2.  
  3. from PyQt5 import QtWidgets, QtGui, QtCore
  4.  
  5. import hal, linuxcnc
  6.  
  7. class TestWidget(QtWidgets.QWidget):
  8. def __init__(self, halcomp, parent=None):
  9. super().__init__(parent)
  10. self.halcomp = hal.component("mytest")
  11. self.halcomp.newpin("test-widget-out", hal.HAL_BIT, hal.HAL_OUT)
  12. self.init_ui()
  13. self.halcomp.ready()
  14.  
  15. def init_ui(self):
  16. self.setWindowTitle("Test Widget")
  17. self.setGeometry(300, 300, 250, 150)
  18.  
  19. self.layout = QtWidgets.QVBoxLayout()
  20. self.setLayout(self.layout)
  21.  
  22. self.test_direct = QtWidgets.QPushButton("Test Direct")
  23. self.test_direct.setCheckable(True)
  24. def set_pin(data):
  25. self.halcomp["test-widget-out"] = data
  26. self.test_direct.clicked.connect(set_pin)
  27.  
  28. self.layout.addWidget(self.test_direct)
  29.  
  30. self.test_hal = QtWidgets.QPushButton("Test HAL")
  31. self.test_hal.clicked.connect(lambda: hal.set_p("halui.mode.teleop", "true"))
  32. self.layout.addWidget(self.test_hal)
  33. self.show()
  34.  
  35.  
  36. def closeEvent(self, event):
  37. event.accept()
  38. self.halcomp.exit()
  39.  
  40.  
  41. if __name__ == "__main__":
  42. app = QtWidgets.QApplication([])
  43. w = TestWidget(None)
  44. app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement