示例#1
0
class ImageAnalysisViewBox(pg.ViewBox):

    '''
    Custom ViewBox used to over-ride the context menu. I don't want the full context menu, 
    just a view all and an export. Export does not call a dialog, just prompts user for filename.
    '''

    def __init__(self,parent=None,border=None,lockAspect=False,enableMouse=True,invertY=False,enableMenu=True,name=None):
        pg.ViewBox.__init__(self,parent,border,lockAspect,enableMouse,invertY,enableMenu,name)
   
        self.menu = None # Override pyqtgraph ViewBoxMenu 
        self.menu = self.getMenu(None)       
        
    def raiseContextMenu(self, ev):
        if not self.menuEnabled(): return
        menu = self.getMenu(ev)
        pos  = ev.screenPos()
        menu.popup(QtCore.QPoint(pos.x(), pos.y()))
        
    def export(self):
        self.exp = ImageExporterCustom(self)
        self.exp.export()

    def getMenu(self,event):
        if self.menu is None:
            self.menu        = QMenuCustom()
            self.viewAll     = QtGui.QAction("View All", self.menu)
            self.exportImage = QtGui.QAction("Export image", self.menu)
            self.viewAll.triggered[()].connect(self.autoRange)
            self.exportImage.triggered[()].connect(self.export)
            self.menu.addAction(self.viewAll)
            self.menu.addAction(self.exportImage)
        return self.menu 
示例#2
0
 def getMenu(self, event):
     if self.menu is None:
         self.menu = QMenuCustom()
         self.viewAll = QtGui.QAction("View All", self.menu)
         self.exportImage = QtGui.QAction("Export image", self.menu)
         self.viewAll.triggered[()].connect(self.autoRange)
         self.exportImage.triggered[()].connect(self.export)
         self.menu.addAction(self.viewAll)
         self.menu.addAction(self.exportImage)
     return self.menu
示例#3
0
 def getMenu(self):
     # Setup menu
     if self.menu is None:
         self.menu         = QMenuCustom()
         self.menuTitle    = QtGui.QAction(self.name,self.menu)
         self.copyAct      = QtGui.QAction("Copy", self.menu)
         self.saveAct      = QtGui.QAction("Save", self.menu)
         self.remAct       = QtGui.QAction("Remove", self.menu)            
         self.menu.actions = [self.menuTitle,self.copyAct,self.saveAct,self.remAct]
         # Connect signals to actions
         self.copyAct.triggered.connect(self.copyClicked)
         self.remAct.triggered.connect(self.removeClicked)
         self.saveAct.triggered.connect(self.saveClicked)
         # Add actions to menu
         self.menu.addAction(self.menuTitle)
         self.menu.addSeparator()
         for action in self.menu.actions[1:]:
             self.menu.addAction(action)
         # Set default properties
         self.menuTitle.setDisabled(True)
         self.menu.setStyleSheet("QMenu::item {color: black; font-weight:normal;}")
         font = QtGui.QFont()
         font.setBold(True)
         self.menuTitle.setFont(font)
     # Enable menus only for selected roi
     if self.isSelected:
         self.copyAct.setVisible(True) 
         self.saveAct.setVisible(True)
         self.remAct.setVisible(True)
     else:               
         self.copyAct.setVisible(False)
         self.saveAct.setVisible(False)
         self.remAct.setVisible(False)  
     return self.menu
示例#4
0
 def getMenu(self,event):
     if self.menu is None:
         self.menu        = QMenuCustom()
         self.viewAll     = QtGui.QAction("View All", self.menu)
         self.exportImage = QtGui.QAction("Export image", self.menu)
         self.viewAll.triggered[()].connect(self.autoRange)
         self.exportImage.triggered[()].connect(self.export)
         self.menu.addAction(self.viewAll)
         self.menu.addAction(self.exportImage)
     return self.menu 
