Merge changes from Kratz:

- isocurveitem documentation
  - updates to GradientEditor and PlotItem docs
  - Fix for Canvas handling of item Z-position
This commit is contained in:
Luke Campagnola 2012-04-28 16:00:42 -04:00
parent f278abd55d
commit d436f4b634
5 changed files with 60 additions and 22 deletions

View File

@ -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

View File

@ -0,0 +1,7 @@
IsocurveItem
========
.. autoclass:: pyqtgraph.IsocurveItem
:members:
.. automethod:: pyqtgraph.IsocurveItem.__init__

View File

@ -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 <pyqtgraph.PlotItem.setLogMode>`)
"""
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.

View File

@ -334,7 +334,7 @@ class GradientEditorItem(TickSliderItem):
**Bases:** :class:`TickSliderItem <pyqtgraph.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 <pyqtgraph.widgets.GradientWidget>` provides a widget
customizable by the user. :class: `GradientWidget <pyqtgraph.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 <pyqtgraph.mkPen>'
Can be any of the valid arguments for :func:`mkPen <pyqtgraph.mkPen>`
============= =================================================================================
"""
self.currentTick = None

View File

@ -71,6 +71,7 @@ class PlotItem(GraphicsWidget):
:func:`setXLink <pyqtgraph.ViewBox.setXLink>`,
:func:`setYLink <pyqtgraph.ViewBox.setYLink>`,
:func:`viewRect <pyqtgraph.ViewBox.viewRect>`,
:func:`viewRange <pyqtgraph.ViewBox.viewRange>`,
:func:`setMouseEnabled <pyqtgraph.ViewBox.setMouseEnabled>`,
:func:`enableAutoRange <pyqtgraph.ViewBox.enableAutoRange>`,
:func:`disableAutoRange <pyqtgraph.ViewBox.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))