Exemple #1
0
    class LineEdit(QLineEdit):
        def __init__(self, *args, **kwargs):
            super(LineEdit, self).__init__(*args, **kwargs)
            self.clearButton = QToolButton(self)
            icon = complete_icon("fileclose")
            self.clearButton.setIcon(icon)
            self.clearButton.setIconSize(icon.pixmap(QSize(16, 16)).size())
            self.clearButton.setCursor(Qt.ArrowCursor)
            self.clearButton.setStyleSheet("QToolButton { border: none; padding: 0px; }")
            self.clearButton.hide()
            self.clearButton.clicked.connect(self.clear)
            self.textChanged.connect(self.updateCloseButton)
            frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
            self.setStyleSheet("QLineEdit { padding-right: %spx; }" % (self.clearButton.sizeHint().width() + frameWidth + 1,))
            msz = self.minimumSizeHint()
            self.setMinimumSize(max(msz.width(), self.clearButton.sizeHint().height() + frameWidth * 2 + 2),
                       max(msz.height(), self.clearButton.sizeHint().height() + frameWidth * 2 + 2));

        def resizeEvent(self, *args, **kwargs):
            super(LineEdit, self).resizeEvent(*args, **kwargs)
            sz = self.clearButton.sizeHint()
            frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
            self.clearButton.move(self.rect().right() - frameWidth - sz.width(),
                          (self.rect().bottom() + 1 - sz.height())/2)

        def updateCloseButton(self, text):
            self.clearButton.setVisible(text != "")
Exemple #2
0
class LocationBar(QLineEdit):
    def __init__(self, *args, icon=None, **kwargs):
        super(LocationBar, self).__init__(*args, **kwargs)
        self.icon = QToolButton(self)
        self._savedText = ""
        if type(icon) is QIcon:
            self.icon.setIcon(icon)
        self.icon.setFixedWidth(16)
        self.icon.setFixedHeight(16)
        self.icon.setStyleSheet("QToolButton { border: 0; background: transparent; width: 16px; height: 16px; }")
        sz = self.icon
        fw = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.s = False
        msz = self.minimumSizeHint()
        self.setMinimumSize(max(msz.width(), self.icon.sizeHint().height() + fw * 2 + 2), max(msz.height(), self.icon.sizeHint().height() + fw * 2 + 2))

    def savedText(self):
        return self._savedText

    def setSavedText(self, text):
        self._savedText = str(text)

    def resizeEvent(self, ev):
        super(LocationBar, self).resizeEvent(ev)
        sz = self.icon
        fw = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.icon.move(QPoint(self.rect().left() + (self.height() + 1 - sz.width())/2, (self.height() + 1 - sz.height())/2))
        if self.s == False:
            self.setStyleSheet("QLineEdit { padding-left: %spx; }" % str(sz.width() + (self.height() + 1 - sz.width())/2))
            self.s = True
            self.redefResizeEvent()

    def redefResizeEvent(self):
        self.resizeEvent = self.shortResizeEvent

    def shortResizeEvent(self, ev):
        super(LocationBar, self).resizeEvent(ev)
        sz = self.icon
        fw = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.icon.move(QPoint(self.rect().left() + (self.height() + 1 - sz.width())/2, (self.height() + 1 - sz.height())/2))

    def setIcon(self, icon):
        self.icon.setIcon(icon)

    # These are just here to maintain some level of compatibility with older extensions.

    def lineEdit(self):
        return self

    def setEditText(self, *args, **kwargs):
        self.setText(*args, **kwargs)

    def addItem(self, *args, **kwargs):
        pass
class LineEdit(QLineEdit):

    def __init__(self):
        super(LineEdit, self).__init__()
        self.setReadOnly(True)
        self.setText(settings.PIREAL_DATABASES)
        self.button = QToolButton(self)
        self.button.setText('...')

    def resizeEvent(self, event):
        QLineEdit.resizeEvent(self, event)
        self.button.setFixedWidth(40)
        self.button.move(self.width() - self.button.width(), 0)
        self.button.setFixedHeight(self.height())
