Ejemplo n.º 1
0
class MoveSymbol(QUndoCommand):
    ''' Undo/Redo command for moving symbols '''
    def __init__(self, symbol_id, old_pos, new_pos, animate=False):
        super(MoveSymbol, self).__init__()
        self.setText('Move symbol')
        self.symbol = symbol_id
        self.old_pos = old_pos
        self.new_pos = new_pos
        if animate:
            self.animation = QPropertyAnimation(self.symbol, "position")
            self.animation.setDuration(500)
            self.animation.setStartValue(self.old_pos)
            self.animation.setEndValue(self.new_pos)
            self.animation.setEasingCurve(QEasingCurve.OutCirc)

    def undo(self):
        ''' Undo a symbol move '''
        self.symbol.position = self.old_pos
        try:
            self.symbol.decisionParent.updateConnectionPointPosition()
        except AttributeError:
            pass

    def redo(self):
        ''' Apply a symbol move '''
        try:
            self.animation.start()
        except AttributeError:
            self.symbol.position = self.new_pos
        try:
            self.symbol.decisionParent.updateConnectionPointPosition()
        except AttributeError:
            pass
class ProgressLineEdit(QLineEdit):
  """A lineedit with a progress bar overlaid"""
  INITIAL_PROGRESS_OPACITY = 0.25
  text_changed = Signal(str)
  
  def __init__(self, parent=None):
    super(ProgressLineEdit, self).__init__(parent)
    self._progress = 0
    self.text_changed.connect(self.setText)
    self.setProperty("_progress_opacity", self.INITIAL_PROGRESS_OPACITY)
    self._progress_finished_anim = QPropertyAnimation(self, "_progress_opacity")
    self._progress_finished_anim.setStartValue(self.INITIAL_PROGRESS_OPACITY)
    self._progress_finished_anim.setEndValue(0)
    self._progress_finished_anim.setDuration(1000)
    self._progress_finished_anim.valueChanged.connect(self.repaint)
    
  def setProgress(self, progress):
    self._progress = progress
    if progress == 100:
      self._progress_finished_anim.start()
    else:
      self.setProperty("_progress_opacity", self.INITIAL_PROGRESS_OPACITY)
      self.repaint()
  
  def paintEvent(self, pe):
    super(ProgressLineEdit, self).paintEvent(pe)
    painter = QPainter(self)
    painter.setOpacity(self.property("_progress_opacity"))
    sopb = QStyleOptionProgressBarV2()
    sopb.minimum = 0
    sopb.maximum = 100
    sopb.progress = self._progress
    sopb.initFrom(self)
    self.style().drawControl(QStyle.CE_ProgressBarContents, sopb, painter, self)
Ejemplo n.º 3
0
class MoveSymbol(QUndoCommand):
    ''' Undo/Redo command for moving symbols '''
    def __init__(self, symbol_id, old_pos, new_pos, animate=False):
        super(MoveSymbol, self).__init__()
        LOG.debug('New Undo command: Move symbol')
        self.setText('Move symbol')
        self.symbol = symbol_id
        self.old_pos = old_pos
        self.new_pos = new_pos
        if animate:
            self.animation = QPropertyAnimation(self.symbol, "position")
            self.animation.setDuration(500)
            self.animation.setStartValue(self.old_pos)
            self.animation.setEndValue(self.new_pos)
            self.animation.setEasingCurve(QEasingCurve.OutCirc)


    def undo(self):
        ''' Undo a symbol move '''
        self.symbol.setPos(self.old_pos)
        try:
            self.symbol.decisionParent.updateConnectionPointPosition()
        except AttributeError:
            pass

    def redo(self):
        ''' Apply a symbol move '''
        try:
            self.animation.start()
        except AttributeError:
            self.symbol.setPos(self.new_pos)
        try:
            self.symbol.decisionParent.updateConnectionPointPosition()
        except AttributeError:
            pass
Ejemplo n.º 4
0
class AnimatedClosableMessage(ClosableMessage):
    def __init__(self,
                 closeWidget,
                 messageString='',
                 opacity=0.60,
                 parent=None):
        super(AnimatedClosableMessage, self).__init__(closeWidget,
                                                      messageString,
                                                      opacity,
                                                      parent=parent)
        self._show_hide_anim = QPropertyAnimation(self, "maximumHeight")
        self._show_hide_anim.setDuration(200)
        self._show_hide_anim.setEasingCurve(QEasingCurve.InSine)

    def setMessage(self, message):
        self._message_str = message
        if not message:
            self._closeMessage()
            return
        self._show_hide_anim.setStartValue(0)
        self._show_hide_anim.setEndValue(self.HEIGHT)
        self._show_hide_anim.finished.connect(self.repaint)
        self._show_hide_anim.start()

    def _closeMessage(self):
        self._show_hide_anim.setStartValue(self.HEIGHT)
        self._show_hide_anim.setEndValue(0)
        self._show_hide_anim.start()
Ejemplo n.º 5
0
class ProgressLineEdit(QLineEdit):
    """A lineedit with a progress bar overlaid"""
    INITIAL_PROGRESS_OPACITY = 0.25
    text_changed = Signal(str)

    def __init__(self, parent=None):
        super(ProgressLineEdit, self).__init__(parent)
        self._progress = 0
        self.text_changed.connect(self.setText)
        self.setProperty("_progress_opacity", self.INITIAL_PROGRESS_OPACITY)
        self._progress_finished_anim = QPropertyAnimation(
            self, "_progress_opacity")
        self._progress_finished_anim.setStartValue(
            self.INITIAL_PROGRESS_OPACITY)
        self._progress_finished_anim.setEndValue(0)
        self._progress_finished_anim.setDuration(1000)
        self._progress_finished_anim.valueChanged.connect(self.repaint)

    def setProgress(self, progress):
        self._progress = progress
        if progress == 100:
            self._progress_finished_anim.start()
        else:
            self.setProperty("_progress_opacity",
                             self.INITIAL_PROGRESS_OPACITY)
            self.repaint()

    def paintEvent(self, pe):
        super(ProgressLineEdit, self).paintEvent(pe)
        painter = QPainter(self)
        painter.setOpacity(self.property("_progress_opacity"))
        sopb = QStyleOptionProgressBarV2()
        sopb.minimum = 0
        sopb.maximum = 100
        sopb.progress = self._progress
        sopb.initFrom(self)
        self.style().drawControl(QStyle.CE_ProgressBarContents, sopb, painter,
                                 self)
class AnimatedClosableMessage(ClosableMessage):
  
  def __init__(self, closeWidget, messageString='',
               opacity=0.60, parent=None):
    super(AnimatedClosableMessage, self).__init__(closeWidget, messageString, opacity, parent=parent)
    self._show_hide_anim = QPropertyAnimation(self, "maximumHeight")
    self._show_hide_anim.setDuration(200)
    self._show_hide_anim.setEasingCurve(QEasingCurve.InSine)
    
  def setMessage(self, message):
    self._message_str = message
    if not message:
      self._closeMessage()
      return
    self._show_hide_anim.setStartValue(0)
    self._show_hide_anim.setEndValue(self.HEIGHT)
    self._show_hide_anim.finished.connect(self.repaint)
    self._show_hide_anim.start()
    
  def _closeMessage(self):
    self._show_hide_anim.setStartValue(self.HEIGHT)
    self._show_hide_anim.setEndValue(0)
    self._show_hide_anim.start() 
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()
    
Ejemplo n.º 8
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()