Beispiel #1
0
class AnimatedCentralScroller(KeyboardResponsiveCentralScroller):
  RIGHT = 0
  LEFT = 1
  ANIM_DURATION = 500
  EASING = QEasingCurve.InOutQuad
  def __init__(self, widgets, parent=None):
    super(AnimatedCentralScroller, self).__init__(widgets, parent)
    self._anim_grp = None
   
  def next(self):
    self_width = self.width()
    self._anim_grp = QParallelAnimationGroup()
    if self._current_index == len(self._widgets) - 1:
      distance = self_width * (len(self._widgets) - 1)
      for window in self._widgets:
        self.animateWidget(window, distance, direction=self.RIGHT)
      self._current_index = 0 
    else:
      for window in self._widgets:
        self.animateWidget(window, self_width, direction=self.LEFT)
      self._current_index += 1
    self._anim_grp.start()
    self.window_changed.emit(self._current_index)
  
  def prev(self):
    self_width = self.width()
    self._anim_grp = QParallelAnimationGroup()
    if self._current_index == 0:
      distance = self_width * (len(self._widgets) - 1)
      for window in self._widgets:
        self.animateWidget(window, distance, direction=self.LEFT)
      self._current_index = len(self._widgets) - 1
    else:
      for window in self._widgets:
        self.animateWidget(window, self_width, direction=self.RIGHT)
      self._current_index -= 1
    self._anim_grp.start()
    self.window_changed.emit(self._current_index)
    
  def animateWidget(self, widget, distance, direction):
    widget_anim = QPropertyAnimation(widget, "geometry")
    cur_geom = widget.geometry()
    next_geom = QRect(cur_geom)
    if direction == self.LEFT:
      next_geom.moveTo(widget.pos() - QPoint(distance, 0))
    elif direction == self.RIGHT:
      next_geom.moveTo(widget.pos() + QPoint(distance, 0))
    widget_anim.setDuration(self.ANIM_DURATION)
    widget_anim.setEasingCurve(self.EASING)
    widget_anim.setStartValue(cur_geom)
    widget_anim.setEndValue(next_geom)
    self._anim_grp.addAnimation(widget_anim)
Beispiel #2
0
 def clear_sweep(self, pos):
     group = QParallelAnimationGroup()
     end_pos = self.cards[pos].card_widget.geometry()
     for card in self.cards:
         widget = card.pop()
         widget.raise_()
         ani = QPropertyAnimation(widget, "geometry")
         ani.setDuration(750)
         ani.setEndValue(end_pos)
         ani.finished.connect(partial(widget.setParent, None))
         group.addAnimation(ani)
     group.start()
     self.ani_group = group # Save to keep from being cleaned up
