Ejemplo n.º 1
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))
Ejemplo n.º 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))
Ejemplo n.º 3
0
 def mousePressEvent(self, e):
     imagePos = OverlayViewer.imageCoordinateF(self,
                                               qcore.QPoint(e.x(), e.y()))
     self.emit(qcore.SIGNAL("mousePressed"),
               (imagePos.x(), imagePos.y(), e.button()))
     OverlayViewer.mousePressEvent(self, e)
     e.ignore()
Ejemplo n.º 4
0
    def __init__(self, image, normalize=True, title=None, parent=None):
        OverlayViewer.__init__(self, parent)
        self.setImage(image, normalize)
        self._savedExpression = "x"
        self._lastSaveType = 2
        self.overlays = []

        if title is not None:
            self.setWindowTitle(title)
        elif hasattr(image, "name"):
            self.setWindowTitle(image.name)
        else:
            for k in xrange(1, 10000):
                if not ImageViewer.activeViewers.has_key(k):
                    break
            ImageViewer.activeViewers[k] = self
            self.setWindowTitle("Image %d" % k)

        self.imageCursor = ImageCursor(self)
        self.imageCursor.setVisible(False)
        self.imageCursor.setPosition(qcore.QPoint(self.image.width // 2, self.image.height // 2))
        OverlayViewer.addOverlay(self, self.imageCursor)

        self.zoomInAction = qt.QAction("Zoom in", self)
        self.zoomInAction.setShortcut("+")
        self.connect(self.zoomInAction, SIGNAL("triggered()"), self.zoomInPopup)

        self.zoomOutAction = qt.QAction("Zoom out", self)
        self.zoomOutAction.setShortcut("-")
        self.connect(self.zoomOutAction, SIGNAL("triggered()"), self.zoomOutPopup)

        self.saveAction = qt.QAction("Save image...", self)
        self.saveAction.setShortcut("S")
        self.connect(self.saveAction, SIGNAL("triggered()"), self.writeImage)

        self.svgAction = qt.QAction("Save as SVG...", self)
        self.svgAction.setShortcut("V")
        self.connect(self.svgAction, SIGNAL("triggered()"), self.writeSVG)

        self.expressionAction = qt.QAction("Apply expression...", self)
        self.expressionAction.setShortcut("E")
        self.connect(self.expressionAction, SIGNAL("triggered()"), self.applyExpression)

        self.cursorAction = qt.QAction("Line cursor", self)
        self.cursorAction.setShortcut("L")
        self.cursorAction.setCheckable(True)
        self.cursorAction.setChecked(False)
        self.connect(self.cursorAction, SIGNAL("triggered()"), self._toggleImageCursor)

        self.popup = qt.QMenu(self)
        self.popup.addAction(self.zoomInAction)
        self.popup.addAction(self.zoomOutAction)

        self.popup.addAction(self.saveAction)
        self.popup.addAction(self.svgAction)
        self.popup.addAction(self.expressionAction)
        self.popup.addAction(self.cursorAction)

        self.overlayMenu = self.popup.addMenu("Overlays")
        self.connect(self.overlayMenu, SIGNAL("aboutToShow()"), self.overlayPopup)
Ejemplo n.º 5
0
 def removeOverlay(self, overlay):
     if type(overlay) == int:
         try:
             OverlayViewer.removeOverlay(self, self.overlays[overlay])
             self.overlays.pop(overlay)
             self.update()
         except IndexError, e:
             print "No such overlay."
Ejemplo n.º 6
0
 def removeOverlay(self, overlay):
     if type(overlay) == int:
         try:
             OverlayViewer.removeOverlay(self, self.overlays[overlay])
             self.overlays.pop(overlay)
             self.update()
         except IndexError, e:
             print "No such overlay."
Ejemplo n.º 7
0
 def addOverlay(self, overlay):
     if not hasattr(overlay, "draw"):
         raise TypeError("addOverlay: " + str(overlay) + "is no valid overlay with 'draw' method!")
     if overlay.parent() is None:
         overlay.setParent(self)
     overlay.visible = True
     if not hasattr(overlay, "name") or not overlay.name:
         overlay.name = self._defaultOverlayName(overlay)
     self.overlays.append(overlay)
     OverlayViewer.addOverlay(self, overlay)
     self.update()
     return len(self.overlays) - 1
Ejemplo n.º 8
0
 def keyPressEvent(self, e):
     "handles keys [S], [E], and possibly [Q] (for toplevel-windows)"
     if e.key() == qcore.Qt.Key_Q and not self.parent():
         self.close()
     elif e.key() == qcore.Qt.Key_S:
         self.writeImage()
     elif e.key() == qcore.Qt.Key_E:
         self.applyExpression()
     elif e.key() == qcore.Qt.Key_L:
         self.cursorAction.trigger()
     else:
         OverlayViewer.keyPressEvent(self, e)
Ejemplo n.º 9
0
 def addOverlay(self, overlay):
     if not hasattr(overlay, "draw"):
         raise TypeError("addOverlay: " + str(overlay) +
                         "is no valid overlay with 'draw' method!")
     if overlay.parent() is None:
         overlay.setParent(self)
     overlay.visible = True
     if not hasattr(overlay, "name") or not overlay.name:
         overlay.name = self._defaultOverlayName(overlay)
     self.overlays.append(overlay)
     OverlayViewer.addOverlay(self, overlay)
     self.update()
     return len(self.overlays) - 1
Ejemplo n.º 10
0
 def removeOverlay(self, overlay):
     if type(overlay) == int:
         try:
             OverlayViewer.removeOverlay(self, self.overlays[overlay])
             self.overlays.pop(overlay)
             self.update()
         except IndexError as e:
             print("No such overlay.")
     else:
         try:
             self.overlays.remove(overlay)
             OverlayViewer.removeOverlay(self, overlay)
             self.update()
         except ValueError as e:
             print("No such overlay.")
Ejemplo n.º 11
0
 def removeOverlay(self, overlay):
     if type(overlay) == int:
         try:
             OverlayViewer.removeOverlay(self, self.overlays[overlay])
             self.overlays.pop(overlay)
             self.update()
         except IndexError as e:
             print("No such overlay.")
     else:
         try:
             self.overlays.remove(overlay)
             OverlayViewer.removeOverlay(self, overlay)
             self.update()
         except ValueError as e:
             print("No such overlay.")
Ejemplo n.º 12
0
 def keyPressEvent(self, e):
     "handles keys [S], [E], and possibly [Q] (for toplevel-windows)"
     if e.key() == qcore.Qt.Key_Q and not self.parent():
         self.close()
     elif e.key() == qcore.Qt.Key_S:
         self.writeImage()
     elif e.key() == qcore.Qt.Key_E:
         self.applyExpression()
     elif e.key() == qcore.Qt.Key_L:
         self.cursorAction.trigger()
     elif e.key() == qcore.Qt.Key_Right or e.key() == qcore.Qt.Key_Left or \
       e.key() == qcore.Qt.Key_Up or e.key() == qcore.Qt.Key_Down:
         OverlayViewer.keyPressEvent(self, e)
     elif e.key() == qcore.Qt.Key_Plus or e.key() == qcore.Qt.Key_Greater:
         OverlayViewer.zoomUp(self)
     elif e.key() == qcore.Qt.Key_Minus or e.key() == qcore.Qt.Key_Less:
         OverlayViewer.zoomDown(self)
     else:
         self.emit(qcore.SIGNAL("keyPressed"), (e.key()))
         e.ignore()
Ejemplo n.º 13
0
 def keyPressEvent(self, e):
     "handles keys [S], [E], and possibly [Q] (for toplevel-windows)"
     if e.key() == qcore.Qt.Key_Q and not self.parent():
         self.close()
     elif e.key() == qcore.Qt.Key_S:
         self.writeImage()
     elif e.key() == qcore.Qt.Key_E:
         self.applyExpression()
     elif e.key() == qcore.Qt.Key_L:
         self.cursorAction.trigger()
     elif e.key() == qcore.Qt.Key_Right or e.key() == qcore.Qt.Key_Left or \
       e.key() == qcore.Qt.Key_Up or e.key() == qcore.Qt.Key_Down:
         OverlayViewer.keyPressEvent(self, e)
     elif e.key() == qcore.Qt.Key_Plus or e.key() == qcore.Qt.Key_Greater:
         OverlayViewer.zoomUp(self)
     elif e.key() == qcore.Qt.Key_Minus or e.key() == qcore.Qt.Key_Less:
         OverlayViewer.zoomDown(self)
     else:
         self.emit(qcore.SIGNAL("keyPressed"), (e.key()))
         e.ignore()
Ejemplo n.º 14
0
    def __init__(self, image, normalize=True, title=None, parent=None):
        OverlayViewer.__init__(self, parent)
        self.setImage(image, normalize)
        self._savedExpression = "x"
        self._lastSaveType = 2
        self.overlays = []

        if title is not None:
            self.setWindowTitle(title)
        elif hasattr(image, "name"):
            self.setWindowTitle(image.name)
        else:
            for k in xrange(1, 10000):
                if not ImageViewer.activeViewers.has_key(k):
                    break
            ImageViewer.activeViewers[k] = self
            self.setWindowTitle("Image %d" % k)

        #self.imageCursor = ImageCursor(self) # doesn't work anymore - setVisible() is gone
        self.imageCursor = Crosshair(self)
        self.imageCursor.setVisible(False)
        self.imageCursor.setPosition(
            qcore.QPoint(self.image.width // 2, self.image.height // 2))
        OverlayViewer.addOverlay(self, self.imageCursor)

        self.zoomInAction = qt.QAction("Zoom in", self)
        self.zoomInAction.setShortcut("+")
        self.connect(self.zoomInAction, SIGNAL("triggered()"),
                     self.zoomInPopup)

        self.zoomOutAction = qt.QAction("Zoom out", self)
        self.zoomOutAction.setShortcut("-")
        self.connect(self.zoomOutAction, SIGNAL("triggered()"),
                     self.zoomOutPopup)

        self.saveAction = qt.QAction("Save image...", self)
        self.saveAction.setShortcut("S")
        self.connect(self.saveAction, SIGNAL("triggered()"), self.writeImage)

        self.svgAction = qt.QAction("Save as SVG...", self)
        self.svgAction.setShortcut("V")
        self.connect(self.svgAction, SIGNAL("triggered()"), self.writeSVG)

        self.expressionAction = qt.QAction("Apply expression...", self)
        self.expressionAction.setShortcut("E")
        self.connect(self.expressionAction, SIGNAL("triggered()"),
                     self.applyExpression)

        self.cursorAction = qt.QAction("Line cursor", self)
        self.cursorAction.setShortcut("L")
        self.cursorAction.setCheckable(True)
        self.cursorAction.setChecked(False)
        self.connect(self.cursorAction, SIGNAL("triggered()"),
                     self._toggleImageCursor)

        self.popup = qt.QMenu(self)
        self.popup.addAction(self.zoomInAction)
        self.popup.addAction(self.zoomOutAction)

        self.popup.addAction(self.saveAction)
        self.popup.addAction(self.svgAction)
        self.popup.addAction(self.expressionAction)
        self.popup.addAction(self.cursorAction)

        self.overlayMenu = self.popup.addMenu("Overlays")
        self.connect(self.overlayMenu, SIGNAL("aboutToShow()"),
                     self.overlayPopup)
Ejemplo n.º 15
0
        OverlayViewer.addOverlay(self, overlay)
        self.update()
        return len(self.overlays) - 1

    def removeOverlay(self, overlay):
        if type(overlay) == int:
            try:
                OverlayViewer.removeOverlay(self, self.overlays[overlay])
                self.overlays.pop(overlay)
                self.update()
            except IndexError, e:
                print "No such overlay."
        else:
            try:
                self.overlays.remove(overlay)
                OverlayViewer.removeOverlay(self, overlay)
                self.update()
            except ValueError, e:
                print "No such overlay."

    def _slideAfterZoom(self, shift):
        if self.zoomLevel() > 0:
            shift *= 1 + self.zoomLevel()
        elif self.zoomLevel() < 0:
            shift /= 1 - self.zoomLevel()
        self.slideBy(shift)

    def zoomInPopup(self):
        beforePos = self.imageCoordinate(self.mousepos)
        self.zoomUp()
        afterPos = self.imageCoordinate(self.mousepos)
Ejemplo n.º 16
0
 def setImage(self, image, normalize=True):
     if not hasattr(image, "qimage"):
         image = image.view(vigra.Image)
     self.image = image
     self._normalized = normalize
     OverlayViewer.setImage(self, image.qimage(normalize))
Ejemplo n.º 17
0
 def mousePressEvent(self, e):
     imagePos = OverlayViewer.imageCoordinateF(self, qcore.QPoint(e.x(), e.y()))
     self.emit(qcore.SIGNAL("mousePressed"), (imagePos.x(), imagePos.y(), e.button()))
     OverlayViewer.mousePressEvent(self, e)
     e.ignore()
Ejemplo n.º 18
0
 def setImage(self, image, normalize=True):
     if not hasattr(image, "qimage"):
         image = image.view(vigra.Image)
     self.image = image
     self._normalized = normalize
     OverlayViewer.setImage(self, image.qimage(normalize))
Ejemplo n.º 19
0
        OverlayViewer.addOverlay(self, overlay)
        self.update()
        return len(self.overlays) - 1

    def removeOverlay(self, overlay):
        if type(overlay) == int:
            try:
                OverlayViewer.removeOverlay(self, self.overlays[overlay])
                self.overlays.pop(overlay)
                self.update()
            except IndexError, e:
                print "No such overlay."
        else:
            try:
                self.overlays.remove(overlay)
                OverlayViewer.removeOverlay(self, overlay)
                self.update()
            except ValueError, e:
                print "No such overlay."

    def _slideAfterZoom(self, shift):
        if self.zoomLevel() > 0:
            shift *= 1 + self.zoomLevel()
        elif self.zoomLevel() < 0:
            shift /= 1 - self.zoomLevel()
        self.slideBy(shift)

    def zoomInPopup(self):
        beforePos = self.imageCoordinate(self.mousepos)
        self.zoomUp()
        afterPos = self.imageCoordinate(self.mousepos)