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.

91 lines
2.9KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # PatchBay Canvas engine using QGraphicsView/Scene
  4. # Copyright (C) 2010-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 QAbstractAnimation
  20. from PyQt5.QtWidgets import QGraphicsObject
  21. # ------------------------------------------------------------------------------------------------------------
  22. # Imports (Custom)
  23. from . import canvas, CanvasBoxType
  24. # ------------------------------------------------------------------------------------------------------------
  25. class CanvasFadeAnimation(QAbstractAnimation):
  26. def __init__(self, item, show):
  27. QAbstractAnimation.__init__(self)
  28. self.m_show = show
  29. self.m_duration = 0
  30. self.m_item = item
  31. self.m_item_is_object = isinstance(item, QGraphicsObject)
  32. def item(self):
  33. return self.m_item
  34. def forceStop(self):
  35. self.blockSignals(True)
  36. self.stop()
  37. self.blockSignals(False)
  38. def setDuration(self, time):
  39. if self.m_item.opacity() == 0 and not self.m_show:
  40. self.m_duration = 0
  41. else:
  42. if self.m_item_is_object:
  43. self.m_item.blockSignals(True)
  44. self.m_item.show()
  45. self.m_item.blockSignals(False)
  46. else:
  47. self.m_item.show()
  48. self.m_duration = time
  49. def duration(self):
  50. return self.m_duration
  51. def updateCurrentTime(self, time):
  52. if self.m_duration == 0:
  53. return
  54. if self.m_show:
  55. value = float(time) / self.m_duration
  56. else:
  57. value = 1.0 - (float(time) / self.m_duration)
  58. try:
  59. self.m_item.setOpacity(value)
  60. except RuntimeError:
  61. print("CanvasFadeAnimation::updateCurrentTime() - failed to animate canvas item, already destroyed?")
  62. self.forceStop()
  63. canvas.animation_list.remove(self)
  64. return
  65. if self.m_item.type() == CanvasBoxType:
  66. self.m_item.setShadowOpacity(value)
  67. def updateDirection(self, direction):
  68. pass
  69. def updateState(self, oldState, newState):
  70. pass
  71. # ------------------------------------------------------------------------------------------------------------