当前位置: 首页>>代码示例>>Python>>正文


Python QGraphicsOpacityEffect.setOpacity方法代码示例

本文整理汇总了Python中PyQt4.QtGui.QGraphicsOpacityEffect.setOpacity方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsOpacityEffect.setOpacity方法的具体用法?Python QGraphicsOpacityEffect.setOpacity怎么用?Python QGraphicsOpacityEffect.setOpacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtGui.QGraphicsOpacityEffect的用法示例。


在下文中一共展示了QGraphicsOpacityEffect.setOpacity方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SliderArea

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
class SliderArea(QFrame):

    def __init__(self, parent):
        super(SliderArea, self).__init__(parent)
        self._parent = parent
        self.setMouseTracking(True)
        self.setCursor(Qt.OpenHandCursor)
        color = "#858585"
        self.setStyleSheet("background: %s;" % color)
        self.goe = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.goe)
        self.goe.setOpacity(MINIMAP_MAX_OPACITY / 2)

        self.pressed = False
        self.__scroll_margins = None

    def paintEvent(self, event):
        """Paint over the widget to overlay its content."""
        super(SliderArea, self).paintEvent(event)

    def update_position(self):
        font_size = QFontMetrics(self._parent.font()).height()
        height = self._parent.lines_count * font_size
        self.setFixedHeight(height)
        self.setFixedWidth(self._parent.width())
        self.__scroll_margins = (height, self._parent.height() - height)

    def move_slider(self, y):
        self.move(0, y)

    def mousePressEvent(self, event):
        super(SliderArea, self).mousePressEvent(event)
        self.pressed = True
        self.setCursor(Qt.ClosedHandCursor)

    def mouseReleaseEvent(self, event):
        super(SliderArea, self).mouseReleaseEvent(event)
        self.pressed = False
        self.setCursor(Qt.OpenHandCursor)

    def mouseMoveEvent(self, event):
        super(SliderArea, self).mouseMoveEvent(event)
        if self.pressed:
            pos = self.mapToParent(event.pos())
            y = pos.y() - (self.height() / 2)
            if y < 0:
                y = 0
            if y < self.__scroll_margins[0]:
                self._parent.verticalScrollBar().setSliderPosition(
                    self._parent.verticalScrollBar().sliderPosition() - 2)
            elif y > self.__scroll_margins[1]:
                self._parent.verticalScrollBar().setSliderPosition(
                    self._parent.verticalScrollBar().sliderPosition() + 2)
            self.move(0, y)
            self._parent.scroll_area(pos, event.pos())
开发者ID:whyzhuce,项目名称:repo1,代码行数:57,代码来源:minimap.py

示例2: SliderArea

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
class SliderArea(QFrame):

    def __init__(self, minimap):
        super(SliderArea, self).__init__(minimap)
        self._minimap = minimap
        self.pressed = False
        self.setMouseTracking(True)
        self.setCursor(Qt.OpenHandCursor)
        color = resources.CUSTOM_SCHEME.get(
            'MinimapVisibleArea', resources.COLOR_SCHEME['MinimapVisibleArea'])
        if ACTIVATE_OPACITY:
            self.setStyleSheet("background: %s;" % color)
            self.goe = QGraphicsOpacityEffect()
            self.setGraphicsEffect(self.goe)
            self.goe.setOpacity(settings.MINIMAP_MAX_OPACITY / 2)
        else:
            self.setStyleSheet("background: transparent;")

    def mousePressEvent(self, event):
        super(SliderArea, self).mousePressEvent(event)
        self.pressed = True
        self.setCursor(Qt.ClosedHandCursor)

    def mouseReleaseEvent(self, event):
        super(SliderArea, self).mouseReleaseEvent(event)
        self.pressed = False
        self.setCursor(Qt.OpenHandCursor)

    def update_position(self):
        font_size = round(self._minimap.font().pointSize() / 2.5)
        lines_count = self._minimap._editor.SendScintilla(
            QsciScintilla.SCI_LINESONSCREEN)
        height = lines_count * font_size
        self.setFixedHeight(height)
        self.setFixedWidth(self._minimap.width())

    def paintEvent(self, event):
        """Paint over the widget to overlay its content."""

        if not ACTIVATE_OPACITY:
            painter = QPainter()
            painter.begin(self)
            painter.setRenderHint(QPainter.TextAntialiasing, True)
            painter.setRenderHint(QPainter.Antialiasing, True)
            painter.fillRect(event.rect(), QBrush(
                QColor(226, 0, 0, 80)))
            painter.setPen(QPen(Qt.NoPen))
            painter.end()
        super(SliderArea, self).paintEvent(event)

    def mouseMoveEvent(self, event):
        super(SliderArea, self).mouseMoveEvent(event)
        if self.pressed:
            pos = self.mapToParent(event.pos())
            self._minimap.scroll_area(pos)
