Пример #1
0
 def _create_animation(self, path):
     if path in self._gif_list.values():
         # We added it already.
         return
     movie = WObjectCache().open(QtGui.QMovie, path)
     self._gif_list[movie] = path
     movie.frameChanged.connect(self.drawAnimate)
     movie.start()
Пример #2
0
 def _create_animation(self, path):
     movie = WObjectCache().open(WMovie, path)
     try:
         movie.frameChanged.connect(self.drawAnimate, QtCore.Qt.UniqueConnection)
     except TypeError:
         # connected already
         pass
     movie.start()
Пример #3
0
 def _create_animation(self, path):
     movie = WObjectCache().open(WMovie, path)
     try:
         movie.frameChanged.connect(self.drawAnimate,
                                    QtCore.Qt.UniqueConnection)
     except TypeError:
         # connected already
         pass
     movie.start()
Пример #4
0
    def __init__(self, parent=None):
        super(WAsyncLabel, self).__init__(parent)
        self._url = ""
        self._image = None

        self.fetcher = AsyncFetcher("".join((down_path, str(WeRuntimeInfo()["uid"]))))

        busyIconPixmap = WObjectCache().open(QtGui.QPixmap, ":/IMG/img/busy.gif")
        self.minimumImageHeight = busyIconPixmap.height()
        self.minimumImageWidth = busyIconPixmap.width()

        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.contextMenu)
Пример #5
0
    def __init__(self, parent=None):
        super(WAsyncLabel, self).__init__(parent)
        self._url = ""
        self._image = None

        self.fetcher = AsyncFetcher("".join(
            (down_path, str(WeRuntimeInfo()["uid"]))))

        busyIconPixmap = WObjectCache().open(QtGui.QPixmap,
                                             ":/IMG/img/busy.gif")
        self.minimumImageHeight = busyIconPixmap.height()
        self.minimumImageWidth = busyIconPixmap.width()

        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.contextMenu)
Пример #6
0
 def setBusy(self, busy):
     if busy:
         # Hack: #74.
         # What's wrong with the busyMovie()? To save the memory,
         # We use a single busyMovie() in the whole program.
         # If the image downloaded here, we'll stop the movie and the
         # busyIcon will disappear. But it may start from somewhere else.
         # The the busyIcon appear again unexpectedly.
         # The quick fix is disconnecting the signal/slot connection
         # when we stop the movie.
         self.animation = WObjectCache().open(QtGui.QMovie,
                                              ":/IMG/img/busy.gif")
         self.animation.start()
         self.animation.frameChanged.connect(self.drawBusyIcon)
     else:
         self.clearBusyIcon()
Пример #7
0
 def setPixmap(self, url):
     super(WAsyncLabel,
           self).setMovie(WObjectCache().open(QtGui.QMovie,
                                              ":/IMG/img/busy.gif"))
     self.start()
     if not ("http" in url):
         self._setPixmap(url)
         return
     self._url = url
     self._fetch()
Пример #8
0
    def _setupTopicTab(self, topic, switch=True):
        index = self._getSameTab("topic", topic)
        if index:
            if switch:
                self.tabWidget.setCurrentIndex(index)
            return

        view = TweetListWidget()
        timeline = TweetTopicModel(self.client.api("search/topics"), topic,
                                   view)
        tab = self._setupCommonTab(timeline, view, switch, protect=False)
        self._setTabIcon(
            tab,
            WObjectCache().open(QtGui.QPixmap, ":/IMG/img/topic.jpg"))
Пример #9
0
class WIconLabel(QtGui.QWidget):

    clicked = QtCore.pyqtSignal()

    def __init__(self, parent=None):
        super().__init__(parent)
        self._icon = None
        self._text = None

    def setIcon(self, icon):
        self._icon = WObjectCache().open(QtGui.QPixmap, icon)
        self.update()

    def setText(self, text):
        if self._text is None:
            self._text = QtGui.QStaticText()
        self._text.setText(text)
        self.update()

    def paintEvent(self, e):
        painter = QtGui.QPainter(self)
        if self._icon:
            painter.drawPixmap(0, 0, self._icon)
        if self._text:
            painter.drawStaticText(self._icon.width(), 0, self._text)

    def sizeHint(self):
        if self._text:
            return QtCore.QSize(self._icon.width() + self._text.size().width(), self._icon.height())
        elif self._icon:
            return self._icon.size()
        else:
            return QtCore.QSize(0, 0)

    def mouseReleaseEvent(self, e):
        self.clicked.emit()
