コード例 #1
0
class BaseDialog(QDialog):
    """ Base para popup dialog en la esquina superior derecha """
    def __init__(self, weditor):
        super(BaseDialog, self).__init__(weditor)
        self._weditor = weditor
        self.line = None
        # Popup
        self.setWindowFlags(Qt.Popup)
        # Posición
        self.qpoint = weditor.rect().topRight()
        self.global_point = weditor.mapToGlobal(self.qpoint)
        # Animación
        self._animation = QPropertyAnimation(self, "geometry")
        self._animation.setDuration(150)
        self._animation.setEasingCurve(QEasingCurve.Linear)

        key_escape = QShortcut(QKeySequence(Qt.Key_Escape), self)
        self.connect(key_escape, SIGNAL("activated()"), self._close)

    def showEvent(self, event):
        super(BaseDialog, self).showEvent(event)
        x, y = self.geometry().x(), self.geometry().y()
        self._animation.setStartValue(QRect(x, 0, self.width(), self.height()))
        self._animation.setEndValue(QRect(x, y, self.width(), self.height()))
        self._animation.start()
        self.line.setFocus()

    def _close(self):
        x, y = self.geometry().x(), self.geometry().y()
        self._animation.setStartValue(QRect(x, y, self.width(), self.height()))
        self._animation.setEndValue(QRect(x, 0, self.width(), self.height()))
        self._animation.start()
        self.connect(self._animation, SIGNAL("finished()"), self.close)
コード例 #2
0
ファイル: scan_wizard.py プロジェクト: zinedine/pyMagic
 def createAnimationFromToFor(widget, fromValue, toValue, duration, propName, curve=QEasingCurve.InOutCubic):
     anim = QPropertyAnimation(widget, propName)
     anim.setDuration(duration)
     anim.setStartValue(fromValue)
     anim.setEndValue(toValue)
     anim.setEasingCurve(curve)
     return anim
コード例 #3
0
ファイル: scan_wizard.py プロジェクト: zinedine/pyMagic
	def createAnimationFromToFor(widget, fromValue, toValue, duration, propName, curve = QEasingCurve.InOutCubic):
		anim = QPropertyAnimation(widget, propName)
		anim.setDuration(duration)
		anim.setStartValue(fromValue)
		anim.setEndValue(toValue)
		anim.setEasingCurve(curve)
		return anim
コード例 #4
0
ファイル: base_dialog.py プロジェクト: Garjy/edis
class BaseDialog(QDialog):

    """ Base para popup dialog en la esquina superior derecha """

    def __init__(self, weditor):
        super(BaseDialog, self).__init__(weditor)
        self._weditor = weditor
        self.line = None
        # Popup
        self.setWindowFlags(Qt.Popup)
        # Posición
        self.qpoint = weditor.rect().topRight()
        self.global_point = weditor.mapToGlobal(self.qpoint)
        # Animación
        self._animation = QPropertyAnimation(self, "geometry")
        self._animation.setDuration(150)
        self._animation.setEasingCurve(QEasingCurve.Linear)

        key_escape = QShortcut(QKeySequence(Qt.Key_Escape), self)
        self.connect(key_escape, SIGNAL("activated()"), self._close)

    def showEvent(self, event):
        super(BaseDialog, self).showEvent(event)
        x, y = self.geometry().x(), self.geometry().y()
        self._animation.setStartValue(QRect(x, 0, self.width(), self.height()))
        self._animation.setEndValue(QRect(x, y, self.width(), self.height()))
        self._animation.start()
        self.line.setFocus()

    def _close(self):
        x, y = self.geometry().x(), self.geometry().y()
        self._animation.setStartValue(QRect(x, y, self.width(), self.height()))
        self._animation.setEndValue(QRect(x, 0, self.width(), self.height()))
        self._animation.start()
        self.connect(self._animation, SIGNAL("finished()"), self.close)
コード例 #5
0
    def slideInWidget(self, widget, direction=Automatic):
        if self.indexOf(widget) == -1 or widget is self.currentWidget():
            return

        if self._active:
            return

        self._active = True

        prev_widget = self.currentWidget()
        next_widget = widget

        if direction == self.Automatic:
            if self.indexOf(prev_widget) < self.indexOf(next_widget):
                direction = self.BottomToTop if self.verticalMode else self.RightToLeft
            else:
                direction = self.TopToBottom if self.verticalMode else self.LeftToRight

        width = self.frameRect().width()
        height = self.frameRect().height()

        # the following is important, to ensure that the new widget has correct geometry information when sliding in the first time
        next_widget.setGeometry(0, 0, width, height)

        if direction in (self.TopToBottom, self.BottomToTop):
            offset = QPoint(
                0, height if direction == self.TopToBottom else -height)
        elif direction in (self.LeftToRight, self.RightToLeft):
            offset = QPoint(width if direction == self.LeftToRight else -width,
                            0)

        # re-position the next widget outside of the display area
        prev_widget_position = prev_widget.pos()
        next_widget_position = next_widget.pos()

        next_widget.move(next_widget_position - offset)
        next_widget.show()
        next_widget.raise_()

        prev_widget_animation = QPropertyAnimation(prev_widget, "pos")
        prev_widget_animation.setDuration(self.animationDuration)
        prev_widget_animation.setEasingCurve(
            QEasingCurve(self.animationEasingCurve))
        prev_widget_animation.setStartValue(prev_widget_position)
        prev_widget_animation.setEndValue(prev_widget_position + offset)

        next_widget_animation = QPropertyAnimation(next_widget, "pos")
        next_widget_animation.setDuration(self.animationDuration)
        next_widget_animation.setEasingCurve(
            QEasingCurve(self.animationEasingCurve))
        next_widget_animation.setStartValue(next_widget_position - offset)
        next_widget_animation.setEndValue(next_widget_position)

        self._animation_group.clear()
        self._animation_group.addAnimation(prev_widget_animation)
        self._animation_group.addAnimation(next_widget_animation)
        self._animation_group.start()
コード例 #6
0
ファイル: containers.py プロジェクト: scudella/blink-qt
    def slideInWidget(self, widget, direction=Automatic):
        if self.indexOf(widget) == -1 or widget is self.currentWidget():
            return

        if self._active:
            return

        self._active = True

        prev_widget = self.currentWidget()
        next_widget = widget

        if direction == self.Automatic:
            if self.indexOf(prev_widget) < self.indexOf(next_widget):
                direction = self.BottomToTop if self.verticalMode else self.RightToLeft
            else:
                direction = self.TopToBottom if self.verticalMode else self.LeftToRight

        width = self.frameRect().width()
        height = self.frameRect().height()

        # the following is important, to ensure that the new widget has correct geometry information when sliding in the first time
        next_widget.setGeometry(0, 0, width, height)

        if direction in (self.TopToBottom, self.BottomToTop):
            offset = QPoint(0, height if direction == self.TopToBottom else -height)
        elif direction in (self.LeftToRight, self.RightToLeft):
            offset = QPoint(width if direction == self.LeftToRight else -width, 0)

        # re-position the next widget outside of the display area
        prev_widget_position = prev_widget.pos()
        next_widget_position = next_widget.pos()

        next_widget.move(next_widget_position - offset)
        next_widget.show()
        next_widget.raise_()

        prev_widget_animation = QPropertyAnimation(prev_widget, "pos")
        prev_widget_animation.setDuration(self.animationDuration)
        prev_widget_animation.setEasingCurve(QEasingCurve(self.animationEasingCurve))
        prev_widget_animation.setStartValue(prev_widget_position)
        prev_widget_animation.setEndValue(prev_widget_position + offset)

        next_widget_animation = QPropertyAnimation(next_widget, "pos")
        next_widget_animation.setDuration(self.animationDuration)
        next_widget_animation.setEasingCurve(QEasingCurve(self.animationEasingCurve))
        next_widget_animation.setStartValue(next_widget_position - offset)
        next_widget_animation.setEndValue(next_widget_position)

        self._animation_group.clear()
        self._animation_group.addAnimation(prev_widget_animation)
        self._animation_group.addAnimation(next_widget_animation)
        self._animation_group.start()
コード例 #7
0
    def trigger(self, ui):
        """
        Trigger this animation
        """
        damage_counter = DamageCounter(damage=str(self.damage),
                                       colour=self.colour,
                                       parent=ui)
        ui.view.scene().addItem(damage_counter)
        damage_counter.setZValue(zorder_counter)

        bounds = damage_counter.boundingRect()
        width = bounds.width()

        rand = Random()

        damage_counter.setPos((self.location[0] * 32
                               + 16 - (width / 2)
                               + rand.randint(-16, 16)) + self.offset[0],
                              self.location[1] * 32 + self.offset[1])

        animation = QSequentialAnimationGroup()

        moving = QPropertyAnimation(damage_counter.adapter,
                                    'y_location')
        moving.setDuration(750)
        moving.setStartValue(self.location[1] * 32 + self.offset[1])
        moving.setEndValue(self.location[1] * 32 - 32 + self.offset[1])
        curve = QEasingCurve(QEasingCurve.OutElastic)
        moving.setEasingCurve(curve)
        animation.addAnimation(moving)

        fading = QPropertyAnimation(damage_counter.adapter,
                                    'opacity')
        fading.setDuration(750)
        fading.setStartValue(1.0)
        fading.setEndValue(0.0)
        animation.addAnimation(fading)

        def clean_up():
            animation.stop()
            ui.animations.remove(animation)
            ui.view.items().remove(damage_counter)
            ui.remove_finished_animation()

        animation.finished.connect(clean_up)
        ui.animations.append(animation)

        animation.start()