开发者ID:jorgesumle,项目名称:ninja-ide,代码行数:57,代码来源:minimap.py

示例3: Minimap

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
class Minimap(QsciScintilla):

    def __init__(self, weditor):
        QsciScintilla.__init__(self, weditor)
        self._weditor = weditor
        self._indentation = self._weditor._indentation
        self.setLexer(self._weditor.lexer())
        # Configuración Scintilla
        self.setMouseTracking(True)
        self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, False)
        self.SendScintilla(QsciScintilla.SCI_HIDESELECTION, True)
        self.setFolding(QsciScintilla.NoFoldStyle, 1)
        self.setReadOnly(True)
        self.setCaretWidth(0)
        self.setStyleSheet("background: transparent; border: 0px;")
        # Opacity
        self.effect = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.effect)
        self.effect.setOpacity(0.5)
        # Deslizador
        self.slider = Slider(self)
        self.slider.hide()

    def resizeEvent(self, event):
        super(Minimap, self).resizeEvent(event)
        self.slider.setFixedWidth(self.width())
        lines_on_screen = self._weditor.SendScintilla(
            QsciScintilla.SCI_LINESONSCREEN)
        self.slider.setFixedHeight(lines_on_screen * 4)

    def update_geometry(self):
        self.setFixedHeight(self._weditor.height())
        self.setFixedWidth(self._weditor.width() * 0.13)
        x = self._weditor.width() - self.width()
        self.move(x, 0)
        self.zoomIn(-3)

    def update_code(self):
        text = self._weditor.text().replace('\t', ' ' * self._indentation)
        self.setText(text)

    def leaveEvent(self, event):
        super(Minimap, self).leaveEvent(event)
        self.slider.animation.setStartValue(0.2)
        self.slider.animation.setEndValue(0)
        self.slider.animation.start()

    def enterEvent(self, event):
        super(Minimap, self).enterEvent(event)
        if not self.slider.isVisible():
            self.slider.show()
        else:
            self.slider.animation.setStartValue(0)
            self.slider.animation.setEndValue(0.2)
            self.slider.animation.start()
开发者ID:Garjy,项目名称:edis,代码行数:57,代码来源:minimap.py

示例4: Slider

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
class Slider(QFrame):

    def __init__(self, minimap):
        QFrame.__init__(self, minimap)
        self._minimap = minimap
        self.setStyleSheet("background: gray; border-radius: 3px;")
        # Opacity
        self.effect = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.effect)
        self.effect.setOpacity(0.2)
        # Animación
        self.animation = QPropertyAnimation(self.effect, "opacity")
        self.animation.setDuration(150)
        # Cursor
        self.setCursor(Qt.OpenHandCursor)

    def mouseMoveEvent(self, event):
        super(Slider, self).mouseMoveEvent(event)
        #FIXME: funciona algo loco
        pos = self.mapToParent(event.pos())
        dy = pos.y() - (self.height() / 2)
        if dy < 0:
            dy = 0
        self.move(0, dy)
        pos.setY(pos.y() - event.pos().y())
        self._minimap._weditor.verticalScrollBar().setValue(pos.y())
        self._minimap.verticalScrollBar().setSliderPosition(
                    self._minimap.verticalScrollBar().sliderPosition() + 2)
        self._minimap.verticalScrollBar().setValue(pos.y() - event.pos().y())

    def mousePressEvent(self, event):
        super(Slider, self).mousePressEvent(event)
        self.setCursor(Qt.ClosedHandCursor)

    def mouseReleaseEvent(self, event):
        super(Slider, self).mouseReleaseEvent(event)
        self.setCursor(Qt.OpenHandCursor)
