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 applyExpression(self, expr=None, normalized=None):
        if expr is not None:
            self._savedExpression = expr
        else:
            d = quickdialog.QuickDialog(self, "Enter Expression")
            d.expression = quickdialog.OptionalStringInput(
                d, "Execute 'lambda x: ")
            d.expression.setText(self._savedExpression)
            d.expression.setFocus()
            d.addSpacing(10)
            d.norm = quickdialog.CheckBox(
                d, "Normalize intensity to range 0...255")
            d.norm.setChecked(self._normalized)
            if d.exec_() == 0:
                return
            self._savedExpression = d.expression.text()
            self._normalized = True if d.norm.selection() else False

        if normalized is not None:
            self._normalized = normalized

        try:
            image, normalized = self.getDisplayedImage()
        except Exception as e:
            qt.QMessageBox.critical(self, "Error Applying Expression", str(e))
            return

        OverlayViewer.setImage(self, image.qimage(normalized))
Example #3
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