コード例 #8
0
ファイル: htmlviewer.py プロジェクト: zoujun8666/Roam
class HtmlViewerWidget(QWidget):
    def __init__(self, parent):
        super(HtmlViewerWidget, self).__init__(parent)
        self.setLayout(QGridLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.view = QWebView()
        self.view.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        self.frame = QFrame()
        self.frame.setLayout(QGridLayout())
        self.frame.layout().setContentsMargins(0, 0, 0, 0)

        self.toolbar = QToolBar()
        self.spacer = QWidget()
        self.spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.copyAction = self.toolbar.addAction(QIcon(":/icons/clipboard"),
                                                 "Copy Text")
        self.label = QLabel()
        self.closeAction = self.toolbar.addAction(QIcon(":/icons/cancel"),
                                                  "Close")
        self.spaceraction = self.toolbar.insertWidget(self.closeAction,
                                                      self.spacer)
        self.labelaction = self.toolbar.insertWidget(self.spaceraction,
                                                     self.label)
        self.closeAction.triggered.connect(self.close)
        self.copyAction.triggered.connect(self.copy_text)
        self.layout().addWidget(self.frame)
        self.frame.layout().addWidget(self.toolbar)
        self.frame.layout().addWidget(self.view)

        self.effect = QGraphicsOpacityEffect()
        self.label.setGraphicsEffect(self.effect)
        self.anim = QPropertyAnimation(self.effect, "opacity")
        self.anim.setDuration(2000)
        self.anim.setStartValue(1.0)
        self.anim.setEndValue(0.0)
        self.anim.setEasingCurve(QEasingCurve.OutQuad)

    def copy_text(self):
        self.label.setText("Copied to clipboard")
        text = self.view.page().mainFrame().toPlainText()
        QApplication.clipboard().setText(text)
        self.anim.stop()
        self.anim.start()

    def showHTML(self, template, level, **data):
        html = templates.render_tample(template, **data)
        self.view.setHtml(html, templates.baseurl)
コード例 #9
0
ファイル: randstudent4.py プロジェクト: iefan/randstudent
def groupAnimation(ws, btngroup):
    # 建立一个平行的动作组
    ag = QParallelAnimationGroup()
    for w in ws:
        tmpbtn = btngroup.button(int(w[0]))
        # 对于每个按钮, 都生成一个进入的动作
        a = QPropertyAnimation(tmpbtn, "alpha")
        a.setDuration(200)
        a.setKeyValueAt(0, 10)
        # a.setKeyValueAt(0.5, 200)
        a.setKeyValueAt(1, 255)
        a.setLoopCount(-1)
        a.setEasingCurve(QEasingCurve.OutQuad)
        # a.setStartValue(QRect(-100, w.y(), w.width(), w.height()))
        # a.setEndValue(w.geometry())
        # 添加到组里面去
        ag.addAnimation(a)
    return ag
コード例 #10
0
ファイル: htmlviewer.py プロジェクト: nicklv/Roam
class HtmlViewerWidget(QWidget):
    def __init__(self, parent):
        super(HtmlViewerWidget, self).__init__(parent)
        self.setLayout(QGridLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.view = QWebView()
        self.view.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        self.frame = QFrame()
        self.frame.setLayout(QGridLayout())
        self.frame.layout().setContentsMargins(0, 0, 0, 0)

        self.toolbar = QToolBar()
        self.spacer = QWidget()
        self.spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.copyAction = self.toolbar.addAction(QIcon(":/icons/clipboard"), "Copy Text")
        self.label = QLabel()
        self.closeAction = self.toolbar.addAction(QIcon(":/icons/cancel"), "Close")
        self.spaceraction = self.toolbar.insertWidget(self.closeAction, self.spacer)
        self.labelaction = self.toolbar.insertWidget(self.spaceraction, self.label)
        self.closeAction.triggered.connect(self.close)
        self.copyAction.triggered.connect(self.copy_text)
        self.layout().addWidget(self.frame)
        self.frame.layout().addWidget(self.toolbar)
        self.frame.layout().addWidget(self.view)

        self.effect = QGraphicsOpacityEffect()
        self.label.setGraphicsEffect(self.effect)
        self.anim = QPropertyAnimation(self.effect, "opacity")
        self.anim.setDuration(2000)
        self.anim.setStartValue(1.0)
        self.anim.setEndValue(0.0)
        self.anim.setEasingCurve(QEasingCurve.OutQuad )

    def copy_text(self):
        self.label.setText("Copied to clipboard")
        text = self.view.page().mainFrame().toPlainText()
        QApplication.clipboard().setText(text)
        self.anim.stop()
        self.anim.start()

    def showHTML(self, template, level, **data):
        html = templates.render_tample(template, **data)
        self.view.setHtml(html, templates.baseurl)
コード例 #11
0
ファイル: gui_new.py プロジェクト: mnunberg/yobot
    def _start_animation(self, show=True):
        if not self.USE_ANIMATIONS:
            g = self.child.geometry()
            self.child_state = self.STATE_ANIMATING
            if show:
                g.setHeight(self.preferred_size.height())
            else:
                g.setHeight(0)
            self.child.setGeometry(g)
            self.mandated_size.setHeight(g.height())
            self.update()
            self.child_state = self.STATE_VISIBLE if show else self.STATE_HIDDEN
            return

        self.update()
        a = QPropertyAnimation(self.child, "geometry", self)
        g = self.child.geometry()
        g.setHeight(0)
        a.setStartValue(g)
        g.setHeight(self.preferred_size.height())
        a.setEndValue(g)
        a.setEasingCurve(QEasingCurve.OutQuad)
        a.setDuration(self.duration)

        def valueChanged(qv):
            r = qv.toRect()
            self.mandated_size.setHeight(r.height())
            self.update()

        connect(a, SIGNAL("valueChanged(QVariant)"), valueChanged)

        if not show:
            a.setDirection(a.Backward)
            connect(a, SIGNAL("finished()"), lambda: setattr(self, "child_state", self.STATE_HIDDEN))
        else:
            a.setDirection(a.Forward)
            connect(a, SIGNAL("finished()"), lambda: setattr(self, "child_state", self.STATE_VISIBLE))

        self.child_state = self.STATE_ANIMATING
        a.start(a.DeleteWhenStopped)
コード例 #12
0
ファイル: tab.py プロジェクト: pyros2097/SabelIDE
class OutputTab(QTabWidget):
    def __init__(self,parent):
        QTabWidget.__init__(self,parent)
        self.setTabBar(MyTabBar(self))
        self.setMaximumHeight(200)#260
        self.anim = QPropertyAnimation(self, "geometry")
        self.anim.setDuration(3000)
        self.anim.setStartValue(QRect(0,0,100,0))
        self.anim.setEndValue(QRect(0,0,100,200))
        self.anim.setEasingCurve(QEasingCurve.InOutQuad)
        
        if(config.hide() == 1):
            #self.setFixedHeight(200)
            self.timer = QTimer(self)
            self.timer.timeout.connect(self.close)
            #self.connect(self.tabBar(), SIGNAL("tabno"),self.pop_out)
            #self.connect(self.tabBar(), SIGNAL("enter"),self.enter_show)
            #self.connect(self.tabBar(), SIGNAL("leave"),self.leave_hide)
            self.hide()
        else:
            #self.setFixedHeight(200)
            self.hide()
        
    def pop_out(self,no):
        #print "Hover Over Output tab: ",no
        if(no != 2):
            self.setCurrentIndex(no)
        
    def enter_show(self):
        self.anim.start()
        self.show()
        
    def leave_hide(self):
        self.timer.start(2000)
        
    def close(self):
        #self.setFixedHeight(30)
        self.timer.stop()    
        
        
コード例 #13
0
ファイル: animations.py プロジェクト: dhrosa/empyre_old
class ExplodingAnimation(Animation):
    def __init__(self, center, duration, parent = None):
        super(ExplodingAnimation, self).__init__(parent)
        self.center = center
        self.__radius = 1.0
        self.anim = QPropertyAnimation(self, "radius")
        self.anim.setStartValue(1.0)
        self.anim.setEndValue(100.0)
        self.anim.setDuration(duration)
        self.anim.setEasingCurve(QEasingCurve.OutExpo)
        self.anim.valueChanged.connect(self.updated)
        self.anim.finished.connect(self.finished)

    def start(self):
        self.anim.start()

    def stop(self):
        self.anim.stop()

    def getRadius(self):
        return self.__radius

    def setRadius(self, r):
        self.__radius = r

    radius = pyqtProperty("qreal", getRadius, setRadius)

    def paint(self, painter):
        opacity = 1.0 - float(self.anim.currentTime()) / self.anim.duration()
        pen = QPen(QColor(255, 0, 0, opacity * 255))
        pen.setWidth(3)
        painter.setPen(pen)
        painter.setBrush(Qt.transparent)
        rect = QRect(0, 0, self.radius * 2, self.radius * 2)
        rect.moveCenter(self.center)
        painter.drawEllipse(rect)
コード例 #14
0
ファイル: qslider.py プロジェクト: YyaZzou/qslider
class QSwitch(QSlider):
    """ Custom Switch Widget, inspired from some QML desktop components """
    style_knob, style_off, style_on = qss_knob, qss_off, qss_on
    clicked, animationOk = pyqtSignal(), pyqtSignal()

    def __init__(self, parent=None):
        """ Init Custom Switch Widget, set Animation and Glow effects """
        QSlider.__init__(self, parent)
        self.setOrientation(Qt.Horizontal)
        self.animationType = QEasingCurve.OutExpo
        self.animation = QPropertyAnimation(self, "value")
        self.animation.setDuration(1000)
        self.animation.finished.connect(self.animationDone)
        self.clicked.connect(self.changeValue)
        self.setStyleSheet(self.style_knob + self.style_off)
        self.glow = QGraphicsDropShadowEffect(self)
        self.glow.setOffset(0)
        self.glow.setBlurRadius(99)
        self.glow.setColor(QColor(99, 255, 255))
        self.setGraphicsEffect(self.glow)
        self.glow.setEnabled(False)

    def changeValue(self):
        """ method to change the actual state ON <--> OFF """
        self.animation.setEasingCurve(self.animationType)
        if self.value() == self.maximum():
            self.animation.setStartValue(self.maximum())
            self.animation.setEndValue(self.minimum())
            self.animation.start()
            self.setStyleSheet(self.style_knob + self.style_off)
            self.glow.setEnabled(False)
            return
        else:
            self.animation.setStartValue(self.minimum())
            self.animation.setEndValue(self.maximum())
            self.setStyleSheet(self.style_knob + self.style_on)
            self.glow.setEnabled(True)
        self.animation.start()

    @pyqtSignature("setAtMax()")
    def setAtMax(self):
        """ method to set at Maximum, aka ON """
        if self.value() == self.minimum():
            self.animation.setEasingCurve(self.animationType)
            self.animation.setStartValue(self.minimum())
            self.animation.setEndValue(self.maximum())
            self.animation.start()
            self.setStyleSheet(self.style_knob + self.style_on)

    @pyqtSignature("setAtMin()")
    def setAtMin(self):
        """ method to set at Minimum, aka OFF """
        if self.value() == self.maximum():
            self.animation.setEasingCurve(self.animationType)
            self.animation.setStartValue(self.maximum())
            self.animation.setEndValue(self.minimum())
            self.animation.start()
            self.setStyleSheet(self.style_knob + self.style_off)

    def mousePressEvent(self, event):
        """ method to respond a signal to mouse pointer clicks """
        self.clicked.emit()

    def isChecked(self):
        """ method to return a bool based on actual state """
        return self.value() == self.maximum()

    def wheelEvent(self, event):
        """ dumb method, its not a bug leave it alone """
        return

    def animationDone(self):
        """ method to respond a signal to animation effects """
        self.animationOk.emit()
コード例 #15
0
class CImprovedButton(QToolButton):
    def __init__(self, parent=None):
        QToolButton.__init__(self, parent)

        #TESTO ALTERNATIVO
        #Spesso se il pulsante ha icona troppo grossa e quando per ragioni di spazio o altro non si può spostare
        #o ridimensionare il pulsante stesso, la label ha posizioni assurde e schifose. Aggiungerne una "+ controllabile"
        #è l'unico modo..
        self.__fixed_label = QLabel("alternative label", self)
        self.__fixed_label.move(0, self.geometry().height() - 35)
        self.__fixed_label.resize(self.geometry().width(), self.__fixed_label.geometry().height())
        self.__fixed_label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
        self.__font = QtGui.QFont("Arial", 10)
        self.__fixed_label.setFont(self.__font)
        self.__fixed_label.show()

        #INDICATORE STILE iOS
        self.__indicator = QLabel("0", self)
        self.__indicator.setStyleSheet("border-image: url(':/images/backgrounds/indicator.png'); padding-right:1px; color: white;")
        self.__indicator.geometry().setWidth(25)
        self.__indicator.geometry().setHeight(20)
        self.__indicator.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
        self.__indicator.setVisible(False)
        self.setIndicatorPos(QPoint(self.width() - self.__indicator.width(), 0)) #default top-right corner
        #Quando il pulsante viene ridimensionato (designer o meno) devo anche sistemare la label di conseguenza
        self.resizeEvent = self.__onResize
        self.__indicator.resizeEvent = self.__on_indicator_Resize

        self.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)

        self.clicked.connect(self.stopAllAnimations)

        #BLINK
        self.__blink_timer = QTimer(parent)
        self.__blink_timer.timeout.connect(self.__on_blink_timer)
        self.__blink_timer_interval = 1000

        #FADING
        self.__opacity_effect = QGraphicsOpacityEffect()
        self.__fading_timer = QTimer(parent)
        self.__fading_timer.timeout.connect(self.__on_fading_timer)
        self.__FADE_TYPE = Enum("IN", "OUT")
        self.__fade_time = 20
        self.__opacity = 1.0
        self.__opacity_fading_coefficient = 0.02
        self.__selected_fade_type = self.__FADE_TYPE.IN

        # ANIMAZIONI GROW
        self.__animationGrow = QPropertyAnimation(self, "iconSize", self)
        self.__animationGrow.setDuration(1000)
        self.__animationGrow.setEasingCurve(QEasingCurve.Linear)
        self.__animationGrow.finished.connect(self.__on_growed)

        self.__animationShrink = QPropertyAnimation(self, "iconSize", self)
        self.__animationShrink.setDuration(1000)
        self.__animationShrink.setEasingCurve(QEasingCurve.Linear)
        self.__animationShrink.finished.connect(self.__on_shrinked)

        self.__defaultIconDimension = 60
        self.__iconGrowsBy = 40
        self.__growing = False

        # ANIMAZIONI BOUNCE
        self.__animationUp = QPropertyAnimation(self, "pos", self)
        self.__animationUp.setDuration(200)
        self.__animationUp.setEasingCurve(QEasingCurve.Linear)
        self.__animationUp.finished.connect(self.__on_top_reached)

        self.__animationBounce = QPropertyAnimation(self, "pos", self)
        self.__animationBounce.setDuration(1000)
        self.__animationBounce.setEasingCurve(QEasingCurve.OutBounce)
        self.__animationBounce.finished.connect(self.__on_bounce_finished)

        self.__bouncing = False
        self.__startPos = QPoint(self.pos().x(), self.pos().y())

        #PIXMAP & MASCHERA
        self.__pmap = QPixmap(self.size())
        self.__pmap_fname = ""
        self.__show_mask_preview = False

    def setDefaultIconSize(self, value):
        """ Sets default icon size when growing stops.
        @param value: size (both width and height)
        @type value: int
        """
        self.__defaultIconDimension = value

    def getDefaultIconSize(self):
        return self.__defaultIconDimension

    defaultIconSize = QtCore.pyqtProperty("int", getDefaultIconSize, setDefaultIconSize)

    def setFixetTextVisibility(self, bool):
        """ Sets if fixed text is visible or not.
        @param bool: visible or not
        @type bool: bool
        """
        self.__fixed_label.setVisible(bool)

    def getFixetTextVisibility(self):
        return self.__fixed_label.isVisible()

    fixetTextVisibility = QtCore.pyqtProperty("bool", fget=getFixetTextVisibility, fset=setFixetTextVisibility)

    def setFixedText(self, txt):
        """ Sets text on the button.
        @param txt: text
        @type txt: string
        """
        self.__fixed_label.setText(txt)

    def getFixedText(self):
        return self.__fixed_label.text()

    fixedText = QtCore.pyqtProperty("QString", getFixedText, setFixedText)

    def setFixedTextPos(self, qpoint):
        """ Sets text position in the button.
        @param qpoint: Position RELATIVE. 0,0 is top left corner of the button.
        @type qpoint: QPoint
        """
        self.__fixed_label.move(qpoint)

    def getFixedTextPos(self):
        return self.__fixed_label.pos()

    fixedTextPos = QtCore.pyqtProperty("QPoint", getFixedTextPos, setFixedTextPos)

    def setFixedTextFont(self, font):
        """ Sets text font.
        @param font: Font for fixed text.
        @type font: QFont
        """
        self.__font = font
        self.__fixed_label.setFont(self.__font)

    def getFixedTextFont(self):
        return self.__font

    fixedTextFont = QtCore.pyqtProperty("QFont", getFixedTextFont, setFixedTextFont)

    #FUNZIONI INDICATORE
    def setIndicatorVisibility(self, bool):
        """ Sets if indicator is visible or not.
        @param bool: visible or not
        @type bool: bool
        """
        self.__indicator.setVisible(bool)

    def getIndicatorVisibility(self):
        return self.__indicator.isVisible()

    indicatorVisibility = QtCore.pyqtProperty("bool", fget=getIndicatorVisibility, fset=setIndicatorVisibility)

    def setIndicatorPos(self, qpoint):
        """ Sets indicator position in the button.
        @param qpoint: Position RELATIVE. 0,0 is top left corner of the button.
        @type qpoint: QPoint
        """
        self.__indicator.move(qpoint)

    def getIndicatorPos(self):
        return self.__indicator.pos()

    indicatorPos = QtCore.pyqtProperty("QPoint", getIndicatorPos, setIndicatorPos)

    def setIndicatorSize(self, size):
        """ Sets indicator size.
        @param size: Size
        @type size: QSize
        """
        self.__indicator.resize(size)

    def getIndicatorSize(self):
        return self.__indicator.size()

    indicatorSize = QtCore.pyqtProperty("QSize", getIndicatorSize, setIndicatorSize)

    def setIndicatorFont(self, font):
        """ Sets indicator text font.
        @param font: Font for indicator text.
        @type font: QFont
        """
        self.__indicator.setFont(font)

    def getIndicatorFont(self):
        return self.__indicator.font()

    indicatorFont = QtCore.pyqtProperty("QFont", getIndicatorFont, setIndicatorFont)


    ## FUNZIONI PER BLINK
    def __on_blink_timer(self):
        self.setVisible(not (self.isVisible()))

    def setBlinking(self, blink):
        """ Sets if the button have to blink or not.
        @param blink: blinking or not
        @type blink: bool
        """
        if blink:
            self.__blink_timer.setInterval(self.__blink_timer_interval)
            self.__blink_timer.start()
        else:
            self.__blink_timer.stop()
            self.setVisible(True)

    def setBlinkInterval(self, value):
        """ Sets blink interval.
        @param blink: blink interval (msec)
        @type blink: int
        """
        self.__blink_timer_interval = value

    def getBlinkInterval(self):
        return self.__blink_timer_interval

    blinkInterval = QtCore.pyqtProperty("int", getBlinkInterval, setBlinkInterval)


    ##FUNZIONI PER FADING
    def fadeIn(self):
        """
         Button fades in from completely invisible to completely visible.
        """
        self.__opacity = 0.0
        self.__selected_fade_type = self.__FADE_TYPE.IN
        self.__fading_timer.start(self.__fade_time)

    def fadeOut(self):
        """
         Button fades out from completely visible to completely invisible.
        """
        self.__selected_fade_type = self.__FADE_TYPE.OUT
        self.__fading_timer.start(self.__fade_time)

    def setFadeTime(self, value):
        """ Sets fading time. Everytime interval is reached, alpha is increased (or decreased) by __opacity_fading_coefficient.
        @param value: fade time (msec)
        @type value: int
        """
        self.__fade_time = value

    def getFadeTime(self):
        return self.__fade_time

    fadeInterval = QtCore.pyqtProperty("int", getFadeTime, setFadeTime)

    def setFadeCoefficient(self, value):
        """ Sets fading coefficient. Alpha is increased (or decreased) by this value.
        @param value: coefficient (min 0.0 - max 1.0)
        @type value: float
        """
        self.__opacity_fading_coefficient = value

    def getFadeCoefficient(self):
        return self.__opacity_fading_coefficient

    fadeCoefficient = QtCore.pyqtProperty("double", getFadeCoefficient, setFadeCoefficient)

    def __on_fading_timer(self):
        if self.__selected_fade_type == self.__FADE_TYPE.OUT:
            if self.__opacity > 0:
                self.__opacity -= self.__opacity_fading_coefficient
                self.__opacity_effect.setOpacity(self.__opacity)
                self.setGraphicsEffect(self.__opacity_effect)
            else:
                self.__fading_timer.stop()

        if self.__selected_fade_type == self.__FADE_TYPE.IN:
            if self.__opacity <= 1.0:
                self.__opacity += self.__opacity_fading_coefficient
                self.__opacity_effect.setOpacity(self.__opacity)
                self.setGraphicsEffect(self.__opacity_effect)
            else:
                self.__fading_timer.stop()

    # FUNZIONI PER GROW\SHRINK
    def __on_growed(self):
        self.__animationShrink.setStartValue(QSize(self.iconSize().width(), self.iconSize().height()))
        self.__animationShrink.setEndValue(
            QSize(self.iconSize().width() - self.__iconGrowsBy, self.iconSize().height() - self.__iconGrowsBy))
        self.__animationShrink.start()

    def __on_shrinked(self):
        self.__animationGrow.setStartValue(QSize(self.iconSize().width(), self.iconSize().height()))
        self.__animationGrow.setEndValue(
            QSize(self.iconSize().width() + self.__iconGrowsBy, self.iconSize().height() + self.__iconGrowsBy))
        self.__animationGrow.start()

    def startGrow(self):
        """
         Button ICON starts to grow and shrink to standard value when maximum size (configured) is reached
        """
        if self.__growing:
            return
        self.__animationGrow.setStartValue(QSize(self.iconSize().width(), self.iconSize().height()))
        self.__animationGrow.setEndValue(
            QSize(self.iconSize().width() + self.__iconGrowsBy, self.iconSize().height() + self.__iconGrowsBy))
        self.__animationGrow.start()
        self.__growing = True

    def stopGrow(self):
        if self.__animationGrow.startValue().toSize() != QSize(0,
                                                               0) and self.__animationShrink.startValue().toSize() != QPoint(
                0, 0):
            self.__animationGrow.stop()
            self.__animationShrink.stop()
            self.setIconSize(QSize(self.__defaultIconDimension, self.__defaultIconDimension))
            self.__growing = False
            
    #FUNZIONI PER BOUNCE
    def startBounce(self):
        """
         Button starts to bounce requiring attention.
        """
        if self.__bouncing:
            return
        self.__startPos = QPoint(self.pos().x(), self.pos().y())
        self.__animationUp.setStartValue(QPoint(self.__startPos.x(), self.__startPos.y()))
        self.__animationUp.setEndValue(QPoint(self.__startPos.x(), self.__startPos.y() - self.geometry().height()))
        self.__animationUp.start()
        self.__bouncing = True
        
    def stopBounce(self):
        if self.__animationUp.startValue().toPoint() != QPoint(0,0) and self.__animationBounce.startValue().toPoint() != QPoint(0,0):
            self.__animationBounce.stop()
            self.__animationUp.stop()
            self.setGeometry(self.__startPos.x(), self.__startPos.y(), self.geometry().width(), self.geometry().height())
            self.__bouncing = False

    def __on_top_reached(self):
        self.__animationBounce.setStartValue(QPoint(self.pos().x(), self.pos().y()))
        self.__animationBounce.setEndValue(QPoint(self.__startPos.x(), self.__startPos.y()))
        self.__animationBounce.start()

    def __on_bounce_finished(self):
        self.__animationUp.start()

    def stopAllAnimations(self):
        self.stopBounce()
        self.stopGrow()

    #FUNZIONI PER PIXMAP & MASCHERA
    def setPixmapFile(self, image_file):
        self.__pmap = image_file
        self.__pmap.scaled(self.size())
        #NB: Il pixmap deve essere BIANCO e NERO. Con heuristicMask il primo pixel in alto a sinistra (0,0) viene
        #usato per decidere il colore trasparente, tutto il resto è visibile.

    def getPixmapFile(self):
        return self.__pmap

    pixmapFile = QtCore.pyqtProperty("QPixmap", getPixmapFile, setPixmapFile)

    def applyMask(self, bool):
        self.__show_mask_preview = bool
        if bool:
            self.setMask(QBitmap(self.__pmap.createHeuristicMask().scaled(self.size())))
        else:
            self.setMask(QBitmap())

    def getMask(self):
        return self.__show_mask_preview

    appliedMask = QtCore.pyqtProperty("bool", fget=getMask, fset=applyMask)

    def __onResize(self, event):
        self.__fixed_label.move(0, self.geometry().height() - 35)
        self.__fixed_label.resize(self.geometry().width(), self.__fixed_label.geometry().height())
        self.setIndicatorPos(QPoint(self.width() - self.__indicator.width(), 0))
        self.__pmap.scaled(self.size())
        if self.__show_mask_preview:
            self.setMask(QBitmap(self.__pmap.createHeuristicMask().scaled(self.size())))

    def __on_indicator_Resize(self, event):
        self.setIndicatorPos(QPoint(self.width() - self.__indicator.width(), 0))
コード例 #16
0
ファイル: SDOM.py プロジェクト: hippiejesus/SDOM
class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        uic.loadUi(cl.UIstem + 'SDOM.ui', self)

        self.label.hide()
        self.toSwitch = None

        self.setWindowTitle('Super Dope Operations Management')
        self.showFullScreen()

        self.label.setPixmap(
            QtGui.QPixmap("/home/pi/python/SDLabs/SDLOGO.jpg"))
        self.label.setScaledContents(True)

        self.actionCustomer_Relations.triggered.connect(
            lambda: self.pageOpen('customerRelations.py'))
        self.actionIntake.triggered.connect(lambda: self.pageOpen('intake.py'))
        self.actionLab.triggered.connect(lambda: self.pageOpen('lab.py'))
        self.actionFinishing.triggered.connect(
            lambda: self.pageOpen('finishing.py'))
        self.actionYield.triggered.connect(lambda: self.pageOpen('yieldW.py'))
        self.actionProduct_Management.triggered.connect(
            lambda: self.pageOpen('productManagement.py'))
        self.actionPackaging.triggered.connect(
            lambda: self.pageOpen('packaging.py'))
        self.actionDistillate.triggered.connect(
            lambda: self.pageOpen('distillate.py'))
        self.actionPOS.triggered.connect(lambda: self.pageOpen('pos.py'))
        self.actionIClick.triggered.connect(lambda: self.pageOpen('iclick.py'))
        self.actionLog_Access.triggered.connect(
            lambda: self.pageOpen('../../.logAccess/logAccess.py'))
        self.actionExit.triggered.connect(logClose)

        self.center()

    def fadeOutPix(self):
        self.effect = QtGui.QGraphicsOpacityEffect()
        self.label.setGraphicsEffect(self.effect)
        self.anim = QPropertyAnimation(self.effect, "opacity")
        self.fadeOut()
        self.anim.finished.connect(self.switch)

    def fadeInPix(self):
        self.effect = QtGui.QGraphicsOpacityEffect()
        self.label.setGraphicsEffect(self.effect)
        self.anim = QPropertyAnimation(self.effect, "opacity")
        self.fadeIn()
        self.anim.finished.connect(self.switch)

    def fadeIn(self):
        self.anim.setDuration(1200)
        self.anim.setStartValue(0.0)
        self.anim.setEndValue(1.0)
        self.anim.setEasingCurve(QtCore.QEasingCurve.OutCubic)
        self.anim.start()

    def fadeOut(self):
        self.anim.setDuration(1000)
        self.anim.setStartValue(1.0)
        self.anim.setEndValue(0.0)
        self.anim.setEasingCurve(QtCore.QEasingCurve.OutCubic)
        self.anim.start()

    def pageOpen(self, page):
        self.toSwitch = page
        self.fadeOut()

    def center(self):
        frameGm = self.frameGeometry()
        screen = QtGui.QApplication.desktop().screenNumber(
            QtGui.QApplication.desktop().cursor().pos())
        centerPoint = QtGui.QApplication.desktop().screenGeometry(
            screen).center()
        frameGm.moveCenter(centerPoint)
        self.move(frameGm.topLeft())
        self.label.move(frameGm.topLeft())

    def switch(self):
        if self.toSwitch == None: return
        elif self.toSwitch == 'quit': exit()
        elif self.toSwitch == 'start':
            self.toSwitch = None
            self.label.show()
            self.fadeInPix()
            return
        self.label.hide()
        completed = subprocess.call('python ' + self.toSwitch, shell=True)
        print('returncode:', completed)
        self.toSwitch = None
        if completed == 0:
            self.label.show()
            self.fadeInPix()
コード例 #17
0
ファイル: qslider.py プロジェクト: juancarlospaco/qslider
class QSwitch(QSlider):
    """ Custom Switch Widget, inspired from some QML desktop components """
    style_knob, style_off, style_on = qss_knob, qss_off, qss_on
    clicked, animationOk = pyqtSignal(), pyqtSignal()

    def __init__(self, parent=None):
        """ Init Custom Switch Widget, set Animation and Glow effects """
        QSlider.__init__(self, parent)
        self.setOrientation(Qt.Horizontal)
        self.animationType = QEasingCurve.OutExpo
        self.animation = QPropertyAnimation(self, "value")
        self.animation.setDuration(1000)
        self.animation.finished.connect(self.animationDone)
        self.clicked.connect(self.changeValue)
        self.setStyleSheet(self.style_knob + self.style_off)
        self.glow = QGraphicsDropShadowEffect(self)
        self.glow.setOffset(0)
        self.glow.setBlurRadius(99)
        self.glow.setColor(QColor(99, 255, 255))
        self.setGraphicsEffect(self.glow)
        self.glow.setEnabled(False)

    def changeValue(self):
        """ method to change the actual state ON <--> OFF """
        self.animation.setEasingCurve(self.animationType)
        if self.value() == self.maximum():
            self.animation.setStartValue(self.maximum())
            self.animation.setEndValue(self.minimum())
            self.animation.start()
            self.setStyleSheet(self.style_knob + self.style_off)
            self.glow.setEnabled(False)
            return
        else:
            self.animation.setStartValue(self.minimum())
            self.animation.setEndValue(self.maximum())
            self.setStyleSheet(self.style_knob + self.style_on)
            self.glow.setEnabled(True)
        self.animation.start()

    @pyqtSignature("setAtMax()")
    def setAtMax(self):
        """ method to set at Maximum, aka ON """
        if self.value() == self.minimum():
            self.animation.setEasingCurve(self.animationType)
            self.animation.setStartValue(self.minimum())
            self.animation.setEndValue(self.maximum())
            self.animation.start()
            self.setStyleSheet(self.style_knob + self.style_on)

    @pyqtSignature("setAtMin()")
    def setAtMin(self):
        """ method to set at Minimum, aka OFF """
        if self.value() == self.maximum():
            self.animation.setEasingCurve(self.animationType)
            self.animation.setStartValue(self.maximum())
            self.animation.setEndValue(self.minimum())
            self.animation.start()
            self.setStyleSheet(self.style_knob + self.style_off)

    def mousePressEvent(self, event):
        """ method to respond a signal to mouse pointer clicks """
        self.clicked.emit()

    def isChecked(self):
        """ method to return a bool based on actual state """
        return self.value() == self.maximum()

    def wheelEvent(self, event):
        """ dumb method, its not a bug leave it alone """
        return

    def animationDone(self):
        """ method to respond a signal to animation effects """
        self.animationOk.emit()
コード例 #18
0
class CImprovedLabel(QLabel):
    def __init__(self, parent=None, caption=None):
        QLabel.__init__(self, parent)
        self.setText(self.accessibleName())
        self.setFont(QtGui.QFont("Arial", 12))
        self.__separator = chr(004)   #Used as separator while scrolling text

        #BLINK
        self.__blink_timer = QTimer(parent)
        self.__blink_timer.timeout.connect(self.__on_blink_timer)
        self.__blink_timer_interval = 1000

        #FADING
        self.__opacity_effect = QGraphicsOpacityEffect()
        self.__fading_timer = QTimer(parent)
        self.__fading_timer.timeout.connect(self.__on_fading_timer)
        self.__FADE_TYPE = Enum("IN", "OUT")
        self.__fade_time = 20
        self.__opacity = 1.0
        self.__opacity_fading_coefficient = 0.02
        self.__selected_fade_type = self.__FADE_TYPE.IN

        #SCROLLING
        self.__scrolling_timer = QTimer(parent)
        self.__scrolling_timer.timeout.connect(self.__on_scrolling_timer)
        self.__scroll_time = 1000
        self.__original_text = ""

        #MOVE
        self.__move_animation_type = QEasingCurve.Linear
        self.__move_time = 350



    ## FUNZIONI PER BLINK
    def __on_blink_timer(self):
        self.setVisible(not (self.isVisible()))

    def setBlinking(self, blink):
        """ Sets if the label have to blink or not.
        @param blink: blinking or not
        @type blink: bool
        """
        if blink:
            self.__blink_timer.setInterval(self.__blink_timer_interval)
            self.__blink_timer.start()
        else:
            self.__blink_timer.stop()
            self.setVisible(True)

    def setBlinkInterval(self, value):
        """ Sets blink interval.
        @param value: blink interval (msec)
        @type value: int
        """
        self.__blink_timer_interval = value

    def getBlinkInterval(self):
        return self.__blink_timer_interval

    blinkInterval = QtCore.pyqtProperty("int", getBlinkInterval, setBlinkInterval)

    ##FUNZIONI PER FADING
    def fadeIn(self):
        """
         Labels fades in from completely invisible to completely visible.
        """
        self.__opacity = 0.0
        self.__selected_fade_type = self.__FADE_TYPE.IN
        self.__fading_timer.start(self.__fade_time)

    def fadeOut(self):
        """
         Labels fades out from completely visible to completely invisible.
        """
        self.__selected_fade_type = self.__FADE_TYPE.OUT
        self.__fading_timer.start(self.__fade_time)

    def setFadeTime(self, value):
        """ Sets fading time. Everytime interval is reached, alpha is increased (or decreased) by __opacity_fading_coefficient.
        @param value: fade time (msec)
        @type value: int
        """
        self.__fade_time = value

    def getFadeTime(self):
        return self.__fade_time

    fadeInterval = QtCore.pyqtProperty("int", getFadeTime, setFadeTime)

    def setFadeCoefficient(self, value):
        """ Sets fading coefficient. Alpha is increased (or decreased) by this value.
        @param value: coefficient (min 0.0 - max 1.0)
        @type value: float
        """
        self.__opacity_fading_coefficient = value

    def getFadeCoefficient(self):
        return self.__opacity_fading_coefficient

    fadeCoefficient = QtCore.pyqtProperty("double", getFadeCoefficient, setFadeCoefficient)

    def __on_fading_timer(self):
        if self.__selected_fade_type == self.__FADE_TYPE.OUT:
            if self.__opacity > 0:
                self.__opacity -= self.__opacity_fading_coefficient
                self.__opacity_effect.setOpacity(self.__opacity)
                self.setGraphicsEffect(self.__opacity_effect)
            else:
                self.__fading_timer.stop()

        if self.__selected_fade_type == self.__FADE_TYPE.IN:
            if self.__opacity <= 1.0:
                self.__opacity += self.__opacity_fading_coefficient
                self.__opacity_effect.setOpacity(self.__opacity)
                self.setGraphicsEffect(self.__opacity_effect)
            else:
                self.__fading_timer.stop()

    #FUNZIONI PER SCROLLING
    def __move_text_left(self):
        if self.__separator not in self.text():
            self.setText(self.text() + "    " + self.__separator + "    ")
        left = str(self.text())[:1]
        right = str(self.text())[1:]
        self.setText(right + left)

    def __on_scrolling_timer(self):
        self.__move_text_left()

    def scrollingText(self, scroll):
        """ Sets if the label have to scroll or not.
        @param scroll: scrolling right to left or not
        @type scroll: bool
        """
        self.__scrolling_timer.setInterval(self.__scroll_time)
        if scroll:
            self.__original_text = self.text()
            self.__scrolling_timer.start()
        else:
            self.__scrolling_timer.stop()
            self.setText(self.__original_text)

    def setScrollingTime(self, value):
        """ Sets scrolling time. Everytime interval is reached, string is scrolled to left by one char.
        @param value: scrolling time (msec)
        @type value: int
        """
        self.__scroll_time = value

    ## FUNZIONI PER SPOSTAMENTO VERSO PUNTO (ANIMATO)
    def setMoveAnimationType(self, animation_type):
        """ Sets move animation type.
        @param animation_type: animation type
        @type animation_type: QtEasingCurve
        """
        self.__move_animation_type = animation_type

    def getMoveAnimationType(self):
        return self.__move_animation_type


    #asd = QtCore.pyqtProperty("QEasingCurve", getMoveAnimationType, setMoveAnimationType)
    #sembra nn essere supportato per ora (06/05/2013)

    def setMoveTime(self, value):
        """ Sets animation moving time.
        @param value: animation time (duration) (msec)
        @type value: int
        """
        self.__move_time = value

    def moveTo(self, x, y):
        """ Move itself to a given point with the given animation in the given duration.
        @param x: X point coordinate
        @type x: int
        @param y: Y point coordinate
        @type y: int
        """
        self.__starting_position = QPoint(self.pos())
        self.__moveAnimation = QPropertyAnimation(self, "pos", self)
        self.__moveAnimation.setDuration(self.__move_time)
        self.__moveAnimation.setEasingCurve(self.__move_animation_type)
        self.__moveAnimation.setStartValue(self.__starting_position)
        self.__moveAnimation.setEndValue(QPoint(x, y))
        self.__moveAnimation.start()

    def returnToOriginalPoint(self):
        """ Label returns to its original position. The original position is stored when calling moveTo() method.
        """
        self.__moveAnimation = QPropertyAnimation(self, "pos", self)
        self.__moveAnimation.setDuration(self.__move_time)
        self.__moveAnimation.setEasingCurve(self.__move_animation_type)
        self.__moveAnimation.setStartValue(QPoint(self.pos().x(), self.pos().y()))
        self.__moveAnimation.setEndValue(self.__starting_position)
        self.__moveAnimation.start()

    def mousePressEvent(self, event):
        self.clicked.emit()
コード例 #19
0
ファイル: vncviewer.py プロジェクト: kevinlovesing/blink-qt
class ScreensharingToolbox(base_class, ui_class):
    exposedPixels = 3

    def __init__(self, parent):
        super(ScreensharingToolbox, self).__init__(parent)
        with Resources.directory:
            self.setupUi()
        parent.installEventFilter(self)
        self.animation = QPropertyAnimation(self, 'pos')
        self.animation.setDuration(250)
        self.animation.setDirection(QPropertyAnimation.Forward)
        self.animation.setEasingCurve(QEasingCurve.Linear) # or OutCirc with 300ms
        self.retract_timer = QTimer(self)
        self.retract_timer.setInterval(3000)
        self.retract_timer.setSingleShot(True)
        self.retract_timer.timeout.connect(self.retract)
        self.resize(self.size().expandedTo(self.toolbox_layout.minimumSize()))

    def setupUi(self):
        super(ScreensharingToolbox, self).setupUi(self)

        # fix the SVG icons, as the generated code loads them as pixmaps, losing their ability to scale -Dan
        scale_icon = QIcon()
        scale_icon.addFile(Resources.get('icons/scale.svg'), mode=QIcon.Normal, state=QIcon.Off)
        viewonly_icon = QIcon()
        viewonly_icon.addFile(Resources.get('icons/viewonly.svg'), mode=QIcon.Normal, state=QIcon.Off)
        screenshot_icon = QIcon()
        screenshot_icon.addFile(Resources.get('icons/screenshot.svg'), mode=QIcon.Normal, state=QIcon.Off)
        fullscreen_icon = QIcon()
        fullscreen_icon.addFile(Resources.get('icons/fullscreen.svg'), mode=QIcon.Normal, state=QIcon.Off)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Normal, state=QIcon.On)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Active, state=QIcon.On)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Disabled, state=QIcon.On)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Selected, state=QIcon.On)
        minimize_icon = QIcon()
        minimize_icon.addFile(Resources.get('icons/minimize.svg'), mode=QIcon.Normal, state=QIcon.Off)
        minimize_icon.addFile(Resources.get('icons/minimize-active.svg'), mode=QIcon.Active, state=QIcon.Off)
        close_icon = QIcon()
        close_icon.addFile(Resources.get('icons/close.svg'), mode=QIcon.Normal, state=QIcon.Off)
        close_icon.addFile(Resources.get('icons/close-active.svg'), mode=QIcon.Active, state=QIcon.Off)

        self.scale_action.setIcon(scale_icon)
        self.viewonly_action.setIcon(viewonly_icon)
        self.screenshot_action.setIcon(screenshot_icon)
        self.fullscreen_action.setIcon(fullscreen_icon)
        self.minimize_action.setIcon(minimize_icon)
        self.close_action.setIcon(close_icon)

        self.scale_button.setIcon(scale_icon)
        self.viewonly_button.setIcon(viewonly_icon)
        self.screenshot_button.setIcon(screenshot_icon)
        self.fullscreen_button.setIcon(fullscreen_icon)
        self.minimize_button.setIcon(minimize_icon)
        self.close_button.setIcon(close_icon)

        self.scale_button.setDefaultAction(self.scale_action)
        self.viewonly_button.setDefaultAction(self.viewonly_action)
        self.screenshot_button.setDefaultAction(self.screenshot_action)
        self.fullscreen_button.setDefaultAction(self.fullscreen_action)
        self.minimize_button.setDefaultAction(self.minimize_action)
        self.close_button.setDefaultAction(self.close_action)

        self.color_depth_button.clear()
        self.color_depth_button.addItem('Default Color Depth', ServerDefault)
        self.color_depth_button.addItem('TrueColor (24 bits)', TrueColor)
        self.color_depth_button.addItem('HighColor (16 bits)', HighColor)
        self.color_depth_button.addItem('LowColor (8 bits)', LowColor)

    def eventFilter(self, watched, event):
        if watched is self.parent() and event.type() == QEvent.Resize:
            new_x = (watched.width() - self.width()) / 2
            self.move(new_x, self.y())
            self.animation.setStartValue(QPoint(new_x, -self.height() + self.exposedPixels))
            self.animation.setEndValue(QPoint(new_x, 0))
        return False

    def enterEvent(self, event):
        super(ScreensharingToolbox, self).enterEvent(event)
        self.retract_timer.stop()
        self.expose()

    def leaveEvent(self, event):
        super(ScreensharingToolbox, self).leaveEvent(event)
        self.retract_timer.start()

    def paintEvent(self, event): # make the widget style aware
        option = QStyleOption()
        option.init(self)
        painter = QStylePainter(self)
        painter.drawPrimitive(QStyle.PE_Widget, option)

    def expose(self):
        if self.animation.state() == QPropertyAnimation.Running and self.animation.direction() == QPropertyAnimation.Forward:
            return
        elif self.animation.state() == QPropertyAnimation.Stopped and self.pos() == self.animation.endValue():
            return
        self.animation.setDirection(QPropertyAnimation.Forward)
        self.animation.start()

    def retract(self):
        if self.animation.state() == QPropertyAnimation.Running and self.animation.direction() == QPropertyAnimation.Backward:
            return
        elif self.animation.state() == QPropertyAnimation.Stopped and self.pos() == self.animation.startValue():
            return
        self.animation.setDirection(QPropertyAnimation.Backward)
        self.animation.start()
