aboutsummaryrefslogtreecommitdiff
path: root/src/toolkit/frame.py
diff options
context:
space:
mode:
authortassaron2017-08-12 09:44:11 -0400
committertassaron2017-08-12 09:44:11 -0400
commit282f1c4b12b485a567f0d055832a5bf4409404a3 (patch)
treeee2d432d772255b1e429e4bd2b088d3aeeb1756d /src/toolkit/frame.py
parent64da6f14cea6eb0bf8fdffcc8277027fb0e96e54 (diff)
move previewWindow class into new file
and cache frequently-created blank frames
Diffstat (limited to 'src/toolkit/frame.py')
-rw-r--r--src/toolkit/frame.py37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/toolkit/frame.py b/src/toolkit/frame.py
index 02f9229..e4332eb 100644
--- a/src/toolkit/frame.py
+++ b/src/toolkit/frame.py
@@ -77,27 +77,40 @@ def defaultSize(framefunc):
def FloodFrame(width, height, RgbaTuple):
+ log.debug('Creating new %s*%s %s flood frame' % (
+ width, height,
+ 'blank' if RgbaTuple[3] == 0 else RgbaTuple
+ )
+ )
return Image.new("RGBA", (width, height), RgbaTuple)
@defaultSize
-def BlankFrame(width, height):
+def BlankFrame(width, height, blankFrames={}):
'''The base frame used by each component to start drawing.'''
- log.debug('Creating new %s*%s blank frame' % (width, height))
- return FloodFrame(width, height, (0, 0, 0, 0))
+ try:
+ return blankFrames[(width, height)]
+ except KeyError:
+ newFrame = FloodFrame(width, height, (0, 0, 0, 0))
+ blankFrames[(width, height)] = newFrame
+ return newFrame
@defaultSize
-def Checkerboard(width, height):
+def Checkerboard(width, height, checkerboards={}):
'''
A checkerboard to represent transparency to the user.
TODO: Would be cool to generate this image with numpy instead.
'''
- log.debug('Creating new %s*%s checkerboard' % (width, height))
- image = FloodFrame(1920, 1080, (0, 0, 0, 0))
- image.paste(Image.open(
- os.path.join(core.Core.wd, "background.png")),
- (0, 0)
- )
- image = image.resize((width, height))
- return image
+ try:
+ return checkerboards[(width, height)]
+ except KeyError:
+ log.debug('Creating new %s*%s checkerboard' % (width, height))
+ image = FloodFrame(1920, 1080, (0, 0, 0, 0))
+ image.paste(Image.open(
+ os.path.join(core.Core.wd, "background.png")),
+ (0, 0)
+ )
+ image = image.resize((width, height))
+ checkerboards[(width, height)] = image
+ return image