示例#1
0
    def show_top(self, widget, duration=2000):
        '''Show the notice at the top center of the specified widget'''

        ref_rect = widget.rect()
        ref_pos = QtCore.QPoint(int(ref_rect.width() * 0.5), ref_rect.top())
        ref_pos = widget.mapToGlobal(ref_pos)

        rect = self.rect()
        rect.setWidth(ref_rect.width())
        self.setGeometry(rect)

        pos = QtCore.QPoint(int(rect.width() * 0.5), rect.top())

        delta = ref_pos - pos
        self.move(delta)

        # Set start and end values for animation
        start_value = self.geometry()
        start_value.setHeight(0)
        end_value = self.geometry()

        self.show()

        anim = QtCore.QPropertyAnimation(
            self,
            QtCore.QByteArray('geometry'.encode()),
            parent=self,
        )
        anim.setDuration(150)
        anim.setEasingCurve(QtCore.QEasingCurve.OutQuad)
        anim.setStartValue(start_value)
        anim.setEndValue(end_value)
        anim.start()
        QtCore.QTimer.singleShot(duration, self._hide_top)
示例#2
0
    def __init__(self, intSize=50, parent=None):
        QtGui.QWidget.__init__(self, parent)

        # Load the file into a QMovie

        self.movie = QtGui.QMovie(getRessources("preloader_%i.gif" % intSize),
                                  QtCore.QByteArray(), self)

        size = self.movie.scaledSize()
        self.setGeometry(intSize, intSize, size.width(), size.height())

        self.movie_screen = QtGui.QLabel(parent=self)
        # Make label fit the gif
        #self.movie_screen.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        self.movie_screen.setAlignment(QtCore.Qt.AlignLeft)

        # Create the layout
        main_layout = QtGui.QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        main_layout.addWidget(self.movie_screen)

        self.setLayout(main_layout)

        # Add the QMovie object to the label
        self.movie.setCacheMode(QtGui.QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.movie.start()
示例#3
0
    def _set_thumbnail(self):
        if os.path.exists(self._thumb_path):
            self.treeWidget().itemWidget(
                self, self._column_names.index_name('thumb'))
            if not self.treeWidget().itemWidget(
                    self, self._column_names.index_name('thumb')):
                image = QtGui.QPixmap(self._thumb_path)
                self.setSizeHint(self._column_names.index_name('thumb'),
                                 image.size())

                thumbnail = QtGui.QLabel("", self.treeWidget())
                thumbnail.setAlignment(QtCore.Qt.AlignHCenter)
                thumbnail.setPixmap(image)
                self.treeWidget().setItemWidget(
                    self, self._column_names.index_name('thumb'), thumbnail)

                # add to json data
                ba = QtCore.QByteArray()
                buff = QtCore.QBuffer(ba)
                buff.open(QtCore.QIODevice.WriteOnly)
                image.save(buff, "JPG")

                if sys.version_info.major == 2:
                    self._fields['data']['thumb'] = ba.toBase64().data()
                elif sys.version_info.major == 3:
                    self._fields['data']['thumb'] = ba.toBase64().data(
                    ).decode('UTF-8')

                # remove tmp file
                os.remove(self._thumb_path)
        elif 'thumb' in self._fields['data'].keys():
            thumb_bytes = None

            if sys.version_info.major == 2:
                thumb_bytes = self._fields['data']['thumb'].encode("utf-8")
            elif sys.version_info.major == 3:
                thumb_bytes = bytes(self._fields['data']['thumb'], 'UTF-8')
            ba = QtCore.QByteArray.fromBase64(thumb_bytes)
            image = QtGui.QPixmap()
            image.loadFromData(ba, "JPG")

            thumbnail = QtGui.QLabel("", self.treeWidget())
            thumbnail.setAlignment(QtCore.Qt.AlignHCenter)
            thumbnail.setPixmap(image)
            self.treeWidget().setItemWidget(
                self, self._column_names.index_name('thumb'), thumbnail)
        else:
            msg = "Could not find thumnail at '%s'. Failed to generate it!" % (
                self._thumb_path)
            self._panel._app.log_error(msg)
示例#4
0
    def _hide_top(self):
        start_value = self.geometry()
        end_value = self.geometry()
        end_value.setHeight(0)

        anim = QtCore.QPropertyAnimation(
            self,
            QtCore.QByteArray('geometry'.encode()),
            parent=self,
        )
        anim.setDuration(150)
        anim.setEasingCurve(QtCore.QEasingCurve.OutQuad)
        anim.setStartValue(start_value)
        anim.setEndValue(end_value)
        anim.finished.connect(self.close)
        anim.start()
示例#5
0
    def _send(self, request):
        # make sure we are connected
        if self.connection.state() in (
            QtNetwork.QAbstractSocket.SocketState.UnconnectedState,
        ):
            self.connect_to_host()

        block = QtCore.QByteArray()

        outstr = QtCore.QDataStream(block, QtCore.QIODevice.WriteOnly)
        outstr.setVersion(QtCore.QDataStream.Qt_4_6)

        outstr.writeString(str(request))

        self.connection.write(block)

        if not self.connection.waitForBytesWritten(MAX_WRITE_RESPONSE_TIME):
            logger.error("Could not write to socket: %s" % self.connection.errorString())
        else:
            logger.debug("Sent data ok. %s" % self.connection.state())