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.

90 lines
2.9KB

  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. BLUE = 1
  25. GREEN = 2
  26. RED = 3
  27. YELLOW = 4
  28. BIG_RED = 5
  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. def setColor(self, color):
  37. self.fColor = color
  38. if color in (self.BLUE, self.GREEN, self.RED, self.YELLOW):
  39. size = 14
  40. elif color == self.BIG_RED:
  41. size = 32
  42. else:
  43. return qCritical("LEDButton::setColor(%i) - Invalid color" % color)
  44. self.setPixmapSize(size)
  45. def setPixmapSize(self, size):
  46. self.fPixmapRect = QRectF(0, 0, size, size)
  47. self.setMinimumSize(size, size)
  48. self.setMaximumSize(size, size)
  49. def paintEvent(self, event):
  50. painter = QPainter(self)
  51. event.accept()
  52. if self.isChecked():
  53. if self.fColor == self.BLUE:
  54. self.fPixmap.load(":/bitmaps/led_blue.png")
  55. elif self.fColor == self.GREEN:
  56. self.fPixmap.load(":/bitmaps/led_green.png")
  57. elif self.fColor == self.RED:
  58. self.fPixmap.load(":/bitmaps/led_red.png")
  59. elif self.fColor == self.YELLOW:
  60. self.fPixmap.load(":/bitmaps/led_yellow.png")
  61. elif self.fColor == self.BIG_RED:
  62. self.fPixmap.load(":/bitmaps/led-big_on.png")
  63. else:
  64. return
  65. else:
  66. if self.fColor in (self.BLUE, self.GREEN, self.RED, self.YELLOW):
  67. self.fPixmap.load(":/bitmaps/led_off.png")
  68. elif self.fColor == self.BIG_RED:
  69. self.fPixmap.load(":/bitmaps/led-big_off.png")
  70. else:
  71. return
  72. painter.drawPixmap(self.fPixmapRect, self.fPixmap, self.fPixmapRect)