# Path: src/plugins/util/custom_pyqtgraph_items.py
# class QMenuCustom(QtGui.QMenu):
#     """ Custum QMenu that closes on leaveEvent """
#     def __init__(self,parent=None):
#         QtGui.QMenu.__init__(self, parent)
# 
#     def leaveEvent(self,ev):
#         self.hide()    


import uuid
import numpy as np
import pyqtgraph.functions as fn
import pyqtgraph.graphicsItems.ROI as pgROI
from pyqtgraph.Point import Point
from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE
from .custom_pyqtgraph_items import QMenuCustom
            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:

# Path: src/plugins/util/custom_pyqtgraph_items.py
# class QMenuCustom(QtGui.QMenu):
#     """ Custum QMenu that closes on leaveEvent """
#     def __init__(self,parent=None):
#         QtGui.QMenu.__init__(self, parent)
# 
#     def leaveEvent(self,ev):
#         self.hide()    


# Path: src/plugins/util/roi.py
import uuid
import numpy as np
import pyqtgraph.functions as fn
import pyqtgraph.graphicsItems.ROI as pgROI
from pyqtgraph.Point import Point
from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE
from .custom_pyqtgraph_items import QMenuCustom

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