开发者ID:Garjy,项目名称:edis,代码行数:39,代码来源:minimap.py

示例5: CImprovedPanel

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
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()
#.........这里部分代码省略.........
开发者ID:Nerkyator,项目名称:pyQt_components,代码行数:103,代码来源:ImprovedPanel.py

示例6: MiniMap

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
class MiniMap(QPlainTextEdit):
    def __init__(self, parent):
        super(MiniMap, self).__init__(parent)
        self.setWordWrapMode(QTextOption.NoWrap)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setReadOnly(True)
        self.setCenterOnScroll(True)
        self.setMouseTracking(True)
        self.viewport().setCursor(Qt.PointingHandCursor)
        self.setTextInteractionFlags(Qt.NoTextInteraction)

        self._parent = parent
        self.highlighter = None
        self.lines_count = 0

        self.connect(self._parent, SIGNAL("updateRequest(const QRect&, int)"), self.update_visible_area)

        if ACTIVATE_OPACITY:
            self.goe = QGraphicsOpacityEffect()
            self.setGraphicsEffect(self.goe)
            self.goe.setOpacity(settings.MINIMAP_MIN_OPACITY)
            self.animation = QPropertyAnimation(self.goe, "opacity")

        self.slider = SliderArea(self)
        self.slider.show()

    def shutdown(self):
        self.disconnect(self._parent, SIGNAL("updateRequest(const QRect&, int)"), self.update_visible_area)

    def __calculate_max(self):
        line_height = self._parent.cursorRect().height()
        if line_height > 0:
            self.lines_count = self._parent.viewport().height() / line_height
        self.slider.update_position()
        self.update_visible_area()

    def set_code(self, source):
        self.setPlainText(source)
        self.__calculate_max()

    def adjust_to_parent(self):
        self.setFixedHeight(self._parent.height())
        self.setFixedWidth(self._parent.width() * settings.SIZE_PROPORTION)
        x = self._parent.width() - self.width()
        self.move(x, 0)
        fontsize = int(self.width() / settings.MARGIN_LINE)
        if fontsize < 1:
            fontsize = 1
        font = self.document().defaultFont()
        font.setPointSize(fontsize)
        self.setFont(font)
        self.__calculate_max()

    def update_visible_area(self):
        if not self.slider.pressed:
            line_number = self._parent.firstVisibleBlock().blockNumber()
            block = self.document().findBlockByLineNumber(line_number)
            cursor = self.textCursor()
            cursor.setPosition(block.position())
            rect = self.cursorRect(cursor)
            self.setTextCursor(cursor)
            self.slider.move_slider(rect.y())

    def enterEvent(self, event):
        if ACTIVATE_OPACITY:
            self.animation.setDuration(300)
            self.animation.setStartValue(settings.MINIMAP_MIN_OPACITY)
            self.animation.setEndValue(settings.MINIMAP_MAX_OPACITY)
            self.animation.start()

    def leaveEvent(self, event):
        if ACTIVATE_OPACITY:
            self.animation.setDuration(300)
            self.animation.setStartValue(settings.MINIMAP_MAX_OPACITY)
            self.animation.setEndValue(settings.MINIMAP_MIN_OPACITY)
            self.animation.start()

    def mousePressEvent(self, event):
        super(MiniMap, self).mousePressEvent(event)
        cursor = self.cursorForPosition(event.pos())
        self._parent.jump_to_line(cursor.blockNumber())

    def resizeEvent(self, event):
        super(MiniMap, self).resizeEvent(event)
        self.slider.update_position()

    def scroll_area(self, pos_parent, pos_slider):
        pos_parent.setY(pos_parent.y() - pos_slider.y())
        cursor = self.cursorForPosition(pos_parent)
        self._parent.verticalScrollBar().setValue(cursor.blockNumber())

    def wheelEvent(self, event):
        super(MiniMap, self).wheelEvent(event)
        self._parent.wheelEvent(event)
开发者ID:Morfyo,项目名称:JAVASCRIPT,代码行数:97,代码来源:minimap.py

