aboutsummaryrefslogtreecommitdiffstats
path: root/offset_layout.py
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
commit55f4e4a5ec657a017e3bf75299ad71fd1c968dd3 (patch)
tree550ce922ea0e125ac6a9738210ce2939bf2fe901 /offset_layout.py
parent413f05aaf54fa08c0ae7e997327a4f4a473c0a8d (diff)
downloadexternal_qemu-55f4e4a5ec657a017e3bf75299ad71fd1c968dd3.zip
external_qemu-55f4e4a5ec657a017e3bf75299ad71fd1c968dd3.tar.gz
external_qemu-55f4e4a5ec657a017e3bf75299ad71fd1c968dd3.tar.bz2
Initial Contribution
Diffstat (limited to 'offset_layout.py')
-rwxr-xr-xoffset_layout.py111
1 files changed, 111 insertions, 0 deletions
diff --git a/offset_layout.py b/offset_layout.py
new file mode 100755
index 0000000..6c2f879
--- /dev/null
+++ b/offset_layout.py
@@ -0,0 +1,111 @@
+#!/usr/bin/python
+
+import re
+import sys
+import getopt
+
+DX = DY = PX = PY = KX = KY = 0
+
+_RE_LINE = re.compile("^\s*(?P<keyword>[\w-]+)\s+{\s*$")
+_RE_XY = re.compile("^(?P<start>\s*)(?P<xy>[x|y]\s+)(?P<num>\d+)(?P<end>\s*)$")
+
+def main():
+ ParseArgs()
+ ParseInput()
+
+def Usage():
+ print >>sys.stderr, """
+ Usage: %s --dx offset-x-display --dy offset-y-display --px offset-x-phone-buttons --py offset-y-phone-buttons --kx offset-x-keyboard --ky offset-y-keyboard < layout > layout2.
+
+ Unspecified offsets default to 0 (unchanged).
+ Reads from stdin, outputs to stdout.
+ Phone buttons: soft-left/top/righ/bottom, home, dpad, dial, power, etc.
+ Keyboard is the soft keyboard.
+
+ If your shell doesn't let you use negative integers, use _ for minus sign,
+ i.e. --dx _40 --dy _42 for <-40,-42).
+ """ % (sys.argv[0])
+ sys.exit(1)
+
+def ParseArgs():
+ global DX, DY, PX, PY, KX, KY
+ try:
+ options, args = getopt.getopt(sys.argv[1:], "", ["dx=", "dy=", "px=", "py=", "kx=", "ky="])
+ for opt, value in options:
+ if opt in ["--dx"]:
+ DX = int(value.replace("_", "-"))
+ elif opt in ["--dy"]:
+ DY = int(value.replace("_", "-"))
+ elif opt in ["--px"]:
+ PX = int(value.replace("_", "-"))
+ elif opt in ["--py"]:
+ PY = int(value.replace("_", "-"))
+ elif opt in ["--kx"]:
+ KX = int(value.replace("_", "-"))
+ elif opt in ["--ky"]:
+ KY = int(value.replace("_", "-"))
+ else:
+ Usage()
+ except getopt.error, msg:
+ Usage()
+
+def ParseInput():
+ global DX, DY, PX, PY, KX, KY
+
+ PHONE = [ "soft-left", "home", "back", "dpad-up", "dpad-down", "dpad-left", "dpad-right", "dpad-center", "phone-dial", "phone-hangup", "power", "volume-up", "volume-down" ]
+ KEYBOARD = [ "DEL", "CAP", "CAP2", "PERIOD", "ENTER", "ALT", "SYM", "AT", "SPACE", "SLASH", "COMMA", "ALT2" ]
+
+ mode = None
+ while True:
+ line = sys.stdin.readline()
+ if not line:
+ return
+ m_line = _RE_LINE.match(line)
+ if m_line:
+ keyword = m_line.group("keyword")
+ if keyword in ["display", "button"]:
+ mode = keyword
+ is_phone = False
+ is_keyboard = False
+ print >>sys.stderr, "Mode:", mode
+ else:
+ if mode == "button" and "{" in line:
+ is_phone = keyword in PHONE
+ is_keyboard = (len(keyword) == 1 and keyword.isalnum())
+ if not is_keyboard:
+ is_keyboard = keyword in KEYBOARD
+ elif "}" in line:
+ is_phone = False
+ is_keyboard = False
+ if mode == "display":
+ mode = None
+ else:
+ m_xy = _RE_XY.match(line)
+ if m_xy:
+ x = 0
+ y = 0
+ if mode == "display":
+ x = DX
+ y = DY
+ elif mode == "button" and is_phone:
+ x = PX
+ y = PY
+ elif mode == "button" and is_keyboard:
+ x = KX
+ y = KY
+ if x or y:
+ d = m_xy.groupdict()
+ n = int(d["num"])
+ if d["xy"].startswith("x"):
+ n += x
+ else:
+ n += y
+ d["num"] = n
+ line = "%(start)s%(xy)s%(num)s%(end)s" % d
+ sys.stdout.write(line)
+
+
+
+
+if __name__ == "__main__":
+ main()