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

  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. # ------------------------------------------------------------------------------------------------------------
  21. # Imports (Custom)
  22. from . import canvas, CanvasBoxType
  23. # ------------------------------------------------------------------------------------------------------------
  24. class CanvasFadeAnimation(QAbstractAnimation):
  25. def __init__(self, item, show):
  26. QAbstractAnimation.__init__(self)
  27. self.m_show = show
  28. self.m_duration = 0
  29. self.m_item = item
  30. def item(self):
  31. return self.m_item
  32. def forceStop(self):
  33. self.blockSignals(True)
  34. self.stop()
  35. def setDuration(self, time):
  36. if self.m_item.opacity() == 0 and not self.m_show:
  37. self.m_duration = 0
  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. # ------------------------------------------------------------------------------------------------------------