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.

ledbutton.py 3.4KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # LED Button, a custom Qt4 widget
  4. # Copyright (C) 2011-2014 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 (Config)
  19. from carla_config import *
  20. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Global)
  22. if config_UseQt5:
  23. from PyQt5.QtCore import qCritical, QRectF
  24. from PyQt5.QtGui import QPainter, QPixmap
  25. from PyQt5.QtWidgets import QPushButton
  26. else:
  27. from PyQt4.QtCore import qCritical, QRectF
  28. from PyQt4.QtGui import QPainter, QPixmap, QPushButton
  29. # ------------------------------------------------------------------------------------------------------------
  30. # Widget Class
  31. class LEDButton(QPushButton):
  32. # normal
  33. OFF = 0
  34. BLUE = 1
  35. GREEN = 2
  36. RED = 3
  37. YELLOW = 4
  38. # extra
  39. CALF = 5
  40. def __init__(self, parent):
  41. QPushButton.__init__(self, parent)
  42. self.fPixmap = QPixmap()
  43. self.fPixmapRect = QRectF(0, 0, 0, 0)
  44. self.setCheckable(True)
  45. self.setText("")
  46. self.fLastColor = self.OFF
  47. self.fPixmap.load(":/bitmaps/led_off.png")
  48. self.setColor(self.BLUE)
  49. def setColor(self, color):
  50. self.fColor = color
  51. self._loadPixmapNow()
  52. # Fix calf off
  53. if color == self.CALF:
  54. self.fPixmap.load(":/bitmaps/led_calf_off.png")
  55. size = self.fPixmap.width()
  56. self.fPixmapRect = QRectF(0, 0, size, size)
  57. self.setMinimumSize(size, size)
  58. self.setMaximumSize(size, size)
  59. def paintEvent(self, event):
  60. painter = QPainter(self)
  61. event.accept()
  62. self._loadPixmapNow()
  63. painter.drawPixmap(self.fPixmapRect, self.fPixmap, self.fPixmapRect)
  64. def _loadPixmapNow(self):
  65. if self.isChecked():
  66. if self.fLastColor != self.fColor:
  67. if self.fColor == self.OFF:
  68. self.fPixmap.load(":/bitmaps/led_off.png")
  69. elif self.fColor == self.BLUE:
  70. self.fPixmap.load(":/bitmaps/led_blue.png")
  71. elif self.fColor == self.GREEN:
  72. self.fPixmap.load(":/bitmaps/led_green.png")
  73. elif self.fColor == self.RED:
  74. self.fPixmap.load(":/bitmaps/led_red.png")
  75. elif self.fColor == self.YELLOW:
  76. self.fPixmap.load(":/bitmaps/led_yellow.png")
  77. elif self.fColor == self.CALF:
  78. self.fPixmap.load(":/bitmaps/led_calf_on.png")
  79. else:
  80. return
  81. self.fLastColor = self.fColor
  82. elif self.fLastColor != self.OFF:
  83. self.fPixmap.load(":/bitmaps/led_calf_off.png" if self.fColor == self.CALF else ":/bitmaps/led_off.png")
  84. self.fLastColor = self.OFF