Minor cleanups for GraphItem

This commit is contained in:
Luke Campagnola 2014-03-03 12:56:15 -05:00
parent 2e3cfcbd6d
commit ad11ff3950

View File

@ -45,7 +45,8 @@ class GraphItem(GraphicsObject):
* None (to disable connection drawing) * None (to disable connection drawing)
* 'default' to use the default foreground color. * 'default' to use the default foreground color.
symbolPen The pen used for drawing nodes. symbolPen The pen(s) used for drawing nodes.
symbolBrush The brush(es) used for drawing nodes.
``**opts`` All other keyword arguments are given to ``**opts`` All other keyword arguments are given to
: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,
@ -54,19 +55,28 @@ class GraphItem(GraphicsObject):
""" """
if 'adj' in kwds: if 'adj' in kwds:
self.adjacency = kwds.pop('adj') self.adjacency = kwds.pop('adj')
assert self.adjacency.dtype.kind in 'iu' if self.adjacency.dtype.kind not in 'iu':
self.picture = None raise Exception("adjacency array must have int or unsigned type.")
self._update()
if 'pos' in kwds: if 'pos' in kwds:
self.pos = kwds['pos'] self.pos = kwds['pos']
self.picture = None self._update()
if 'pen' in kwds: if 'pen' in kwds:
self.setPen(kwds.pop('pen')) self.setPen(kwds.pop('pen'))
self.picture = None self._update()
if 'symbolPen' in kwds: if 'symbolPen' in kwds:
kwds['pen'] = kwds.pop('symbolPen') kwds['pen'] = kwds.pop('symbolPen')
if 'symbolBrush' in kwds:
kwds['brush'] = kwds.pop('symbolBrush')
self.scatter.setData(**kwds) self.scatter.setData(**kwds)
self.informViewBoundsChanged() self.informViewBoundsChanged()
def _update(self):
self.picture = None
self.prepareGeometryChange()
self.update()
def setPen(self, *args, **kwargs): def setPen(self, *args, **kwargs):
""" """
Set the pen used to draw graph lines. Set the pen used to draw graph lines.
@ -83,6 +93,7 @@ class GraphItem(GraphicsObject):
else: else:
self.pen = fn.mkPen(*args, **kwargs) self.pen = fn.mkPen(*args, **kwargs)
self.picture = None self.picture = None
self.update()
def generatePicture(self): def generatePicture(self):
self.picture = QtGui.QPicture() self.picture = QtGui.QPicture()