Commit 1489643a authored by Luke Campagnola's avatar Luke Campagnola
Browse files

GraphicsLayout: added convenience method for creating sub-layouts

parent b78662c3
...@@ -26,12 +26,15 @@ class GraphicsLayout(GraphicsWidget): ...@@ -26,12 +26,15 @@ class GraphicsLayout(GraphicsWidget):
self.currentRow += 1 self.currentRow += 1
self.currentCol = 0 self.currentCol = 0
def nextCol(self, colspan=1): def nextColumn(self, colspan=1):
"""Advance to next column, while returning the current column number """Advance to next column, while returning the current column number
(generally only for internal use--called by addItem)""" (generally only for internal use--called by addItem)"""
self.currentCol += colspan self.currentCol += colspan
return self.currentCol-colspan return self.currentCol-colspan
def nextCol(self, *args, **kargs):
return self.nextColumn(*args, **kargs)
def addPlot(self, row=None, col=None, rowspan=1, colspan=1, **kargs): def addPlot(self, row=None, col=None, rowspan=1, colspan=1, **kargs):
plot = PlotItem(**kargs) plot = PlotItem(**kargs)
self.addItem(plot, row, col, rowspan, colspan) self.addItem(plot, row, col, rowspan, colspan)
...@@ -47,7 +50,11 @@ class GraphicsLayout(GraphicsWidget): ...@@ -47,7 +50,11 @@ class GraphicsLayout(GraphicsWidget):
self.addItem(text, row, col, rowspan, colspan) self.addItem(text, row, col, rowspan, colspan)
return text return text
def addLayout(self, row=None, col=None, rowspan=1, colspan=1, **kargs):
layout = GraphicsLayout(**kargs)
self.addItem(layout, row, col, rowspan, colspan)
return layout
def addItem(self, item, row=None, col=None, rowspan=1, colspan=1): def addItem(self, item, row=None, col=None, rowspan=1, colspan=1):
if row is None: if row is None:
row = self.currentRow row = self.currentRow
......
...@@ -7,6 +7,6 @@ class GraphicsLayoutWidget(GraphicsView): ...@@ -7,6 +7,6 @@ class GraphicsLayoutWidget(GraphicsView):
def __init__(self, parent=None, **kargs): def __init__(self, parent=None, **kargs):
GraphicsView.__init__(self, parent) GraphicsView.__init__(self, parent)
self.ci = GraphicsLayout(**kargs) self.ci = GraphicsLayout(**kargs)
for n in ['nextRow', 'nextCol', 'addPlot', 'addViewBox', 'addItem', 'getItem', 'addLabel']: for n in ['nextRow', 'nextCol', 'nextColumn', 'addPlot', 'addViewBox', 'addItem', 'getItem', 'addLabel', 'addLayout']:
setattr(self, n, getattr(self.ci, n)) setattr(self, n, getattr(self.ci, n))
self.setCentralItem(self.ci) self.setCentralItem(self.ci)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment