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

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
11 years ago
11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.QtSvg import QSvgWidget
  20. from PyQt5.QtWidgets import 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.fSvgWidget = QSvgWidget(self)
  35. self.setCheckable(True)
  36. self.setText("")
  37. self.fLastColor = self.OFF
  38. self.fSvgWidget.load(":/scalable/led_off.svg")
  39. self.setColor(self.BLUE)
  40. def setColor(self, color):
  41. self.fColor = color
  42. self._loadSVGNow()
  43. # Fix calf off
  44. if color == self.CALF:
  45. self.fSvgWidget.load(":/bitmaps/led_calf_off.png")
  46. def paintEvent(self, event):
  47. event.accept()
  48. self._loadSVGNow()
  49. def _loadSVGNow(self):
  50. if self.isChecked():
  51. if self.fLastColor != self.fColor:
  52. if self.fColor == self.OFF:
  53. self.fSvgWidget.load(":/scalable/led_off.svg")
  54. elif self.fColor == self.BLUE:
  55. self.fSvgWidget.load(":/scalable/led_blue.svg")
  56. elif self.fColor == self.GREEN:
  57. self.fSvgWidget.load(":/scalable/led_green.svg")
  58. elif self.fColor == self.RED:
  59. self.fSvgWidget.load(":/scalable/led_red.svg")
  60. elif self.fColor == self.YELLOW:
  61. self.fSvgWidget.load(":/scalable/led_yellow.svg")
  62. elif self.fColor == self.CALF:
  63. self.fSvgWidget.load(":/bitmaps/led_calf_on.png")
  64. else:
  65. return
  66. self.fLastColor = self.fColor
  67. elif self.fLastColor != self.OFF:
  68. self.fSvgWidget.load(":/scalable/led_calf_off.png" if self.fColor == self.CALF else ":/scalable/led_off.svg")
  69. self.fLastColor = self.OFF