Make setPen() methods more consistent throughout the package.

Merge remote-tracking branch 'termim/develop' into develop

Conflicts:
	pyqtgraph/graphicsItems/ROI.py
This commit is contained in:
Luke Campagnola 2014-03-01 09:37:59 -05:00
commit 2e3cfcbd6d
9 changed files with 48 additions and 26 deletions

View File

@ -17,6 +17,7 @@ pyqtgraph-0.9.9 [unreleased]
sigTransformChanged => sigDeviceTransformChanged. sigTransformChanged => sigDeviceTransformChanged.
- GLViewWidget.itemsAt() now measures y from top of widget to match mouse - GLViewWidget.itemsAt() now measures y from top of widget to match mouse
event position. event position.
- Made setPen() methods consistent throughout the package
New Features: New Features:
- Added ViewBox.setLimits() method - Added ViewBox.setLimits() method

View File

@ -10,7 +10,7 @@ Copyright 2012 Luke Campagnola, University of North Carolina at Chapel Hill
Maintainer Maintainer
---------- ----------
* Luke Campagnola ('luke.campagnola@%s.com' % 'gmail') * Luke Campagnola <luke.campagnola@gmail.com>
Contributors Contributors
------------ ------------
@ -26,6 +26,7 @@ Contributors
* Antony Lee * Antony Lee
* Mattias Põldaru * Mattias Põldaru
* Thomas S. * Thomas S.
* Mikhail Terekhov
Requirements Requirements
------------ ------------

View File

@ -221,8 +221,11 @@ class MouseClickEvent(object):
return self._modifiers return self._modifiers
def __repr__(self): def __repr__(self):
try:
p = self.pos() p = self.pos()
return "<MouseClickEvent (%g,%g) button=%d>" % (p.x(), p.y(), int(self.button())) return "<MouseClickEvent (%g,%g) button=%d>" % (p.x(), p.y(), int(self.button()))
except:
return "<MouseClickEvent button=%d>" % (int(self.button()))
def time(self): def time(self):
return self._time return self._time

View File

@ -501,8 +501,8 @@ class NodeGraphicsItem(GraphicsObject):
bounds = self.boundingRect() bounds = self.boundingRect()
self.nameItem.setPos(bounds.width()/2. - self.nameItem.boundingRect().width()/2., 0) self.nameItem.setPos(bounds.width()/2. - self.nameItem.boundingRect().width()/2., 0)
def setPen(self, pen): def setPen(self, *args, **kwargs):
self.pen = pen self.pen = fn.mkPen(*args, **kwargs)
self.update() self.update()
def setBrush(self, brush): def setBrush(self, brush):

View File

@ -74,6 +74,9 @@ class AxisItem(GraphicsWidget):
self.setRange(0, 1) self.setRange(0, 1)
if pen is None:
self.setPen()
else:
self.setPen(pen) self.setPen(pen)
self._linkedView = None self._linkedView = None
@ -271,16 +274,17 @@ class AxisItem(GraphicsWidget):
return fn.mkPen(getConfigOption('foreground')) return fn.mkPen(getConfigOption('foreground'))
return fn.mkPen(self._pen) return fn.mkPen(self._pen)
def setPen(self, pen): def setPen(self, *args, **kwargs):
""" """
Set the pen used for drawing text, axes, ticks, and grid lines. Set the pen used for drawing text, axes, ticks, and grid lines.
if pen == None, the default will be used (see :func:`setConfigOption If no arguments are given, the default foreground color will be used
<pyqtgraph.setConfigOption>`) (see :func:`setConfigOption <pyqtgraph.setConfigOption>`).
""" """
self.picture = None self.picture = None
if pen is None: if args or kwargs:
pen = getConfigOption('foreground') self._pen = fn.mkPen(*args, **kwargs)
self._pen = fn.mkPen(pen) else:
self._pen = fn.mkPen(getConfigOption('foreground'))
self.labelStyle['color'] = '#' + fn.colorStr(self._pen.color())[:6] self.labelStyle['color'] = '#' + fn.colorStr(self._pen.color())[:6]
self.setLabel() self.setLabel()
self.update() self.update()

