예제 #1
0
class ImageMediaView(MediaView):
    def __init__(self, media, parent):
        super(ImageMediaView, self).__init__(media, parent)
        self._widget = QLabel(parent)
        self._widget.setGeometry(media['_geometry'])
        self._img = QImage()
        self.set_default_widget_prop()

    @Slot()
    def play(self):
        self._finished = 0
        path = "%s/%s" % (self._save_dir, self._options['uri'])
        rect = self._widget.geometry()
        self._img.load(path)
        self._img = self._img.scaled(rect.width(), rect.height(),
                                     Qt.IgnoreAspectRatio,
                                     Qt.SmoothTransformation)

        self._widget.setPixmap(QPixmap.fromImage(self._img))
        self._widget.show()
        self._widget.raise_()

        self._play_timer.setInterval(int(float(self._duration) * 1000))
        self._play_timer.start()
        self.started_signal.emit()
예제 #2
0
class ImageMediaView(MediaView):
    def __init__(self, media, parent):
        super(ImageMediaView, self).__init__(media, parent)
        self.widget = QLabel(parent)
        self.widget.setGeometry(media['geometry'])
        self.img = QImage()
        self.set_default_widget_prop()

    @Slot()
    def play(self):
        self.finished = 0
        path = '%s/%s' % (self.save_dir, self.options['uri'])
        rect = self.widget.geometry()
        self.img.load(path)
        self.img = self.img.scaled(rect.width(), rect.height(),
                                   Qt.IgnoreAspectRatio,
                                   Qt.SmoothTransformation)
        self.widget.setPixmap(QPixmap.fromImage(self.img))
        self.widget.show()
        self.widget.raise_()
        if float(self.duration) > 0:
            self.play_timer.setInterval(int(float(self.duration) * 1000))
            self.play_timer.start()
        self.started_signal.emit()

    @Slot()
    def stop(self, delete_widget=False):
        #---- kong ----
        if not self.widget:
            return False
        del self.img
        self.img = QImage()
        #----
        super(ImageMediaView, self).stop(delete_widget)
        return True
예제 #3
0
파일: xlfview.py 프로젝트: ajiwo/xiboside
class ImageMediaView(MediaView):
    def __init__(self, media, parent):
        super(ImageMediaView, self).__init__(media, parent)
        self._widget = QLabel(parent)
        self._widget.setGeometry(media['_geometry'])
        self._img = QImage()
        self.set_default_widget_prop()

    @Slot()
    def play(self):
        self._finished = 0
        path = "%s/%s" % (self._save_dir, self._options['uri'])
        rect = self._widget.geometry()
        self._img.load(path)
        self._img = self._img.scaled(rect.width(), rect.height(),
                                     Qt.IgnoreAspectRatio, Qt.SmoothTransformation)

        self._widget.setPixmap(QPixmap.fromImage(self._img))
        self._widget.show()
        self._widget.raise_()

        self._play_timer.setInterval(int(float(self._duration) * 1000))
        self._play_timer.start()
        self.started_signal.emit()
