コード例 #1
0
ファイル: undoCommands.py プロジェクト: fagan2888/opengeode
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
コード例 #2
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)
コード例 #3
0
ファイル: undoCommands.py プロジェクト: dbrabera/opengeode
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
コード例 #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()
コード例 #5
0
 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)
コード例 #6
0
ファイル: table.py プロジェクト: mstead/tarabish
 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
コード例 #7
0
ファイル: slideshow.py プロジェクト: realmhamdy/VisualScrape
 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)
コード例 #8
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)
コード例 #9
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() 
コード例 #10
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()
    
コード例 #11
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()