View File

@ -28,7 +28,7 @@ class GraphItem(GraphicsObject):
""" """
Change the data displayed by the graph. Change the data displayed by the graph.
============== ========================================================= ============== =======================================================================
**Arguments:** **Arguments:**
pos (N,2) array of the positions of each node in the graph. pos (N,2) array of the positions of each node in the graph.
adj (M,2) array of connection data. Each row contains indexes adj (M,2) array of connection data. Each row contains indexes
@ -50,7 +50,7 @@ class GraphItem(GraphicsObject):
:func:`ScatterPlotItem.setData() <pyqtgraph.ScatterPlotItem.setData>` :func:`ScatterPlotItem.setData() <pyqtgraph.ScatterPlotItem.setData>`
to affect the appearance of nodes (symbol, size, brush, to affect the appearance of nodes (symbol, size, brush,
etc.) etc.)
============== ========================================================= ============== =======================================================================
""" """
if 'adj' in kwds: if 'adj' in kwds:
self.adjacency = kwds.pop('adj') self.adjacency = kwds.pop('adj')
@ -67,8 +67,21 @@ class GraphItem(GraphicsObject):
self.scatter.setData(**kwds) self.scatter.setData(**kwds)
self.informViewBoundsChanged() self.informViewBoundsChanged()
def setPen(self, pen): def setPen(self, *args, **kwargs):
self.pen = pen """
Set the pen used to draw graph lines.
May be:
* None to disable line drawing
* Record array with fields (red, green, blue, alpha, width)
* Any set of arguments and keyword arguments accepted by
:func:`mkPen <pyqtgraph.mkPen>`.
* 'default' to use the default foreground color.
"""
if len(args) == 1 and len(kwargs) == 0:
self.pen = args[0]
else:
self.pen = fn.mkPen(*args, **kwargs)
self.picture = None self.picture = None
def generatePicture(self): def generatePicture(self):

View File

@ -73,10 +73,10 @@ class InfiniteLine(GraphicsObject):
self.maxRange = bounds self.maxRange = bounds
self.setValue(self.value()) self.setValue(self.value())
def setPen(self, pen): def setPen(self, *args, **kwargs):
"""Set the pen for drawing the line. Allowable arguments are any that are valid """Set the pen for drawing the line. Allowable arguments are any that are valid
for :func:`mkPen <pyqtgraph.mkPen>`.""" for :func:`mkPen <pyqtgraph.mkPen>`."""
self.pen = fn.mkPen(pen) self.pen = fn.mkPen(*args, **kwargs)
self.currentPen = self.pen self.currentPen = self.pen
self.update() self.update()

View File

@ -194,11 +194,12 @@ class ROI(GraphicsObject):
""" """
return self.mapToParent(self.boundingRect()).boundingRect() return self.mapToParent(self.boundingRect()).boundingRect()
def setPen(self, pen): def setPen(self, *args, **kwargs):
""" """
Set the pen to use when drawing the ROI shape. Set the pen to use when drawing the ROI shape.
For arguments, see :func:`mkPen <pyqtgraph.mkPen>`.
""" """
self.pen = fn.mkPen(pen) self.pen = fn.mkPen(*args, **kwargs)
self.currentPen = self.pen self.currentPen = self.pen
self.update() self.update()

View File

@ -23,8 +23,8 @@ class PathButton(QtGui.QPushButton):
def setBrush(self, brush): def setBrush(self, brush):
self.brush = fn.mkBrush(brush) self.brush = fn.mkBrush(brush)
def setPen(self, pen): def setPen(self, *args, **kwargs):
self.pen = fn.mkPen(pen) self.pen = fn.mkPen(*args, **kwargs)
def setPath(self, path): def setPath(self, path):
self.path = path self.path = path
@ -48,4 +48,3 @@ class PathButton(QtGui.QPushButton):
p.end() p.end()