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 2.3KB

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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. def __init__(self, parent):
  29. QPushButton.__init__(self, parent)
  30. self.fPixmap = QPixmap()
  31. self.fPixmapRect = QRectF(0, 0, 0, 0)
  32. self.setCheckable(True)
  33. self.setText("")
  34. self.setColor(self.BLUE)
  35. def setColor(self, color):
  36. self.fColor = color
  37. size = 14
  38. self.fPixmapRect = QRectF(0, 0, size, size)
  39. self.setMinimumSize(size, size)
  40. self.setMaximumSize(size, size)
  41. def paintEvent(self, event):
  42. painter = QPainter(self)
  43. event.accept()
  44. if self.isChecked():
  45. if self.fColor == self.BLUE:
  46. self.fPixmap.load(":/bitmaps/led_blue.png")
  47. elif self.fColor == self.GREEN:
  48. self.fPixmap.load(":/bitmaps/led_green.png")
  49. elif self.fColor == self.RED:
  50. self.fPixmap.load(":/bitmaps/led_red.png")
  51. elif self.fColor == self.YELLOW:
  52. self.fPixmap.load(":/bitmaps/led_yellow.png")
  53. else:
  54. return
  55. else:
  56. self.fPixmap.load(":/bitmaps/led_off.png")
  57. painter.drawPixmap(self.fPixmapRect, self.fPixmap, self.fPixmapRect)