Exemple #4
0
class LineEdit(QLineEdit):
    """Extended QLineEdit.
    Supports prompt and Clear button
    """

    clearButtonClicked = pyqtSignal()
    """
    clearButtonClicked()

    **Signal** emitted, when Clear button has been clicked
    """

    def __init__(self, parent):
        QLineEdit.__init__(self, parent)

        self._margin = self.sizeHint().height() - 2
        self._spacing = 0
        self._promptText = ""

        self._tbClear = QToolButton(self)
        self._tbClear.setIcon(QIcon(":enkiicons/edit-clear-rtl.png"))
        self._tbClear.setToolTip(tr("Clear"))
        self._tbClear.setStyleSheet("QToolButton { border: none; padding: 0px; }")
        self._tbClear.setCursor(Qt.ArrowCursor)
        self._tbClear.setFocusPolicy(Qt.NoFocus)

        self.setClearButtonVisible(False)

        self.textChanged.connect(self._onTextChanged)
        self._tbClear.clicked.connect(self.clear)
        self._tbClear.clicked.connect(self.clearButtonClicked)

    def promptText(self):
        """Current prompt text
        """
        return self._promptText

    def setPromptText(self, prompt):
        """Set prompt text
        """
        self._promptText = prompt
        self.update()

    def paintEvent(self, event):
        """QLineEdit.paintEvent implementation.
        Draws prompt
        """
        QLineEdit.paintEvent(self, event)

        if self._promptText and not self.text() and self.isEnabled():
            option = QStyleOptionFrameV3()
            self.initStyleOption(option)

            left, top, right, bottom = self.getTextMargins()

            va = self.style().visualAlignment(self.layoutDirection(), self.alignment())
            rect = (
                self.style()
                .subElementRect(QStyle.SE_LineEditContents, option, self)
                .adjusted(2, 0, 0, 0)
                .adjusted(left, top, -right, -bottom)
            )
            fm = QFontMetrics(self.font())
            text = fm.elidedText(self._promptText, Qt.ElideRight, rect.width())
            painter = QPainter(self)

            painter.setPen(self.palette().color(QPalette.Disabled, QPalette.Text))
            painter.drawText(rect, va, text)

    def resizeEvent(self, event):
        """QLineEdit.resizeEvent implementation
        Adjusts Clear button position
        """
        QLineEdit.resizeEvent(self, event)

        self._tbClear.resize(QSize(self._margin, self.height() - 2))
        self._tbClear.move(self.width() - self._margin - 3, 0)

    def setClearButtonVisible(self, visible):
        """Set Clear button visible
        """
        self._tbClear.setVisible(visible)

        left, top, right, bottom = self.getTextMargins()

        if visible:
            right = self._margin + self._spacing
        else:
            right = 0

        self.setTextMargins(left, top, right, bottom)

    def _onTextChanged(self, text):
        """Text changed, update Clear button visibility
        """
        self.setClearButtonVisible(len(text) > 0)
