From d436f4b6340b7d00f682e22e71c3f620912f45c3 Mon Sep 17 00:00:00 2001 From: Luke Campagnola <> Date: Sat, 28 Apr 2012 16:00:42 -0400 Subject: [PATCH] Merge changes from Kratz: - isocurveitem documentation - updates to GradientEditor and PlotItem docs - Fix for Canvas handling of item Z-position --- canvas/Canvas.py | 12 +++- .../source/graphicsItems/isocurveitem.rst | 7 +++ graphicsItems/AxisItem.py | 56 +++++++++++++------ graphicsItems/GradientEditorItem.py | 4 +- graphicsItems/PlotItem/PlotItem.py | 3 +- 5 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 documentation/source/graphicsItems/isocurveitem.rst diff --git a/canvas/Canvas.py b/canvas/Canvas.py index 5176f41d..75f19502 100644 --- a/canvas/Canvas.py +++ b/canvas/Canvas.py @@ -369,10 +369,16 @@ class Canvas(QtGui.QWidget): z = citem.zValue() if z is None: zvals = [i.zValue() for i in siblings] - if len(zvals) == 0: - z = 0 + if parent == self.itemList.invisibleRootItem(): + if len(zvals) == 0: + z = 0 + else: + z = max(zvals)+10 else: - z = max(zvals)+10 + if len(zvals) == 0: + z = parent.canvasItem.zValue() + else: + z = max(zvals)+1 citem.setZValue(z) ## determine location to insert item relative to its siblings diff --git a/documentation/source/graphicsItems/isocurveitem.rst b/documentation/source/graphicsItems/isocurveitem.rst new file mode 100644 index 00000000..5a027581 --- /dev/null +++ b/documentation/source/graphicsItems/isocurveitem.rst @@ -0,0 +1,7 @@ +IsocurveItem +======== + +.. autoclass:: pyqtgraph.IsocurveItem + :members: + + .. automethod:: pyqtgraph.IsocurveItem.__init__ \ No newline at end of file diff --git a/graphicsItems/AxisItem.py b/graphicsItems/AxisItem.py index bd72561f..bd91055e 100644 --- a/graphicsItems/AxisItem.py +++ b/graphicsItems/AxisItem.py @@ -8,15 +8,27 @@ from GraphicsWidget import GraphicsWidget __all__ = ['AxisItem'] class AxisItem(GraphicsWidget): + """ + GraphicsItem showing a single plot axis with ticks, values, and label. + Can be configured to fit on any side of a plot, and can automatically synchronize its displayed scale with ViewBox items. + Ticks can be extended to draw a grid. + If maxTickLength is negative, ticks point into the plot. + """ + def __init__(self, orientation, pen=None, linkView=None, parent=None, maxTickLength=-5, showValues=True): """ - GraphicsItem showing a single plot axis with ticks, values, and label. - Can be configured to fit on any side of a plot, and can automatically synchronize its displayed scale with ViewBox items. - Ticks can be extended to make a grid. - If maxTickLength is negative, ticks point into the plot. + ============== =============================================================== + **Arguments:** + orientation one of 'left', 'right', 'top', or 'bottom' + maxTickLength (px) maximum length of ticks to draw. Negative values draw + into the plot, positive values draw outward. + linkView (ViewBox) causes the range of values displayed in the axis + to be linked to the visible range of a ViewBox. + showValues (bool) Whether to display values adjacent to ticks + pen (QPen) Pen used when drawing ticks. + ============== =============================================================== """ - GraphicsWidget.__init__(self, parent) self.label = QtGui.QGraphicsTextItem(self) self.showValues = showValues @@ -78,6 +90,11 @@ class AxisItem(GraphicsWidget): self.update() def setLogMode(self, log): + """ + If *log* is True, then ticks are displayed on a logarithmic scale and values + are adjusted accordingly. (This is usually accessed by changing the log mode + of a :func:`PlotItem `) + """ self.logMode = log self.picture = None self.update() @@ -110,6 +127,7 @@ class AxisItem(GraphicsWidget): self.picture = None def showLabel(self, show=True): + """Show/hide the label text for this axis.""" #self.drawLabel = show self.label.setVisible(show) if self.orientation in ['left', 'right']: @@ -120,6 +138,7 @@ class AxisItem(GraphicsWidget): self.setScale() def setLabel(self, text=None, units=None, unitPrefix=None, **args): + """Set the text displayed adjacent to the axis.""" if text is not None: self.labelText = text self.showLabel() @@ -179,10 +198,11 @@ class AxisItem(GraphicsWidget): Set the value scaling for this axis. The scaling value 1) multiplies the values displayed along the axis and 2) changes the way units are displayed in the label. - For example: - If the axis spans values from -0.1 to 0.1 and has units set to 'V' - then a scale of 1000 would cause the axis to display values -100 to 100 - and the units would appear as 'mV' + + For example: If the axis spans values from -0.1 to 0.1 and has units set + to 'V' then a scale of 1000 would cause the axis to display values -100 to 100 + and the units would appear as 'mV' + If scale is None, then it will be determined automatically based on the current range displayed by the axis. """ @@ -207,6 +227,7 @@ class AxisItem(GraphicsWidget): self.update() def setRange(self, mn, mx): + """Set the range of values displayed by the axis""" if mn in [np.nan, np.inf, -np.inf] or mx in [np.nan, np.inf, -np.inf]: raise Exception("Not setting range to [%s, %s]" % (str(mn), str(mx))) self.range = [mn, mx] @@ -223,6 +244,7 @@ class AxisItem(GraphicsWidget): return self._linkedView() def linkToView(self, view): + """Link this axis to a ViewBox, causing its displayed range to match the visible range of the view.""" oldView = self.linkedView() self._linkedView = weakref.ref(view) if self.orientation in ['right', 'left']: @@ -272,7 +294,8 @@ class AxisItem(GraphicsWidget): This method is called whenever the axis needs to be redrawn and is a good method to override in subclasses that require control over tick locations. - The return value must be a list of three tuples: + The return value must be a list of three tuples:: + [ (major tick spacing, offset), (minor tick spacing, offset), @@ -311,12 +334,13 @@ class AxisItem(GraphicsWidget): def tickValues(self, minVal, maxVal, size): """ - Return the values and spacing of ticks to draw - [ - (spacing, [major ticks]), - (spacing, [minor ticks]), - ... - ] + Return the values and spacing of ticks to draw:: + + [ + (spacing, [major ticks]), + (spacing, [minor ticks]), + ... + ] By default, this method calls tickSpacing to determine the correct tick locations. This is a good method to override in subclasses. diff --git a/graphicsItems/GradientEditorItem.py b/graphicsItems/GradientEditorItem.py index 6f3387a5..3675191c 100644 --- a/graphicsItems/GradientEditorItem.py +++ b/graphicsItems/GradientEditorItem.py @@ -334,7 +334,7 @@ class GradientEditorItem(TickSliderItem): **Bases:** :class:`TickSliderItem ` An item that can be used to define a color gradient. Implements common pre-defined gradients that are - customizable by the user. :class: `GradientWidget ` provides a widget + customizable by the user. :class: `GradientWidget ` provides a widget with a GradientEditorItem that can be added to a GUI. ======================== =========================================================== @@ -359,7 +359,7 @@ class GradientEditorItem(TickSliderItem): 'top', and 'bottom'. allowAdd Default is True. Specifies whether ticks can be added to the item. tickPen Default is white. Specifies the color of the outline of the ticks. - Can be any of the valid arguments for :func:`mkPen ' + Can be any of the valid arguments for :func:`mkPen ` ============= ================================================================================= """ self.currentTick = None diff --git a/graphicsItems/PlotItem/PlotItem.py b/graphicsItems/PlotItem/PlotItem.py index d1b11060..2bbbc39f 100644 --- a/graphicsItems/PlotItem/PlotItem.py +++ b/graphicsItems/PlotItem/PlotItem.py @@ -71,6 +71,7 @@ class PlotItem(GraphicsWidget): :func:`setXLink `, :func:`setYLink `, :func:`viewRect `, + :func:`viewRange `, :func:`setMouseEnabled `, :func:`enableAutoRange `, :func:`disableAutoRange `, @@ -188,7 +189,7 @@ class PlotItem(GraphicsWidget): ## Wrap a few methods from viewBox for m in [ 'setXRange', 'setYRange', 'setXLink', 'setYLink', - 'setRange', 'autoRange', 'viewRect', 'setMouseEnabled', + 'setRange', 'autoRange', 'viewRect', 'viewRange', 'setMouseEnabled', 'enableAutoRange', 'disableAutoRange', 'setAspectLocked', 'register', 'unregister']: ## NOTE: If you update this list, please update the class docstring as well. setattr(self, m, getattr(self.vb, m))