Ejemplo n.º 1
0
 def load_image(self, data):
     self.is_valid = False
     try:
         fmt = identify_data(data)[-1].encode('ascii')
     except Exception:
         fmt = b''
     self.original_image_format = fmt.decode('ascii').lower()
     self.selection_state.reset()
     self.original_image_data = data
     self.current_image = i = self.original_image = (
         QImage.fromData(data, format=fmt) if fmt else QImage.fromData(data))
     self.is_valid = not i.isNull()
     self.update()
     self.image_changed.emit(self.current_image)
Ejemplo n.º 2
0
 def load_image(self, data):
     self.is_valid = False
     try:
         fmt = identify_data(data)[-1].encode('ascii')
     except Exception:
         fmt = b''
     self.original_image_format = fmt.decode('ascii').lower()
     self.selection_state.reset()
     self.original_image_data = data
     self.current_image = i = self.original_image = (
         QImage.fromData(data, format=fmt) if fmt else QImage.fromData(data))
     self.is_valid = not i.isNull()
     self.update()
     self.image_changed.emit(self.current_image)
Ejemplo n.º 3
0
def magick_to_qimage(img):
    fmt = get_pixel_map()
    # ImageMagick can output only output raw data in some formats that can be
    # read into QImage directly, if the QImage format is not one of those, use
    # PNG
    if fmt in {'RGBA', 'BGRA'}:
        w, h = img.size
        img.depth = 8  # QImage expects 8bpp
        raw = img.export(fmt)
        i = QImage(raw, w, h, QImage.Format_ARGB32)
        del raw  # According to the documentation, raw is supposed to not be deleted, but it works, so make it explicit
        return i
    else:
        raw = img.export('PNG')
        return QImage.fromData(QByteArray(raw), 'PNG')
Ejemplo n.º 4
0
def magick_to_qimage(img):
    fmt = get_pixel_map()
    # ImageMagick can output only output raw data in some formats that can be
    # read into QImage directly, if the QImage format is not one of those, use
    # PNG
    if fmt in {'RGBA', 'BGRA'}:
        w, h = img.size
        img.depth = 8  # QImage expects 8bpp
        raw = img.export(fmt)
        i = QImage(raw, w, h, QImage.Format_ARGB32)
        del raw  # According to the documentation, raw is supposed to not be deleted, but it works, so make it explicit
        return i
    else:
        raw = img.export('PNG')
        return QImage.fromData(QByteArray(raw), 'PNG')
Ejemplo n.º 5
0
 def get_service_icon(self, id, name, url):
     icon, st = None, self.app.preferences.settings
     if not st.contains('icon/'+name):
         icon = get_favicon(url)
         if icon:
             icon = QIcon(QPixmap.fromImage(QImage.fromData(icon)))
             print name, "icon loaded?", not icon.isNull()
             if not icon.isNull():
                 st.setValue('icon/'+name, icon)
         else: print "error while loading", name, "icon"
     else:
         icon = st.value('icon/'+name, None)
         if icon: icon = QIcon(icon)
     if icon:
         self.app.preferences.ui.accountsTabWidget.setTabIcon(id, icon)
     return icon
Ejemplo n.º 6
0
Archivo: icons.py Proyecto: dodo/blain
 def get_service_icon(self, name, url):
     key = "service/" + name
     if key in self.icons:
         return self.icons[key]
     icon, st = None, self.app.accounts.settings
     if not st.contains('icon/'+name):
         icon = get_favicon(url)
         if icon:
             icon = QIcon(QPixmap.fromImage(QImage.fromData(icon)))
             #print name, "icon loaded?", not icon.isNull()
             if not icon.isNull():
                 st.setValue('icon/'+name, icon)
         else: print "[ERROR] while loading", name, "icon"
     else:
         icon = st.value('icon/'+name, None)
         if icon: icon = QIcon(icon)
     if icon:
         self.icons[key] = icon
     return icon