コード例 #20
0
class CLightBlueSwitch(QSlider):
    '''
    classdocs
    '''
    styleKnob = 'QSlider::handle:horizontal {border-image: url(:/images/switches/white_round_knob_2.png); border: 0px solid; width: 32px; margin-left: 3px; margin-bottom: 3px; margin-top: 2px;}'
    styleBkgOFF = 'QSlider::groove:horizontal {border: 1px solid #999999; height: 35px; border-image: url(:/images/switches/off_black_2.png); margin: 1px;};'
    styleBkgON = 'QSlider::groove:horizontal {border: 1px solid #999999; height: 35px; border-image: url(:/images/switches/on_lblue_1.png); margin: 1px;};'

    clicked = QtCore.pyqtSignal()
    animationOk = QtCore.pyqtSignal()

    def __init__(self, parent=None):
        '''
        Constructor
        '''
        QSlider.__init__(self, parent)
        self.setOrientation(QtCore.Qt.Horizontal)
        self.animationType = QEasingCurve.OutExpo
        self.animation = QPropertyAnimation(self, "value")
        self.animation.setDuration(250)
        self.animation.finished.connect(self.animationDone)
        self.resize(85, 50)
        self.clicked.connect(self.changeValue)
        self.setStyleSheet(self.styleKnob + self.styleBkgOFF)

    def changeValue(self):
        """Slot utilizzato per cambiare lo stato e la grafica del check."""
        self.animation.setEasingCurve(self.animationType)
        if self.value() == self.maximum():
            self.animation.setStartValue(self.maximum())
            self.animation.setEndValue(self.minimum())
            self.animation.start()
            self.setStyleSheet(self.styleKnob + self.styleBkgOFF)
            return
        else:
            self.animation.setStartValue(self.minimum())
            self.animation.setEndValue(self.maximum())
            self.setStyleSheet(self.styleKnob + self.styleBkgON)
        self.animation.start()

    @QtCore.pyqtSignature("setAtMax()")
    def setAtMax(self):
        if self.value() == self.minimum():
            self.animation.setEasingCurve(self.animationType)
            self.animation.setStartValue(self.minimum())
            self.animation.setEndValue(self.maximum())
            self.animation.start()
            self.setStyleSheet(self.styleKnob + self.styleBkgON)

    @QtCore.pyqtSignature("setAtMin()")
    def setAtMin(self):
        if self.value() == self.maximum():
            self.animation.setEasingCurve(self.animationType)
            self.animation.setStartValue(self.maximum())
            self.animation.setEndValue(self.minimum())
            self.animation.start()
            self.setStyleSheet(self.styleKnob + self.styleBkgOFF)

    def mousePressEvent(self, event):
        self.clicked.emit()

    def isChecked(self):
        return (self.value() == self.maximum())

    def wheelEvent(self, event):
        # è uno switch 1\0, quindi devo disabilitare la rotellina del mouse prima che lo slider faccia il lavoro per cui è stato creato..
        return

    def animationDone(self):
        self.animationOk.emit()
