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.1KB

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