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.

84 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 GPL.txt file
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt4.QtCore import qCritical, QRectF
  20. from PyQt4.QtGui import QPainter, QPixmap, QPushButton
  21. # ------------------------------------------------------------------------------------------------------------
  22. # Widget Class
  23. class LEDButton(QPushButton):
  24. OFF = 0
  25. BLUE = 1
  26. GREEN = 2
  27. RED = 3
  28. YELLOW = 4
  29. def __init__(self, parent):
  30. QPushButton.__init__(self, parent)
  31. self.fPixmap = QPixmap()
  32. self.fPixmapRect = QRectF(0, 0, 0, 0)
  33. self.setCheckable(True)
  34. self.setText("")
  35. self.setColor(self.BLUE)
  36. self.fLastColor = self.OFF
  37. self.fPixmap.load(":/bitmaps/led_off.png")
  38. def setColor(self, color):
  39. self.fColor = color
  40. size = 14
  41. self.fPixmapRect = QRectF(0, 0, size, size)
  42. self.setMinimumSize(size, size)
  43. self.setMaximumSize(size, size)
  44. def paintEvent(self, event):
  45. painter = QPainter(self)
  46. event.accept()
  47. if self.isChecked():
  48. if self.fLastColor != self.fColor:
  49. if self.fColor == self.OFF:
  50. self.fPixmap.load(":/bitmaps/led_off.png")
  51. elif self.fColor == self.BLUE:
  52. self.fPixmap.load(":/bitmaps/led_blue.png")
  53. elif self.fColor == self.GREEN:
  54. self.fPixmap.load(":/bitmaps/led_green.png")
  55. elif self.fColor == self.RED:
  56. self.fPixmap.load(":/bitmaps/led_red.png")
  57. elif self.fColor == self.YELLOW:
  58. self.fPixmap.load(":/bitmaps/led_yellow.png")
  59. else:
  60. return
  61. self.fLastColor = self.fColor
  62. elif self.fLastColor != self.OFF:
  63. self.fPixmap.load(":/bitmaps/led_off.png")
  64. self.fLastColor = self.OFF
  65. painter.drawPixmap(self.fPixmapRect, self.fPixmap, self.fPixmapRect)