コード例 #1
0
ファイル: thumbnail.py プロジェクト: kzwkt/dff
    class __ThumbnailManager(QObject):
        def __init__(self):
            QObject.__init__(self)
            self.pixmapCache = QPixmapCache()
            self.pixmapCache.setCacheLimit(61440)
            self.thread = QThread()
            self.scaler = Scaler()
            self.scaler.moveToThread(self.thread)
            self.connect(self.scaler, SIGNAL("scaledFinished"), self.finished)
            self.thread.start()
            self.thumbnailers = []
            self.handledRequest = set()
            self.corruptionHandler = CorruptedPictureHandler()
            self.pixmapCorrupted = QPixmap(":file_broken.png")

        def register(self, thumbnailer):
            self.thumbnailers.append(thumbnailer)

        def unregister(self, thumbnailer):
            try:
                self.thumbnailers.remove(thumbnailer)
            except:
                pass

        def generate(self, config):
            pixmap = self.pixmapCache.find(str(config))
            if pixmap:
                return pixmap
            elif self.corruptionHandler.isCorrupted(config.node):
                return self.pixmapCorrupted
            else:
                if config not in self.handledRequest:
                    QApplication.postEvent(self.scaler, ScaleEvent(config))
                    self.handledRequest.add(config)

        def finished(self, config, scaledImage):
            if scaledImage:
                pixmap = QPixmap().fromImage(scaledImage)
                self.pixmapCache.insert(str(config), pixmap)
                self.emitUpdate(config, pixmap)
            else:
                self.corruptionHandler.setAttributes(config.node)
                self.emitUpdate(config, self.pixmapCorrupted)

        def emitUpdate(self, config, pixmap):
            for thumbnailer in self.thumbnailers:
                try:
                    if thumbnailer.request(config):
                        thumbnailer.emit(SIGNAL("ThumbnailUpdate"),
                                         config.node, pixmap)
                        thumbnailer.requestRemove(config)
                except:
                    pass
            try:
                self.handledRequest.remove(config)
            except KeyError:
                pass
コード例 #2
0
ファイル: thumbnail.py プロジェクト: arxsys/dff-api
    class __ThumbnailManager(QObject):
        def __init__(self):
            QObject.__init__(self)
            self.pixmapCache = QPixmapCache()
            self.pixmapCache.setCacheLimit(61440)
            self.thread = QThread()
            self.scaler = Scaler()
            self.scaler.moveToThread(self.thread)
            self.connect(self.scaler, SIGNAL("scaledFinished"), self.finished)
            self.thread.start()
            self.thumbnailers = []
            self.handledRequest = set()
            self.corruptionHandler = CorruptedPictureHandler()
            self.pixmapCorrupted = QPixmap(":file_broken.png")

        def register(self, thumbnailer):
            self.thumbnailers.append(thumbnailer)

        def unregister(self, thumbnailer):
            try:
                self.thumbnailers.remove(thumbnailer)
            except:
                pass

        def generate(self, config):
            pixmap = self.pixmapCache.find(str(config))
            if pixmap:
                return pixmap
            elif self.corruptionHandler.isCorrupted(config.node):
                return self.pixmapCorrupted
            else:
                if config not in self.handledRequest:
                    QApplication.postEvent(self.scaler, ScaleEvent(config))
                    self.handledRequest.add(config)

        def finished(self, config, scaledImage):
            if scaledImage:
                pixmap = QPixmap().fromImage(scaledImage)
                self.pixmapCache.insert(str(config), pixmap)
                self.emitUpdate(config, pixmap)
            else:
                self.corruptionHandler.setAttributes(config.node)
                self.emitUpdate(config, self.pixmapCorrupted)

        def emitUpdate(self, config, pixmap):
            for thumbnailer in self.thumbnailers:
                try:
                    if thumbnailer.request(config):
                        thumbnailer.emit(SIGNAL("ThumbnailUpdate"), config.node, pixmap)
                        thumbnailer.requestRemove(config)
                except:
                    pass
            try:
                self.handledRequest.remove(config)
            except KeyError:
                pass
