Beispiel #1
0
 def store_file(self, id, file):
     directory = ApplicationData.get('images')
     filename = os.path.join(directory, id + '.png')
     if filename == os.path.normpath(file):
         return self.iconmap.get(id, None)
     makedirs(directory)
     pixmap = QPixmap()
     if file is not None and pixmap.load(file):
         if pixmap.size().width() > self.max_size or pixmap.size().height(
         ) > self.max_size:
             pixmap = pixmap.scaled(self.max_size, self.max_size,
                                    Qt.KeepAspectRatio,
                                    Qt.SmoothTransformation)
         buffer = QBuffer()
         pixmap.save(buffer, 'png')
         data = str(buffer.data())
         with open(filename, 'wb') as f:
             f.write(data)
         icon = QIcon(pixmap)
         icon.filename = filename
         icon.content = data
     else:
         unlink(filename)
         icon = None
     self.iconmap[id] = icon
     return icon
Beispiel #2
0
 def store_data(self, id, data):
     directory = ApplicationData.get('images')
     filename = os.path.join(directory, id + '.png')
     makedirs(directory)
     pixmap = QPixmap()
     if data is not None and pixmap.loadFromData(data):
         image_size = pixmap.size()
         if image_size.width() > self.max_size or image_size.height(
         ) > self.max_size:
             pixmap = pixmap.scaled(self.max_size, self.max_size,
                                    Qt.KeepAspectRatio,
                                    Qt.SmoothTransformation)
         if imghdr.what(None, data) != 'png' or pixmap.size() != image_size:
             buffer = QBuffer()
             pixmap.save(buffer, 'png')
             data = str(buffer.data())
         with open(filename, 'wb') as f:
             f.write(data)
         icon = QIcon(pixmap)
         icon.filename = filename
         icon.content = data
     else:
         unlink(filename)
         icon = None
     self.iconmap[id] = icon
     return icon
Beispiel #3
0
 def get(self, id):
     try:
         return self.iconmap[id]
     except KeyError:
         pixmap = QPixmap()
         filename = ApplicationData.get(os.path.join('images', id + '.png'))
         try:
             with open(filename, 'rb') as f:
                 data = f.read()
         except (IOError, OSError):
             data = None
         if data is not None and pixmap.loadFromData(data):
             icon = QIcon(pixmap)
             icon.filename = filename
             icon.content = data
         else:
             icon = None
         return self.iconmap.setdefault(id, icon)
Beispiel #4
0
 def get(self, id):
     try:
         return self.iconmap[id]
     except KeyError:
         pixmap = QPixmap()
         filename = ApplicationData.get(os.path.join('images', id + '.png'))
         try:
             with open(filename, 'rb') as f:
                 data = f.read()
         except (IOError, OSError):
             data = None
         if data is not None and pixmap.loadFromData(data):
             icon = QIcon(pixmap)
             icon.filename = filename
             icon.content = data
         else:
             icon = None
         return self.iconmap.setdefault(id, icon)
Beispiel #5
0
 def store_file(self, id, file):
     directory = ApplicationData.get('images')
     filename = os.path.join(directory, id + '.png')
     if filename == os.path.normpath(file):
         return self.iconmap.get(id, None)
     makedirs(directory)
     pixmap = QPixmap()
     if file is not None and pixmap.load(file):
         if pixmap.size().width() > self.max_size or pixmap.size().height() > self.max_size:
             pixmap = pixmap.scaled(self.max_size, self.max_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
         buffer = QBuffer()
         pixmap.save(buffer, 'png')
         data = str(buffer.data())
         with open(filename, 'wb') as f:
             f.write(data)
         icon = QIcon(pixmap)
         icon.filename = filename
         icon.content = data
     else:
         unlink(filename)
         icon = None
     self.iconmap[id] = icon
     return icon
Beispiel #6
0
 def store_data(self, id, data):
     directory = ApplicationData.get('images')
     filename = os.path.join(directory, id + '.png')
     makedirs(directory)
     pixmap = QPixmap()
     if data is not None and pixmap.loadFromData(data):
         image_size = pixmap.size()
         if image_size.width() > self.max_size or image_size.height() > self.max_size:
             pixmap = pixmap.scaled(self.max_size, self.max_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
         if imghdr.what(None, data) != 'png' or pixmap.size() != image_size:
             buffer = QBuffer()
             pixmap.save(buffer, 'png')
             data = str(buffer.data())
         with open(filename, 'wb') as f:
             f.write(data)
         icon = QIcon(pixmap)
         icon.filename = filename
         icon.content = data
     else:
         unlink(filename)
         icon = None
     self.iconmap[id] = icon
     return icon