Пример #1
0
                        im = Image.merge("RGB", (r, g, b)) # If no secondary, at least we removed the alpha channel
                else:
                    # Force grayscale
                    im = im.convert('L')

                if SCALE_DOWN is not None:
                    size = im.size
                    im = im.resize((size[0]/SCALE_DOWN, size[1]/SCALE_DOWN), Image.BICUBIC)
                if QUALITY is not None:
                    kwargs = {'quality': QUALITY}
                else:
                    kwargs = {}
                im.save(os.path.join(path, output), **kwargs) # 'JPEG' as second param to force JPEG
            elif TOOL == 'PM':
                im = Image()
                im.read(os.path.join(path, name))
                if QUALITY is not None:
                    im.quality(QUALITY)
                try:
                    im.write(os.path.join(path, output))
                except Exception, e:
                    print "ERROR:", str(e)
            elif TOOL == 'OJ': # OpenJPEG
                curr_command = COMMAND + '-i %s -o %s' % (input_filename, output_filename)
                print '    ' + curr_command
                process = subprocess.Popen(
                    curr_command,
                    shell=True,
                    stdout=subprocess.PIPE,
                ).communicate()
            elif TOOL == 'VIEW':
Пример #2
0
                    im = im.convert('L')

                if SCALE_DOWN is not None:
                    size = im.size
                    im = im.resize(
                        (size[0] / SCALE_DOWN, size[1] / SCALE_DOWN),
                        Image.BICUBIC)
                if QUALITY is not None:
                    kwargs = {'quality': QUALITY}
                else:
                    kwargs = {}
                im.save(os.path.join(path, output),
                        **kwargs)  # 'JPEG' as second param to force JPEG
            elif TOOL == 'PM':
                im = Image()
                im.read(os.path.join(path, name))
                if QUALITY is not None:
                    im.quality(QUALITY)
                try:
                    im.write(os.path.join(path, output))
                except Exception, e:
                    print "ERROR:", str(e)
            elif TOOL == 'OJ':  # OpenJPEG
                curr_command = COMMAND + '-i %s -o %s' % (input_filename,
                                                          output_filename)
                print '    ' + curr_command
                process = subprocess.Popen(
                    curr_command,
                    shell=True,
                    stdout=subprocess.PIPE,
                ).communicate()
Пример #3
0
    def dropEvent(self, event):
        data = event.mimeData()
        if data.hasUrls():
            ul = event.mimeData().urls()
            u = ul.front()
            if u.scheme() == "file":
                fi = QFileInfo(u.path())
                s = Image(None)
                suffix = QString(fi.suffix().toLower())
                if suffix == "svg":
                    s = SvgImage(GL.gscore)
                elif suffix == "jpg" or suffix == "png" or suffix == "xpm":
                    s = RasterImage(GL.gscore)
                else:
                    return
                mag = PALETTE_SPATIUM * self.extraMag / GL.gscore.spatium()
                s.setPath(u.toLocalFile())
                s.setSize(QSizeF(self.hgrid / mag, self.hgrid / mag))
                e = s
                name = s.path()
        elif data.hasFormat(mimeSymbolFormat):
            data = QByteArray(event.mimeData().data(mimeSymbolFormat))
            doc = QDomDocument()
            (ok, err, line, column) = doc.setContent(data)
            if not ok:
                print "error reading drag data\n"
                return
            docName = "--"
            el = doc.documentElement()
            (type, dragOffset, duration) = Element.readType(el)

            if type == ElementType.IMAGE:
                path = QString()
                ee = el.firstChildElement()
                while not ee.isNull():
                    tag = QString(ee.tagName())
                    if tag == "path":
                        path = ee.text()
                        break
                    ee = ee.nextSiblingElement()
                image = 0
                s = QString(path.toLower())
                if s.endsWith(".svg"):
                    image = SvgImage(GL.gscore)
                elif s.endsWith(".jpg") or s.endsWith(".png") or s.endsWith(
                        ".xpm"):
                    image = RasterImage(GL.gscore)
                else:
                    print "unknown image format <%s>\n" % path.toLatin1().data(
                    )
                if image:
                    image.read(el)
                    e = image
            elif type == ElementType.SYMBOL:
                s = Symbol(GL.gscore)
                s.read(el)
                e = s
            else:
                e = Element.create(type, GL.gscore)
                if e:
                    e.read(el)
                if e.type() == ElementType.TEXTLINE:
                    tl = e
                    tl.setLen(GL.gscore.spatium() * 7)
                    tl.setTrack(0)
        if e:
            e.setSelected(False)
            ok = False
            if event.source() == self:
                i = self.idx(event.pos())
                if i == -1:
                    self.cells.append(self.cells[self.dragSrcIdx])
                    self.cells[self.dragSrcIdx] = 0
                    ok = True
                elif self.dragSrcIdx != i:
                    c = self.cells[self.dragSrcIdx]
                    self.cells[self.dragSrcIdx] = self.cells[i]
                    self.cells[i] = c
                    del e
                    ok = True
                event.setDropAction(Qt.MoveAction)
            else:
                self.append(e, name)
                ok = True
            if ok:
                event.acceptProposedAction()
                self.update()
                self.changed.emit()