示例#5
0
class ImageAnalysisViewBox(pg.ViewBox):
    """
    Custom ViewBox used to over-ride the context menu. I don't want the full context menu, 
    just a view all and an export. Export does not call a dialog, just prompts user for filename.
    """
    def __init__(self,
                 parent=None,
                 border=None,
                 lockAspect=False,
                 enableMouse=True,
                 invertY=False,
                 enableMenu=True,
                 name=None):
        pg.ViewBox.__init__(self, parent, border, lockAspect, enableMouse,
                            invertY, enableMenu, name)

        self.menu = None  # Override pyqtgraph ViewBoxMenu
        self.menu = self.getMenu(None)

    def raiseContextMenu(self, ev):
        if not self.menuEnabled(): return
        menu = self.getMenu(ev)
        pos = ev.screenPos()
        menu.popup(QtCore.QPoint(pos.x(), pos.y()))

    def export(self):
        self.exp = ImageExporterCustom(self)
        self.exp.export()

    def getMenu(self, event):
        if self.menu is None:
            self.menu = QMenuCustom()
            self.viewAll = QtGui.QAction("View All", self.menu)
            self.exportImage = QtGui.QAction("Export image", self.menu)
            self.viewAll.triggered[()].connect(self.autoRange)
            self.exportImage.triggered[()].connect(self.export)
            self.menu.addAction(self.viewAll)
            self.menu.addAction(self.exportImage)
        return self.menu
示例#6
0
 def getMenu(self):
     # Setup menu
     if self.menu is None:
         self.menu = QMenuCustom()
         self.menuTitle = QtGui.QAction(self.name, self.menu)
         self.copyAct = QtGui.QAction("Copy", self.menu)
         self.saveAct = QtGui.QAction("Save", self.menu)
         self.remAct = QtGui.QAction("Remove", self.menu)
         self.menu.actions = [
             self.menuTitle, self.copyAct, self.saveAct, self.remAct
         ]
         # Connect signals to actions
         self.copyAct.triggered.connect(self.copyClicked)
         self.remAct.triggered.connect(self.removeClicked)
         self.saveAct.triggered.connect(self.saveClicked)
         # Add actions to menu
         self.menu.addAction(self.menuTitle)
         self.menu.addSeparator()
         for action in self.menu.actions[1:]:
             self.menu.addAction(action)
         # Set default properties
         self.menuTitle.setDisabled(True)
         self.menu.setStyleSheet(
             "QMenu::item {color: black; font-weight:normal;}")
         font = QtGui.QFont()
         font.setBold(True)
         self.menuTitle.setFont(font)
     # Enable menus only for selected roi
     if self.isSelected:
         self.copyAct.setVisible(True)
         self.saveAct.setVisible(True)
         self.remAct.setVisible(True)
     else:
         self.copyAct.setVisible(False)
         self.saveAct.setVisible(False)
         self.remAct.setVisible(False)
     return self.menu
