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.

87 lines
2.8KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Pixmap Button, a custom Qt4 widget
  4. # Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # 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 COPYING file
  17. # Imports (Global)
  18. from PyQt4.QtCore import qCritical, QRectF
  19. from PyQt4.QtGui import QPainter, QPixmap, QPushButton
  20. # Widget Class
  21. class LEDButton(QPushButton):
  22. BLUE = 1
  23. GREEN = 2
  24. RED = 3
  25. YELLOW = 4
  26. BIG_RED = 5
  27. def __init__(self, parent):
  28. QPushButton.__init__(self, parent)
  29. self.m_pixmap = QPixmap()
  30. self.m_pixmap_rect = QRectF(0, 0, 0, 0)
  31. self.setCheckable(True)
  32. self.setText("")
  33. self.setColor(self.BLUE)
  34. def setColor(self, color):
  35. self.m_color = color
  36. if color in (self.BLUE, self.GREEN, self.RED, self.YELLOW):
  37. size = 14
  38. elif color == self.BIG_RED:
  39. size = 32
  40. else:
  41. return qCritical("LEDButton::setColor(%i) - Invalid color" % color)
  42. self.setPixmapSize(size)
  43. def setPixmapSize(self, size):
  44. self.m_pixmap_rect = QRectF(0, 0, size, size)
  45. self.setMinimumWidth(size)
  46. self.setMaximumWidth(size)
  47. self.setMinimumHeight(size)
  48. self.setMaximumHeight(size)
  49. def paintEvent(self, event):
  50. painter = QPainter(self)
  51. if self.isChecked():
  52. if self.m_color == self.BLUE:
  53. self.m_pixmap.load(":/bitmaps/led_blue.png")
  54. elif self.m_color == self.GREEN:
  55. self.m_pixmap.load(":/bitmaps/led_green.png")
  56. elif self.m_color == self.RED:
  57. self.m_pixmap.load(":/bitmaps/led_red.png")
  58. elif self.m_color == self.YELLOW:
  59. self.m_pixmap.load(":/bitmaps/led_yellow.png")
  60. elif self.m_color == self.BIG_RED:
  61. self.m_pixmap.load(":/bitmaps/led-big_on.png")
  62. else:
  63. return
  64. else:
  65. if self.m_color in (self.BLUE, self.GREEN, self.RED, self.YELLOW):
  66. self.m_pixmap.load(":/bitmaps/led_off.png")
  67. elif self.m_color == self.BIG_RED:
  68. self.m_pixmap.load(":/bitmaps/led-big_off.png")
  69. else:
  70. return
  71. painter.drawPixmap(self.m_pixmap_rect, self.m_pixmap, self.m_pixmap_rect)