class HomeRecommendedItem(QWidget, fc_home_recommended_item):
    """
    This class represents a HomeRecommendedItem widget which is shown on the home page. This widget can either show
    a channel or a torrent.
    """

    def __init__(self, parent):
        QWidget.__init__(self, parent)
        fc_home_recommended_item.__init__(self)

        self.setupUi(self)

        self.show_torrent = True
        self.torrent_info = None
        self.channel_info = None
        self.download_uri = None
        self.dialog = None

        # Create the category label, shown on cells that display a torrent on the home page
        self.category_label = QLabel(self)
        self.category_label.setFixedHeight(24)
        self.category_label.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed))
        self.category_label.setStyleSheet("""
        border: 2px solid white;
        border-radius: 12px;
        background-color: transparent;
        color: white;
        padding-left: 4px;
        padding-right: 4px;
        font-weight: bold;
        """)
        self.category_label.move(QPoint(6, 6))
        self.category_label.show()

        # Create the dark overlay and download button over the thumbnail on hover
        self.dark_overlay = QWidget(self)
        self.dark_overlay.setStyleSheet("background-color: rgba(0, 0, 0, 0.65);")
        self.dark_overlay.hide()

        self.download_button = QToolButton(self)
        self.download_button.setFixedSize(QSize(40, 40))
        self.download_button.setStyleSheet("""
        QToolButton {
            background-color: transparent;
            border: 2px solid white;
            border-radius: 20px;
        }

        QToolButton::hover {
            border: 2px solid #B5B5B5;
        }
        """)
        self.download_button.setIcon(QIcon(get_image_path('downloads.png')))
        self.download_button.setIconSize(QSize(18, 18))
        self.download_button.clicked.connect(self.on_download_button_clicked)
        self.download_button.hide()

    def on_download_button_clicked(self):
        if not self.torrent_info:
            return
        self.download_uri = (u"magnet:?xt=urn:btih:%s&dn=%s" %
                             (self.torrent_info["infohash"], self.torrent_info['name'])).encode('utf-8')
        self.window().start_download_from_uri(self.download_uri)

    def update_with_torrent(self, torrent):
        if not torrent:
            return
        self.show_torrent = True
        self.torrent_info = torrent
        self.thumbnail_widget.initialize(torrent["name"], HOME_ITEM_FONT_SIZE)
        self.main_label.setText(torrent["name"])
        self.category_label.setText(torrent["category"].lower())
        self.category_label.adjustSize()
        self.category_label.setHidden(False)
        self.setCursor(Qt.ArrowCursor)
        self.detail_label.setText("Size: " + format_size(torrent["size"]))

    def update_with_channel(self, channel):
        if not channel:
            return
        self.show_torrent = False
        self.channel_info = channel
        self.thumbnail_widget.initialize(channel["name"], HOME_ITEM_FONT_SIZE)

        self.main_label.setText(channel["name"])
        self.detail_label.setText("Updated " + pretty_date(channel["modified"]))
        self.category_label.setHidden(True)
        self.setCursor(Qt.PointingHandCursor)

    def enterEvent(self, _):
        if self.show_torrent:
            self.dark_overlay.resize(self.thumbnail_widget.size())
            self.dark_overlay.show()
            self.download_button.move((self.thumbnail_widget.width() - self.download_button.width()) / 2,
                                      (self.thumbnail_widget.height() - self.download_button.height()) / 2)
            self.download_button.show()

    def leaveEvent(self, _):
        self.dark_overlay.hide()
        self.download_button.hide()