コード例 #3
0
    def __init__(self, desktopFileName=None):
        if desktopFileName is None:
            desktopFileName = 'default'
        self.__svg = None
        self.__pmap = None
        QPixmapCache.setCacheLimit(20480)  # the chinese landscape needs much
        self.defineCatalog()
        self.desktopFileName = desktopFileName
        self.path = locatebackground(desktopFileName + '.desktop')
        if self.path.isEmpty():
            self.path = locatebackground('default.desktop')
            if self.path.isEmpty():
                directories = '\n\n' + '\n'.join(
                    str(x) for x in KGlobal.dirs().resourceDirs(
                        "kmahjonggbackground"))
                logException(BackgroundException(m18n( \
                'cannot find any background in the following directories, is libkmahjongg installed?') + directories))
            else:
                logWarning(
                    m18n('cannot find background %1, using default',
                         desktopFileName))
                self.desktopFileName = 'default'
        config, group = konfigGroup(self.path, "KMahjonggBackground")
        assert config
        self.name = group.readEntry(
            "Name", "unknown background").toString()  # Returns translated data

        #Version control
        backgroundversion, entryOK = group.readEntry("VersionFormat",
                                                     QVariant(0)).toInt()
        #Format is increased when we have incompatible changes, meaning that
        # older clients are not able to use the remaining information safely
        if not entryOK or backgroundversion > BACKGROUNDVERSIONFORMAT:
            logException(BackgroundException('backgroundversion file / program: %d/%d' % \
                (backgroundversion, BACKGROUNDVERSIONFORMAT)))

        self.tiled = group.readEntry('Tiled') == '1'
        if self.tiled:
            self.imageWidth, entryOk = group.readEntry('Width').toInt()
            if not entryOk:
                raise Exception('cannot scan Width from background file')
            self.imageHeight, entryOk = group.readEntry('Height').toInt()
            if not entryOk:
                raise Exception('cannot scan Height from background file')
        self.isPlain = bool(group.readEntry('Plain'))
        if not self.isPlain:
            graphName = QString(group.readEntry("FileName"))
            self.__graphicspath = locatebackground(graphName)
            if self.__graphicspath.isEmpty():
                logException(BackgroundException(
                    'cannot find kmahjongglib/backgrounds/%s for %s' % \
                        (graphName, self.desktopFileName )))
コード例 #4
0
ファイル: background.py プロジェクト: jsj2008/kdegames
    def __init__(self, desktopFileName=None):
        if desktopFileName is None:
            desktopFileName = 'default'
        self.__svg = None
        self.__pmap = None
        QPixmapCache.setCacheLimit(20480) # the chinese landscape needs much
        self.defineCatalog()
        self.desktopFileName = desktopFileName
        self.path = locatebackground(desktopFileName + '.desktop')
        if self.path.isEmpty():
            self.path = locatebackground('default.desktop')
            if self.path.isEmpty():
                directories = '\n\n' +'\n'.join(str(x) for x in KGlobal.dirs().resourceDirs("kmahjonggbackground"))
                logException(BackgroundException(m18n( \
                'cannot find any background in the following directories, is libkmahjongg installed?') + directories))
            else:
                logWarning(m18n('cannot find background %1, using default', desktopFileName))
                self.desktopFileName = 'default'
        config, group = konfigGroup(self.path, "KMahjonggBackground")
        assert config
        self.name = group.readEntry("Name", "unknown background").toString() # Returns translated data

        #Version control
        backgroundversion, entryOK = group.readEntry("VersionFormat", QVariant(0)).toInt()
        #Format is increased when we have incompatible changes, meaning that
        # older clients are not able to use the remaining information safely
        if not entryOK or backgroundversion > BACKGROUNDVERSIONFORMAT:
            logException(BackgroundException('backgroundversion file / program: %d/%d' % \
                (backgroundversion, BACKGROUNDVERSIONFORMAT)))

        self.tiled = group.readEntry('Tiled') == '1'
        if self.tiled:
            self.imageWidth, entryOk = group.readEntry('Width').toInt()
            if not entryOk:
                raise Exception('cannot scan Width from background file')
            self.imageHeight, entryOk = group.readEntry('Height').toInt()
            if not entryOk:
                raise Exception('cannot scan Height from background file')
        self.isPlain = bool(group.readEntry('Plain'))
        if not self.isPlain:
            graphName = QString(group.readEntry("FileName"))
            self.__graphicspath = locatebackground(graphName)
            if self.__graphicspath.isEmpty():
                logException(BackgroundException(
                    'cannot find kmahjongglib/backgrounds/%s for %s' % \
                        (graphName, self.desktopFileName )))
