예제 #1
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)
예제 #2
0
 def setPosition(self, pos):
     self.position = pos
     if self.visible:
         ImageCursor.setPosition(self, self.position)
예제 #3
0
 def setVisible(self, what=True):
     self.visible = what
     if what:
         ImageCursor.setPosition(self, self.position)
     else:
         ImageCursor.setPosition(self, qcore.QPoint(-1, -1))
예제 #4
0
 def __init__(self, *args):
     ImageCursor.__init__(self, *args)
     self.visible = False
     self.position = qcore.QPoint(-1, -1)
예제 #5
0
 def setPosition(self, pos):
     self.position = pos
     if self.visible:
         ImageCursor.setPosition(self, self.position)
예제 #6
0
 def setVisible(self, what=True):
     self.visible = what
     if what:
         ImageCursor.setPosition(self, self.position)
     else:
         ImageCursor.setPosition(self, qcore.QPoint(-1, -1))
예제 #7
0
 def __init__(self, *args):
     ImageCursor.__init__(self, *args)
     self.visible = False
     self.position = qcore.QPoint(-1, -1)
예제 #8
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)
예제 #9
0
class ImageViewer(OverlayViewer):

    activeViewers = weakref.WeakValueDictionary()

    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)

    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))

    def showImageCursor(self, yesOrNo=True):
        if yesOrNo != self.cursorAction.isChecked():
            self.cursorAction.trigger()

    def _toggleImageCursor(self):
        self.imageCursor.activateTool(self.cursorAction.isChecked())
        self.imageCursor.setVisible(self.cursorAction.isChecked())

    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

    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:
예제 #10
0
파일: imagewindow.py 프로젝트: jfhci/vigra
class ImageViewer(OverlayViewer):
    
    activeViewers = weakref.WeakValueDictionary()

    def __init__(self, image, normalize = True, title = None, parent = None):
        OverlayViewer.__init__(self, parent)
        self.setImage(image, normalize)
        self._savedExpression = "x"
        self._lastSaveType = 2

        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))
        self.addOverlay(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.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.expressionAction)
        self.popup.addAction(self.cursorAction)
    
    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))
    
    def showImageCursor(self, yesOrNo = True):
        if yesOrNo != self.cursorAction.isChecked():
            self.cursorAction.trigger()

    def _toggleImageCursor(self):
        self.imageCursor.activateTool(self.cursorAction.isChecked())
        self.imageCursor.setVisible(self.cursorAction.isChecked())

    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)
        self._slideAfterZoom(afterPos - beforePos)

    def zoomOutPopup(self):
        beforePos = self.imageCoordinate(self.mousepos)
        self.zoomDown()
        afterPos = self.imageCoordinate(self.mousepos)
        self._slideAfterZoom(afterPos - beforePos)

#    def overlayPopup(self):
#        self.overlayMenu.clear()
#        index = 0
#        hideable = False
#        showable = False
#        for o in self.viewer.overlays:
#            if hasattr(o, "name"):
#                overlayName = o.name
#            else:
#                overlayName = self.viewer._defaultOverlayName(o)
#            text = "[%d] %s" % (index, overlayName)
#
#            color = None
#            if hasattr(o, "color") and isinstance(o.color, qt.QColor):
#                color = o.color
#                pmHeight = 5
#            elif hasattr(o, "fillColor") and isinstance(o.fillColor, qt.QColor):
#                color = o.fillColor
#                pmHeight = 16
#
#            if color:
#                colorPM = qt.QPixmap(16, pmHeight)
#                colorPM.fill(color)
#                iconSet = qt.QIconSet()
#                iconSet.setPixmap(colorPM, qt.QIconSet.Automatic,
#                                  qt.QIconSet.Normal, qt.QIconSet.On)
#                id = self.overlayMenu.insertItem(iconSet,
#                       text, self.viewer.toggleOverlayVisibility)
#            else:
#                id = self.overlayMenu.insertItem(
#                    text, self.viewer.toggleOverlayVisibility)
#
#            self.overlayMenu.setItemChecked(id, o.visible)
#            self.overlayMenu.setItemParameter(id, index)
#            if o.visible:
#                hideable = True
#            else:
#                showable = True
#            index += 1
#        id = self.overlayMenu.insertItem("&Hide all", self.viewer.showOverlays)
#        self.overlayMenu.setItemParameter(id, False)
#        self.overlayMenu.setItemEnabled(id, hideable)
#        id = self.overlayMenu.insertItem("&Show all", self.viewer.showOverlays)
#        self.overlayMenu.setItemParameter(id, True)
#        self.overlayMenu.setItemEnabled(id, showable)
        
    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, e:
            qt.QMessageBox.critical(self, "Error Applying Expression", str(e))
            return

        OverlayViewer.setImage(self, image.qimage(normalized))
예제 #11
0
class ImageViewer(OverlayViewer):

    activeViewers = weakref.WeakValueDictionary()

    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)

    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))

    def showImageCursor(self, yesOrNo=True):
        if yesOrNo != self.cursorAction.isChecked():
            self.cursorAction.trigger()

    def _toggleImageCursor(self):
        self.imageCursor.activateTool(self.cursorAction.isChecked())
        self.imageCursor.setVisible(self.cursorAction.isChecked())

    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

    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: