diff options
Diffstat (limited to 'pixelcore/Screen.py')
-rw-r--r-- | pixelcore/Screen.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py index a6fc8c4..9a81df7 100644 --- a/pixelcore/Screen.py +++ b/pixelcore/Screen.py @@ -10,38 +10,40 @@ import itertools import sys import pdb from logger import main_log -#Class representing a collection of Pixels grouped into PixelStrips. Needs a -#PixelMapper, currently set via setMapper by may be migrated into the argDict. class Screen: + """Class representing a collection of Pixels grouped into PixelStrips. Needs a + PixelMapper, currently set via setMapper by may be migrated into the argDict.""" + def __init__(self): self.responseQueue = [] self.pixelStrips = [] self.xSortedPixels = [] self.xPixelLocs = [] sizeValid = False - + self.pixelsSorted = False + def addStrip(self, lS): self.pixelStrips.append(lS) self.sizeValid = False #keep track of whether or not our screen size has + self.pixelsSorted = False #been invalidated by adding more pixels - self.computeXSortedPixels() - #Returns (pixelIndex, pixel). Does a binary search. def pixelsInRange(self, minX, maxX): + """Returns (pixelIndex, pixel). Does a binary search.""" + if not self.pixelsSorted: + self.computeXSortedPixels() minIndex = Search.find_ge(self.xPixelLocs, minX) maxIndex = Search.find_le(self.xPixelLocs, maxX)+1 return self.xSortedPixels[minIndex:maxIndex] def computeXSortedPixels(self): + self.xSortedPixels = [] for pixel in self: self.xSortedPixels.append((pixel.location[0], pixel)) self.xSortedPixels.sort() self.xPixelLocs = [p[0] for p in self.xSortedPixels] - - #For debug only - def allOn(self): - [lS.allOn(-1) for lS in self.pixelStrips] - + self.pixelsSorted = True + def __iter__(self): #the iterator of all our pixel strips chained togther return itertools.chain(*[strip.__iter__() for strip in \ self.pixelStrips]) #the * operator breaks the list into args @@ -77,6 +79,7 @@ class Screen: maxY = max(y, maxY) self.size = (0,0, maxX, maxY) self.sizeValid = True + print self.size return (0, 0, maxX+100, maxY+100) #TODO: cleaner #private |