コード例 #5
0
ファイル: EkdWidgets.py プロジェクト: Ptaah/Ekd
 def __init__(self, imagePath, width=64, height=0, quality=0, Cache=True, keepRatio=True, magnify=False):
     """
     imagePath : chemin de l'image a charger
     size : taille de la préview a générer
     quality : qualité de la preview (0=mavaise, 10=très bonne)
     keepRation : garde-t-on les proportion de l'image
     magnify : agrandit-on l'image si la preview demandée est plus grande que l'image originale
     """
     self.preview = QPixmap()
     if width == 0:
         width = 64
     if height == 0:
         height = width
     self.size = QSize(width, height)
     self.quality = quality
     self.imageName = imagePath
     self.keepRatio = keepRatio
     self.magnify = magnify
     self.cache = Cache
     QPixmapCache.setCacheLimit(50*1024)
     self.update()
コード例 #6
0
#
#   \author     Dr. D Studios
#   \date       08/09/11
#

from PyQt4.QtCore import Qt

from PyQt4.QtGui                import  QPixmap,\
                                        QPixmapCache

from ....delegates.griddelegate import GridDelegate
from ..... import settings
from ..... import resources

# up the cache limit since this is a graphics heavy app
QPixmapCache.setCacheLimit(10240 * 48)  # in kilobytes


class ThumbnailDelegate(GridDelegate):
    def drawOverlay(self, painter, option, index):
        """
                Paints the overlay color for this item if the current thumbnail
                based on whether or not it is the latest thumbnail available
                
                :param      painter:
                :type       <QPainter>:
                
                :param      option:
                :param      <QStyleOptionItem>:
                
                :param      index:
コード例 #7
0
#               in the playlistwidget
#
#   \author     Dr. D Studios
#   \date       08/09/11
#

from PyQt4.QtCore import Qt

from PyQt4.QtGui import QPixmap, QPixmapCache

from ....delegates.griddelegate import GridDelegate
from ..... import settings
from ..... import resources

# up the cache limit since this is a graphics heavy app
QPixmapCache.setCacheLimit(10240 * 48)  # in kilobytes


class ThumbnailDelegate(GridDelegate):
    def drawOverlay(self, painter, option, index):
        """
                Paints the overlay color for this item if the current thumbnail
                based on whether or not it is the latest thumbnail available
                
                :param      painter:
                :type       <QPainter>:
                
                :param      option:
                :param      <QStyleOptionItem>:
                
                :param      index:
コード例 #8
0
ファイル: vfsitemmodel.py プロジェクト: halbbob/dff
from api.types.libtypes import Variant, vtime
from api.vfs.libvfs import VFS
from api.events.libevents import EventHandler

from Queue import *

HNAME = 0
HSIZE = 1
HMODULE = 2
HCHANGED = 3
HMODIFIED = 4
HACCESSED = 5

pixmapCache = QPixmapCache()
pixmapCache.setCacheLimit(61440)

class ImageThumb():
  def __init__(self):
    pass

  def getImage(self, type, node, index):
    buff = ""
    tags = None
    img = QImage()
    if type.find('jpeg') != -1:
      try:
        buff = self.getThumb(node)
        load = img.loadFromData(buff, type)
	if load == False:
	 buff = ""
