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

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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Pixmap 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 modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # 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 COPYING 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. BIG_RED = 5
  29. def __init__(self, parent):
  30. QPushButton.__init__(self, parent)
  31. self.m_pixmap = QPixmap()
  32. self.m_pixmapRect = QRectF(0, 0, 0, 0)
  33. self.setCheckable(True)
  34. self.setText("")
  35. self.setColor(self.BLUE)
  36. def setColor(self, color):
  37. self.m_color = color
  38. if color in (self.BLUE, self.GREEN, self.RED, self.YELLOW):
  39. size = 14
  40. elif color == self.BIG_RED:
  41. size = 32
  42. else:
  43. return qCritical("LEDButton::setColor(%i) - Invalid color" % color)
  44. self.setPixmapSize(size)
  45. def setPixmapSize(self, size):
  46. self.m_pixmapRect = QRectF(0, 0, size, size)
  47. self.setMinimumWidth(size)
  48. self.setMaximumWidth(size)
  49. self.setMinimumHeight(size)
  50. self.setMaximumHeight(size)
  51. def paintEvent(self, event):
  52. painter = QPainter(self)
  53. if self.isChecked():
  54. if self.m_color == self.BLUE:
  55. self.m_pixmap.load(":/bitmaps/led_blue.png")
  56. elif self.m_color == self.GREEN:
  57. self.m_pixmap.load(":/bitmaps/led_green.png")
  58. elif self.m_color == self.RED:
  59. self.m_pixmap.load(":/bitmaps/led_red.png")
  60. elif self.m_color == self.YELLOW:
  61. self.m_pixmap.load(":/bitmaps/led_yellow.png")
  62. elif self.m_color == self.BIG_RED:
  63. self.m_pixmap.load(":/bitmaps/led-big_on.png")
  64. else:
  65. return
  66. else:
  67. if self.m_color in (self.BLUE, self.GREEN, self.RED, self.YELLOW):
  68. self.m_pixmap.load(":/bitmaps/led_off.png")
  69. elif self.m_color == self.BIG_RED:
  70. self.m_pixmap.load(":/bitmaps/led-big_off.png")
  71. else:
  72. return
  73. painter.drawPixmap(self.m_pixmapRect, self.m_pixmap, self.m_pixmapRect)
  74. event.accept()