class AnimatedSlideshowWidget(SlideshowWidget):
  """
  Override the click handlers to create an animation
  """
  RIGHT = 0
  LEFT = 1
  ANIM_DURATION = 500
  EASING = QEasingCurve.InOutQuad
  def __init__(self, *args, **kwargs):
    super(AnimatedSlideshowWidget, self).__init__(*args, **kwargs)
    self._anim_grp = None
   
  def nextImage(self):
    self_width = self.width()
    self._anim_grp = QParallelAnimationGroup()
    if self._cur_widget_index == len(self._image_widgets) - 1:
      distance = self_width * (len(self._image_widgets) - 1)
      for image_widget in self._image_widgets:
        self.animateWidget(image_widget, distance, direction=self.RIGHT)
      self._cur_widget_index = 0 
    else:
      for image_widget in self._image_widgets:
        self.animateWidget(image_widget, self_width, direction=self.LEFT)
      self._cur_widget_index += 1
    self._anim_grp.start()
  
  def prevImage(self):
    self_width = self.width()
    self._anim_grp = QParallelAnimationGroup()
    if self._cur_widget_index == 0:
      distance = self_width * (len(self._image_widgets) - 1)
      for image_widget in self._image_widgets:
        self.animateWidget(image_widget, distance, direction=self.LEFT)
      self._cur_widget_index = len(self._image_widgets) - 1
    else:
      for image_widget in self._image_widgets:
        self.animateWidget(image_widget, self_width, direction=self.RIGHT)
      self._cur_widget_index -= 1
    self._anim_grp.start()
    
  def animateWidget(self, widget, distance, direction):
    widget_anim = QPropertyAnimation(widget, "geometry")
    cur_geom = widget.geometry()
    next_geom = QRect(cur_geom)
    if direction == self.LEFT:
      next_geom.moveTo(widget.pos() - QPoint(distance, 0))
    elif direction == self.RIGHT:
      next_geom.moveTo(widget.pos() + QPoint(distance, 0))
    widget_anim.setDuration(self.ANIM_DURATION)
    widget_anim.setEasingCurve(self.EASING)
    widget_anim.setStartValue(cur_geom)
    widget_anim.setEndValue(next_geom)
    self._anim_grp.addAnimation(widget_anim)

  @staticmethod
  def slideshowCreator(imageList):
    """Return a suitable widget according to the number of images in imageList"""
    from visualscrape.ui.viewer.support import ImageWidget
    if not imageList:
      return QWidget()
    elif len(imageList) == 1:
      return ImageWidget(imageList[0])
    else:
      return AnimatedSlideshowWidget(imageList)
Beispiel #4
0
class AnimatedSlideshowWidget(SlideshowWidget):
    """
  Override the click handlers to create an animation
  """
    RIGHT = 0
    LEFT = 1
    ANIM_DURATION = 500
    EASING = QEasingCurve.InOutQuad

    def __init__(self, *args, **kwargs):
        super(AnimatedSlideshowWidget, self).__init__(*args, **kwargs)
        self._anim_grp = None

    def nextImage(self):
        self_width = self.width()
        self._anim_grp = QParallelAnimationGroup()
        if self._cur_widget_index == len(self._image_widgets) - 1:
            distance = self_width * (len(self._image_widgets) - 1)
            for image_widget in self._image_widgets:
                self.animateWidget(image_widget,
                                   distance,
                                   direction=self.RIGHT)
            self._cur_widget_index = 0
        else:
            for image_widget in self._image_widgets:
                self.animateWidget(image_widget,
                                   self_width,
                                   direction=self.LEFT)
            self._cur_widget_index += 1
        self._anim_grp.start()

    def prevImage(self):
        self_width = self.width()
        self._anim_grp = QParallelAnimationGroup()
        if self._cur_widget_index == 0:
            distance = self_width * (len(self._image_widgets) - 1)
            for image_widget in self._image_widgets:
                self.animateWidget(image_widget, distance, direction=self.LEFT)
            self._cur_widget_index = len(self._image_widgets) - 1
        else:
            for image_widget in self._image_widgets:
                self.animateWidget(image_widget,
                                   self_width,
                                   direction=self.RIGHT)
            self._cur_widget_index -= 1
        self._anim_grp.start()

    def animateWidget(self, widget, distance, direction):
        widget_anim = QPropertyAnimation(widget, "geometry")
        cur_geom = widget.geometry()
        next_geom = QRect(cur_geom)
        if direction == self.LEFT:
            next_geom.moveTo(widget.pos() - QPoint(distance, 0))
        elif direction == self.RIGHT:
            next_geom.moveTo(widget.pos() + QPoint(distance, 0))
        widget_anim.setDuration(self.ANIM_DURATION)
        widget_anim.setEasingCurve(self.EASING)
        widget_anim.setStartValue(cur_geom)
        widget_anim.setEndValue(next_geom)
        self._anim_grp.addAnimation(widget_anim)

    @staticmethod
    def slideshowCreator(imageList):
        """Return a suitable widget according to the number of images in imageList"""
        from visualscrape.ui.viewer.support import ImageWidget
        if not imageList:
            return QWidget()
        elif len(imageList) == 1:
            return ImageWidget(imageList[0])
        else:
            return AnimatedSlideshowWidget(imageList)