示例7: SliderArea

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
class SliderArea(QFrame):
    def __init__(self, parent):
        super(SliderArea, self).__init__(parent)
        self._parent = parent
        self.setMouseTracking(True)
        self.setCursor(Qt.OpenHandCursor)
        color = resources.CUSTOM_SCHEME.get("current-line", resources.COLOR_SCHEME["current-line"])
        if ACTIVATE_OPACITY:
            self.setStyleSheet("background: %s;" % color)
            self.goe = QGraphicsOpacityEffect()
            self.setGraphicsEffect(self.goe)
            self.goe.setOpacity(settings.MINIMAP_MAX_OPACITY / 2)
        else:
            self.setStyleSheet("background: transparent;")

        self.pressed = False
        self.__scroll_margins = None

    def paintEvent(self, event):
        """Paint over the widget to overlay its content."""
        if not ACTIVATE_OPACITY:
            painter = QPainter()
            painter.begin(self)
            painter.setRenderHint(QPainter.TextAntialiasing, True)
            painter.setRenderHint(QPainter.Antialiasing, True)
            painter.fillRect(event.rect(), QBrush(QColor(255, 255, 255, 80)))
            painter.setPen(QPen(Qt.NoPen))
            painter.end()
        super(SliderArea, self).paintEvent(event)

    def update_position(self):
        font_size = QFontMetrics(self._parent.font()).height()
        height = self._parent.lines_count * font_size
        self.setFixedHeight(height)
        self.setFixedWidth(self._parent.width())
        self.__scroll_margins = (height, self._parent.height() - height)

    def move_slider(self, y):
        self.move(0, y)

    def mousePressEvent(self, event):
        super(SliderArea, self).mousePressEvent(event)
        self.pressed = True
        self.setCursor(Qt.ClosedHandCursor)

    def mouseReleaseEvent(self, event):
        super(SliderArea, self).mouseReleaseEvent(event)
        self.pressed = False
        self.setCursor(Qt.OpenHandCursor)

    def mouseMoveEvent(self, event):
        super(SliderArea, self).mouseMoveEvent(event)
        if self.pressed:
            pos = self.mapToParent(event.pos())
            y = pos.y() - (self.height() / 2)
            if y < 0:
                y = 0
            if y < self.__scroll_margins[0]:
                self._parent.verticalScrollBar().setSliderPosition(
                    self._parent.verticalScrollBar().sliderPosition() - 2
                )
            elif y > self.__scroll_margins[1]:
                self._parent.verticalScrollBar().setSliderPosition(
                    self._parent.verticalScrollBar().sliderPosition() + 2
                )
            self.move(0, y)
            self._parent.scroll_area(pos, event.pos())
开发者ID:Morfyo,项目名称:JAVASCRIPT,代码行数:69,代码来源:minimap.py

示例8: CImprovedButton

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]

#.........这里部分代码省略.........
         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()))
开发者ID:Nerkyator,项目名称:pyQt_components,代码行数:70,代码来源:ImprovedButton.py