Пример #10
0
 def setBusy(self, busy):
     if busy:
         # Hack: #74.
         # What's wrong with the busyMovie()? To save the memory,
         # We use a single busyMovie() in the whole program.
         # If the image downloaded here, we'll stop the movie and the
         # busyIcon will disappear. But it may start from somewhere else.
         # The the busyIcon appear again unexpectedly.
         # The quick fix is disconnecting the signal/slot connection
         # when we stop the movie.
         self.animation = WObjectCache().open(QtGui.QMovie, ":/IMG/img/busy.gif")
         self.animation.start()
         self.animation.frameChanged.connect(self.drawBusyIcon)
     else:
         self.clearBusyIcon()
Пример #11
0
 def setIcon(self, icon):
     self._icon = WObjectCache().open(QtGui.QPixmap, icon)
     self.update()
Пример #12
0
class WAsyncLabel(WImageLabel):

    clicked = QtCore.pyqtSignal(int)

    def __init__(self, parent=None):
        super(WAsyncLabel, self).__init__(parent)
        self._url = ""
        self._image = None

        self.fetcher = AsyncFetcher("".join((down_path, str(WeRuntimeInfo()["uid"]))))

        busyIconPixmap = WObjectCache().open(QtGui.QPixmap, ":/IMG/img/busy.gif")
        self.minimumImageHeight = busyIconPixmap.height()
        self.minimumImageWidth = busyIconPixmap.width()

        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.contextMenu)

    def url(self):
        return self._url

    def setBusy(self, busy):
        if busy:
            # Hack: #74.
            # What's wrong with the busyMovie()? To save the memory,
            # We use a single busyMovie() in the whole program.
            # If the image downloaded here, we'll stop the movie and the
            # busyIcon will disappear. But it may start from somewhere else.
            # The the busyIcon appear again unexpectedly.
            # The quick fix is disconnecting the signal/slot connection
            # when we stop the movie.
            self.animation = WObjectCache().open(QtGui.QMovie, ":/IMG/img/busy.gif")
            self.animation.start()
            self.animation.frameChanged.connect(self.drawBusyIcon)
        else:
            self.clearBusyIcon()

    @QtCore.pyqtSlot()
    def drawBusyIcon(self):
        image = QtGui.QPixmap(self._image)
        icon = self.animation.currentPixmap()

        height = (image.height() - icon.height()) / 2
        width = (image.width() - icon.width()) / 2
        painter = QtGui.QPainter(image)
        painter.drawPixmap(width, height, icon)
        painter.end()
        super(WAsyncLabel, self).setPixmap(image)

    def clearBusyIcon(self):
        self.animation.stop()
        self.animation.frameChanged.disconnect(self.drawBusyIcon)
        super(WAsyncLabel, self).setPixmap(self._image)

    def _setPixmap(self, path):
        _image = QtGui.QPixmap(path)
        minimalHeight = self.minimumImageHeight
        minimalWidth = self.minimumImageWidth

        if _image.height() < minimalHeight or _image.width() < minimalWidth:
            if _image.height() > minimalHeight:
                height = _image.height()
            else:
                height = minimalHeight

            if _image.width() > minimalWidth:
                width = _image.width()
            else:
                width = minimalWidth

            image = QtGui.QPixmap(width, height)
            painter = QtGui.QPainter(image)
            path = QtGui.QPainterPath()
            path.addRect(0, 0, width, height)
            painter.fillPath(path, QtGui.QBrush(QtCore.Qt.gray))
            painter.drawPixmap((width - _image.width()) / 2,
                               (height - _image.height()) / 2,
                               _image)
            painter.end()
        else:
            image = _image

        self._image = image
        super(WAsyncLabel, self).setPixmap(image)

    def setPixmap(self, url):
        super(WAsyncLabel, self).setMovie(
            WObjectCache().open(QtGui.QMovie, ":/IMG/img/busy.gif")
        )
        self.start()
        if not ("http" in url):
            self._setPixmap(url)
            return
        self._url = url
        self._fetch()

    def _fetch(self):
        self.fetcher.addTask(self._url, self.setPixmap)

    def mouseReleaseEvent(self, e):
        if e.button() == QtCore.Qt.LeftButton and self._image:
            self.clicked.emit(QtCore.Qt.LeftButton)
        elif e.button() == QtCore.Qt.MiddleButton and self._image:
            self.clicked.emit(QtCore.Qt.MiddleButton)

    def contextMenu(self, pos):
        if not self._image:
            return
        saveAction = QtGui.QAction(self)
        saveAction.setText(self.tr("&Save"))
        saveAction.triggered.connect(self.save)
        menu = QtGui.QMenu()
        menu.addAction(saveAction)
        menu.exec(self.mapToGlobal(pos))

    def save(self):
        file = QtGui.QFileDialog.getOpenFileName(self,
                                                 self.tr("Choose a path"))
        self._image.save(file)