class LoadingWidget(QWidget):
  """A widget with a little animation for showing progress.
    Call setMessage to change the secondary message and emit
    the finished signal with an appropriate string to set as the
    primary message when done.
  """
  finished = Signal(str)
  animation_finished = Signal()
  
  def __init__(self, loadIcon="loading_bar", primaryMessage="Please, Wait", message='', parent=None):
    super(LoadingWidget, self).__init__(parent)
    self.finished.connect(self._updateUI)
    self.setStyleSheet("""
      QWidget {
        background-color: #ffffff
      }
    """)
    self._icon_load = loadIcon
    self._primary_message = primaryMessage
    self._label_message = QLabel(message)
    self._label_message.setWordWrap(True)
    self._label_message.setAlignment(Qt.AlignCenter)
    self._label_primary_message = QLabel(self._primary_message)
    self._label_primary_message.setStyleSheet("""
      QLabel {
        font-size: 20px;
        font-weight:bold;
        color: rgb(65,65,65);
      }
    """)
    self._label_primary_message.setAlignment(Qt.AlignCenter)
    self._label_movie = QLabel()
    self._label_movie.setAlignment(Qt.AlignCenter)
    self._movie = QMovie(self._icon_load)
    self._label_movie.setMovie(self._movie)
    self._movie.start()
    layout = QVBoxLayout()
    layout.addWidget(self._label_primary_message)
    layout.addSpacing(5)
    layout.addWidget(self._label_message)
    layout.addSpacing(5)
    layout.addWidget(self._label_movie)
    layout.addStretch()
    #self._setupAnimation() # this should be done after showing everything to get correct geometries
    self.setLayout(layout)
  
  def _setupAnimation(self):
    self._load_animation = QPropertyAnimation(self._label_movie, "geometry")
    # since the opacity is failing, make it run out of the area!
    anim_label_geom = self._label_movie.geometry()
    self._load_animation.setStartValue(anim_label_geom)
    target_anim_geom = QRect(anim_label_geom)
    target_anim_geom.moveTop(self.height())
    # make the animation target a rectangle that's directly under it but shifted downwards outside of parent
    self._load_animation.setEndValue(target_anim_geom)
    self._load_animation.setEasingCurve(QEasingCurve.InBack)
    self._load_animation.setDuration(1000)
    self._load_animation.finished.connect(self.animation_finished)
    self._load_animation.finished.connect(self._hideAnimLabel)
  
  def setMessage(self, message):
    self._label_message.setText(message)
    
  def _updateUI(self, message=''):
    if not message:
      message = "All Done!"
    self._label_primary_message.setText(message)
    self._label_message.setText('')
    self._movie.stop()
    self._setupAnimation()
    self.layout().removeWidget(self._label_movie)
    self._label_movie.setGeometry(self._load_animation.startValue())
    self._load_animation.start()
    
  def _hideAnimLabel(self):
    self._label_movie.hide()
    
예제 #5
0
class LoadingWidget(QWidget):
    """A widget with a little animation for showing progress.
    Call setMessage to change the secondary message and emit
    the finished signal with an appropriate string to set as the
    primary message when done.
  """
    finished = Signal(str)
    animation_finished = Signal()

    def __init__(self,
                 loadIcon="loading_bar",
                 primaryMessage="Please, Wait",
                 message='',
                 parent=None):
        super(LoadingWidget, self).__init__(parent)
        self.finished.connect(self._updateUI)
        self.setStyleSheet("""
      QWidget {
        background-color: #ffffff
      }
    """)
        self._icon_load = loadIcon
        self._primary_message = primaryMessage
        self._label_message = QLabel(message)
        self._label_message.setWordWrap(True)
        self._label_message.setAlignment(Qt.AlignCenter)
        self._label_primary_message = QLabel(self._primary_message)
        self._label_primary_message.setStyleSheet("""
      QLabel {
        font-size: 20px;
        font-weight:bold;
        color: rgb(65,65,65);
      }
    """)
        self._label_primary_message.setAlignment(Qt.AlignCenter)
        self._label_movie = QLabel()
        self._label_movie.setAlignment(Qt.AlignCenter)
        self._movie = QMovie(self._icon_load)
        self._label_movie.setMovie(self._movie)
        self._movie.start()
        layout = QVBoxLayout()
        layout.addWidget(self._label_primary_message)
        layout.addSpacing(5)
        layout.addWidget(self._label_message)
        layout.addSpacing(5)
        layout.addWidget(self._label_movie)
        layout.addStretch()
        #self._setupAnimation() # this should be done after showing everything to get correct geometries
        self.setLayout(layout)

    def _setupAnimation(self):
        self._load_animation = QPropertyAnimation(self._label_movie,
                                                  "geometry")
        # since the opacity is failing, make it run out of the area!
        anim_label_geom = self._label_movie.geometry()
        self._load_animation.setStartValue(anim_label_geom)
        target_anim_geom = QRect(anim_label_geom)
        target_anim_geom.moveTop(self.height())
        # make the animation target a rectangle that's directly under it but shifted downwards outside of parent
        self._load_animation.setEndValue(target_anim_geom)
        self._load_animation.setEasingCurve(QEasingCurve.InBack)
        self._load_animation.setDuration(1000)
        self._load_animation.finished.connect(self.animation_finished)
        self._load_animation.finished.connect(self._hideAnimLabel)

    def setMessage(self, message):
        self._label_message.setText(message)

    def _updateUI(self, message=''):
        if not message:
            message = "All Done!"
        self._label_primary_message.setText(message)
        self._label_message.setText('')
        self._movie.stop()
        self._setupAnimation()
        self.layout().removeWidget(self._label_movie)
        self._label_movie.setGeometry(self._load_animation.startValue())
        self._load_animation.start()

    def _hideAnimLabel(self):
        self._label_movie.hide()