コード例 #21
0
    def slideIn(self, index, direction=Direction.Automatic):
        """
        Slides in the panel at the inputed index in the given
        direction for this widget.
        
        :param      index | <int>
                    direction | <XStackedWidget.Direction>
        
        :return     <bool> | success
        """
        # do not allow multiple slides while it is active
        if self._active:
            return False

        # determine the proper index to calculate
        invert = False
        if self.count() <= index:
            if not self.wrap():
                return False
            index = self.count() % index
            invert = True
        elif index < 0:
            if not self.wrap():
                return False
            index = self.count() + index
            invert = True

        # define the direction information
        if index == self.currentIndex():
            return False
        elif self.currentIndex() < index:
            if direction == XStackedWidget.Direction.Automatic:
                if self.isVerticalMode():
                    direction = XStackedWidget.Direction.BottomToTop
                else:
                    direction = XStackedWidget.Direction.RightToLeft
        else:
            if direction == XStackedWidget.Direction.Automatic:
                if self.isVerticalMode():
                    direction = XStackedWidget.Direction.TopToBottom
                else:
                    direction = XStackedWidget.Direction.LeftToRight

        # invert the animation if we are wrapping
        if invert:
            if direction == XStackedWidget.Direction.BottomToTop:
                direction = XStackedWidget.Direction.TopToBottom
            elif direction == XStackedWidget.Direction.TopToBottom:
                direction = XStackedWidget.Direction.BottomToTop
            elif direction == XStackedWidget.Direction.LeftToRight:
                direction = XStackedWidget.Direction.RightToLeft
            else:
                direction = XStackedWidget.Direction.LeftToRight

        self._active = True
        offset_x = self.frameRect().width()
        offset_y = self.frameRect().height()

        next_widget = self.widget(index)
        curr_widget = self.widget(self.currentIndex())

        next_widget.setGeometry(0, 0, offset_x, offset_y)

        if direction == XStackedWidget.Direction.BottomToTop:
            offset_x = 0
            offset_y = -offset_y
        elif direction == XStackedWidget.Direction.TopToBottom:
            offset_x = 0
        elif direction == XStackedWidget.Direction.RightToLeft:
            offset_x = -offset_x
            offset_y = 0
        elif direction == XStackedWidget.Direction.LeftToRight:
            offset_y = 0

        next_point = next_widget.pos()
        curr_point = curr_widget.pos()

        self._nextIndex = index
        self._lastIndex = self.currentIndex()
        self._lastPoint = QPoint(curr_point)

        next_widget.move(next_point.x() - offset_x, next_point.y() - offset_y)
        next_widget.raise_()
        next_widget.show()

        curr_anim = QPropertyAnimation(curr_widget, 'pos')
        curr_anim.setDuration(self.speed())
        curr_anim.setEasingCurve(self.animationType())
        curr_anim.setStartValue(curr_point)
        curr_anim.setEndValue(
            QPoint(curr_point.x() + offset_x,
                   curr_point.y() + offset_y))

        next_anim = QPropertyAnimation(next_widget, 'pos')
        next_anim.setDuration(self.speed())
        next_anim.setEasingCurve(self.animationType())
        next_anim.setStartValue(
            QPoint(next_point.x() - offset_x,
                   next_point.y() - offset_y))
        next_anim.setEndValue(next_point)

        anim_group = QParallelAnimationGroup(self)
        anim_group.addAnimation(curr_anim)
        anim_group.addAnimation(next_anim)

        anim_group.finished.connect(self._finishAnimation)
        anim_group.finished.connect(anim_group.deleteLater)
        anim_group.start()

        return True
コード例 #22
0
ファイル: robot.py プロジェクト: mike-perdide/gitbuster
    def __init__(self, parent=None):
        RoboPart.__init__(self)

        self.setFlag(QGraphicsItem.ItemHasNoContents)

        self.torsoItem = RobotTorso(self)
        self.headItem = RobotHead(self.torsoItem)
        self.upperLeftArmItem = RobotLimb(self.torsoItem)
        self.lowerLeftArmItem = RobotLimb(self.upperLeftArmItem)
        self.upperRightArmItem = RobotLimb(self.torsoItem)
        self.lowerRightArmItem = RobotLimb(self.upperRightArmItem)
        self.upperRightLegItem = RobotLimb(self.torsoItem)
        self.lowerRightLegItem = RobotLimb(self.upperRightLegItem)
        self.upperLeftLegItem = RobotLimb(self.torsoItem)
        self.lowerLeftLegItem = RobotLimb(self.upperLeftLegItem)

        self.headItem.setPos(0, -18)
        self.upperLeftArmItem.setPos(-15, -10)
        self.lowerLeftArmItem.setPos(30, 0)
        self.upperRightArmItem.setPos(15, -10)
        self.lowerRightArmItem.setPos(30, 0)
        self.upperRightLegItem.setPos(10, 32)
        self.lowerRightLegItem.setPos(30, 0)
        self.upperLeftLegItem.setPos(-10, 32)
        self.lowerLeftLegItem.setPos(30, 0)

        self.animation = QParallelAnimationGroup(None)


        #self.headAnimation = QPropertyAnimation(self.headItem, "scale")
        #self.headAnimation.setStartValue(20)
        #self.headAnimation.setEndValue(-20)

        #self.headScaleAnimation = QPropertyAnimation(self.headItem, "scale")
        #self.headScaleAnimation.setEndValue(1.1)
        #self.animation.addAnimation(self.headAnimation)
        #self.animation.addAnimation(self.headScaleAnimation)

        #self.upperLeftArmAnimation = QPropertyAnimation(self.upperLeftArmItem, "rotation")
        #self.upperLeftArmAnimation.setStartValue(190)
        #self.upperLeftArmAnimation.setEndValue(180)
        #self.animation.addAnimation(self.upperLeftArmAnimation)

        #self.lowerLeftArmAnimation = QPropertyAnimation(self.lowerLeftArmItem, "rotation")
        #self.lowerLeftArmAnimation.setStartValue(50)
        #self.lowerLeftArmAnimation.setEndValue(10)
        #self.animation.addAnimation(self.lowerLeftArmAnimation)

        #self.upperRightArmAnimation = QPropertyAnimation(self.upperRightArmItem, "rotation")
        #self.upperRightArmAnimation.setStartValue(300)
        #self.upperRightArmAnimation.setEndValue(310)
        #self.animation.addAnimation(self.upperRightArmAnimation)

        #self.lowerRightArmAnimation = QPropertyAnimation(self.lowerRightArmItem, "rotation")
        #self.lowerRightArmAnimation.setStartValue(0)
        #self.lowerRightArmAnimation.setEndValue(-70)
        #self.animation.addAnimation(self.lowerRightArmAnimation)

        #self.upperLeftLegAnimation = QPropertyAnimation(self.upperLeftLegItem, "rotation")
        #self.upperLeftLegAnimation.setStartValue(150)
        #self.upperLeftLegAnimation.setEndValue(80)
        #self.animation.addAnimation(self.upperLeftLegAnimation)

        #self.lowerLeftLegAnimation = QPropertyAnimation(self.lowerLeftLegItem, "rotation")
        #self.lowerLeftLegAnimation.setStartValue(70)
        #self.lowerLeftLegAnimation.setEndValue(10)
        #self.animation.addAnimation(self.lowerLeftLegAnimation)

        #self.upperRightLegAnimation = QPropertyAnimation(self.upperRightLegItem, "rotation")
        #self.upperRightLegAnimation.setStartValue(40)
        #self.upperRightLegAnimation.setEndValue(120)
        #self.animation.addAnimation(self.upperRightLegAnimation)

        #self.lowerRightLegAnimation = QPropertyAnimation(self.lowerRightLegItem, "rotation")
        #self.lowerRightLegAnimation.setStartValue(10)
        #self.lowerRightLegAnimation.setEndValue(50)
        #self.animation.addAnimation(self.lowerRightLegAnimation)

        #self.torsoAnimation = QPropertyAnimation(self.torsoItem, "rotation")
        #self.torsoAnimation.setStartValue(5)
        #self.torsoAnimation.setEndValue(-20)
        #self.animation.addAnimation(self.torsoAnimation)

        for i in xrange(self.animation.animationCount()):
            anim = QPropertyAnimation(self.animation.animationAt(i))
            anim.setEasingCurve(QEasingCurve.SineCurve)
            anim.setDuration(2000)

        self.animation.setLoopCount(-1)
        self.animation.start()
