Adds dmitool import iconstate splicing

Adds the ability to splice in specific directions and/or frames when
importing icon states with dmitool.
This commit is contained in:
mwerezak
2015-06-13 12:19:42 -04:00
parent 1cbfff09d7
commit 0527e4b05f
4 changed files with 81 additions and 29 deletions

View File

@@ -8,7 +8,7 @@ _JAVA_PATH = ["java"]
_DMITOOL_CMD = ["-jar", "dmitool.jar"]
def _dmitool_call(*dmitool_args, **popen_args):
return Popen(_JAVA_PATH + _DMITOOL_CMD + list(dmitool_args), **popen_args)
return Popen(_JAVA_PATH + _DMITOOL_CMD + [str(arg) for arg in dmitool_args], **popen_args)
def _safe_parse(dict, key, deferred_value):
try:
@@ -19,12 +19,14 @@ def _safe_parse(dict, key, deferred_value):
return False
def version():
""" Prints the version to stdout. """
return _dmitool_call("version")
""" Returns the version as a string. """
stdout, stderr = _dmitool_call("version", stdout=PIPE).communicate()
return str(stdout).strip()
def help():
""" Prints the help text to stdout. """
return _dmitool_call("help")
""" Returns the help text as a string. """
stdout, stderr = _dmitool_call("help", stdout=PIPE).communicate()
return str(stdout).strip()
def info(filepath):
""" Totally not a hack that parses the output from dmitool into a dictionary.
@@ -68,11 +70,11 @@ def extract_state(input_path, output_path, icon_state, direction=None, frame=Non
If provided frame should be a frame number or a string of two frame number separated by a dash.
"""
args = ["extract", input_path, icon_state, output_path]
if direction: args.extend(("direction" , str(direction)))
if frame: args.extend(("frame" , str(frame)))
if direction is not None: args.extend(("direction" , str(direction)))
if frame is not None: args.extend(("frame" , str(frame)))
return _dmitool_call(*args)
def import_state(target_path, input_path, icon_state, replace=False, delays=None, rewind=False, loop=None, ismovement=False, direction=None):
def import_state(target_path, input_path, icon_state, replace=False, delays=None, rewind=False, loop=None, ismovement=False, direction=None, frame=None):
""" Inserts an input png given by the input_path into the target_path.
"""
args = ["import", target_path, icon_state, input_path]
@@ -81,7 +83,8 @@ def import_state(target_path, input_path, icon_state, replace=False, delays=None
if rewind: args.append("rewind")
if ismovement: args.append("movement")
if delays: args.extend(("delays", ",".join(delays)))
if direction: args.extend(("direction", direction))
if direction is not None: args.extend(("direction", direction))
if frame is not None: args.extend(("frame", frame))
if loop in ("inf", "infinity"):
args.append("loop")