diff --git a/README.txt b/README.txt index b51b9aa31386113081c899661ea5ab67cfed9791..d209ef010051dad78794ad6df5b021b81c8729bb 100644 --- a/README.txt +++ b/README.txt @@ -2,10 +2,16 @@ PyQtGraph - A pure-Python graphics library for PyQt/PySide Copyright 2012 Luke Campagnola, University of North Carolina at Chapel Hill http://www.pyqtgraph.org -Authors: +Maintainer: Luke Campagnola ('luke.campagnola@%s.com' % 'gmail') + +Contributors: Megan Kratz + Paul Manis Ingo Breßler + Christian Gavin + Michael Cristopher Hogg + Ulrich Leutner Requirements: PyQt 4.7+ or PySide diff --git a/pyqtgraph/dockarea/DockArea.py b/pyqtgraph/dockarea/DockArea.py index 752cf3b6f2c4efe1e105cfb478d803451cfc496a..882b29a3ffc72dbd2d4efc266b831b65c02990c0 100644 --- a/pyqtgraph/dockarea/DockArea.py +++ b/pyqtgraph/dockarea/DockArea.py @@ -40,11 +40,11 @@ class DockArea(Container, QtGui.QWidget, DockDrop): Arguments: dock The new Dock object to add. If None, then a new Dock will be created. - position 'bottom', 'top', 'left', 'right', 'over', or 'under' + position 'bottom', 'top', 'left', 'right', 'above', or 'below' relativeTo If relativeTo is None, then the new Dock is added to fill an entire edge of the window. If relativeTo is another Dock, then the new Dock is placed adjacent to it (or in a tabbed - configuration for 'over' and 'under'). + configuration for 'above' and 'below'). =========== ================================================================= All extra keyword arguments are passed to Dock.__init__() if *dock* is @@ -316,4 +316,4 @@ class DockArea(Container, QtGui.QWidget, DockDrop): DockDrop.dropEvent(self, *args) - \ No newline at end of file + diff --git a/pyqtgraph/graphicsItems/GraphicsWidgetAnchor.py b/pyqtgraph/graphicsItems/GraphicsWidgetAnchor.py index 3174e6e042a155568cc3bd6d037545df4cce2c30..251bc0c8ee5513509fb005f34e03c415da345c91 100644 --- a/pyqtgraph/graphicsItems/GraphicsWidgetAnchor.py +++ b/pyqtgraph/graphicsItems/GraphicsWidgetAnchor.py @@ -47,7 +47,52 @@ class GraphicsWidgetAnchor(object): self.__parentAnchor = parentPos self.__offset = offset self.__geometryChanged() + + + def autoAnchor(self, pos, relative=True): + """ + Set the position of this item relative to its parent by automatically + choosing appropriate anchor settings. + + If relative is True, one corner of the item will be anchored to + the appropriate location on the parent with no offset. The anchored + corner will be whichever is closest to the parent's boundary. + + If relative is False, one corner of the item will be anchored to the same + corner of the parent, with an absolute offset to achieve the correct + position. + """ + pos = Point(pos) + br = self.mapRectToParent(self.boundingRect()).translated(pos - self.pos()) + pbr = self.parentItem().boundingRect() + anchorPos = [0,0] + parentPos = Point() + itemPos = Point() + if abs(br.left() - pbr.left()) < abs(br.right() - pbr.right()): + anchorPos[0] = 0 + parentPos[0] = pbr.left() + itemPos[0] = br.left() + else: + anchorPos[0] = 1 + parentPos[0] = pbr.right() + itemPos[0] = br.right() + + if abs(br.top() - pbr.top()) < abs(br.bottom() - pbr.bottom()): + anchorPos[1] = 0 + parentPos[1] = pbr.top() + itemPos[1] = br.top() + else: + anchorPos[1] = 1 + parentPos[1] = pbr.bottom() + itemPos[1] = br.bottom() + if relative: + relPos = [(itemPos[0]-pbr.left()) / pbr.width(), (itemPos[1]-pbr.top()) / pbr.height()] + self.anchor(anchorPos, relPos) + else: + offset = itemPos - parentPos + self.anchor(anchorPos, anchorPos, offset) + def __geometryChanged(self): if self.__parent is None: return diff --git a/pyqtgraph/graphicsItems/LegendItem.py b/pyqtgraph/graphicsItems/LegendItem.py index 1fc886629fbce4d54ecc855a743e063c1801eedc..86973b04fe4f0c95e7cfb8193420f5a5fc06d67e 100644 --- a/pyqtgraph/graphicsItems/LegendItem.py +++ b/pyqtgraph/graphicsItems/LegendItem.py @@ -101,7 +101,6 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor): label.close() self.updateSize() # redraq box - def updateSize(self): if self.size is not None: return @@ -115,15 +114,22 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor): #print(width, height) #print width, height self.setGeometry(0, 0, width+25, height) - + def boundingRect(self): return QtCore.QRectF(0, 0, self.width(), self.height()) - + def paint(self, p, *args): p.setPen(fn.mkPen(255,255,255,100)) p.setBrush(fn.mkBrush(100,100,100,50)) p.drawRect(self.boundingRect()) + + def hoverEvent(self, ev): + ev.acceptDrags(QtCore.Qt.LeftButton) + def mouseDragEvent(self, ev): + if ev.button() == QtCore.Qt.LeftButton: + dpos = ev.pos() - ev.lastPos() + self.autoAnchor(self.pos() + dpos) class ItemSample(GraphicsWidget): """ Class responsible for drawing a single item in a LegendItem (sans label). diff --git a/pyqtgraph/widgets/MatplotlibWidget.py b/pyqtgraph/widgets/MatplotlibWidget.py index 25e058f96c0e12e40f62e6855b14595d82c58ba3..6a22c973ab6f5429e7b3438d33e3bb7c67d29a5e 100644 --- a/pyqtgraph/widgets/MatplotlibWidget.py +++ b/pyqtgraph/widgets/MatplotlibWidget.py @@ -1,5 +1,9 @@ -from pyqtgraph.Qt import QtGui, QtCore +from pyqtgraph.Qt import QtGui, QtCore, USE_PYSIDE import matplotlib + +if USE_PYSIDE: + matplotlib.rcParams['backend.qt4']='PySide' + from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar from matplotlib.figure import Figure