Example #1
0
    def writeSVG(self):
        d = quickdialog.QuickDialog(self, "Write Viewer Contents to SVG")

        d.filedialog = quickdialog.OutputFile(d, "Output filename:",
                                              "SVG Files (*.svg)")
        d.filedialog.setFocus()

        d.choices = quickdialog.HDialogGroup(d)

        d.which = quickdialog.VChoice(d.choices, "Save ...")
        d.which.addButton("all overlays", 0)
        d.which.addButton("only displayed overlays", 1)

        d.which.selectButton(self._lastSaveType)

        while True:
            if d.exec_() == 0:
                return

            self._lastSaveType = d.which.selection()
            allOVs = (d.which.selection() == 0)

            filename = d.filedialog.text()
            basename, ext = os.path.splitext(filename)

            try:
                if ext == ".SVG" or ext == ".svg":
                    viewer2svg.viewer2svg(self, basename, not allOVs)
                else:
                    viewer2svg.viewer2svg(self, filename, not allOVs)
            except RuntimeError as e:
                qt.QMessageBox.critical(self, "Error", str(e))
            return
Example #2
0
    def writeImage(self):
        d = quickdialog.QuickDialog(self, "Write Image")

        imageFileExtensions = '*.' + ' *.'.join(
            vigra.impex.listExtensions().split(' '))
        d.filedialog = quickdialog.OutputFile(
            d, "Output filename:", "Image Files (" + imageFileExtensions + ")")
        d.filedialog.setFocus()

        d.choices = quickdialog.HDialogGroup(d)

        d.type = quickdialog.VChoice(d.choices, "Output Pixel Type")
        d.type.addButton("Byte", "UINT8")
        d.type.addButton("Normalized to byte", "NBYTE")
        d.type.addButton("Keep type", "NATIVE")
        d.type.selectButton(1 if self._normalized else 0)
        d.type.buttonBox.setEnabled(self._lastSaveType)

        d.choices.addStretch(1)

        d.which = quickdialog.VChoice(d.choices, "Save ...")
        d.which.addButton("displayed image (zoomed, overlays)", 0)
        d.which.addButton("displayed image (1:1)", 1)
        d.which.addButton("original image", 2)
        d.connect(d.which.buttonBox, SIGNAL("clicked(int)"), \
                  d.type.buttonBox.setEnabled)
        d.which.selectButton(self._lastSaveType)

        while True:
            if d.exec_() == 0:
                return

            filename = d.filedialog.text()
            pixelType = d.type.selection()

            self._lastSaveType = d.which.selection()
            if d.which.selection():
                if d.which.selection() == 2:
                    image = self.image
                else:
                    image = self.getDisplay()[0]
                try:
                    image.writeImage(filename, pixelType)
                except RuntimeError as e:
                    qt.QMessageBox.critical(self, "Error", str(e))
                else:
                    return
            else:
                formats = {"png": "PNG", \
                           "bmp": "BMP", \
                           "xbm": "XBM", \
                           "xpm": "XPM", \
                           "pnm": "PPM", \
                           "ppm": "PPM", \
                           "png": "PNG", \
                           "jpg": "JPEG", \
                           "jpeg": "JPEG", \
                           "tif": "TIF"}

                _, ext = os.path.splitext(filename)
                if not formats.has_key(ext[1:]):
                    f = " ".join(formats.keys())
                    qt.QMessageBox.critical(self, "Error", \
                                   "Displayed image with overlays can only be stored as\n" + f)
                else:
                    pixmap = self.getContentsPixmap()
                    pixmap.save(filename, formats[ext[1:]])
                    return