コード例 #23
0
 def slideIn(self, index, direction=Direction.Automatic):
     """
     Slides in the panel at the inputed index in the given
     direction for this widget.
     
     :param      index | <int>
                 direction | <XStackedWidget.Direction>
     
     :return     <bool> | success
     """
     # do not allow multiple slides while it is active
     if self._active:
         return False
     
     # determine the proper index to calculate
     invert = False
     if self.count() <= index:
         if not self.wrap():
             return False
         index = self.count() % index
         invert = True
     elif index < 0:
         if not self.wrap():
             return False
         index = self.count() + index
         invert = True
     
     # define the direction information
     if index == self.currentIndex():
         return False
     elif self.currentIndex() < index:
         if direction == XStackedWidget.Direction.Automatic:
             if self.isVerticalMode():
                 direction = XStackedWidget.Direction.BottomToTop
             else:
                 direction = XStackedWidget.Direction.RightToLeft
     else:
         if direction == XStackedWidget.Direction.Automatic:
             if self.isVerticalMode():
                 direction = XStackedWidget.Direction.TopToBottom
             else:
                 direction = XStackedWidget.Direction.LeftToRight
     
     # invert the animation if we are wrapping
     if invert:
         if direction == XStackedWidget.Direction.BottomToTop:
             direction = XStackedWidget.Direction.TopToBottom
         elif direction == XStackedWidget.Direction.TopToBottom:
             direction = XStackedWidget.Direction.BottomToTop
         elif direction == XStackedWidget.Direction.LeftToRight:
             direction = XStackedWidget.Direction.RightToLeft
         else:
             direction = XStackedWidget.Direction.LeftToRight
     
     self._active = True
     offset_x = self.frameRect().width()
     offset_y = self.frameRect().height()
     
     next_widget = self.widget(index)
     curr_widget = self.widget(self.currentIndex())
     
     next_widget.setGeometry(0, 0, offset_x, offset_y)
     
     if direction == XStackedWidget.Direction.BottomToTop:
         offset_x = 0
         offset_y = -offset_y
     elif direction == XStackedWidget.Direction.TopToBottom:
         offset_x = 0
     elif direction == XStackedWidget.Direction.RightToLeft:
         offset_x = -offset_x
         offset_y = 0
     elif direction == XStackedWidget.Direction.LeftToRight:
         offset_y = 0
     
     next_point = next_widget.pos()
     curr_point = curr_widget.pos()
     
     self._nextIndex = index
     self._lastIndex = self.currentIndex()
     self._lastPoint = QPoint(curr_point)
     
     next_widget.move(next_point.x()-offset_x, next_point.y()-offset_y)
     next_widget.raise_()
     next_widget.show()
     
     curr_anim = QPropertyAnimation(curr_widget, 'pos')
     curr_anim.setDuration(self.speed())
     curr_anim.setEasingCurve(self.animationType())
     curr_anim.setStartValue(curr_point)
     curr_anim.setEndValue(QPoint(curr_point.x()+offset_x,
                                  curr_point.y()+offset_y))
     
     next_anim = QPropertyAnimation(next_widget, 'pos')
     next_anim.setDuration(self.speed())
     next_anim.setEasingCurve(self.animationType())
     next_anim.setStartValue(QPoint(next_point.x()-offset_x,
                                    next_point.y()-offset_y))
     next_anim.setEndValue(next_point)
     
     anim_group = QParallelAnimationGroup(self)
     anim_group.addAnimation(curr_anim)
     anim_group.addAnimation(next_anim)
     
     anim_group.finished.connect(self._finishAnimation)
     anim_group.finished.connect(anim_group.deleteLater)
     anim_group.start()
     
     return True
コード例 #24
0
class CImprovedStackWidget(QStackedWidget):
    __SLIDE_TYPE = Enum("TOP2BOTTOM", "BOTTOM2TOP", "RIGHT2LEFT", "LEFT2RIGHT",
                        "AUTOMATIC")

    animationOk = QtCore.pyqtSignal()

    def __init__(self, parent=None):
        """ Inizializza il componente"""
        QStackedWidget.__init__(self, parent)
        self.__m_vertical = False
        self.__m_speed = 500
        self.__m_animationtype = QEasingCurve.OutQuint  #QEasingCurve.OutBack
        self.__m_now = 0
        self.__m_next = 0
        self.__m_pnow = QPoint(0, 0)
        self.__m_active = False
        self.__direction = self.__SLIDE_TYPE.RIGHT2LEFT
        self.__animgroup = QtCore.QParallelAnimationGroup()
        self.__animgroup.finished.connect(self.__animationDone)
        self.__animnext = QPropertyAnimation(None, "pos")
        self.__animnow = QPropertyAnimation(None, "pos")
        #self.setMinimumSize(300, 300)
        self.setStyleSheet("background-color: rgb(184, 184, 184);")

    def setVerticalMode(self, bool):
        """ Setta la modalità slide in verticale
        @param bool: Impostata a true o false, determina se lo slide è verticale o orizzontale.
        @type bool: Boolean
        """
        self.__m_vertical = bool

    def setSpeed(self, speed_value):
        """ Setta la velocità di slide tra una pagine e l'altra.
        @param speed_value: Velocità in msec.
        @type speed_value: int
        """
        self.__m_speed = speed_value

    def getSpeed(self):
        return self.__m_speed

    slidingSpeed = QtCore.pyqtProperty("int", getSpeed, setSpeed)

    def setAnimation(self, animation_type):
        """ Setta il la tipologia di animazione da utilizzare per gli slide.
        @param animation_type: Tipo di animazione.
        @type animation_type: QEasingCurve
        """
        self.__m_animationtype = animation_type

    def slideNext(self):
        """Sposta alla finestra successiva"""
        now = self.currentIndex()
        self.slideIdx(now + 1)

    def slidePrev(self):
        """Sposta alla finestra precedente"""
        now = self.currentIndex()
        self.slideIdx(now - 1)

    def slideIdx(self, idx):
        """ Sposta la visualizzazione alla finestra indicata.
        @param idx: Indice finestra da visualizzare
        @type idx: int
        """

        if (idx > self.count() - 1):
            if (self.__m_vertical):
                self.__direction = self.__SLIDE_TYPE.TOP2BOTTOM
            else:
                self.__direction = self.__SLIDE_TYPE.RIGHT2LEFT
            idx = (idx) % self.count()

        elif (idx < 0):
            if (self.__m_vertical):
                self.__direction = self.__SLIDE_TYPE.BOTTOM2TOP
            else:
                self.__direction = self.__SLIDE_TYPE.LEFT2RIGHT
            idx = (idx + self.count()) % self.count()

        self.slideInWgt(self.widget(idx))

    def slideInWgt(self, widget):
        if self.__m_active:
            return  #se l'animazione e' attiva, nn faccio nulla.
        else:
            self.__m_active = True
        now = self.currentIndex()
        next = self.indexOf(widget)

        if (now == next):
            self.__m_active = False
            return
        elif (now < next):
            if (self.__m_vertical):
                dhint = self.__SLIDE_TYPE.TOP2BOTTOM
            else:
                dhint = self.__SLIDE_TYPE.RIGHT2LEFT

        else:
            if (self.__m_vertical):
                dhint = self.__SLIDE_TYPE.BOTTOM2TOP
            else:
                dhint = self.__SLIDE_TYPE.LEFT2RIGHT

        #=======================================================================
        # if(self.__direction == self.AUTOMATIC):
        #    self.__direction = dhint
        #=======================================================================
        self.__direction = dhint
        offsetX = self.frameRect().width()
        offsetY = self.frameRect().height()

        self.widget(next).setGeometry(0, 0, offsetX, offsetY)

        if (self.__direction == self.__SLIDE_TYPE.BOTTOM2TOP):
            offsetX = 0
            offsetY = -offsetY
        elif (self.__direction == self.__SLIDE_TYPE.TOP2BOTTOM):
            offsetX = 0
        elif (self.__direction == self.__SLIDE_TYPE.RIGHT2LEFT):
            offsetX = -offsetX
            offsetY = 0
        elif (self.__direction == self.__SLIDE_TYPE.LEFT2RIGHT):
            offsetY = 0

        pnext = self.widget(next).pos()
        pnow = self.widget(now).pos()
        self.__m_pnow = pnow

        self.widget(next).move(pnext.x() - offsetX, pnext.y() - offsetY)
        self.widget(next).show()

        self.__animnow.setTargetObject(self.widget(now))
        self.__animnow.setDuration(self.__m_speed)
        self.__animnow.setEasingCurve(self.__m_animationtype)
        self.__animnow.setStartValue(QPoint(pnow.x(), pnow.y()))
        self.__animnow.setEndValue(
            QPoint(offsetX + pnow.x(), offsetY + pnow.y()))

        self.__animnext.setTargetObject(self.widget(next))
        self.__animnext.setDuration(self.__m_speed)
        self.__animnext.setEasingCurve(self.__m_animationtype)
        self.__animnext.setStartValue(
            QPoint(-offsetX + pnext.x(), offsetY + pnext.y()))
        self.__animnext.setEndValue(QPoint(pnext.x(), pnext.y()))

        self.__animgroup.addAnimation(self.__animnow)
        self.__animgroup.addAnimation(self.__animnext)

        self.__m_next = next
        self.__m_now = now
        self.__m_active = True
        self.__animgroup.start()

    def __animationDone(self):
        self.setCurrentIndex(self.__m_next)

        self.widget(self.__m_now).hide()

        self.widget(self.__m_now).move(self.__m_pnow)
        self.__m_active = False

        self.animationOk.emit()
コード例 #25
0
class CLightBlueSwitch(QSlider):
    '''
    classdocs
    '''
    styleKnob   =   'QSlider::handle:horizontal {border-image: url(:/images/switches/white_round_knob_2.png); border: 0px solid; width: 32px; margin-left: 3px; margin-bottom: 3px; margin-top: 2px;}'
    styleBkgOFF =   'QSlider::groove:horizontal {border: 1px solid #999999; height: 35px; border-image: url(:/images/switches/off_black_2.png); margin: 1px;};'
    styleBkgON  =   'QSlider::groove:horizontal {border: 1px solid #999999; height: 35px; border-image: url(:/images/switches/on_lblue_1.png); margin: 1px;};'
    
    clicked = QtCore.pyqtSignal()
    animationOk = QtCore.pyqtSignal()

    def __init__(self, parent=None):
        '''
        Constructor
        '''
        QSlider.__init__(self, parent)
        self.setOrientation(QtCore.Qt.Horizontal)
        self.animationType = QEasingCurve.OutExpo
        self.animation = QPropertyAnimation(self, "value")
        self.animation.setDuration(250)
        self.animation.finished.connect(self.animationDone)
        self.resize(85, 50)
        self.clicked.connect(self.changeValue)
        self.setStyleSheet(self.styleKnob + self.styleBkgOFF)
        
    def changeValue(self):
        """Slot utilizzato per cambiare lo stato e la grafica del check."""
        self.animation.setEasingCurve(self.animationType)
        if self.value() == self.maximum():
            self.animation.setStartValue(self.maximum())
            self.animation.setEndValue(self.minimum())
            self.animation.start()
            self.setStyleSheet(self.styleKnob + self.styleBkgOFF)
            return
        else:
            self.animation.setStartValue(self.minimum())
            self.animation.setEndValue(self.maximum())
            self.setStyleSheet(self.styleKnob + self.styleBkgON)
        self.animation.start()
        
    @QtCore.pyqtSignature("setAtMax()")
    def setAtMax(self):
        if self.value() == self.minimum():
            self.animation.setEasingCurve(self.animationType)
            self.animation.setStartValue(self.minimum())
            self.animation.setEndValue(self.maximum())
            self.animation.start()
            self.setStyleSheet(self.styleKnob + self.styleBkgON)
            
    @QtCore.pyqtSignature("setAtMin()")        
    def setAtMin(self):
        if self.value() == self.maximum():
            self.animation.setEasingCurve(self.animationType)
            self.animation.setStartValue(self.maximum())
            self.animation.setEndValue(self.minimum())
            self.animation.start()
            self.setStyleSheet(self.styleKnob + self.styleBkgOFF)
        
    def mousePressEvent(self, event):
        self.clicked.emit()
        
    def isChecked(self):
        return (self.value() == self.maximum())
    
    def wheelEvent(self, event):
        # è uno switch 1\0, quindi devo disabilitare la rotellina del mouse prima che lo slider faccia il lavoro per cui è stato creato..
        return
    
    def animationDone(self):
        self.animationOk.emit()