示例#7
0
class selectableROI(object):
    
    """ A ROI class that can be used with a multiRoiViewbox """

    sigRemoveRequested = QtCore.Signal(object)
    sigCopyRequested   = QtCore.Signal(object)
    sigSaveRequested   = QtCore.Signal(object)  

    def __init__(self):
        self.penActive   = fn.mkPen(  0, 255, 0)
        self.penInactive = fn.mkPen(255,   0, 0) 
        self.penHover    = fn.mkPen(255, 255, 0)   
        self.penActive.setWidth(1)
        self.penInactive.setWidth(1) 
        self.penHover.setWidth(1)   
        self.setName()
        self.isSelected = False
        self.menu = None
        self.setActive(True)

    def setActive(self,isActive):
        self.isActive = isActive
        if isActive:
            self.setAcceptedMouseButtons(QtCore.Qt.LeftButton or QtCore.Qt.RightButton)
        else:       
            self.setAcceptedMouseButtons(QtCore.Qt.NoButton)

    def __lt__(self,other):
        selfid  = int(self.name.split('-')[-1])
        otherid = int(other.name.split('-')[-1])
        return selfid < otherid
        
    def setName(self,name=None):
        self.name = name     
        
    def removeClicked(self):
        self.sigRemoveRequested.emit(self) 
        
    def copyClicked(self):
        self.sigCopyRequested.emit(self) 
        
    def saveClicked(self):
        self.sigSaveRequested.emit(self)  
        
    def hoverEvent(self, ev):
        hover = False
        if not ev.isExit():
            if self.translatable and ev.acceptDrags(QtCore.Qt.LeftButton):
                hover=True
            for btn in [QtCore.Qt.LeftButton, QtCore.Qt.RightButton, QtCore.Qt.MidButton]:
                if int(self.acceptedMouseButtons() & btn) > 0 and ev.acceptClicks(btn):
                    hover=True                
            if self.contextMenuEnabled():
                ev.acceptClicks(QtCore.Qt.RightButton)
        
        if hover:
            self.setMouseHover(True)
            self.sigHoverEvent.emit(self)
            ev.acceptClicks(QtCore.Qt.RightButton)
        else:
            self.setMouseHover(False)         
        
    def mouseDragEvent(self, ev):
        if ev.isStart():  
            # Drag using left button only if selected  
            if ev.button() == QtCore.Qt.LeftButton:
                if self.translatable:
                    self.isMoving = True
                    self.preMoveState = self.getState()
                    self.cursorOffset = self.pos() - self.mapToParent(ev.buttonDownPos())
                    self.sigRegionChangeStarted.emit(self)
                    ev.accept()
                else:
                    ev.ignore()
        elif ev.isFinish():
            if self.translatable:
                if self.isMoving:
                    self.stateChangeFinished()
                self.isMoving = False
            return
        if self.translatable and self.isMoving and ev.buttons() == QtCore.Qt.LeftButton:
            snap = True if (ev.modifiers() & QtCore.Qt.ControlModifier) else None
            newPos = self.mapToParent(ev.pos()) + self.cursorOffset
            self.translate(newPos - self.pos(), snap=snap, finish=False)
      
    def mouseClickEvent(self, ev):
        if ev.button() == QtCore.Qt.RightButton and self.isMoving:
            ev.accept()
            self.cancelMove()
        elif ev.button() == QtCore.Qt.RightButton and self.contextMenuEnabled():
            self.raiseContextMenu(ev)
            ev.accept()
        elif int(ev.button() & self.acceptedMouseButtons()) > 0:
            ev.accept()
            self.sigClicked.emit(self, ev)
        else:
            ev.ignore()
    
    def contextMenuEnabled(self):
        return (self.removable and self.isActive)
    
    def raiseContextMenu(self, ev):
        if not self.contextMenuEnabled():
            return
        menu = self.getMenu()
        pos  = ev.screenPos()
        menu.popup(QtCore.QPoint(pos.x(), pos.y()))

    def getMenu(self):
        # Setup menu
        if self.menu is None:
            self.menu         = QMenuCustom()
            self.menuTitle    = QtGui.QAction(self.name,self.menu)
            self.copyAct      = QtGui.QAction("Copy", self.menu)
            self.saveAct      = QtGui.QAction("Save", self.menu)
            self.remAct       = QtGui.QAction("Remove", self.menu)            
            self.menu.actions = [self.menuTitle,self.copyAct,self.saveAct,self.remAct]
            # Connect signals to actions
            self.copyAct.triggered.connect(self.copyClicked)
            self.remAct.triggered.connect(self.removeClicked)
            self.saveAct.triggered.connect(self.saveClicked)
            # Add actions to menu
            self.menu.addAction(self.menuTitle)
            self.menu.addSeparator()
            for action in self.menu.actions[1:]:
                self.menu.addAction(action)
            # Set default properties
            self.menuTitle.setDisabled(True)
            self.menu.setStyleSheet("QMenu::item {color: black; font-weight:normal;}")
            font = QtGui.QFont()
            font.setBold(True)
            self.menuTitle.setFont(font)
        # Enable menus only for selected roi
        if self.isSelected:
            self.copyAct.setVisible(True) 
            self.saveAct.setVisible(True)
            self.remAct.setVisible(True)
        else:               
            self.copyAct.setVisible(False)
            self.saveAct.setVisible(False)
            self.remAct.setVisible(False)  
        return self.menu
