class DocumentPropertiesWidget(QObject):
    def __init__(self, fileInfo, gallery, parent=None):
        QObject.__init__(self, parent)

        self.parent = parent
        self.request = QGalleryQueryRequest(gallery, self)
        self.request.setFilter(QDocumentGallery.filePath.equals(fileInfo))
        self.resultSet = None

        self.propertyKeys = []
        self.dialogContent = []
        self.propertyLabels = {}

        propertyNames = [
            QDocumentGallery.fileName, QDocumentGallery.mimeType,
            QDocumentGallery.path, QDocumentGallery.fileSize,
            QDocumentGallery.lastModified, QDocumentGallery.lastAccessed
        ]

        labels = [
            self.tr('File Name'),
            self.tr('Type'),
            self.tr('Path'),
            self.tr('Size'),
            self.tr('Modified'),
            self.tr('Accessed')
        ]

        self.requestProperties(QDocumentGallery.File, propertyNames, labels)

    def itemsInserted(self, index, count):
        self.resultSet.fetch(0)

        self.metaDataChanged(index, count, [])

        if index == 0 and str(self.request.rootType()) == str(
                QDocumentGallery.File):
            itemType = self.resultSet.itemType()

            if str(itemType) == str(QDocumentGallery.Audio):
                QTimer.singleShot(0, self.requestAudioProperties)
            elif str(itemType) == str(QDocumentGallery.Document):
                QTimer.singleShot(0, self.requestDocumentProperties)
            elif str(itemType) == str(QDocumentGallery.Image):
                QTimer.singleShot(0, self.requestImageProperties)
            elif str(itemType) == str(QDocumentGallery.Video):
                QTimer.singleShot(0, self.requestVideoProperties)

    def itemsRemoved(self, index, count):
        self.metaDataChanged(index, count, [])

    def metaDataChanged(self, index, count, keys):
        if index == 0:
            if not keys:
                for i, key in enumerate(self.propertyKeys):
                    self.updateValue(i, self.resultSet.propertyKey(str(key)))
            else:
                for key in keys:
                    i = self.propertyKeys.index(key)
                    if i >= 0:
                        self.updateValue(i, key)

    def requestAudioProperties(self):
        propertyNames = [
            QDocumentGallery.title, QDocumentGallery.artist,
            QDocumentGallery.albumTitle, QDocumentGallery.albumArtist,
            QDocumentGallery.genre, QDocumentGallery.duration
        ]

        labels = [
            self.tr('Title'),
            self.tr('Artist'),
            self.tr('Album'),
            self.tr('Album Artist'),
            self.tr('Genre'),
            self.tr('Duration')
        ]

        self.requestProperties(QDocumentGallery.Audio, propertyNames, labels)

    def requestDocumentProperties(self):
        propertyNames = [
            QDocumentGallery.title, QDocumentGallery.author,
            QDocumentGallery.pageCount
        ]

        labels = [self.tr('Title'), self.tr('Author'), self.tr('Page Count')]

        self.requestProperties(QDocumentGallery.Document, propertyNames,
                               labels)

    def requestImageProperties(self):
        propertyNames = [
            QDocumentGallery.title,
            QDocumentGallery.width,
            QDocumentGallery.height,
        ]

        labels = [
            self.tr('Title'),
            self.tr('Width'),
            self.tr('Height'),
        ]

        self.requestProperties(QDocumentGallery.Image, propertyNames, labels)

    def requestVideoProperties(self):
        propertyNames = [
            QDocumentGallery.title, QDocumentGallery.width,
            QDocumentGallery.height, QDocumentGallery.duration
        ]

        labels = [
            self.tr('Title'),
            self.tr('Width'),
            self.tr('Height'),
            self.tr('Duration')
        ]

        self.requestProperties(QDocumentGallery.Video, propertyNames, labels)

    def requestProperties(self, itemType, propertyNames, labels):
        currentPropertyNames = self.request.propertyNames()

        self.request.setRootType(str(itemType))
        self.request.setPropertyNames(
            map(str, currentPropertyNames + propertyNames))
        self.request.execute()

        self.resultSet = self.request.resultSet()

        if self.resultSet:
            self.resultSet.itemsInserted.connect(self.itemsInserted)
            self.resultSet.itemsRemoved.connect(self.itemsRemoved)
            self.resultSet.metaDataChanged.connect(self.metaDataChanged)

            for i, propertyName in enumerate(currentPropertyNames):
                self.propertyKeys[i] = propertyName

            for i, propertyName in enumerate(propertyNames):
                self.insertRow(i, propertyName, labels[i])

            if self.resultSet.itemCount():
                self.itemsInserted(0, self.resultSet.itemCount())

    def insertRow(self, index, propertyName, label):
        propertyKey = self.resultSet.propertyKey(str(propertyName))

        propertyType = self.resultSet.propertyType(propertyKey)
        propertyAttributes = self.resultSet.propertyAttributes(propertyKey)

        self.dialogContent.insert(index, label)
        self.propertyKeys.insert(index, propertyName)
        self.propertyLabels[str(propertyName)] = label

    def updateValue(self, widgetIndex, propertyKey):
        propertyAttributes = self.resultSet.propertyAttributes(propertyKey)

        value = self.resultSet.metaData(propertyKey)

        data = ""
        if isinstance(value, float) or isinstance(value, int):
            data = str(value)
        elif isinstance(value, QDate):
            data = value.toString()
        elif isinstance(value, QTime):
            data = value.toString()
        elif isinstance(value, QDateTime):
            data = value.toString()
        elif isinstance(value, list):
            data = str('; '.join(value))
        elif isinstance(value, QImage) or isinstance(value, QPixmap):
            data = "Image not supported yet!"
        else:
            data = value

        self.dialogContent[widgetIndex] = self.propertyLabels[str(
            self.propertyKeys[widgetIndex])] + ": " + data
        self.parent.updateDialog.emit()
示例#2
0
class DocumentPropertiesWidget(QWidget):
    def __init__(self, fileInfo, gallery, parent=None, flags=Qt.Widget):
        QWidget.__init__(self, parent, flags)

        self.setLayout(QFormLayout(parent=self))
        self.request = QGalleryQueryRequest(gallery, self)
        self.request.setFilter(
            QDocumentGallery.filePath.equals(fileInfo.absoluteFilePath()))
        self.resultSet = None

        self.propertyKeys = []
        self.widgets = []

        propertyNames = [
            QDocumentGallery.fileName,
            QDocumentGallery.mimeType,
            QDocumentGallery.path,
            QDocumentGallery.fileSize,
            QDocumentGallery.lastModified,
            QDocumentGallery.lastAccessed,
        ]

        labels = [
            self.tr('File Name'),
            self.tr('Type'),
            self.tr('Path'),
            self.tr('Size'),
            self.tr('Modified'),
            self.tr('Accessed'),
        ]

        self.requestProperties(QDocumentGallery.File, propertyNames, labels)

    def itemsInserted(self, index, count):
        self.resultSet.fetch(0)

        self.metaDataChanged(index, count, [])

        if index == 0 and self.request.rootType() == QDocumentGallery.File:
            itemType = self.resultSet.itemType()

            if itemType == QDocumentGallery.Audio:
                QTimer.singleShot(0, self.requestAudioProperties)
            elif itemType == QDocumentGallery.Document:
                QTimer.singleShot(0, self.requestDocumentProperties)
            elif itemType == QDocumentGallery.Image:
                QTimer.singleShot(0, self.requestImageProperties)
            elif itemType == QDocumentGallery.Video:
                QTimer.singleShot(0, self.requestVideoProperties)

    def itemsRemoved(self, index, count):
        self.metaDataChanged(index, count, [])

    def metaDataChanged(self, index, count, keys):
        if index == 0:
            if not keys:
                for i, key in enumerate(self.propertyKeys):
                    self.updateValue(i, key)
            else:
                for key in keys:
                    i = self.propertyKeys.index(key)
                    if i >= 0:
                        self.updateValue(i, key)

    def requestAudioProperties(self):
        propertyNames = [
            QDocumentGallery.title,
            QDocumentGallery.artist,
            QDocumentGallery.albumTitle,
            QDocumentGallery.albumArtist,
            QDocumentGallery.genre,
            QDocumentGallery.duration,
        ]

        labels = [
            self.tr('Title'),
            self.tr('Artist'),
            self.tr('Album'),
            self.tr('Album Artist'),
            self.tr('Genre'),
            self.tr('Duration'),
        ]

        self.requestProperties(QDocumentGallery.Audio, propertyNames, labels)

    def requestDocumentProperties(self):
        propertyNames = [
            QDocumentGallery.title,
            QDocumentGallery.author,
            QDocumentGallery.pageCount,
        ]

        labels = [
            self.tr('Title'),
            self.tr('Author'),
            self.tr('Page Count'),
        ]

        self.requestProperties(QDocumentGallery.Document, propertyNames,
                               labels)

    def requestImageProperties(self):
        propertyNames = [
            QDocumentGallery.title,
            QDocumentGallery.width,
            QDocumentGallery.height,
            QDocumentGallery.keywords,
        ]

        labels = [
            self.tr('Title'),
            self.tr('Width'),
            self.tr('Height'),
            self.tr('Keywords'),
        ]

        self.requestProperties(QDocumentGallery.Image, propertyNames, labels)

    def requestVideoProperties(self):
        propertyNames = [
            QDocumentGallery.title,
            QDocumentGallery.width,
            QDocumentGallery.height,
            QDocumentGallery.duration,
        ]

        labels = [
            self.tr('Title'),
            self.tr('Width'),
            self.tr('Height'),
            self.tr('Duration'),
        ]

        self.requestProperties(QDocumentGallery.Video, propertyNames, labels)

    def requestProperties(self, itemType, propertyNames, labels):
        currentPropertyNames = self.request.propertyNames()

        self.request.setRootType(str(itemType))
        self.request.setPropertyNames(
            map(str, propertyNames + currentPropertyNames))
        self.request.execute()

        self.resultSet = self.request.resultSet()

        if self.resultSet:
            self.resultSet.itemsInserted.connect(self.itemsInserted)
            self.resultSet.itemsRemoved.connect(self.itemsRemoved)
            self.resultSet.metaDataChanged.connect(self.metaDataChanged)

            for i, propertyName in enumerate(currentPropertyNames):
                self.propertyKeys[i] = self.resultSet.propertyKey(propertyName)

            for i, propertyName in enumerate(propertyNames):
                self.insertRow(i, propertyName, labels[i])

            if self.resultSet.itemCount():
                self.itemsInserted(0, self.resultSet.itemCount())

    def insertRow(self, index, propertyName, label):
        propertyKey = self.resultSet.propertyKey(str(propertyName))

        propertyType = self.resultSet.propertyType(propertyKey)
        propertyAttributes = self.resultSet.propertyAttributes(propertyKey)

        widget = None

        if propertyAttributes & QGalleryProperty.CanWrite:
            if propertyType == str:
                widget = QLineEdit()
            elif propertyType == float:
                widget = QDoubleSpinBox()
            elif propertyType == int:
                widget = QSpinBox()
            elif propertyType == QDateTime:
                widget = QDateTimeEdit()
            else:
                widget = QLabel()
        elif propertyAttributes & QGalleryProperty.CanRead:
            widget = QLabel()

        self.propertyKeys.insert(index, propertyKey)
        self.widgets.insert(index, widget)

        self.layout().insertRow(index, label, widget)

    def updateValue(self, widgetIndex, propertyKey):
        propertyAttributes = self.resultSet.propertyAttributes(propertyKey)

        widget = self.widgets[widgetIndex]
        value = self.resultSet.metaData(propertyKey)

        if propertyAttributes & QGalleryProperty.CanWrite:
            if isinstance(value, str):
                widget.setText(value)
            elif isinstance(value, float) or isinstance(value, int):
                widget.setValue(value)
            elif isinstance(value, QDate):
                widget.setDate(value)
            elif isinstance(value, QTime):
                widget.setTime(value)
            elif isinstance(value, QDateTime):
                widget.setDateTime(value)
            elif isinstance(value, QImage) or isinstance(value, QPixmap):
                widget.setPixmap(value)
            elif isinstance(value, list):
                widget.setText('; '.join(value))
            else:
                widget.setText(value)
        elif propertyAttributes & QGalleryProperty.CanRead:
            if isinstance(value, list):
                widget.setText('; '.join(value))
            else:
                widget.setText(value)
示例#3
0
class DocumentPropertiesWidget(QWidget):

    def __init__(self, fileInfo, gallery, parent=None, flags=Qt.Widget):
        QWidget.__init__(self, parent, flags)

        self.setLayout(QFormLayout(parent=self))
        self.request = QGalleryQueryRequest(gallery, self)
        self.request.setFilter(QDocumentGallery.filePath.equals(fileInfo.absoluteFilePath()))
        self.resultSet = None

        self.propertyKeys = []
        self.widgets = []

        propertyNames = [
                QDocumentGallery.fileName,
                QDocumentGallery.mimeType,
                QDocumentGallery.path,
                QDocumentGallery.fileSize,
                QDocumentGallery.lastModified,
                QDocumentGallery.lastAccessed,
        ]

        labels = [
                self.tr('File Name'),
                self.tr('Type'),
                self.tr('Path'),
                self.tr('Size'),
                self.tr('Modified'),
                self.tr('Accessed'),
        ]

        self.requestProperties(QDocumentGallery.File, propertyNames, labels)

    def itemsInserted(self, index, count):
        self.resultSet.fetch(0)

        self.metaDataChanged(index, count, [])

        if index == 0 and self.request.rootType() == QDocumentGallery.File:
            itemType = self.resultSet.itemType()

            if itemType == QDocumentGallery.Audio:
                QTimer.singleShot(0, self.requestAudioProperties)
            elif itemType == QDocumentGallery.Document:
                QTimer.singleShot(0, self.requestDocumentProperties)
            elif itemType == QDocumentGallery.Image:
                QTimer.singleShot(0, self.requestImageProperties)
            elif itemType == QDocumentGallery.Video:
                QTimer.singleShot(0, self.requestVideoProperties)


    def itemsRemoved(self, index, count):
        self.metaDataChanged(index, count, [])

    def metaDataChanged(self, index, count, keys):
        if index == 0:
            if not keys:
                for i, key in enumerate(self.propertyKeys):
                    self.updateValue(i, key)
            else:
                for key in keys:
                    i = self.propertyKeys.index(key)
                    if i >= 0:
                        self.updateValue(i, key)

    def requestAudioProperties(self):
        propertyNames = [
                QDocumentGallery.title,
                QDocumentGallery.artist,
                QDocumentGallery.albumTitle,
                QDocumentGallery.albumArtist,
                QDocumentGallery.genre,
                QDocumentGallery.duration,
        ]

        labels = [
                self.tr('Title'),
                self.tr('Artist'),
                self.tr('Album'),
                self.tr('Album Artist'),
                self.tr('Genre'),
                self.tr('Duration'),
        ]

        self.requestProperties(QDocumentGallery.Audio, propertyNames, labels)

    def requestDocumentProperties(self):
        propertyNames = [
                QDocumentGallery.title,
                QDocumentGallery.author,
                QDocumentGallery.pageCount,
        ]

        labels = [
                self.tr('Title'),
                self.tr('Author'),
                self.tr('Page Count'),
        ]

        self.requestProperties(QDocumentGallery.Document, propertyNames, labels)

    def requestImageProperties(self):
        propertyNames = [
                QDocumentGallery.title,
                QDocumentGallery.width,
                QDocumentGallery.height,
                QDocumentGallery.keywords,
        ]

        labels = [
                self.tr('Title'),
                self.tr('Width'),
                self.tr('Height'),
                self.tr('Keywords'),
        ]

        self.requestProperties(QDocumentGallery.Image, propertyNames, labels)

    def requestVideoProperties(self):
        propertyNames = [
                QDocumentGallery.title,
                QDocumentGallery.width,
                QDocumentGallery.height,
                QDocumentGallery.duration,
        ]

        labels = [
                self.tr('Title'),
                self.tr('Width'),
                self.tr('Height'),
                self.tr('Duration'),
        ]

        self.requestProperties(QDocumentGallery.Video, propertyNames, labels)

    def requestProperties(self, itemType, propertyNames, labels):
        currentPropertyNames = self.request.propertyNames()

        self.request.setRootType(str(itemType))
        self.request.setPropertyNames(map(str, propertyNames + currentPropertyNames))
        self.request.execute()

        self.resultSet = self.request.resultSet()

        if self.resultSet:
            self.resultSet.itemsInserted.connect(self.itemsInserted)
            self.resultSet.itemsRemoved.connect(self.itemsRemoved)
            self.resultSet.metaDataChanged.connect(self.metaDataChanged)

            for i, propertyName in enumerate(currentPropertyNames):
                self.propertyKeys[i] = self.resultSet.propertyKey(propertyName)

            for i, propertyName in enumerate(propertyNames):
                self.insertRow(i, propertyName, labels[i])

            if self.resultSet.itemCount():
                self.itemsInserted(0, self.resultSet.itemCount())

    def insertRow(self, index, propertyName, label):
        propertyKey = self.resultSet.propertyKey(str(propertyName))

        propertyType = self.resultSet.propertyType(propertyKey)
        propertyAttributes = self.resultSet.propertyAttributes(propertyKey)

        widget = None

        if propertyAttributes & QGalleryProperty.CanWrite:
            if propertyType == str:
                widget = QLineEdit()
            elif propertyType == float:
                widget = QDoubleSpinBox()
            elif propertyType == int:
                widget = QSpinBox()
            elif propertyType == QDateTime:
                widget = QDateTimeEdit()
            else:
                widget = QLabel()
        elif propertyAttributes & QGalleryProperty.CanRead:
            widget = QLabel()

        self.propertyKeys.insert(index, propertyKey)
        self.widgets.insert(index, widget)

        self.layout().insertRow(index, label, widget)

    def updateValue(self, widgetIndex, propertyKey):
        propertyAttributes = self.resultSet.propertyAttributes(propertyKey)

        widget = self.widgets[widgetIndex]
        value = self.resultSet.metaData(propertyKey)

        if propertyAttributes & QGalleryProperty.CanWrite:
            if isinstance(value, str):
                widget.setText(value)
            elif isinstance(value, float) or isinstance(value, int):
                widget.setValue(value)
            elif isinstance(value, QDate):
                widget.setDate(value)
            elif isinstance(value, QTime):
                widget.setTime(value)
            elif isinstance(value, QDateTime):
                widget.setDateTime(value)
            elif isinstance(value, QImage) or isinstance(value, QPixmap):
                widget.setPixmap(value)
            elif isinstance(value, list):
                widget.setText('; '.join(value))
            else:
                widget.setText(value)
        elif propertyAttributes & QGalleryProperty.CanRead:
            if isinstance(value, list):
                widget.setText('; '.join(value))
            else:
                widget.setText(unicode(value))