コード例 #26
0
class CImprovedPanel(QFrame):
    def __init__(self, parent=None):
        QFrame.__init__(self, parent)

        #FADING
        self.__opacity_effect = QGraphicsOpacityEffect()
        self.__fading_timer = QTimer(parent)
        self.__fading_timer.timeout.connect(self.__on_fading_timer)
        self.__FADE_TYPE = Enum("IN", "OUT")
        self.__fade_time = 20
        self.__opacity = 1.0
        self.__opacity_fading_coefficient = 0.02
        self.__selected_fade_type = self.__FADE_TYPE.IN
        self.resizeEvent = self.__onResize

        #MOVE
        self.__move_animation_type = QEasingCurve.Linear
        self.__move_time = 350
        self.__is_moving = False

        #RESIZE
        self.__resize_animation_type = QEasingCurve.Linear
        self.__resize_time = 700
        self.__is_resizing = False

        #PIXMAP & MASCHERA
        self.__pmap = QPixmap(self.size())
        self.__pmap_fname = ""
        self.__show_mask_preview = False

        #SHADOW
        self.__shadow_Xoffset = 3.0 #default value
        self.__shadow_Yoffset = 3.0 #default value
        self.__shadow_blur_radius = 8.0 #default value
        self.__shadow_color = QColor(38,38,38,150) #default value

        self.__shadow_effect = QGraphicsDropShadowEffect()
        self.__shadow_effect.setXOffset(self.__shadow_Xoffset)
        self.__shadow_effect.setYOffset(self.__shadow_Yoffset)
        self.__shadow_effect.setBlurRadius(self.__shadow_blur_radius)
        self.__shadow_effect.setColor(self.__shadow_color)
        self._shadow_visible = False


    ##FUNZIONI PER FADING
    def fadeIn(self):
        """
         Labels fades in from completely invisible to completely visible.
        """
        self.__opacity = 0.0
        self.__selected_fade_type = self.__FADE_TYPE.IN
        self.__fading_timer.start(self.__fade_time)

    def fadeOut(self):
        """
         Labels fades out from completely visible to completely invisible.
        """
        self.__selected_fade_type = self.__FADE_TYPE.OUT
        self.__fading_timer.start(self.__fade_time)

    def setFadeTime(self, value):
        """ Sets fading time. Everytime interval is reached, alpha is increased (or decreased) by __opacity_fading_coefficient.
        @param value: fade time (msec)
        @type value: int
        """
        self.__fade_time = value

    def getFadeTime(self):
        return self.__fade_time

    fadeInterval = QtCore.pyqtProperty("int", getFadeTime, setFadeTime)

    def setFadeCoefficient(self, value):
        """ Sets fading coefficient. Alpha is increased (or decreased) by this value.
        @param value: coefficient (min 0.0 - max 1.0)
        @type value: float
        """
        self.__opacity_fading_coefficient = value

    def getFadeCoefficient(self):
        return self.__opacity_fading_coefficient

    fadeCoefficient = QtCore.pyqtProperty("double", getFadeCoefficient, setFadeCoefficient)

    def __on_fading_timer(self):
        if self.__selected_fade_type == self.__FADE_TYPE.OUT:
            if self.__opacity > 0:
                self.__opacity -= self.__opacity_fading_coefficient
                self.__opacity_effect.setOpacity(self.__opacity)
                self.setGraphicsEffect(self.__opacity_effect)
            else:
                self.__fading_timer.stop()

        if self.__selected_fade_type == self.__FADE_TYPE.IN:
            if self.__opacity <= 1.0:
                self.__opacity += self.__opacity_fading_coefficient
                self.__opacity_effect.setOpacity(self.__opacity)
                self.setGraphicsEffect(self.__opacity_effect)
            else:
                self.__fading_timer.stop()

    ## FUNZIONI PER SPOSTAMENTO VERSO PUNTO (ANIMATO)
    def setMoveAnimationType(self, animation_type):
        """ Sets move animation type.
        @param animation_type: animation type
        @type animation_type: QtEasingCurve
        """
        self.__move_animation_type = animation_type

    def getMoveAnimationType(self):
        return self.__move_animation_type

    #asd = QtCore.pyqtProperty("QEasingCurve", getMoveAnimationType, setMoveAnimationType)
    #sembra nn essere supportato per ora (06/05/2013)

    def setMoveTime(self, value):
        """ Sets animation moving time.
        @param value: animation time (duration) (msec)
        @type value: int
        """
        self.__move_time = value

    def getMoveTime(self):
        return self.__move_time

    moveTime = QtCore.pyqtProperty("int", getMoveTime, setMoveTime)

    def setResizeTime(self, value):
        """ Sets animation resize time.
        @param value: animation time (duration) (msec)
        @type value: int
        """
        self.__resize_time = value

    def getResizeTime(self):
        return self.__resize_time

    resizeTime = QtCore.pyqtProperty("int", getResizeTime, setResizeTime)

    def moveTo(self, x, y):
        """ Move itself to a given point with the given animation in the given duration.
        @param x: X point coordinate
        @type x: int
        @param y: Y point coordinate
        @type y: int
        """
        if self.__is_moving:
            return
        self.__is_moving = True
        self.__starting_position = QPoint(self.pos())
        self.__moveAnimation = QPropertyAnimation(self, "pos", self)
        self.__moveAnimation.finished.connect(self.__on_finished_moving)
        self.__moveAnimation.setDuration(self.__move_time)
        self.__moveAnimation.setEasingCurve(self.__move_animation_type)
        self.__moveAnimation.setStartValue(self.__starting_position)
        self.__moveAnimation.setEndValue(QPoint(x, y))
        self.__moveAnimation.start()


    def hideLeft(self):
        """ Panel hides sliding on the left. The slide amount is equal to his width - 5px.
        """
        dest_x = self.geometry().x() - self.width() - 5
        dest_y = self.geometry().y()
        self.moveTo(dest_x, dest_y)

    def showFromLeft(self):
        """ Panel shows sliding from the left. The slide amount is equal to his width + 5px.
        """
        dest_x = self.geometry().x() + self.width() + 5
        dest_y = self.geometry().y()
        self.moveTo(dest_x, dest_y)

    def hideRight(self):
        """ Panel hides sliding on the right. The slide amount is equal to his width - 5px.
        """
        dest_x = self.geometry().x() + self.width() + 5
        dest_y = self.geometry().y()
        self.moveTo(dest_x, dest_y)

    def showFromRight(self):
        """ Panel shows sliding from the right. The slide amount is equal to his width + 5px.
        """
        dest_x = self.geometry().x() - self.width() - 5
        dest_y = self.geometry().y()
        self.moveTo(dest_x, dest_y)

    def hideTop(self):
        """ Panel hides sliding on the top. The slide amount is equal to his height - 5px.
        """
        dest_x = self.geometry().x()
        dest_y = self.geometry().y() - self.height() - 5
        self.moveTo(dest_x, dest_y)

    def showFromTop(self):
        """ Panel shows sliding from the top. The slide amount is equal to his height - 5px.
        """
        dest_x = self.geometry().x()
        dest_y = self.geometry().y() + self.height() - 5
        self.moveTo(dest_x, dest_y)

    def hideBottom(self):
        """ Panel hides sliding to the bottom. The slide amount is equal to his height - 5px.
        """
        dest_x = self.geometry().x()
        dest_y = self.geometry().y() + self.height() + 5
        self.moveTo(dest_x, dest_y)

    def showFromBottom(self):
        """ Panel hides sliding from the bottom. The slide amount is equal to his height - 5px.
        """
        dest_x = self.geometry().x()
        dest_y = self.geometry().y() - self.height() - 5
        self.moveTo(dest_x, dest_y)

    def returnToOriginalPoint(self):
        """ Panel returns in its original position. The original position is stored when calling moveTo() method.
        """
        if self.__is_moving:
            return
        self.__is_moving = True
        self.__moveAnimation = QPropertyAnimation(self, "pos", self)
        self.__moveAnimation.finished.connect(self.__on_finished_moving)
        self.__moveAnimation.setDuration(self.__move_time)
        self.__moveAnimation.setEasingCurve(self.__move_animation_type)
        self.__moveAnimation.setStartValue(QPoint(self.pos().x(), self.pos().y()))
        self.__moveAnimation.setEndValue(self.__starting_position)
        self.__moveAnimation.start()

    #FUNZIONI PER RIDIMENSIONAMENTO
    def setResizeAnimationType(self, animation_type):
        """ Sets move animation type.
        @param animation_type: animation type
        @type animation_type: QtEasingCurve
        """
        self.__resize_animation_type = animation_type

    def resizeTo(self, width, height):
        """ Resize itself to a given size with the given animation in the given duration.
        @param width: New width
        @type width: int
        @param height: New height
        @type height: int
        """
        if self.__is_resizing:
            return
        self.__is_resizing = True
        self.__original_size = self.geometry()
        self.__resizeAnimation = QPropertyAnimation(self, "geometry", self)
        self.__resizeAnimation.finished.connect(self.__on_finished_resizing)
        self.__resizeAnimation.setDuration(self.__resize_time)
        self.__resizeAnimation.setEasingCurve(self.__resize_animation_type)
        self.__resizeAnimation.setStartValue(self.__original_size)
        self.__resizeAnimation.setEndValue(QRect(self.pos().x(), self.pos().y(), width, height))
        self.__resizeAnimation.start()

    def foldLeft(self):
        """ Panel hides folding to the left.
        """
        new_width = 0
        new_height = self.height()
        self.resizeTo(new_width, new_height)

    def unfoldLeft(self):
        """ Panel shows folding from the left.
        """
        new_width = self.__original_size.width()
        new_height = self.height()
        self.resizeTo(new_width, new_height)

    def foldTop(self):
        """ Panel hides folding to the top.
        """
        new_width = self.width()
        new_height = 0
        self.resizeTo(new_width, new_height)

    def unfoldTop(self):
        """ Panel shows folding from the top.
        """
        new_width = self.width()
        new_height = self.__original_size.height()
        self.resizeTo(new_width, new_height)

    #FUNZIONI PER PIXMAP & MASCHERA
    def setPixmapFile(self, image_file):
        self.__pmap = image_file
        self.__pmap.scaled(self.size())
        #NB: Il pixmap deve essere BIANCO e NERO. Con heuristicMask il primo pixel in alto a sinistra (0,0) viene
        #usato per decidere il colore trasparente, tutto il resto è visibile.

    def getPixmapFile(self):
        return self.__pmap

    pixmapFile = QtCore.pyqtProperty("QPixmap", getPixmapFile, setPixmapFile)


    def applyMask(self, bool):
        self.__show_mask_preview = bool
        if bool:
            self.setMask(QBitmap(self.__pmap.createHeuristicMask().scaled(self.size())))
        else:
            self.setMask(QBitmap())

    def getMask(self):
        return self.__show_mask_preview

    appliedMask = QtCore.pyqtProperty("bool", fget=getMask, fset=applyMask)

    def __on_finished_moving(self):
        self.__is_moving = False

    def __on_finished_resizing(self):
        self.__is_resizing = False

    def __onResize(self, event):
        self.__pmap.scaled(self.size())
        if self.__show_mask_preview:
            self.setMask(QBitmap(self.__pmap.createHeuristicMask().scaled(self.size())))

        #FUNZIONI PER SHADOW

    def getShadow(self):
        return self._shadow_visible

    def setShadow(self, bool):
        self.setGraphicsEffect(self.__shadow_effect)
        self._shadow_visible = bool
        self.__shadow_effect.setEnabled(bool)

    shadow = QtCore.pyqtProperty("bool", fget=getShadow, fset=setShadow)

    def setShadowXOffset(self, value):
        """ Sets shadow offset on X.
        @param value: offset
        @type value: float
        """
        self.__shadow_Xoffset = value
        self.__shadow_effect.setXOffset(self.__shadow_Xoffset)

    def getShadowXOffset(self):
        return self.__shadow_Xoffset

    shadowXOffset = QtCore.pyqtProperty("double", getShadowXOffset, setShadowXOffset)

    def setShadowYOffset(self, value):
        """ Sets shadow offset on Y.
        @param value: offset
        @type value: float
        """
        self.__shadow_Yoffset = value
        self.__shadow_effect.setYOffset(self.__shadow_Yoffset)

    def getShadowYOffset(self):
        return self.__shadow_Yoffset

    shadowYOffset = QtCore.pyqtProperty("double", getShadowYOffset, setShadowYOffset)


    def setShadowBlur(self, value):
        """ Sets blurred effect on item's shadow.
        @param value: coefficient
        @type value: float
        """
        self.__shadow_blur_radius = value
        self.__shadow_effect.setBlurRadius(self.__shadow_blur_radius)

    def getShadowBlur(self):
        return self.__shadow_blur_radius


    shadowBlur = QtCore.pyqtProperty("double", getShadowBlur, setShadowBlur)


    def setShadowColor(self, color):
        """ Sets shadow's color.
        @param color: value
        @type color: color
        """
        self.__shadow_color = color
        self.__shadow_effect.setColor(self.__shadow_color)

    def getShadowColor(self):
        return self.__shadow_color
コード例 #27
0
ファイル: pyChezzMin.py プロジェクト: zhollosy/pyChezz
class myGraphicsSvgItem(QtSvg.QGraphicsSvgItem):
    def __init__(self,
                 parent=None,
                 limitRect=QtCore.QRectF(0, 0, 1000, 1000),
                 cursorShape=QtCore.Qt.OpenHandCursor,
                 name=None,
                 *args,
                 **kwargs):
        super(myGraphicsSvgItem, self).__init__(parent, *args, **kwargs)
        self.anim_slide = None
        self.anim_tilt = None
        self.anim_fade = None
        self.center = self.boundingRect().center()
        self.cursorShape = cursorShape
        self.limitRect = QtCore.QRectF(limitRect)
        self.table_widget = self.getWidget('interactiveTable')
        self.fields_widget = self.getWidget('grdFields')
        # self.fields_widget = self.parentWidget()
        self.setCursor(cursorShape)
        self.setObjectName(name)
        self.updateCenter()

    def itemChange(self, change, value):
        if change == QtGui.QGraphicsItem.ItemPositionChange:
            new_value = value.toPointF()

            if not self.limitRect.contains(new_value):
                new_value.setX(
                    min(self.limitRect.right(),
                        max(new_value.x(), self.limitRect.left())))
                new_value.setY(
                    min(self.limitRect.bottom(),
                        max(new_value.y(), self.limitRect.top())))
                # print new_value, '  <---- NOT Contains'
                value = QtCore.QVariant(new_value)
            return QtGui.QGraphicsItem.itemChange(self, change, value)
        if change == QtGui.QGraphicsItem.ItemPositionHasChanged:
            pass

        return QtGui.QGraphicsItem.itemChange(self, change, value)

    def mousePressEvent(self, event):
        print "-----------------"
        self.setCursor(QtCore.Qt.ClosedHandCursor)
        pos, item = self.getItemAtMousePos_byMouseEvent(event)
        print "Press", pos, item.objectName() if item else None
        self.doAanim_tilt(False)
        super(myGraphicsSvgItem, self).mousePressEvent(event)

    def mouseReleaseEvent(self, event):
        print "-----"
        self.setCursor(self.cursorShape)
        pos, item = self.getItemAtMousePos_byMouseEvent(event)
        print "Release", pos, item.objectName() if item else None

        self.doAnim_slideTiltFade(item, doTilting=True)
        # self.anim_do_slide(item)
        # self.anim_do_tilt(False)
        super(myGraphicsSvgItem, self).mouseReleaseEvent(event)

    def getWidget(self, name):
        wdg = pyChezzApp.findChildren(
            (QtGui.QWidget, QtGui.QFrame, QtGui.QSpacerItem),
            QtCore.QString(name))[0]
        return wdg

    def getItemAtMousePos_byMouseEvent(self, event):
        posGlobal = self.table_widget.mapToGlobal(self.pos().toPoint())
        posLocal = self.fields_widget.mapFromGlobal(posGlobal)
        widget = self.fields_widget.childAt(posLocal)
        return posLocal, widget

    def getWidgetAtTablePos(self, pos):
        posGlobal = self.table_widget.mapToGlobal(pos)
        posLocal = self.fields_widget.mapFromGlobal(posGlobal)
        widget = self.fields_widget.childAt(posLocal)
        return widget

    def move_to_pos(self, pos, duration=200):
        wdg = self.getWidgetAtTablePos(pos.toPoint())
        self.doAnim_slide(wdg, duration)

    def doAnim_slideTiltFade(self,
                             to_widget,
                             doTilting=False,
                             isBecomeVisible=False,
                             duration=400):
        self.anim_group = QtCore.QParallelAnimationGroup()
        self.doAnim_slide(to_widget, duration=duration, doStart=False)
        self.anim_group.addAnimation(self.anim_slide)
        if doTilting:
            isTilted = abs(self.rotation()) > 1.0
            self.doAanim_tilt(isTilted, duration=duration, doStart=False)
            self.anim_group.addAnimation(self.anim_tilt)
        if isBecomeVisible:
            self.doAanim_fade(isBecomeVisible,
                              duration=duration,
                              doStart=False)
            self.anim_group.addAnimation(self.anim_fade)
        self.anim_group.start()

    def doAnim_slide(self, to_widget, duration=200, doStart=True):
        if to_widget is None:
            self.anim_slide = None
            return
        posGlobal = self.fields_widget.mapToGlobal(
            to_widget.geometry().center())
        posLocal = self.table_widget.mapFromGlobal(posGlobal)
        self.anim_slide = QPropertyAnimation(self, "pos")
        self.anim_slide.setDuration(duration)
        self.anim_slide.setStartValue(self.pos())
        self.anim_slide.setEndValue(posLocal)
        self.anim_slide.setEasingCurve(QtCore.QEasingCurve.InOutQuint)
        if doStart:
            self.anim_slide.start()
        return self.anim_slide

    def doAanim_tilt(self, isTilted, duration=400, doStart=True):
        self.anim_tilt = QPropertyAnimation(self, "rotation")
        self.anim_tilt.setDuration(duration)
        self.anim_tilt.setStartValue(-30 if isTilted else 0)
        self.anim_tilt.setEndValue(0 if isTilted else -30)
        self.anim_tilt.setEasingCurve(QtCore.QEasingCurve.OutBack)
        if doStart:
            self.anim_tilt.start()
        return self.anim_tilt

    def doAanim_fade(self, isBecomeVisible, duration=400, doStart=True):
        self.anim_fade = QPropertyAnimation(self, "opacity")
        self.anim_fade.setDuration(duration)
        self.anim_fade.setStartValue(0.0 if isBecomeVisible else 1.0)
        self.anim_fade.setEndValue(1.0 if isBecomeVisible else 0.0)
        self.anim_fade.setEasingCurve(QtCore.QEasingCurve.InCirc)
        if doStart:
            self.anim_fade.start()
        return self.anim_fade

    def updateCenter(self):
        self.center = self.boundingRect().center()
        self.setTransformOriginPoint(self.center)
        print '________\n' \
              'Name: {},\n' \
              'Pos: {},\n' \
              'Bound: {},\n' \
              'Center: {}\n' \
              'Origin: {}'.format(self.objectName(),
                                  self.pos(),
                                  self.boundingRect(),
                                  self.boundingRect().center(),
                                  self.transformOriginPoint())
