summaryrefslogtreecommitdiffstats
path: root/tools/grit
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 16:03:12 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 16:03:12 +0000
commit77c4f1f19f14c1a6f2c136d0ccb242afbfd6b7c4 (patch)
treee2b0f6faabe98228fa8baa10d90b3b708eb93ff7 /tools/grit
parentdb9074beb04cd9129f7a1f58bd77c7596ba0f4d2 (diff)
downloadchromium_src-77c4f1f19f14c1a6f2c136d0ccb242afbfd6b7c4.zip
chromium_src-77c4f1f19f14c1a6f2c136d0ccb242afbfd6b7c4.tar.gz
chromium_src-77c4f1f19f14c1a6f2c136d0ccb242afbfd6b7c4.tar.bz2
Make ChromeOS's options dialog wider for it and da.
- Add "pp_if", "pp_ifdef" support to xtb's <if> expr; - Use that to specify a wider width for options dialog for ChromeOS on it and da; BUG=none TEST=Verify options dialog tab headers are not truncaated on ChromeOS for it and da. Review URL: http://codereview.chromium.org/2655003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49256 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/grit')
-rw-r--r--tools/grit/grit/node/io.py8
-rw-r--r--tools/grit/grit/node/misc.py2
-rw-r--r--tools/grit/grit/tool/build.py1
-rw-r--r--tools/grit/grit/xtb_reader.py24
4 files changed, 30 insertions, 5 deletions
diff --git a/tools/grit/grit/node/io.py b/tools/grit/grit/node/io.py
index 00943af..17e5a6f 100644
--- a/tools/grit/grit/node/io.py
+++ b/tools/grit/grit/node/io.py
@@ -40,11 +40,17 @@ class FileNode(base.Node):
if not self.should_load_:
return
+ root = self.GetRoot()
+ defs = {}
+ if hasattr(root, 'defines'):
+ defs = root.defines
+
xtb_file = file(self.GetFilePath())
try:
lang = xtb_reader.Parse(xtb_file,
self.UberClique().GenerateXtbParserCallback(
- self.attrs['lang'], debug=debug))
+ self.attrs['lang'], debug=debug),
+ defs=defs)
except:
print "Exception during parsing of %s" % self.GetFilePath()
raise
diff --git a/tools/grit/grit/node/misc.py b/tools/grit/grit/node/misc.py
index 61917e4..9320a67 100644
--- a/tools/grit/grit/node/misc.py
+++ b/tools/grit/grit/node/misc.py
@@ -234,6 +234,8 @@ class GritNode(base.Node):
self.output_language = output_language
self.defines = defines
+ def SetDefines(self, defines):
+ self.defines = defines
class IdentifierNode(base.Node):
'''A node for specifying identifiers that should appear in the resource
diff --git a/tools/grit/grit/tool/build.py b/tools/grit/grit/tool/build.py
index 2b7fa70..3d76a06 100644
--- a/tools/grit/grit/tool/build.py
+++ b/tools/grit/grit/tool/build.py
@@ -91,6 +91,7 @@ are exported to translation interchange files (e.g. XMB files), etc.
(self.output_directory,
os.path.abspath(self.output_directory)))
self.res = grd_reader.Parse(opts.input, debug=opts.extra_verbose)
+ self.res.SetDefines(self.defines)
self.res.RunGatherers(recursive = True)
self.Process()
return 0
diff --git a/tools/grit/grit/xtb_reader.py b/tools/grit/grit/xtb_reader.py
index ad29d03..8263614 100644
--- a/tools/grit/grit/xtb_reader.py
+++ b/tools/grit/grit/xtb_reader.py
@@ -17,7 +17,7 @@ class XtbContentHandler(xml.sax.handler.ContentHandler):
translation in the XTB file.
'''
- def __init__(self, callback, debug=False):
+ def __init__(self, callback, defs=None, debug=False):
self.callback = callback
self.debug = debug
# 0 if we are not currently parsing a translation, otherwise the message
@@ -31,6 +31,11 @@ class XtbContentHandler(xml.sax.handler.ContentHandler):
self.language = ''
# Keep track of the if block we're inside. We can't nest ifs.
self.if_expr = None
+ # Root defines to be used with if expr.
+ if defs:
+ self.defines = defs
+ else:
+ self.defines = {}
def startElement(self, name, attrs):
if name == 'translation':
@@ -50,11 +55,21 @@ class XtbContentHandler(xml.sax.handler.ContentHandler):
if name == 'translation':
assert self.current_id != 0
+ defs = self.defines
+ def pp_ifdef(define):
+ return define in defs
+ def pp_if(define):
+ return define in defs and defs[define]
+
# If we're in an if block, only call the callback (add the translation)
# if the expression is True.
should_run_callback = True
if self.if_expr:
- should_run_callback = eval(self.if_expr, {}, {'os': sys.platform})
+ should_run_callback = eval(self.if_expr, {},
+ {'os': sys.platform,
+ 'defs' : defs,
+ 'pp_ifdef' : pp_ifdef,
+ 'pp_if' : pp_if})
if should_run_callback:
self.callback(self.current_id, self.current_structure)
@@ -86,7 +101,7 @@ class XtbErrorHandler(xml.sax.handler.ErrorHandler):
pass
-def Parse(xtb_file, callback_function, debug=False):
+def Parse(xtb_file, callback_function, defs={}, debug=False):
'''Parse xtb_file, making a call to callback_function for every translation
in the XTB file.
@@ -109,7 +124,8 @@ def Parse(xtb_file, callback_function, debug=False):
front_of_file = xtb_file.read(1024)
xtb_file.seek(front_of_file.find('<translationbundle'))
- handler = XtbContentHandler(callback=callback_function, debug=debug)
+ handler = XtbContentHandler(callback=callback_function, defs=defs,
+ debug=debug)
xml.sax.parse(xtb_file, handler)
assert handler.language != ''
return handler.language