示例#4
0
class DocumentPropertiesWidget(QObject):

    def __init__(self, fileInfo, gallery, parent=None):
        QObject.__init__(self, parent)

        self.parent = parent
        self.request = QGalleryQueryRequest(gallery, self)
        self.request.setFilter(QDocumentGallery.filePath.equals(fileInfo))
        self.resultSet = None

        self.propertyKeys = []
        self.dialogContent = []
        self.propertyLabels = {}

        propertyNames = [
                QDocumentGallery.fileName,
                QDocumentGallery.mimeType,
                QDocumentGallery.path,
                QDocumentGallery.fileSize,
                QDocumentGallery.lastModified,
                QDocumentGallery.lastAccessed
        ]

        labels = [
                self.tr('File Name'),
                self.tr('Type'),
                self.tr('Path'),
                self.tr('Size'),
                self.tr('Modified'),
                self.tr('Accessed')
        ]

        self.requestProperties(QDocumentGallery.File, propertyNames, labels)

    def itemsInserted(self, index, count):
        self.resultSet.fetch(0)

        self.metaDataChanged(index, count, [])

        if index == 0 and str(self.request.rootType()) == str(QDocumentGallery.File):
            itemType = self.resultSet.itemType()

            if str(itemType) == str(QDocumentGallery.Audio):
                QTimer.singleShot(0, self.requestAudioProperties)
            elif str(itemType) == str(QDocumentGallery.Document):
                QTimer.singleShot(0, self.requestDocumentProperties)
            elif str(itemType) == str(QDocumentGallery.Image):
                QTimer.singleShot(0, self.requestImageProperties)
            elif str(itemType) == str(QDocumentGallery.Video):
                QTimer.singleShot(0, self.requestVideoProperties)


    def itemsRemoved(self, index, count):
        self.metaDataChanged(index, count, [])

    def metaDataChanged(self, index, count, keys):
        if index == 0:
            if not keys:
                for i, key in enumerate(self.propertyKeys):
                    self.updateValue(i, self.resultSet.propertyKey(str(key)))
            else:
                for key in keys:
                    i = self.propertyKeys.index(key)
                    if i >= 0:
                        self.updateValue(i, key)

    def requestAudioProperties(self):
        propertyNames = [
                QDocumentGallery.title,
                QDocumentGallery.artist,
                QDocumentGallery.albumTitle,
                QDocumentGallery.albumArtist,
                QDocumentGallery.genre,
                QDocumentGallery.duration
        ]

        labels = [
                self.tr('Title'),
                self.tr('Artist'),
                self.tr('Album'),
                self.tr('Album Artist'),
                self.tr('Genre'),
                self.tr('Duration')
        ]

        self.requestProperties(QDocumentGallery.Audio, propertyNames, labels)

    def requestDocumentProperties(self):
        propertyNames = [
                QDocumentGallery.title,
                QDocumentGallery.author,
                QDocumentGallery.pageCount
        ]

        labels = [
                self.tr('Title'),
                self.tr('Author'),
                self.tr('Page Count')
        ]

        self.requestProperties(QDocumentGallery.Document, propertyNames, labels)

    def requestImageProperties(self):
        propertyNames = [
                QDocumentGallery.title,
                QDocumentGallery.width,
                QDocumentGallery.height,
        ]

        labels = [
                self.tr('Title'),
                self.tr('Width'),
                self.tr('Height'),
        ]

        self.requestProperties(QDocumentGallery.Image, propertyNames, labels)

    def requestVideoProperties(self):
        propertyNames = [
                QDocumentGallery.title,
                QDocumentGallery.width,
                QDocumentGallery.height,
                QDocumentGallery.duration
        ]

        labels = [
                self.tr('Title'),
                self.tr('Width'),
                self.tr('Height'),
                self.tr('Duration')
        ]

        self.requestProperties(QDocumentGallery.Video, propertyNames, labels)

    def requestProperties(self, itemType, propertyNames, labels):
        currentPropertyNames = self.request.propertyNames()

        self.request.setRootType(str(itemType))
        self.request.setPropertyNames(map(str, currentPropertyNames + propertyNames))
        self.request.execute()

        self.resultSet = self.request.resultSet()

        if self.resultSet:
            self.resultSet.itemsInserted.connect(self.itemsInserted)
            self.resultSet.itemsRemoved.connect(self.itemsRemoved)
            self.resultSet.metaDataChanged.connect(self.metaDataChanged)

            for i, propertyName in enumerate(currentPropertyNames):
                self.propertyKeys[i] = propertyName

            for i, propertyName in enumerate(propertyNames):
                self.insertRow(i, propertyName, labels[i])

            if self.resultSet.itemCount():
                self.itemsInserted(0, self.resultSet.itemCount())

    def insertRow(self, index, propertyName, label):
        propertyKey = self.resultSet.propertyKey(str(propertyName))

        propertyType = self.resultSet.propertyType(propertyKey)
        propertyAttributes = self.resultSet.propertyAttributes(propertyKey)

        self.dialogContent.insert(index, label)
        self.propertyKeys.insert(index, propertyName)
        self.propertyLabels[str(propertyName)] = label

    def updateValue(self, widgetIndex, propertyKey):
        propertyAttributes = self.resultSet.propertyAttributes(propertyKey)

        value = self.resultSet.metaData(propertyKey)

        data = ""
        if isinstance(value, float) or isinstance(value, int):
            data = str(value)
        elif isinstance(value, QDate):
            data = value.toString()
        elif isinstance(value, QTime):
            data = value.toString()
        elif isinstance(value, QDateTime):
            data = value.toString()
        elif isinstance(value, list):
            data = str('; '.join(value))
        elif isinstance(value, QImage) or isinstance(value, QPixmap):
            data = "Image not supported yet!"
        else:
            data = value

        self.dialogContent[widgetIndex] = self.propertyLabels[str(self.propertyKeys[widgetIndex])] + ": " + data
        self.parent.updateDialog.emit()