コード例 #9
0
ファイル: thumbsitemmodel.py プロジェクト: alepee/dff
class ThumbsItemModel(QStandardItemModel):
    def __init__(self, thread):
        super(ThumbsItemModel,  self).__init__()
        self.__thread = thread
        self.currentNodeDir = None
        self.initSignals()
        self.pixmapCache = QPixmapCache()     
        self.pixmapCache.setCacheLimit(61440) 
	self.__thread.pixmapCache = self.pixmapCache
 
    def initSignals(self):
        self.connect(self.__thread, 
                     SIGNAL("addIcon"),
                     self.addIcon)
        self.connect(self.__thread, 
                     SIGNAL("addIconFromCache"),
                     self.addIconFromCache)
        self.connect(self.__thread, 
                     SIGNAL("addIconFromImage"),
                     self.addIconFromImage)
   
    def removeAll(self):
        if self.rowCount() > 0:
            for i in range(0,  self.rowCount()) :
                item = self.item(i)
                del item
            self.removeRows(0, self.rowCount())
        self.reset()
    

    def addIcon(self, node):
        item = NodeItem(node)
        if node.next.empty():
          icon = QIcon(":folder_empty_128.png")
        else:
          if node.attr.size != 0: 
   	    icon = QIcon(":folder_documents_128.png") 
          else:
	    icon = QIcon(":folder_128.png")
        item.setIcon(icon)
        item.setText(str(node.name))
        item.setEditable(False)
        items = []
        items.append(item)
        self.appendRow(items)
   
    def addIconFromCache(self, node):
        item = NodeItem(node)
	pixmap = self.pixmapCache.find(node.path + "/" + node.name)
        icon = QIcon(pixmap)
        item.setIcon(icon)
        item.setText(str(node.name))
        item.setEditable(False)
        items = []
        items.append(item)
        self.appendRow(items)

    def addIconFromImage(self, img, node):
        item = NodeItem(node)
        pixmap = QPixmap()
        pixmap = pixmap.fromImage(img)
        self.pixmapCache.insert(node.path + "/" + node.name, pixmap) 
        icon = QIcon(pixmap)
        item.setIcon(icon)
        item.setText(str(node.name))
        item.setEditable(False)
        items = []
        items.append(item)
        self.appendRow(items)
コード例 #10
0
class ThumbsItemModel(QStandardItemModel):
    def __init__(self, thread):
        super(ThumbsItemModel, self).__init__()
        self.__thread = thread
        self.currentNodeDir = None
        self.initSignals()
        self.pixmapCache = QPixmapCache()
        self.pixmapCache.setCacheLimit(61440)
        self.__thread.pixmapCache = self.pixmapCache

    def initSignals(self):
        self.connect(self.__thread, SIGNAL("addIcon"), self.addIcon)
        self.connect(self.__thread, SIGNAL("addIconFromCache"),
                     self.addIconFromCache)
        self.connect(self.__thread, SIGNAL("addIconFromImage"),
                     self.addIconFromImage)

    def removeAll(self):
        if self.rowCount() > 0:
            for i in range(0, self.rowCount()):
                item = self.item(i)
                del item
            self.removeRows(0, self.rowCount())
        self.reset()

    def addIcon(self, node):
        item = NodeItem(node)
        if node.next.empty():
            icon = QIcon(":folder_empty_128.png")
        else:
            if node.attr.size != 0:
                icon = QIcon(":folder_documents_128.png")
            else:
                icon = QIcon(":folder_128.png")
        item.setIcon(icon)
        item.setText(str(node.name))
        item.setEditable(False)
        items = []
        items.append(item)
        self.appendRow(items)

    def addIconFromCache(self, node):
        item = NodeItem(node)
        pixmap = self.pixmapCache.find(node.path + "/" + node.name)
        icon = QIcon(pixmap)
        item.setIcon(icon)
        item.setText(str(node.name))
        item.setEditable(False)
        items = []
        items.append(item)
        self.appendRow(items)

    def addIconFromImage(self, img, node):
        item = NodeItem(node)
        pixmap = QPixmap()
        pixmap = pixmap.fromImage(img)
        self.pixmapCache.insert(node.path + "/" + node.name, pixmap)
        icon = QIcon(pixmap)
        item.setIcon(icon)
        item.setText(str(node.name))
        item.setEditable(False)
        items = []
        items.append(item)
        self.appendRow(items)