示例#8
0
class selectableROI(object):
    """ A ROI class that can be used with a multiRoiViewbox """

    sigRemoveRequested = QtCore.Signal(object)
    sigCopyRequested = QtCore.Signal(object)
    sigSaveRequested = QtCore.Signal(object)

    def __init__(self):
        self.penActive = fn.mkPen(0, 255, 0)
        self.penInactive = fn.mkPen(255, 0, 0)
        self.penHover = fn.mkPen(255, 255, 0)
        self.penActive.setWidth(1)
        self.penInactive.setWidth(1)
        self.penHover.setWidth(1)
        self.setName()
        self.isSelected = False
        self.menu = None
        self.setActive(True)

    def setActive(self, isActive):
        self.isActive = isActive
        if isActive:
            self.setAcceptedMouseButtons(QtCore.Qt.LeftButton
                                         or QtCore.Qt.RightButton)
        else:
            self.setAcceptedMouseButtons(QtCore.Qt.NoButton)

    def __lt__(self, other):
        selfid = int(self.name.split('-')[-1])
        otherid = int(other.name.split('-')[-1])
        return selfid < otherid

    def setName(self, name=None):
        self.name = name

    def removeClicked(self):
        self.sigRemoveRequested.emit(self)

    def copyClicked(self):
        self.sigCopyRequested.emit(self)

    def saveClicked(self):
        self.sigSaveRequested.emit(self)

    def hoverEvent(self, ev):
        hover = False
        if not ev.isExit():
            if self.translatable and ev.acceptDrags(QtCore.Qt.LeftButton):
                hover = True
            for btn in [
                    QtCore.Qt.LeftButton, QtCore.Qt.RightButton,
                    QtCore.Qt.MidButton
            ]:
                if int(self.acceptedMouseButtons()
                       & btn) > 0 and ev.acceptClicks(btn):
                    hover = True
            if self.contextMenuEnabled():
                ev.acceptClicks(QtCore.Qt.RightButton)

        if hover:
            self.setMouseHover(True)
            self.sigHoverEvent.emit(self)
            ev.acceptClicks(QtCore.Qt.RightButton)
        else:
            self.setMouseHover(False)

    def mouseDragEvent(self, ev):
        if ev.isStart():
            # Drag using left button only if selected
            if ev.button() == QtCore.Qt.LeftButton:
                if self.translatable:
                    self.isMoving = True
                    self.preMoveState = self.getState()
                    self.cursorOffset = self.pos() - self.mapToParent(
                        ev.buttonDownPos())
                    self.sigRegionChangeStarted.emit(self)
                    ev.accept()
                else:
                    ev.ignore()
        elif ev.isFinish():
            if self.translatable:
                if self.isMoving:
                    self.stateChangeFinished()
                self.isMoving = False
            return
        if self.translatable and self.isMoving and ev.buttons(
        ) == QtCore.Qt.LeftButton:
            snap = True if (ev.modifiers()
                            & QtCore.Qt.ControlModifier) else None
            newPos = self.mapToParent(ev.pos()) + self.cursorOffset
            self.translate(newPos - self.pos(), snap=snap, finish=False)

    def mouseClickEvent(self, ev):
        if ev.button() == QtCore.Qt.RightButton and self.isMoving:
            ev.accept()
            self.cancelMove()
        elif ev.button() == QtCore.Qt.RightButton and self.contextMenuEnabled(
        ):
            self.raiseContextMenu(ev)
            ev.accept()
        elif int(ev.button() & self.acceptedMouseButtons()) > 0:
            ev.accept()
            self.sigClicked.emit(self, ev)
        else:
            ev.ignore()

    def contextMenuEnabled(self):
        return (self.removable and self.isActive)

    def raiseContextMenu(self, ev):
        if not self.contextMenuEnabled():
            return
        menu = self.getMenu()
        pos = ev.screenPos()
        menu.popup(QtCore.QPoint(pos.x(), pos.y()))

    def getMenu(self):
        # Setup menu
        if self.menu is None:
            self.menu = QMenuCustom()
            self.menuTitle = QtGui.QAction(self.name, self.menu)
            self.copyAct = QtGui.QAction("Copy", self.menu)
            self.saveAct = QtGui.QAction("Save", self.menu)
            self.remAct = QtGui.QAction("Remove", self.menu)
            self.menu.actions = [
                self.menuTitle, self.copyAct, self.saveAct, self.remAct
            ]
            # Connect signals to actions
            self.copyAct.triggered.connect(self.copyClicked)
            self.remAct.triggered.connect(self.removeClicked)
            self.saveAct.triggered.connect(self.saveClicked)
            # Add actions to menu
            self.menu.addAction(self.menuTitle)
            self.menu.addSeparator()
            for action in self.menu.actions[1:]:
                self.menu.addAction(action)
            # Set default properties
            self.menuTitle.setDisabled(True)
            self.menu.setStyleSheet(
                "QMenu::item {color: black; font-weight:normal;}")
            font = QtGui.QFont()
            font.setBold(True)
            self.menuTitle.setFont(font)
        # Enable menus only for selected roi
        if self.isSelected:
            self.copyAct.setVisible(True)
            self.saveAct.setVisible(True)
            self.remAct.setVisible(True)
        else:
            self.copyAct.setVisible(False)
            self.saveAct.setVisible(False)
            self.remAct.setVisible(False)
        return self.menu