Пример #13
0
 def _create_animation(self, path):
     movie = WObjectCache().open(WMovie, path)
     movie.frameChanged.connect(self.drawAnimate, QtCore.Qt.UniqueConnection)
     movie.start()
Пример #14
0
 def setAvatar(f):
     self._setTabIcon(tab, WObjectCache().open(QtGui.QPixmap, f))
Пример #15
0
 def setupUi(self):
     self.layout = QtGui.QVBoxLayout(self)
     self.setLayout(self.layout)
     self.busyMovie = WObjectCache().open(QtGui.QMovie,
                                          ":/IMG/img/busy.gif")
Пример #16
0
class WAsyncLabel(WImageLabel):

    clicked = QtCore.pyqtSignal(int)

    def __init__(self, parent=None):
        super(WAsyncLabel, self).__init__(parent)
        self._url = ""
        self._image = None

        self.fetcher = AsyncFetcher("".join(
            (down_path, str(WeRuntimeInfo()["uid"]))))

        busyIconPixmap = WObjectCache().open(QtGui.QPixmap,
                                             ":/IMG/img/busy.gif")
        self.minimumImageHeight = busyIconPixmap.height()
        self.minimumImageWidth = busyIconPixmap.width()

        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.contextMenu)

    def url(self):
        return self._url

    def setBusy(self, busy):
        if busy:
            # Hack: #74.
            # What's wrong with the busyMovie()? To save the memory,
            # We use a single busyMovie() in the whole program.
            # If the image downloaded here, we'll stop the movie and the
            # busyIcon will disappear. But it may start from somewhere else.
            # The the busyIcon appear again unexpectedly.
            # The quick fix is disconnecting the signal/slot connection
            # when we stop the movie.
            self.animation = WObjectCache().open(QtGui.QMovie,
                                                 ":/IMG/img/busy.gif")
            self.animation.start()
            self.animation.frameChanged.connect(self.drawBusyIcon)
        else:
            self.clearBusyIcon()

    @QtCore.pyqtSlot()
    def drawBusyIcon(self):
        image = QtGui.QPixmap(self._image)
        icon = self.animation.currentPixmap()

        height = (image.height() - icon.height()) / 2
        width = (image.width() - icon.width()) / 2
        painter = QtGui.QPainter(image)
        painter.drawPixmap(width, height, icon)
        painter.end()
        super(WAsyncLabel, self).setPixmap(image)

    def clearBusyIcon(self):
        self.animation.stop()
        self.animation.frameChanged.disconnect(self.drawBusyIcon)
        super(WAsyncLabel, self).setPixmap(self._image)

    def _setPixmap(self, path):
        _image = QtGui.QPixmap(path)
        minimalHeight = self.minimumImageHeight
        minimalWidth = self.minimumImageWidth

        if _image.height() < minimalHeight or _image.width() < minimalWidth:
            if _image.height() > minimalHeight:
                height = _image.height()
            else:
                height = minimalHeight

            if _image.width() > minimalWidth:
                width = _image.width()
            else:
                width = minimalWidth

            image = QtGui.QPixmap(width, height)
            painter = QtGui.QPainter(image)
            path = QtGui.QPainterPath()
            path.addRect(0, 0, width, height)
            painter.fillPath(path, QtGui.QBrush(QtCore.Qt.gray))
            painter.drawPixmap((width - _image.width()) / 2,
                               (height - _image.height()) / 2, _image)
            painter.end()
        else:
            image = _image

        self._image = image
        super(WAsyncLabel, self).setPixmap(image)

    def setPixmap(self, url):
        super(WAsyncLabel,
              self).setMovie(WObjectCache().open(QtGui.QMovie,
                                                 ":/IMG/img/busy.gif"))
        self.start()
        if not ("http" in url):
            self._setPixmap(url)
            return
        self._url = url
        self._fetch()

    def _fetch(self):
        self.fetcher.addTask(self._url, self.setPixmap)

    def mouseReleaseEvent(self, e):
        if e.button() == QtCore.Qt.LeftButton and self._image:
            self.clicked.emit(QtCore.Qt.LeftButton)
        elif e.button() == QtCore.Qt.MiddleButton and self._image:
            self.clicked.emit(QtCore.Qt.MiddleButton)

    def contextMenu(self, pos):
        if not self._image:
            return
        saveAction = QtGui.QAction(self)
        saveAction.setText(self.tr("&Save"))
        saveAction.triggered.connect(self.save)
        menu = QtGui.QMenu()
        menu.addAction(saveAction)
        menu.exec(self.mapToGlobal(pos))

    def save(self):
        file = QtGui.QFileDialog.getOpenFileName(self,
                                                 self.tr("Choose a path"))
        self._image.save(file)