示例9: MiniMap

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
class MiniMap(QPlainTextEdit):

    def __init__(self, parent):
        super(MiniMap, self).__init__(parent)
        self.setWordWrapMode(QTextOption.NoWrap)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setReadOnly(True)
        self.setCenterOnScroll(True)
        self.setMouseTracking(True)
        self.setTextInteractionFlags(Qt.NoTextInteraction)

        self._parent = parent
        self.highlighter = None
        styles.set_style(self, 'minimap')
        self.max_line = 0

        self.goe = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.goe)
        self.goe.setOpacity(settings.MINIMAP_MIN_OPACITY)
        self.animation = QPropertyAnimation(self.goe, "opacity")

    def __calculate_max(self):
        first_line = self._parent.firstVisibleBlock().blockNumber()
        last_line = self._parent._sidebarWidget.highest_line
        self.max_line = last_line - first_line
        self.update_visible_area()

    def set_code(self, source):
        self.setPlainText(source)
        self.__calculate_max()

    def adjust_to_parent(self):
        self.setFixedHeight(self._parent.height())
        self.setFixedWidth(self._parent.width() * settings.SIZE_PROPORTION)
        x = self._parent.width() - self.width()
        self.move(x, 0)
        fontsize = int(self.width() / settings.MARGIN_LINE)
        if fontsize < 1:
            fontsize = 1
        font = self.document().defaultFont()
        font.setPointSize(fontsize)
        self.setFont(font)
        self.__calculate_max()

    def update_visible_area(self):
        block = self._parent.firstVisibleBlock()
        first_line = block.blockNumber()
        max_count = self.blockCount()
        parent_cursor = self._parent.textCursor()
        parent_cursor.setPosition(block.position())
        self.setTextCursor(parent_cursor)
        lines_count = self.max_line
        if (first_line + self.max_line) > max_count:
            lines_count = max_count - first_line
        extraSelections = []
        for i in xrange(lines_count):
            selection = QTextEdit.ExtraSelection()
            lineColor = QColor(resources.CUSTOM_SCHEME.get('current-line',
                        resources.COLOR_SCHEME['current-line']))
            lineColor.setAlpha(100)
            selection.format.setBackground(lineColor)
            selection.format.setProperty(QTextFormat.FullWidthSelection, True)
            cursor = self.textCursor()
            cursor.setPosition(block.position())
            selection.cursor = cursor
            selection.cursor.clearSelection()
            extraSelections.append(selection)
            block = block.next()
        self.setExtraSelections(extraSelections)

    def enterEvent(self, event):
        self.animation.setDuration(300)
        self.animation.setStartValue(settings.MINIMAP_MIN_OPACITY)
        self.animation.setEndValue(settings.MINIMAP_MAX_OPACITY)
        self.animation.start()

    def leaveEvent(self, event):
        self.animation.setDuration(300)
        self.animation.setStartValue(settings.MINIMAP_MAX_OPACITY)
        self.animation.setEndValue(settings.MINIMAP_MIN_OPACITY)
        self.animation.start()

    def mousePressEvent(self, event):
        super(MiniMap, self).mousePressEvent(event)
        cursor = self.cursorForPosition(event.pos())
        self._parent.jump_to_line(cursor.blockNumber())
开发者ID:ntcong,项目名称:ninja-ide,代码行数:89,代码来源:minimap.py