コード例 #28
0
class CImprovedStackWidget(QStackedWidget):
    __SLIDE_TYPE = Enum("TOP2BOTTOM",
                        "BOTTOM2TOP",
                        "RIGHT2LEFT",
                        "LEFT2RIGHT",
                        "AUTOMATIC")

    animationOk = QtCore.pyqtSignal()

    def __init__(self, parent=None):
        """ Inizializza il componente"""
        QStackedWidget.__init__(self, parent)
        self.__m_vertical=False
        self.__m_speed=500
        self.__m_animationtype = QEasingCurve.OutQuint #QEasingCurve.OutBack
        self.__m_now=0
        self.__m_next=0
        self.__m_pnow=QPoint(0,0)
        self.__m_active = False
        self.__direction = self.__SLIDE_TYPE.RIGHT2LEFT
        self.__animgroup = QtCore.QParallelAnimationGroup()
        self.__animgroup.finished.connect(self.__animationDone)
        self.__animnext = QPropertyAnimation(None, "pos")
        self.__animnow = QPropertyAnimation(None, "pos")
        #self.setMinimumSize(300, 300)
        self.setStyleSheet("background-color: rgb(184, 184, 184);")

    def setVerticalMode(self, bool):
        """ Setta la modalità slide in verticale
        @param bool: Impostata a true o false, determina se lo slide è verticale o orizzontale.
        @type bool: Boolean
        """
        self.__m_vertical = bool

    def setSpeed(self, speed_value):
        """ Setta la velocità di slide tra una pagine e l'altra.
        @param speed_value: Velocità in msec.
        @type speed_value: int
        """
        self.__m_speed = speed_value

    def getSpeed(self):
        return self.__m_speed

    slidingSpeed = QtCore.pyqtProperty("int", getSpeed, setSpeed)

    def setAnimation(self, animation_type):
        """ Setta il la tipologia di animazione da utilizzare per gli slide.
        @param animation_type: Tipo di animazione.
        @type animation_type: QEasingCurve
        """
        self.__m_animationtype = animation_type

    def slideNext(self):
        """Sposta alla finestra successiva"""
        now = self.currentIndex()
        self.slideIdx(now + 1)

    def slidePrev(self):
        """Sposta alla finestra precedente"""
        now = self.currentIndex()
        self.slideIdx(now - 1)

    def slideIdx(self, idx):
        """ Sposta la visualizzazione alla finestra indicata.
        @param idx: Indice finestra da visualizzare
        @type idx: int
        """

        if(idx > self.count()-1):
            if(self.__m_vertical):
                self.__direction = self.__SLIDE_TYPE.TOP2BOTTOM
            else:
                self.__direction = self.__SLIDE_TYPE.RIGHT2LEFT
            idx = (idx) % self.count()

        elif (idx<0):
            if(self.__m_vertical):
                self.__direction = self.__SLIDE_TYPE.BOTTOM2TOP
            else:
                self.__direction = self.__SLIDE_TYPE.LEFT2RIGHT
            idx = (idx + self.count()) % self.count()

        self.slideInWgt(self.widget(idx))

    def slideInWgt(self, widget):
        if self.__m_active:
            return    #se l'animazione e' attiva, nn faccio nulla.
        else:
            self.__m_active = True
        now = self.currentIndex()
        next = self.indexOf(widget)


        if(now==next):
            self.__m_active = False
            return
        elif(now < next):
            if(self.__m_vertical):
                dhint = self.__SLIDE_TYPE.TOP2BOTTOM
            else:
                dhint = self.__SLIDE_TYPE.RIGHT2LEFT

        else:
            if(self.__m_vertical):
                dhint = self.__SLIDE_TYPE.BOTTOM2TOP
            else:
                dhint = self.__SLIDE_TYPE.LEFT2RIGHT

        #=======================================================================
        # if(self.__direction == self.AUTOMATIC):
        #    self.__direction = dhint
        #=======================================================================
        self.__direction = dhint
        offsetX = self.frameRect().width()
        offsetY = self.frameRect().height()

        self.widget(next).setGeometry ( 0,  0, offsetX, offsetY )

        if (self.__direction==self.__SLIDE_TYPE.BOTTOM2TOP):
            offsetX=0
            offsetY=-offsetY
        elif (self.__direction==self.__SLIDE_TYPE.TOP2BOTTOM):
            offsetX=0
        elif (self.__direction==self.__SLIDE_TYPE.RIGHT2LEFT):
            offsetX=-offsetX
            offsetY=0
        elif (self.__direction==self.__SLIDE_TYPE.LEFT2RIGHT):
            offsetY=0


        pnext = self.widget(next).pos()
        pnow  = self.widget(now).pos()
        self.__m_pnow = pnow

        self.widget(next).move(pnext.x() - offsetX, pnext.y() - offsetY)
        self.widget(next).show()

        self.__animnow.setTargetObject(self.widget(now))
        self.__animnow.setDuration(self.__m_speed)
        self.__animnow.setEasingCurve(self.__m_animationtype)
        self.__animnow.setStartValue(QPoint(pnow.x(), pnow.y()))
        self.__animnow.setEndValue(QPoint(offsetX+pnow.x(), offsetY+pnow.y()))

        self.__animnext.setTargetObject(self.widget(next))
        self.__animnext.setDuration(self.__m_speed)
        self.__animnext.setEasingCurve(self.__m_animationtype)
        self.__animnext.setStartValue(QPoint(-offsetX+pnext.x(), offsetY+pnext.y()))
        self.__animnext.setEndValue(QPoint(pnext.x(), pnext.y()))

        self.__animgroup.addAnimation(self.__animnow)
        self.__animgroup.addAnimation(self.__animnext)

        self.__m_next=next
        self.__m_now=now
        self.__m_active=True
        self.__animgroup.start()

    def __animationDone(self):
        self.setCurrentIndex(self.__m_next)

        self.widget(self.__m_now).hide()

        self.widget(self.__m_now).move(self.__m_pnow)
        self.__m_active=False

        self.animationOk.emit()
コード例 #29
0
class CImprovedLabel(QLabel):
    def __init__(self, parent=None, caption=None):
        QLabel.__init__(self, parent)
        self.setText(self.accessibleName())
        self.setFont(QtGui.QFont("Arial", 12))
        self.__separator = chr(004)  #Used as separator while scrolling text

        #BLINK
        self.__blink_timer = QTimer(parent)
        self.__blink_timer.timeout.connect(self.__on_blink_timer)
        self.__blink_timer_interval = 1000

        #FADING
        self.__opacity_effect = QGraphicsOpacityEffect()
        self.__fading_timer = QTimer(parent)
        self.__fading_timer.timeout.connect(self.__on_fading_timer)
        self.__FADE_TYPE = Enum("IN", "OUT")
        self.__fade_time = 20
        self.__opacity = 1.0
        self.__opacity_fading_coefficient = 0.02
        self.__selected_fade_type = self.__FADE_TYPE.IN

        #SCROLLING
        self.__scrolling_timer = QTimer(parent)
        self.__scrolling_timer.timeout.connect(self.__on_scrolling_timer)
        self.__scroll_time = 1000
        self.__original_text = ""

        #MOVE
        self.__move_animation_type = QEasingCurve.Linear
        self.__move_time = 350

    ## FUNZIONI PER BLINK
    def __on_blink_timer(self):
        self.setVisible(not (self.isVisible()))

    def setBlinking(self, blink):
        """ Sets if the label have to blink or not.
        @param blink: blinking or not
        @type blink: bool
        """
        if blink:
            self.__blink_timer.setInterval(self.__blink_timer_interval)
            self.__blink_timer.start()
        else:
            self.__blink_timer.stop()
            self.setVisible(True)

    def setBlinkInterval(self, value):
        """ Sets blink interval.
        @param value: blink interval (msec)
        @type value: int
        """
        self.__blink_timer_interval = value

    def getBlinkInterval(self):
        return self.__blink_timer_interval

    blinkInterval = QtCore.pyqtProperty("int", getBlinkInterval,
                                        setBlinkInterval)

    ##FUNZIONI PER FADING
    def fadeIn(self):
        """
         Labels fades in from completely invisible to completely visible.
        """
        self.__opacity = 0.0
        self.__selected_fade_type = self.__FADE_TYPE.IN
        self.__fading_timer.start(self.__fade_time)

    def fadeOut(self):
        """
         Labels fades out from completely visible to completely invisible.
        """
        self.__selected_fade_type = self.__FADE_TYPE.OUT
        self.__fading_timer.start(self.__fade_time)

    def setFadeTime(self, value):
        """ Sets fading time. Everytime interval is reached, alpha is increased (or decreased) by __opacity_fading_coefficient.
        @param value: fade time (msec)
        @type value: int
        """
        self.__fade_time = value

    def getFadeTime(self):
        return self.__fade_time

    fadeInterval = QtCore.pyqtProperty("int", getFadeTime, setFadeTime)

    def setFadeCoefficient(self, value):
        """ Sets fading coefficient. Alpha is increased (or decreased) by this value.
        @param value: coefficient (min 0.0 - max 1.0)
        @type value: float
        """
        self.__opacity_fading_coefficient = value

    def getFadeCoefficient(self):
        return self.__opacity_fading_coefficient

    fadeCoefficient = QtCore.pyqtProperty("double", getFadeCoefficient,
                                          setFadeCoefficient)

    def __on_fading_timer(self):
        if self.__selected_fade_type == self.__FADE_TYPE.OUT:
            if self.__opacity > 0:
                self.__opacity -= self.__opacity_fading_coefficient
                self.__opacity_effect.setOpacity(self.__opacity)
                self.setGraphicsEffect(self.__opacity_effect)
            else:
                self.__fading_timer.stop()

        if self.__selected_fade_type == self.__FADE_TYPE.IN:
            if self.__opacity <= 1.0:
                self.__opacity += self.__opacity_fading_coefficient
                self.__opacity_effect.setOpacity(self.__opacity)
                self.setGraphicsEffect(self.__opacity_effect)
            else:
                self.__fading_timer.stop()

    #FUNZIONI PER SCROLLING
    def __move_text_left(self):
        if self.__separator not in self.text():
            self.setText(self.text() + "    " + self.__separator + "    ")
        left = str(self.text())[:1]
        right = str(self.text())[1:]
        self.setText(right + left)

    def __on_scrolling_timer(self):
        self.__move_text_left()

    def scrollingText(self, scroll):
        """ Sets if the label have to scroll or not.
        @param scroll: scrolling right to left or not
        @type scroll: bool
        """
        self.__scrolling_timer.setInterval(self.__scroll_time)
        if scroll:
            self.__original_text = self.text()
            self.__scrolling_timer.start()
        else:
            self.__scrolling_timer.stop()
            self.setText(self.__original_text)

    def setScrollingTime(self, value):
        """ Sets scrolling time. Everytime interval is reached, string is scrolled to left by one char.
        @param value: scrolling time (msec)
        @type value: int
        """
        self.__scroll_time = value

    ## FUNZIONI PER SPOSTAMENTO VERSO PUNTO (ANIMATO)
    def setMoveAnimationType(self, animation_type):
        """ Sets move animation type.
        @param animation_type: animation type
        @type animation_type: QtEasingCurve
        """
        self.__move_animation_type = animation_type

    def getMoveAnimationType(self):
        return self.__move_animation_type

    #asd = QtCore.pyqtProperty("QEasingCurve", getMoveAnimationType, setMoveAnimationType)
    #sembra nn essere supportato per ora (06/05/2013)

    def setMoveTime(self, value):
        """ Sets animation moving time.
        @param value: animation time (duration) (msec)
        @type value: int
        """
        self.__move_time = value

    def moveTo(self, x, y):
        """ Move itself to a given point with the given animation in the given duration.
        @param x: X point coordinate
        @type x: int
        @param y: Y point coordinate
        @type y: int
        """
        self.__starting_position = QPoint(self.pos())
        self.__moveAnimation = QPropertyAnimation(self, "pos", self)
        self.__moveAnimation.setDuration(self.__move_time)
        self.__moveAnimation.setEasingCurve(self.__move_animation_type)
        self.__moveAnimation.setStartValue(self.__starting_position)
        self.__moveAnimation.setEndValue(QPoint(x, y))
        self.__moveAnimation.start()

    def returnToOriginalPoint(self):
        """ Label returns to its original position. The original position is stored when calling moveTo() method.
        """
        self.__moveAnimation = QPropertyAnimation(self, "pos", self)
        self.__moveAnimation.setDuration(self.__move_time)
        self.__moveAnimation.setEasingCurve(self.__move_animation_type)
        self.__moveAnimation.setStartValue(
            QPoint(self.pos().x(),
                   self.pos().y()))
        self.__moveAnimation.setEndValue(self.__starting_position)
        self.__moveAnimation.start()

    def mousePressEvent(self, event):
        self.clicked.emit()
