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.

98 lines
3.1KB

  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 PyQt4.QtCore import qCritical, QRectF
  20. from PyQt4.QtGui import QPainter, QPixmap, QPushButton
  21. # ------------------------------------------------------------------------------------------------------------
  22. # Widget Class
  23. class LEDButton(QPushButton):
  24. # normal
  25. OFF = 0
  26. BLUE = 1
  27. GREEN = 2
  28. RED = 3
  29. YELLOW = 4
  30. # extra
  31. CALF = 5
  32. def __init__(self, parent):
  33. QPushButton.__init__(self, parent)
  34. self.fPixmap = QPixmap()
  35. self.fPixmapRect = QRectF(0, 0, 0, 0)
  36. self.setCheckable(True)
  37. self.setText("")
  38. self.fLastColor = self.OFF
  39. self.fPixmap.load(":/bitmaps/led_off.png")
  40. self.setColor(self.BLUE)
  41. def setColor(self, color):
  42. self.fColor = color
  43. self._loadPixmapNow()
  44. # Fix calf off
  45. if color == self.CALF:
  46. self.fPixmap.load(":/bitmaps/led_calf_off.png")
  47. size = self.fPixmap.width()
  48. self.fPixmapRect = QRectF(0, 0, size, size)
  49. self.setMinimumSize(size, size)
  50. self.setMaximumSize(size, size)
  51. def paintEvent(self, event):
  52. painter = QPainter(self)
  53. event.accept()
  54. self._loadPixmapNow()
  55. painter.drawPixmap(self.fPixmapRect, self.fPixmap, self.fPixmapRect)
  56. def _loadPixmapNow(self):
  57. if self.isChecked():
  58. if self.fLastColor != self.fColor:
  59. if self.fColor == self.OFF:
  60. self.fPixmap.load(":/bitmaps/led_off.png")
  61. elif self.fColor == self.BLUE:
  62. self.fPixmap.load(":/bitmaps/led_blue.png")
  63. elif self.fColor == self.GREEN:
  64. self.fPixmap.load(":/bitmaps/led_green.png")
  65. elif self.fColor == self.RED:
  66. self.fPixmap.load(":/bitmaps/led_red.png")
  67. elif self.fColor == self.YELLOW:
  68. self.fPixmap.load(":/bitmaps/led_yellow.png")
  69. elif self.fColor == self.CALF:
  70. self.fPixmap.load(":/bitmaps/led_calf_on.png")
  71. else:
  72. return
  73. self.fLastColor = self.fColor
  74. elif self.fLastColor != self.OFF:
  75. self.fPixmap.load(":/bitmaps/led_calf_off.png" if self.fColor == self.CALF else ":/bitmaps/led_off.png")
  76. self.fLastColor = self.OFF