Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Unified Diff: scripts/newbitmaps/lib/bmpblock.py

Issue 6598046: Add stuff to support new bitmap format. (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git@master
Patch Set: Add French and Spanish Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: scripts/newbitmaps/lib/bmpblock.py
diff --git a/scripts/newbitmaps/lib/bmpblock.py b/scripts/newbitmaps/lib/bmpblock.py
new file mode 100755
index 0000000000000000000000000000000000000000..ca549b385df9b54f543c875986d250f1d1212596
--- /dev/null
+++ b/scripts/newbitmaps/lib/bmpblock.py
@@ -0,0 +1,103 @@
+#!/usr/bin/python -tt
+# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""A BmpBlock class"""
+
+import os
+import yaml
+
+class BmpBlock(object):
+ """A wrapper for the config.yaml file.
+ It has a few special attributes to specify which part we're focusing on.
+ """
+
+ def __init__(self, filename=None):
+ self.yaml = None
+ self.filename = None
+ self.current_screen = None
+ self.filename = filename # always set, so we can reload
+ if filename:
+ self.LoadFile(filename)
+
+ def LoadFile(self, filename):
+ """Load the specified yaml file and verify that it's a valid BmpBlock"""
+ print "Loading", filename
+ with open(filename, 'rb') as f:
+ stuff = yaml.safe_load(f)
+ # FIXME: this is pretty lame
Randall Spangler 2011/03/01 17:37:18 # FIXME: lame that we need to chdir to the same di
+ if os.path.dirname(filename):
+ os.chdir(os.path.dirname(filename))
+ if self.IsValidSyntax(stuff):
+ self.yaml = stuff
+ self.current_screen = sorted(self.yaml["screens"].keys())[0]
+
+ def Reload(self):
+ tmp = self.current_screen
+ self.LoadFile(self.filename)
+ if tmp in self.yaml["screens"]:
+ self.current_screen = tmp
+
+ def IsValidSyntax(self, thing):
+ """Raise an error if the specified dict is not a valid BmpBlock structure"""
+
+ assert isinstance(thing, dict)
+ assert thing["bmpblock"] == 1.0
+
+ seen_images = {}
+ seen_screens = {}
+
+ images = thing["images"]
+ assert isinstance(images, dict)
+ assert len(images) > 0
+ # image values should all be filenames (ie, strings)
+ for val in images.values():
+ assert type(val) == str and len(val) > 0
Randall Spangler 2011/03/01 17:37:18 assert val and type(val) == str (since an empty s
+
+ screens = thing["screens"]
+ assert isinstance(screens, dict)
+ assert len(screens) > 0
Randall Spangler 2011/03/01 17:37:18 Can just assert screens, since empty dict evaluate
+ # screen values should all be lists of 3-tuples
+ for scrname, imglist in screens.items():
+ assert len(imglist) <= 8
+ for img in imglist:
+ assert 3 == len(img)
+ # must have defined all referenced bitmaps
+ x,y,i = img
+ assert i in images
+ seen_images[i] = True
+
+ localizations = thing["localizations"]
+ assert isinstance(localizations, (list, tuple))
Randall Spangler 2011/03/01 17:37:18 Slightly more pythonic way of seeing if something
+ assert len(localizations) > 0
+ # localizations should all be lists with the same number of screens
+ len0 = len(localizations[0])
+ assert len0 > 0
+ for elt in localizations:
+ assert len0 == len(elt)
+ # we must have defined all referenced screens
+ for scr in elt:
+ assert scr in screens
+ seen_screens[scr] = True
+
+ # TODO: should these be fatal?
Randall Spangler 2011/03/01 17:37:18 It'll still work if there are unused images; just
+ for unused_img in [x for x in images if x not in seen_images]:
+ print " Unused image:", unused_img
+ for unused_scr in [x for x in screens if x not in seen_screens]:
+ print " Unused screen:", unused_scr
+
+ return True
+
+ def RegisterScreenDisplayObject(self, displayer):
+ """Register an object with a .Redisplay() function to display updates."""
+ self.displayer = displayer
+
+
+ def Redisplay(self):
+ """Redisplay contents."""
+ if self.displayer:
+ if self.current_screen:
+ sc = self.yaml['screens'][self.current_screen]
+ slist = [(x,y,self.yaml['images'][z]) for x,y,z in sc]
+ self.displayer.DisplayScreen(self.current_screen, slist)

Powered by Google App Engine
This is Rietveld 408576698