Exemple #6
0
class FilterLineEdit(QLineEdit):

    clearIconClicked = pyqtSignal()
    shiftReturnPressed = pyqtSignal()
    onlyReturnPressed = pyqtSignal()
    setClearIconState = pyqtSignal()

    # ---------------------------------------------------------------------
    def __init__(self, parent=None):
        super(FilterLineEdit, self).__init__(parent)

        self.button = QToolButton(self)
        self.button.setIconSize(QSize(16, 16))
        # self.button = QtGui.QPushButton(self)
        # self.button.setText("clear")
        # self.button.setIcon(QtGui.QIcon(':/icons/icons/clear_left_active.png'))
        self.button.setStyleSheet('QToolButton {border: 0px; padding: 0px; image: url(:/icons/icons/clear_left_inactive.png);}'
                                  'QToolButton:hover {image: url(:/icons/icons/clear_left_hover.png);}'
                                  'QToolButton:pressed {image: url(:/icons/icons/clear_left_pressed.png);}')
        self.button.setCursor(Qt.ArrowCursor)
        self.button.clicked.connect(self.clearIconClicked.emit)

        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        buttonSize = self.button.sizeHint()

        self.setStyleSheet('QLineEdit {padding-right: %dpx; }' % (buttonSize.width() + frameWidth + 1))
        self.setMinimumSize(max(self.minimumSizeHint().width(), buttonSize.width() + frameWidth * 2 + 2),
                            max(self.minimumSizeHint().height(), buttonSize.height() + frameWidth * 2 + 2))

        self.setClearIconState.connect(self.inActivateButtonIfNoText)
        self.textEdited.connect(self.inActivateButtonIfNoText)

    # ---------------------------------------------------------------------
    def resizeEvent(self, event):
        buttonSize = self.button.sizeHint()
        frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.button.move(self.rect().right() - frameWidth - buttonSize.width(),
                         (self.rect().bottom() - buttonSize.height() + 1) / 2)
        super(FilterLineEdit, self).resizeEvent(event)

    # ---------------------------------------------------------------------
    @pyqtSlot()
    def inActivateButtonIfNoText(self):

        if self.text() == "":
            self.button.setStyleSheet('QToolButton {border: 0px; padding: 0px; image: url(:/icons/icons/clear_left_inactive.png);}'
                                      'QToolButton:hover {image: url(:/icons/icons/clear_left_hover.png);}'
                                      'QToolButton:pressed {image: url(:/icons/icons/clear_left_pressed.png);}')
        else:
            self.button.setStyleSheet('QToolButton {border: 0px; padding: 0px; image: url(:/icons/icons/clear_left_active.png);}'
                                      'QToolButton:hover {image: url(:/icons/icons/clear_left_hover.png);}'
                                      'QToolButton:pressed {image: url(:/icons/icons/clear_left_pressed.png);}')

    # ---------------------------------------------------------------------
    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Return:

            if event.modifiers() & Qt.ShiftModifier:
                self.shiftReturnPressed.emit()
            else:  # diger modiferlar da kaliyor ama olsun, c*k onemli degil..
                self.onlyReturnPressed.emit()

        super(FilterLineEdit, self).keyPressEvent(event)
Exemple #7
0
class LocationBar(QLineEdit):
    def __init__(self, *args, icon=None, **kwargs):
        super(LocationBar, self).__init__(*args, **kwargs)
        self.icon = QToolButton(self)
        self._savedText = ""
        if type(icon) is QIcon:
            self.icon.setIcon(icon)
        self.icon.setFixedWidth(16)
        self.icon.setFixedHeight(16)
        self.icon.setStyleSheet(
            "QToolButton { border: 0; background: transparent; width: 16px; height: 16px; }"
        )
        sz = self.icon
        fw = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.s = False
        msz = self.minimumSizeHint()
        self.setMinimumSize(
            max(msz.width(),
                self.icon.sizeHint().height() + fw * 2 + 2),
            max(msz.height(),
                self.icon.sizeHint().height() + fw * 2 + 2))

    def savedText(self):
        return self._savedText

    def setSavedText(self, text):
        self._savedText = str(text)

    def resizeEvent(self, ev):
        super(LocationBar, self).resizeEvent(ev)
        sz = self.icon
        fw = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.icon.move(
            QPoint(self.rect().left() + (self.height() + 1 - sz.width()) / 2,
                   (self.height() + 1 - sz.height()) / 2))
        if self.s == False:
            self.setStyleSheet("QLineEdit { padding-left: %spx; }" %
                               str(sz.width() +
                                   (self.height() + 1 - sz.width()) / 2))
            self.s = True
            self.redefResizeEvent()

    def redefResizeEvent(self):
        self.resizeEvent = self.shortResizeEvent

    def shortResizeEvent(self, ev):
        super(LocationBar, self).resizeEvent(ev)
        sz = self.icon
        fw = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.icon.move(
            QPoint(self.rect().left() + (self.height() + 1 - sz.width()) / 2,
                   (self.height() + 1 - sz.height()) / 2))

    def setIcon(self, icon):
        self.icon.setIcon(icon)

    # These are just here to maintain some level of compatibility with older extensions.

    def lineEdit(self):
        return self

    def setEditText(self, *args, **kwargs):
        self.setText(*args, **kwargs)

    def addItem(self, *args, **kwargs):
        pass
