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.

93 lines
3.0KB

  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.m_pixmap = QPixmap()
  32. self.m_pixmapRect = QRectF(0, 0, 0, 0)
  33. self.setCheckable(True)
  34. self.setText("")
  35. self.setColor(self.BLUE)
  36. def setColor(self, color):
  37. self.m_color = 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.m_pixmapRect = QRectF(0, 0, size, size)
  47. self.setMinimumWidth(size)
  48. self.setMaximumWidth(size)
  49. self.setMinimumHeight(size)
  50. self.setMaximumHeight(size)
  51. def paintEvent(self, event):
  52. painter = QPainter(self)
  53. if self.isChecked():
  54. if self.m_color == self.BLUE:
  55. self.m_pixmap.load(":/bitmaps/led_blue.png")
  56. elif self.m_color == self.GREEN:
  57. self.m_pixmap.load(":/bitmaps/led_green.png")
  58. elif self.m_color == self.RED:
  59. self.m_pixmap.load(":/bitmaps/led_red.png")
  60. elif self.m_color == self.YELLOW:
  61. self.m_pixmap.load(":/bitmaps/led_yellow.png")
  62. elif self.m_color == self.BIG_RED:
  63. self.m_pixmap.load(":/bitmaps/led-big_on.png")
  64. else:
  65. return
  66. else:
  67. if self.m_color in (self.BLUE, self.GREEN, self.RED, self.YELLOW):
  68. self.m_pixmap.load(":/bitmaps/led_off.png")
  69. elif self.m_color == self.BIG_RED:
  70. self.m_pixmap.load(":/bitmaps/led-big_off.png")
  71. else:
  72. return
  73. painter.drawPixmap(self.m_pixmapRect, self.m_pixmap, self.m_pixmapRect)
  74. event.accept()