Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.7KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # LED Button, a custom Qt4 widget
  4. # Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt5.QtCore import qCritical, QRectF
  20. from PyQt5.QtGui import QPainter, QPixmap
  21. from PyQt5.QtWidgets import QPushButton
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Widget Class
  24. class LEDButton(QPushButton):
  25. OFF = 0
  26. BLUE = 1
  27. GREEN = 2
  28. RED = 3
  29. YELLOW = 4
  30. def __init__(self, parent):
  31. QPushButton.__init__(self, parent)
  32. self.fPixmap = QPixmap()
  33. self.fPixmapRect = QRectF(0, 0, 0, 0)
  34. self.setCheckable(True)
  35. self.setText("")
  36. self.setColor(self.BLUE)
  37. self.fLastColor = self.OFF
  38. self.fPixmap.load(":/bitmaps/led_off.png")
  39. def setColor(self, color):
  40. self.fColor = color
  41. size = 14
  42. self.fPixmapRect = QRectF(0, 0, size, size)
  43. self.setMinimumSize(size, size)
  44. self.setMaximumSize(size, size)
  45. def paintEvent(self, event):
  46. painter = QPainter(self)
  47. event.accept()
  48. if self.isChecked():
  49. if self.fLastColor != self.fColor:
  50. if self.fColor == self.OFF:
  51. self.fPixmap.load(":/bitmaps/led_off.png")
  52. elif self.fColor == self.BLUE:
  53. self.fPixmap.load(":/bitmaps/led_blue.png")
  54. elif self.fColor == self.GREEN:
  55. self.fPixmap.load(":/bitmaps/led_green.png")
  56. elif self.fColor == self.RED:
  57. self.fPixmap.load(":/bitmaps/led_red.png")
  58. elif self.fColor == self.YELLOW:
  59. self.fPixmap.load(":/bitmaps/led_yellow.png")
  60. else:
  61. return
  62. self.fLastColor = self.fColor
  63. elif self.fLastColor != self.OFF:
  64. self.fPixmap.load(":/bitmaps/led_off.png")
  65. self.fLastColor = self.OFF
  66. painter.drawPixmap(self.fPixmapRect, self.fPixmap, self.fPixmapRect)