示例10: MiniMap

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
class MiniMap(QsciScintilla):

    def __init__(self, editor):
        super(MiniMap, self).__init__(editor)
        self._editor = editor
        self.SendScintilla(QsciScintilla.SCI_SETCARETSTYLE, 0)
        self.SendScintilla(QsciScintilla.SCI_SETBUFFEREDDRAW, 0)
        self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
        self.SendScintilla(QsciScintilla.SCI_SETVSCROLLBAR, 0)
        self.SendScintilla(QsciScintilla.SCI_SETZOOM, -10)
        self.SendScintilla(QsciScintilla.SCI_SETREADONLY, 1)
        self.SendScintilla(QsciScintilla.SCI_HIDESELECTION, 1)
        self.SendScintilla(QsciScintilla.SCI_SETCURSOR, 8)
        # Hide markers
        for i in range(1, 5):
            self.SendScintilla(
                QsciScintilla.SCI_MARKERDEFINE, i, QsciScintilla.SC_MARK_EMPTY)
        self.SendScintilla(QsciScintilla.SCI_SETMARGINWIDTHN, 1, 0)

        self.setMouseTracking(True)

        if ACTIVATE_OPACITY:
            self.goe = QGraphicsOpacityEffect()
            self.setGraphicsEffect(self.goe)
            self.goe.setOpacity(settings.MINIMAP_MIN_OPACITY)
            self.animation = QPropertyAnimation(self.goe, "opacity")
            self.animation.setDuration(300)

        self.slider = SliderArea(self)
        self.slider.show()

    def adjust_to_parent(self):
        self.setFixedHeight(self._editor.height())
        self.setFixedWidth(self._editor.width() * settings.SIZE_PROPORTION)
        x = self._editor.width() - self.width()
        self.move(x, 0)
        self.slider.update_position()

    def shutdown(self):
        self._editor.SCN_UPDATEUI.disconnect()
        self._editor.SCN_ZOOM.disconnect()

    def fold(self, line):
        self.foldLine(line)

    def scroll_map(self):
        first_visible_line = self._editor.SendScintilla(
            QsciScintilla.SCI_GETFIRSTVISIBLELINE)
        num_doc_lines = self._editor.SendScintilla(
            QsciScintilla.SCI_GETLINECOUNT)
        num_visible_lines = self._editor.SendScintilla(
            QsciScintilla.SCI_DOCLINEFROMVISIBLE, num_doc_lines)
        lines_on_screen = self._editor.SendScintilla(
            QsciScintilla.SCI_LINESONSCREEN)

        if num_visible_lines > lines_on_screen:
            last_top_visible_line = num_visible_lines - lines_on_screen
            num_map_visible_lines = self.SendScintilla(
                QsciScintilla.SCI_DOCLINEFROMVISIBLE, num_doc_lines)
            # Lines on screen map
            lines_on_screenm = self.SendScintilla(
                QsciScintilla.SCI_LINESONSCREEN)
            # Last top visible line on map
            last_top_visible_linem = num_map_visible_lines - lines_on_screenm
            # Portion covered
            portion = first_visible_line / last_top_visible_line
            first_visible_linem = round(last_top_visible_linem * portion)
            # Scroll
            self.verticalScrollBar().setValue(first_visible_linem)

            # Move slider
            higher_pos = self._editor.SendScintilla(
                QsciScintilla.SCI_POSITIONFROMPOINT, 0, 0)
            y = self.SendScintilla(
                QsciScintilla.SCI_POINTYFROMPOSITION, 0, higher_pos)

            self.slider.move(0, y)

        self._current_scroll_value = self._editor.verticalScrollBar().value()

    def scroll_area(self, pos_parent):
        line = self.__line_from_position(pos_parent)
        self._editor.verticalScrollBar().setValue(line)

    def mousePressEvent(self, event):
        super(MiniMap, self).mousePressEvent(event)
        line = self.__line_from_position(event.pos())
        self._editor.jump_to_line(line)

        # Go to center
        los = self._editor.SendScintilla(QsciScintilla.SCI_LINESONSCREEN) / 2
        scroll_value = self._editor.verticalScrollBar().value()

        if self._current_scroll_value < scroll_value:
            self._editor.verticalScrollBar().setValue(scroll_value + los)
        else:
            self._editor.verticalScrollBar().setValue(scroll_value - los)

    def __line_from_position(self, point):
        position = self.SendScintilla(QsciScintilla.SCI_POSITIONFROMPOINT,
#.........这里部分代码省略.........
开发者ID:jorgesumle,项目名称:ninja-ide,代码行数:103,代码来源:minimap.py

示例11: CImprovedLabel

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]

#.........这里部分代码省略.........
         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()
开发者ID:Nerkyator,项目名称:pyQt_components,代码行数:70,代码来源:ImprovedLabel.py

示例12: MiniMap

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
class MiniMap(QsciScintilla):
    def __init__(self, parent):
        super(MiniMap, self).__init__(parent)
        # self.setWordWrapMode(QTextOption.NoWrap)
        # self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        # self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setReadOnly(True)
        self.SendScintilla(QsciScintilla.SCI_SETBUFFEREDDRAW, 0)
        self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
        self.SendScintilla(QsciScintilla.SCI_SETVSCROLLBAR, 0)
        self.setMarginWidth(1, 0)
        self.setFolding(self.NoFoldStyle, 2)
        # self.setCenterOnScroll(True)
        self.setMouseTracking(True)
        # self.viewport().setCursor(Qt.PointingHandCursor)
        # self.setTextInteractionFlags(Qt.NoTextInteraction)

        self._parent = parent
        # self.highlighter = None
        # self.lines_count = 0

        self.connect(self._parent, SIGNAL("updateRequest(const QRect&, int)"), self.update_visible_area)

        if ACTIVATE_OPACITY:
            self.goe = QGraphicsOpacityEffect()
            self.setGraphicsEffect(self.goe)
            self.goe.setOpacity(settings.MINIMAP_MIN_OPACITY)
            self.animation = QPropertyAnimation(self.goe, "opacity")

        # self.slider = SliderArea(self)
        # self.slider.show()

    def shutdown(self):
        self.disconnect(self._parent, SIGNAL("updateRequest(const QRect&, int)"), self.update_visible_area)

    def __calculate_max(self):
        # line_height = self._parent.cursorRect().height()
        # if line_height > 0:
        # self.lines_count = self._parent.viewport().height() / line_height
        # self.slider.update_position()
        self.update_visible_area()

    def set_code(self, source):
        # self.setPlainText(source)
        self.__calculate_max()

    def adjust_to_parent(self):
        self.setFixedHeight(self._parent.height())
        self.setFixedWidth(self._parent.width() * settings.SIZE_PROPORTION)
        x = self._parent.width() - self.width()
        self.move(x, 0)
        # fontsize = int(self.width() / settings.MARGIN_LINE)
        # if fontsize < 1:
        # fontsize = 1
        # font = self.document().defaultFont()
        # font.setPointSize(fontsize)
        # self.setFont(font)
        self.__calculate_max()

    def update_visible_area(self):
        pass