コード例 #30
0
class CImprovedButton(QToolButton):
    def __init__(self, parent=None):
        QToolButton.__init__(self, parent)

        #TESTO ALTERNATIVO
        #Spesso se il pulsante ha icona troppo grossa e quando per ragioni di spazio o altro non si può spostare
        #o ridimensionare il pulsante stesso, la label ha posizioni assurde e schifose. Aggiungerne una "+ controllabile"
        #è l'unico modo..
        self.__fixed_label = QLabel("alternative label", self)
        self.__fixed_label.move(0, self.geometry().height() - 35)
        self.__fixed_label.resize(self.geometry().width(),
                                  self.__fixed_label.geometry().height())
        self.__fixed_label.setAlignment(QtCore.Qt.AlignHCenter
                                        | QtCore.Qt.AlignVCenter)
        self.__font = QtGui.QFont("Arial", 10)
        self.__fixed_label.setFont(self.__font)
        self.__fixed_label.show()

        #INDICATORE STILE iOS
        self.__indicator = QLabel("0", self)
        self.__indicator.setStyleSheet(
            "border-image: url(':/images/backgrounds/indicator.png'); padding-right:1px; color: white;"
        )
        self.__indicator.geometry().setWidth(25)
        self.__indicator.geometry().setHeight(20)
        self.__indicator.setAlignment(QtCore.Qt.AlignHCenter
                                      | QtCore.Qt.AlignVCenter)
        self.__indicator.setVisible(False)
        self.setIndicatorPos(QPoint(self.width() - self.__indicator.width(),
                                    0))  #default top-right corner
        #Quando il pulsante viene ridimensionato (designer o meno) devo anche sistemare la label di conseguenza
        self.resizeEvent = self.__onResize
        self.__indicator.resizeEvent = self.__on_indicator_Resize

        self.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)

        self.clicked.connect(self.stopAllAnimations)

        #BLINK
        self.__blink_timer = QTimer(parent)
        self.__blink_timer.timeout.connect(self.__on_blink_timer)
        self.__blink_timer_interval = 1000

        #FADING
        self.__opacity_effect = QGraphicsOpacityEffect()
        self.__fading_timer = QTimer(parent)
        self.__fading_timer.timeout.connect(self.__on_fading_timer)
        self.__FADE_TYPE = Enum("IN", "OUT")
        self.__fade_time = 20
        self.__opacity = 1.0
        self.__opacity_fading_coefficient = 0.02
        self.__selected_fade_type = self.__FADE_TYPE.IN

        # ANIMAZIONI GROW
        self.__animationGrow = QPropertyAnimation(self, "iconSize", self)
        self.__animationGrow.setDuration(1000)
        self.__animationGrow.setEasingCurve(QEasingCurve.Linear)
        self.__animationGrow.finished.connect(self.__on_growed)

        self.__animationShrink = QPropertyAnimation(self, "iconSize", self)
        self.__animationShrink.setDuration(1000)
        self.__animationShrink.setEasingCurve(QEasingCurve.Linear)
        self.__animationShrink.finished.connect(self.__on_shrinked)

        self.__defaultIconDimension = 60
        self.__iconGrowsBy = 40
        self.__growing = False

        # ANIMAZIONI BOUNCE
        self.__animationUp = QPropertyAnimation(self, "pos", self)
        self.__animationUp.setDuration(200)
        self.__animationUp.setEasingCurve(QEasingCurve.Linear)
        self.__animationUp.finished.connect(self.__on_top_reached)

        self.__animationBounce = QPropertyAnimation(self, "pos", self)
        self.__animationBounce.setDuration(1000)
        self.__animationBounce.setEasingCurve(QEasingCurve.OutBounce)
        self.__animationBounce.finished.connect(self.__on_bounce_finished)

        self.__bouncing = False
        self.__startPos = QPoint(self.pos().x(), self.pos().y())

        #PIXMAP & MASCHERA
        self.__pmap = QPixmap(self.size())
        self.__pmap_fname = ""
        self.__show_mask_preview = False

    def setDefaultIconSize(self, value):
        """ Sets default icon size when growing stops.
        @param value: size (both width and height)
        @type value: int
        """
        self.__defaultIconDimension = value

    def getDefaultIconSize(self):
        return self.__defaultIconDimension

    defaultIconSize = QtCore.pyqtProperty("int", getDefaultIconSize,
                                          setDefaultIconSize)

    def setFixetTextVisibility(self, bool):
        """ Sets if fixed text is visible or not.
        @param bool: visible or not
        @type bool: bool
        """
        self.__fixed_label.setVisible(bool)

    def getFixetTextVisibility(self):
        return self.__fixed_label.isVisible()

    fixetTextVisibility = QtCore.pyqtProperty("bool",
                                              fget=getFixetTextVisibility,
                                              fset=setFixetTextVisibility)

    def setFixedText(self, txt):
        """ Sets text on the button.
        @param txt: text
        @type txt: string
        """
        self.__fixed_label.setText(txt)

    def getFixedText(self):
        return self.__fixed_label.text()

    fixedText = QtCore.pyqtProperty("QString", getFixedText, setFixedText)

    def setFixedTextPos(self, qpoint):
        """ Sets text position in the button.
        @param qpoint: Position RELATIVE. 0,0 is top left corner of the button.
        @type qpoint: QPoint
        """
        self.__fixed_label.move(qpoint)

    def getFixedTextPos(self):
        return self.__fixed_label.pos()

    fixedTextPos = QtCore.pyqtProperty("QPoint", getFixedTextPos,
                                       setFixedTextPos)

    def setFixedTextFont(self, font):
        """ Sets text font.
        @param font: Font for fixed text.
        @type font: QFont
        """
        self.__font = font
        self.__fixed_label.setFont(self.__font)

    def getFixedTextFont(self):
        return self.__font

    fixedTextFont = QtCore.pyqtProperty("QFont", getFixedTextFont,
                                        setFixedTextFont)

    #FUNZIONI INDICATORE
    def setIndicatorVisibility(self, bool):
        """ Sets if indicator is visible or not.
        @param bool: visible or not
        @type bool: bool
        """
        self.__indicator.setVisible(bool)

    def getIndicatorVisibility(self):
        return self.__indicator.isVisible()

    indicatorVisibility = QtCore.pyqtProperty("bool",
                                              fget=getIndicatorVisibility,
                                              fset=setIndicatorVisibility)

    def setIndicatorPos(self, qpoint):
        """ Sets indicator position in the button.
        @param qpoint: Position RELATIVE. 0,0 is top left corner of the button.
        @type qpoint: QPoint
        """
        self.__indicator.move(qpoint)

    def getIndicatorPos(self):
        return self.__indicator.pos()

    indicatorPos = QtCore.pyqtProperty("QPoint", getIndicatorPos,
                                       setIndicatorPos)

    def setIndicatorSize(self, size):
        """ Sets indicator size.
        @param size: Size
        @type size: QSize
        """
        self.__indicator.resize(size)

    def getIndicatorSize(self):
        return self.__indicator.size()

    indicatorSize = QtCore.pyqtProperty("QSize", getIndicatorSize,
                                        setIndicatorSize)

    def setIndicatorFont(self, font):
        """ Sets indicator text font.
        @param font: Font for indicator text.
        @type font: QFont
        """
        self.__indicator.setFont(font)

    def getIndicatorFont(self):
        return self.__indicator.font()

    indicatorFont = QtCore.pyqtProperty("QFont", getIndicatorFont,
                                        setIndicatorFont)

    ## FUNZIONI PER BLINK
    def __on_blink_timer(self):
        self.setVisible(not (self.isVisible()))

    def setBlinking(self, blink):
        """ Sets if the button have to blink or not.
        @param blink: blinking or not
        @type blink: bool
        """
        if blink:
            self.__blink_timer.setInterval(self.__blink_timer_interval)
            self.__blink_timer.start()
        else:
            self.__blink_timer.stop()
            self.setVisible(True)

    def setBlinkInterval(self, value):
        """ Sets blink interval.
        @param blink: blink interval (msec)
        @type blink: int
        """
        self.__blink_timer_interval = value

    def getBlinkInterval(self):
        return self.__blink_timer_interval

    blinkInterval = QtCore.pyqtProperty("int", getBlinkInterval,
                                        setBlinkInterval)

    ##FUNZIONI PER FADING
    def fadeIn(self):
        """
         Button fades in from completely invisible to completely visible.
        """
        self.__opacity = 0.0
        self.__selected_fade_type = self.__FADE_TYPE.IN
        self.__fading_timer.start(self.__fade_time)

    def fadeOut(self):
        """
         Button fades out from completely visible to completely invisible.
        """
        self.__selected_fade_type = self.__FADE_TYPE.OUT
        self.__fading_timer.start(self.__fade_time)

    def setFadeTime(self, value):
        """ Sets fading time. Everytime interval is reached, alpha is increased (or decreased) by __opacity_fading_coefficient.
        @param value: fade time (msec)
        @type value: int
        """
        self.__fade_time = value

    def getFadeTime(self):
        return self.__fade_time

    fadeInterval = QtCore.pyqtProperty("int", getFadeTime, setFadeTime)

    def setFadeCoefficient(self, value):
        """ Sets fading coefficient. Alpha is increased (or decreased) by this value.
        @param value: coefficient (min 0.0 - max 1.0)
        @type value: float
        """
        self.__opacity_fading_coefficient = value

    def getFadeCoefficient(self):
        return self.__opacity_fading_coefficient

    fadeCoefficient = QtCore.pyqtProperty("double", getFadeCoefficient,
                                          setFadeCoefficient)

    def __on_fading_timer(self):
        if self.__selected_fade_type == self.__FADE_TYPE.OUT:
            if self.__opacity > 0:
                self.__opacity -= self.__opacity_fading_coefficient
                self.__opacity_effect.setOpacity(self.__opacity)
                self.setGraphicsEffect(self.__opacity_effect)
            else:
                self.__fading_timer.stop()

        if self.__selected_fade_type == self.__FADE_TYPE.IN:
            if self.__opacity <= 1.0:
                self.__opacity += self.__opacity_fading_coefficient
                self.__opacity_effect.setOpacity(self.__opacity)
                self.setGraphicsEffect(self.__opacity_effect)
            else:
                self.__fading_timer.stop()

    # FUNZIONI PER GROW\SHRINK
    def __on_growed(self):
        self.__animationShrink.setStartValue(
            QSize(self.iconSize().width(),
                  self.iconSize().height()))
        self.__animationShrink.setEndValue(
            QSize(self.iconSize().width() - self.__iconGrowsBy,
                  self.iconSize().height() - self.__iconGrowsBy))
        self.__animationShrink.start()

    def __on_shrinked(self):
        self.__animationGrow.setStartValue(
            QSize(self.iconSize().width(),
                  self.iconSize().height()))
        self.__animationGrow.setEndValue(
            QSize(self.iconSize().width() + self.__iconGrowsBy,
                  self.iconSize().height() + self.__iconGrowsBy))
        self.__animationGrow.start()

    def startGrow(self):
        """
         Button ICON starts to grow and shrink to standard value when maximum size (configured) is reached
        """
        if self.__growing:
            return
        self.__animationGrow.setStartValue(
            QSize(self.iconSize().width(),
                  self.iconSize().height()))
        self.__animationGrow.setEndValue(
            QSize(self.iconSize().width() + self.__iconGrowsBy,
                  self.iconSize().height() + self.__iconGrowsBy))
        self.__animationGrow.start()
        self.__growing = True

    def stopGrow(self):
        if self.__animationGrow.startValue().toSize() != QSize(
                0,
                0) and self.__animationShrink.startValue().toSize() != QPoint(
                    0, 0):
            self.__animationGrow.stop()
            self.__animationShrink.stop()
            self.setIconSize(
                QSize(self.__defaultIconDimension,
                      self.__defaultIconDimension))
            self.__growing = False

    #FUNZIONI PER BOUNCE
    def startBounce(self):
        """
         Button starts to bounce requiring attention.
        """
        if self.__bouncing:
            return
        self.__startPos = QPoint(self.pos().x(), self.pos().y())
        self.__animationUp.setStartValue(
            QPoint(self.__startPos.x(), self.__startPos.y()))
        self.__animationUp.setEndValue(
            QPoint(self.__startPos.x(),
                   self.__startPos.y() - self.geometry().height()))
        self.__animationUp.start()
        self.__bouncing = True

    def stopBounce(self):
        if self.__animationUp.startValue().toPoint() != QPoint(
                0,
                0) and self.__animationBounce.startValue().toPoint() != QPoint(
                    0, 0):
            self.__animationBounce.stop()
            self.__animationUp.stop()
            self.setGeometry(self.__startPos.x(), self.__startPos.y(),
                             self.geometry().width(),
                             self.geometry().height())
            self.__bouncing = False

    def __on_top_reached(self):
        self.__animationBounce.setStartValue(
            QPoint(self.pos().x(),
                   self.pos().y()))
        self.__animationBounce.setEndValue(
            QPoint(self.__startPos.x(), self.__startPos.y()))
        self.__animationBounce.start()

    def __on_bounce_finished(self):
        self.__animationUp.start()

    def stopAllAnimations(self):
        self.stopBounce()
        self.stopGrow()

    #FUNZIONI PER PIXMAP & MASCHERA
    def setPixmapFile(self, image_file):
        self.__pmap = image_file
        self.__pmap.scaled(self.size())
        #NB: Il pixmap deve essere BIANCO e NERO. Con heuristicMask il primo pixel in alto a sinistra (0,0) viene
        #usato per decidere il colore trasparente, tutto il resto è visibile.

    def getPixmapFile(self):
        return self.__pmap

    pixmapFile = QtCore.pyqtProperty("QPixmap", getPixmapFile, setPixmapFile)

    def applyMask(self, bool):
        self.__show_mask_preview = bool
        if bool:
            self.setMask(
                QBitmap(self.__pmap.createHeuristicMask().scaled(self.size())))
        else:
            self.setMask(QBitmap())

    def getMask(self):
        return self.__show_mask_preview

    appliedMask = QtCore.pyqtProperty("bool", fget=getMask, fset=applyMask)

    def __onResize(self, event):
        self.__fixed_label.move(0, self.geometry().height() - 35)
        self.__fixed_label.resize(self.geometry().width(),
                                  self.__fixed_label.geometry().height())
        self.setIndicatorPos(QPoint(self.width() - self.__indicator.width(),
                                    0))
        self.__pmap.scaled(self.size())
        if self.__show_mask_preview:
            self.setMask(
                QBitmap(self.__pmap.createHeuristicMask().scaled(self.size())))

    def __on_indicator_Resize(self, event):
        self.setIndicatorPos(QPoint(self.width() - self.__indicator.width(),
                                    0))
コード例 #31
0
class ScreensharingToolbox(base_class, ui_class):
    exposedPixels = 3

    def __init__(self, parent):
        super(ScreensharingToolbox, self).__init__(parent)
        with Resources.directory:
            self.setupUi()
        parent.installEventFilter(self)
        self.animation = QPropertyAnimation(self, 'pos')
        self.animation.setDuration(250)
        self.animation.setDirection(QPropertyAnimation.Forward)
        self.animation.setEasingCurve(
            QEasingCurve.Linear)  # or OutCirc with 300ms
        self.retract_timer = QTimer(self)
        self.retract_timer.setInterval(3000)
        self.retract_timer.setSingleShot(True)
        self.retract_timer.timeout.connect(self.retract)
        self.resize(self.size().expandedTo(self.toolbox_layout.minimumSize()))

    def setupUi(self):
        super(ScreensharingToolbox, self).setupUi(self)

        # fix the SVG icons, as the generated code loads them as pixmaps, losing their ability to scale -Dan
        scale_icon = QIcon()
        scale_icon.addFile(Resources.get('icons/scale.svg'),
                           mode=QIcon.Normal,
                           state=QIcon.Off)
        viewonly_icon = QIcon()
        viewonly_icon.addFile(Resources.get('icons/viewonly.svg'),
                              mode=QIcon.Normal,
                              state=QIcon.Off)
        screenshot_icon = QIcon()
        screenshot_icon.addFile(Resources.get('icons/screenshot.svg'),
                                mode=QIcon.Normal,
                                state=QIcon.Off)
        fullscreen_icon = QIcon()
        fullscreen_icon.addFile(Resources.get('icons/fullscreen.svg'),
                                mode=QIcon.Normal,
                                state=QIcon.Off)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'),
                                mode=QIcon.Normal,
                                state=QIcon.On)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'),
                                mode=QIcon.Active,
                                state=QIcon.On)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'),
                                mode=QIcon.Disabled,
                                state=QIcon.On)
        fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'),
                                mode=QIcon.Selected,
                                state=QIcon.On)
        minimize_icon = QIcon()
        minimize_icon.addFile(Resources.get('icons/minimize.svg'),
                              mode=QIcon.Normal,
                              state=QIcon.Off)
        minimize_icon.addFile(Resources.get('icons/minimize-active.svg'),
                              mode=QIcon.Active,
                              state=QIcon.Off)
        close_icon = QIcon()
        close_icon.addFile(Resources.get('icons/close.svg'),
                           mode=QIcon.Normal,
                           state=QIcon.Off)
        close_icon.addFile(Resources.get('icons/close-active.svg'),
                           mode=QIcon.Active,
                           state=QIcon.Off)

        self.scale_action.setIcon(scale_icon)
        self.viewonly_action.setIcon(viewonly_icon)
        self.screenshot_action.setIcon(screenshot_icon)
        self.fullscreen_action.setIcon(fullscreen_icon)
        self.minimize_action.setIcon(minimize_icon)
        self.close_action.setIcon(close_icon)

        self.scale_button.setIcon(scale_icon)
        self.viewonly_button.setIcon(viewonly_icon)
        self.screenshot_button.setIcon(screenshot_icon)
        self.fullscreen_button.setIcon(fullscreen_icon)
        self.minimize_button.setIcon(minimize_icon)
        self.close_button.setIcon(close_icon)

        self.scale_button.setDefaultAction(self.scale_action)
        self.viewonly_button.setDefaultAction(self.viewonly_action)
        self.screenshot_button.setDefaultAction(self.screenshot_action)
        self.fullscreen_button.setDefaultAction(self.fullscreen_action)
        self.minimize_button.setDefaultAction(self.minimize_action)
        self.close_button.setDefaultAction(self.close_action)

        self.color_depth_button.clear()
        self.color_depth_button.addItem('Default Color Depth', ServerDefault)
        self.color_depth_button.addItem('TrueColor (24 bits)', TrueColor)
        self.color_depth_button.addItem('HighColor (16 bits)', HighColor)
        self.color_depth_button.addItem('LowColor (8 bits)', LowColor)

    def eventFilter(self, watched, event):
        if watched is self.parent() and event.type() == QEvent.Resize:
            new_x = (watched.width() - self.width()) / 2
            self.move(new_x, self.y())
            self.animation.setStartValue(
                QPoint(new_x, -self.height() + self.exposedPixels))
            self.animation.setEndValue(QPoint(new_x, 0))
        return False

    def enterEvent(self, event):
        super(ScreensharingToolbox, self).enterEvent(event)
        self.retract_timer.stop()
        self.expose()

    def leaveEvent(self, event):
        super(ScreensharingToolbox, self).leaveEvent(event)
        self.retract_timer.start()

    def paintEvent(self, event):  # make the widget style aware
        option = QStyleOption()
        option.init(self)
        painter = QStylePainter(self)
        painter.drawPrimitive(QStyle.PE_Widget, option)

    def expose(self):
        if self.animation.state(
        ) == QPropertyAnimation.Running and self.animation.direction(
        ) == QPropertyAnimation.Forward:
            return
        elif self.animation.state() == QPropertyAnimation.Stopped and self.pos(
        ) == self.animation.endValue():
            return
        self.animation.setDirection(QPropertyAnimation.Forward)
        self.animation.start()

    def retract(self):
        if self.animation.state(
        ) == QPropertyAnimation.Running and self.animation.direction(
        ) == QPropertyAnimation.Backward:
            return
        elif self.animation.state() == QPropertyAnimation.Stopped and self.pos(
        ) == self.animation.startValue():
            return
        self.animation.setDirection(QPropertyAnimation.Backward)
        self.animation.start()