Exemple #8
0
class Demo(QWidget):
    def __init__(self):
        super().__init__()

        self.__setup_ui__()

    def __setup_ui__(self):
        self.setWindowTitle("测试")
        #窗口大小
        self.resize(1400, 800)
        # 工具栏
        self.frame_tool = QFrame(self)
        self.frame_tool.setObjectName("frame_tool")
        self.frame_tool.setGeometry(0, 0, self.width(), 25)
        self.frame_tool.setStyleSheet("border-color: rgb(0, 0, 0);")
        self.frame_tool.setFrameShape(QFrame.Panel)
        self.frame_tool.setFrameShadow(QFrame.Raised)

        # 1.1 界面1按钮
        self.window1_btn = QToolButton(self.frame_tool)
        self.window1_btn.setCheckable(True)
        self.window1_btn.setText("window1")
        self.window1_btn.setObjectName("menu_btn")
        self.window1_btn.resize(100, 25)
        self.window1_btn.clicked.connect(self.click_window1)
        self.window1_btn.setAutoRaise(True)

        # 1.2 界面2按钮
        self.window2_btn = QToolButton(self.frame_tool)
        self.window2_btn.setCheckable(True)
        self.window2_btn.setText("window2")
        self.window2_btn.setObjectName("menu_btn")
        self.window2_btn.resize(100, 25)
        self.window2_btn.move(self.window1_btn.width(), 0)
        self.window2_btn.clicked.connect(self.click_window2)
        self.window2_btn.setAutoRaise(True)

        self.btn_group = QButtonGroup(self.frame_tool)
        self.btn_group.addButton(self.window1_btn, 1)
        self.btn_group.addButton(self.window2_btn, 2)

        # 2. 工作区域
        self.main_frame = QFrame(self)
        self.main_frame.setGeometry(0, 25, self.width(),
                                    self.height() - self.frame_tool.height())
        # self.main_frame.setStyleSheet("background-color: rgb(65, 95, 255)")

        # 创建堆叠布局
        self.stacked_layout = QStackedLayout(self.main_frame)

        # 第一个布局界面
        self.main_frame1 = QMainWindow()
        self.frame1_bar = QStatusBar()
        self.frame1_bar.setObjectName("frame1_bar")
        self.main_frame1.setStatusBar(self.frame1_bar)
        self.frame1_bar.showMessage("欢迎进入frame1")

        rom_frame = QFrame(self.main_frame1)
        rom_frame.setGeometry(0, 0, self.width(),
                              self.main_frame.height() - 25)
        rom_frame.setFrameShape(QFrame.Panel)
        rom_frame.setFrameShadow(QFrame.Raised)

        frame1_bar_frame = QFrame(self.main_frame1)
        frame1_bar_frame.setGeometry(0, self.main_frame.height(), self.width(),
                                     25)

        # 第二个布局界面
        self.main_frame2 = QMainWindow()
        self.frame2_bar = QStatusBar()
        self.frame2_bar.setObjectName("frame2_bar")
        self.main_frame2.setStatusBar(self.frame2_bar)
        self.frame2_bar.showMessage("欢迎进入frame2")

        custom_frame = QFrame(self.main_frame2)
        custom_frame.setGeometry(0, 0, self.width(),
                                 self.main_frame.height() - 25)
        custom_frame.setFrameShape(QFrame.Panel)
        custom_frame.setFrameShadow(QFrame.Raised)

        frame2_bar_frame = QFrame(self.main_frame2)
        frame2_bar_frame.setGeometry(0, self.main_frame.height(), self.width(),
                                     25)

        # 把两个布局界面放进去
        self.stacked_layout.addWidget(self.main_frame1)
        self.stacked_layout.addWidget(self.main_frame2)

    def click_window1(self):
        if self.stacked_layout.currentIndex() != 0:
            self.stacked_layout.setCurrentIndex(0)
            self.frame1_bar.showMessage("欢迎进入frame1")

    def click_window2(self):
        if self.stacked_layout.currentIndex() != 1:
            self.stacked_layout.setCurrentIndex(1)
            self.frame2_bar.showMessage("欢迎进入frame2")