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.
- GLViewWidget.itemsAt() now measures y from top of widget to match mouse
event position.
- Made setPen() methods consistent throughout the package
New Features:
- Added ViewBox.setLimits() method

View File

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

View File

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

View File

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

View File

@ -74,7 +74,10 @@ class AxisItem(GraphicsWidget):
self.setRange(0, 1)
self.setPen(pen)
if pen is None:
self.setPen()
else:
self.setPen(pen)
self._linkedView = None
if linkView is not None:
@ -271,16 +274,17 @@ class AxisItem(GraphicsWidget):
return fn.mkPen(getConfigOption('foreground'))
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.
if pen == None, the default will be used (see :func:`setConfigOption
<pyqtgraph.setConfigOption>`)
If no arguments are given, the default foreground color will be used
(see :func:`setConfigOption <pyqtgraph.setConfigOption>`).
"""
self.picture = None
if pen is None:
pen = getConfigOption('foreground')
self._pen = fn.mkPen(pen)
if args or kwargs:
self._pen = fn.mkPen(*args, **kwargs)
else:
self._pen = fn.mkPen(getConfigOption('foreground'))
self.labelStyle['color'] = '#' + fn.colorStr(self._pen.color())[:6]
self.setLabel()
self.update()

View File

@ -28,7 +28,7 @@ class GraphItem(GraphicsObject):
"""
Change the data displayed by the graph.
============== =========================================================
============== =======================================================================
**Arguments:**
pos (N,2) array of the positions of each node in the graph.
adj (M,2) array of connection data. Each row contains indexes
@ -50,7 +50,7 @@ class GraphItem(GraphicsObject):
:func:`ScatterPlotItem.setData() <pyqtgraph.ScatterPlotItem.setData>`
to affect the appearance of nodes (symbol, size, brush,
etc.)
============== =========================================================
============== =======================================================================
"""
if 'adj' in kwds:
self.adjacency = kwds.pop('adj')
@ -67,8 +67,21 @@ class GraphItem(GraphicsObject):
self.scatter.setData(**kwds)
self.informViewBoundsChanged()
def setPen(self, pen):
self.pen = pen
def setPen(self, *args, **kwargs):
"""
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
def generatePicture(self):

View File

@ -73,10 +73,10 @@ class InfiniteLine(GraphicsObject):
self.maxRange = bounds
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
for :func:`mkPen <pyqtgraph.mkPen>`."""
self.pen = fn.mkPen(pen)
self.pen = fn.mkPen(*args, **kwargs)
self.currentPen = self.pen
self.update()

View File

@ -194,11 +194,12 @@ class ROI(GraphicsObject):
"""
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.update()

View File

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