开发者ID:danicampora,项目名称:ninja-ide,代码行数:63,代码来源:minimap.py

示例13: HiddenWidgetBase

# 需要导入模块: from PyQt4.QtGui import QGraphicsOpacityEffect [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsOpacityEffect import setOpacity [as 别名]
class HiddenWidgetBase(object):
    INITIAL_TIMEOUT = 2000
    NUM_STEPS = 15
    INTERVAL = 20
    
    def __init__(self, logger):
        self.logger = logger
        self.good = False
        self.fadingEnabled = False
        self.minOpacity = 0.
        self.maxOpacity = 1.
        self.incr = (self.maxOpacity - self.minOpacity) / self.NUM_STEPS
        self.fadeIn = False
        try:
            from PyQt4.QtGui import QGraphicsOpacityEffect
            
            self.effect = QGraphicsOpacityEffect(self)
            self.setGraphicsEffect(self.effect)
            
            self.timer = QTimer(self)
            self.timer.timeout.connect(self._fade)
            self.good = True
        except:
            self.logger.debug(u"Could not enable opacity effects. %s: %s", sys.exc_info()[0].__name__, unicode(sys.exc_info()[1]))
        
    # cannot use loggingSlot here because this is no QObject
    @loggingFunc
    def setMinOpacity(self, newVal):
        self.minOpacity = newVal
        self.incr = (self.maxOpacity - self.minOpacity) / self.NUM_STEPS
        if self.fadingEnabled and not self.timer.isActive():
            self.timer.start(self.INTERVAL)
    
    # cannot use loggingSlot here because this is no QObject
    @loggingFunc
    def setMaxOpacity(self, newVal):
        self.maxOpacity = newVal
        self.incr = (self.maxOpacity - self.minOpacity) / self.NUM_STEPS
        if self.fadingEnabled and not self.timer.isActive():
            self.timer.start(self.INTERVAL)
        
    # cannot use loggingSlot here because this is no QObject
    @loggingFunc
    def showTemporarily(self):
        if self.good:
            self.fadingEnabled = False
            self.fadeIn = False
            self.timer.stop()
            self.effect.setOpacity(self.maxOpacity)
            QTimer.singleShot(self.INITIAL_TIMEOUT, self._fadeOut)
        
    def _fadeOut(self):
        self.fadingEnabled = True
        self.timer.start(self.INTERVAL * 1.5)
    
    # cannot use loggingSlot here because this is no QObject
    @loggingFunc
    def _fade(self):
        if self.fadeIn:
            desOp = self.maxOpacity
        else:
            desOp = self.minOpacity
        
        opacity = self.effect.opacity()
        if abs(opacity - desOp) < self.incr:
            # prevent flickering if timer does not stop immediately
            return
        
        if opacity < desOp:
            opacity += self.incr
            self.effect.setOpacity(opacity)
        else:
            opacity -= self.incr
            self.effect.setOpacity(opacity)
        
        #finish animation if desired opacity is reached
        if abs(opacity - desOp) < self.incr:
            self.timer.stop()
        
    def _mouseEntered(self):
        if self.good and self.fadingEnabled:
            self.fadeIn = True
            self.timer.start(self.INTERVAL)
        
    def _mouseLeft(self):
        if self.good and self.fadingEnabled:
            self.fadeIn = False
            self.timer.start(self.INTERVAL)
开发者ID:hannesrauhe,项目名称:lunchinator,代码行数:90,代码来源:remote_pictures_gui.py


注:本文中的PyQt4.QtGui.QGraphicsOpacityEffect.setOpacity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。