Ejemplo n.º 1
0
 def updateViewLists(self):
     try:
         self.window()
     except RuntimeError:  ## this view has already been deleted; it will probably be collected shortly.
         return
         
     def cmpViews(a, b):
         wins = 100 * cmp(a.window() is self.window(), b.window() is self.window())
         alpha = cmp(a.name, b.name)
         return wins + alpha
         
     ## make a sorted list of all named views
     nv = list(ViewBox.NamedViews.values())
     #print "new view list:", nv
     sortList(nv, cmpViews) ## see pyqtgraph.python2_3.sortList
     
     if self in nv:
         nv.remove(self)
         
     self.menu.setViewList(nv)
     
     for ax in [0,1]:
         link = self.state['linkedViews'][ax]
         if isinstance(link, basestring):     ## axis has not been linked yet; see if it's possible now
             for v in nv:
                 if link == v.name:
                     self.linkView(ax, v)
Ejemplo n.º 2
0
 def listTicks(self):
     """Return a sorted list of all the Tick objects on the slider."""
     ## public
     ticks = list(self.ticks.items())
     sortList(
         ticks,
         lambda a, b: cmp(a[1], b[1]))  ## see pyqtgraph.python2_3.sortList
     return ticks
Ejemplo n.º 3
0
    def itemsNearEvent(self,
                       event,
                       selMode=QtCore.Qt.IntersectsItemShape,
                       sortOrder=QtCore.Qt.DescendingOrder,
                       hoverable=False):
        """
        Return an iterator that iterates first through the items that directly intersect point (in Z order)
        followed by any other items that are within the scene's click radius.
        """
        #tr = self.getViewWidget(event.widget()).transform()
        view = self.views()[0]
        tr = view.viewportTransform()
        r = self._clickRadius
        rect = view.mapToScene(QtCore.QRect(0, 0, 2 * r, 2 * r)).boundingRect()

        seen = set()
        if hasattr(event, 'buttonDownScenePos'):
            point = event.buttonDownScenePos()
        else:
            point = event.scenePos()
        w = rect.width()
        h = rect.height()
        rgn = QtCore.QRectF(point.x() - w, point.y() - h, 2 * w, 2 * h)
        #self.searchRect.setRect(rgn)

        items = self.items(point, selMode, sortOrder, tr)

        ## remove items whose shape does not contain point (scene.items() apparently sucks at this)
        items2 = []
        for item in items:
            if hoverable and not hasattr(item, 'hoverEvent'):
                continue
            shape = item.shape()
            if shape is None:
                continue
            if item.mapToScene(shape).contains(point):
                items2.append(item)

        ## Sort by descending Z-order (don't trust scene.itms() to do this either)
        ## use 'absolute' z value, which is the sum of all item/parent ZValues
        def absZValue(item):
            if item is None:
                return 0
            return item.zValue() + absZValue(item.parentItem())

        sortList(items2, lambda a, b: cmp(absZValue(b), absZValue(a)))

        return items2
Ejemplo n.º 4
0
    def itemsNearEvent(
        self, event, selMode=QtCore.Qt.IntersectsItemShape, sortOrder=QtCore.Qt.DescendingOrder, hoverable=False
    ):
        """
        Return an iterator that iterates first through the items that directly intersect point (in Z order)
        followed by any other items that are within the scene's click radius.
        """
        # tr = self.getViewWidget(event.widget()).transform()
        view = self.views()[0]
        tr = view.viewportTransform()
        r = self._clickRadius
        rect = view.mapToScene(QtCore.QRect(0, 0, 2 * r, 2 * r)).boundingRect()

        seen = set()
        if hasattr(event, "buttonDownScenePos"):
            point = event.buttonDownScenePos()
        else:
            point = event.scenePos()
        w = rect.width()
        h = rect.height()
        rgn = QtCore.QRectF(point.x() - w, point.y() - h, 2 * w, 2 * h)
        # self.searchRect.setRect(rgn)

        items = self.items(point, selMode, sortOrder, tr)

        ## remove items whose shape does not contain point (scene.items() apparently sucks at this)
        items2 = []
        for item in items:
            if hoverable and not hasattr(item, "hoverEvent"):
                continue
            shape = item.shape()
            if shape is None:
                continue
            if item.mapToScene(shape).contains(point):
                items2.append(item)

        ## Sort by descending Z-order (don't trust scene.itms() to do this either)
        ## use 'absolute' z value, which is the sum of all item/parent ZValues
        def absZValue(item):
            if item is None:
                return 0
            return item.zValue() + absZValue(item.parentItem())

        sortList(items2, lambda a, b: cmp(absZValue(b), absZValue(a)))

        return items2
Ejemplo n.º 5
0
 def listTicks(self):
     """Return a sorted list of all the Tick objects on the slider."""
     ## public
     ticks = list(self.ticks.items())
     sortList(ticks, lambda a,b: cmp(a[1], b[1]))  ## see pyqtgraph.python2_3.sortList
     return ticks