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.

83 lines
2.5KB

  1. #!/usr/bin/env python3
  2. # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. # ------------------------------------------------------------------------------------------------------------
  5. # Imports (Global)
  6. from qt_compat import qt_config
  7. if qt_config == 5:
  8. from PyQt5.QtCore import QAbstractAnimation
  9. from PyQt5.QtWidgets import QGraphicsObject
  10. elif qt_config == 6:
  11. from PyQt6.QtCore import QAbstractAnimation
  12. from PyQt6.QtWidgets import QGraphicsObject
  13. # ------------------------------------------------------------------------------------------------------------
  14. # Imports (Custom)
  15. from . import canvas, CanvasBoxType
  16. # ------------------------------------------------------------------------------------------------------------
  17. class CanvasFadeAnimation(QAbstractAnimation):
  18. def __init__(self, item, show):
  19. QAbstractAnimation.__init__(self)
  20. self.m_show = show
  21. self.m_duration = 0
  22. self.m_item = item
  23. self.m_item_is_object = isinstance(item, QGraphicsObject)
  24. def item(self):
  25. return self.m_item
  26. def forceStop(self):
  27. self.blockSignals(True)
  28. self.stop()
  29. self.blockSignals(False)
  30. def setDuration(self, time):
  31. if self.m_item.opacity() == 0 and not self.m_show:
  32. self.m_duration = 0
  33. else:
  34. if self.m_item_is_object:
  35. self.m_item.blockSignals(True)
  36. self.m_item.show()
  37. self.m_item.blockSignals(False)
  38. else:
  39. self.m_item.show()
  40. self.m_duration = time
  41. def duration(self):
  42. return self.m_duration
  43. def updateCurrentTime(self, time):
  44. if self.m_duration == 0:
  45. return
  46. if self.m_show:
  47. value = float(time) / self.m_duration
  48. else:
  49. value = 1.0 - (float(time) / self.m_duration)
  50. try:
  51. self.m_item.setOpacity(value)
  52. except RuntimeError:
  53. print("CanvasFadeAnimation::updateCurrentTime() - failed to animate canvas item, already destroyed?")
  54. self.forceStop()
  55. canvas.animation_list.remove(self)
  56. return
  57. if self.m_item.type() == CanvasBoxType:
  58. self.m_item.setShadowOpacity(value)
  59. def updateDirection(self, direction):
  60. pass
  61. def updateState(self, oldState, newState):
  62. pass
  63. # ------------------------------------------------------------------------------------------------------------