Esempio n. 1
0
def command_handler(cmd, cmdlist):
	global body, context
	if cmd[0][:3] in cmdlist and \
	   (cmd[0] == cmd[0][:3] or cmd[0] in commands.fullnames): # Three character command.
		c = commands.commands[cmd[0][:3]](cmd[1:], context)
		cc = cmd[0][:3]
	elif cmd[0][:2] in cmdlist and \
	     (cmd[0] == cmd[0][:2] or cmd[0] in commands.fullnames): # Two character command.
		c = commands.commands[cmd[0][:2]](cmd[1:], context)
		cc = cmd[0][:2]
	elif cmd[0][:1] in cmdlist and \
	     (cmd[0] == cmd[0][:1] or cmd[0] in commands.fullnames): # One character command.
		c = commands.commands[cmd[0][:1]](cmd[1:], context)
		cc = cmd[0][:1]
	elif not len(cmd[0]):
		clear()
		return
	else:
		clear()
		body = "Command unknown or out of context."
		return
	if c: # Process returned control hooks.
		if "body" in c: # Set the interface body text.
			body = c["body"]
		if "context" in c: # Modify context.
			if c["context"][0] == "SCENE":
				print c["context"][1]
				context[0] = "Scene: \"{0}\"".format(
					storyfile.get_scene_by_id(c["context"][1])[1]
				)
			context[1] = c["context"][0]
			context[2] = c["context"][1]
		elif "back" in c: # Move to STORY menu.
			context[0] = "\"{0}\"".format(storyfile.data[-1]["info"]["name"])
			context[1] = "STORY"
			context[2] = None
		elif "close" in c: # Close the file.
			close()
		elif "name" in c: # Change the story/scene's name.
			context[0] = c["name"]
		elif "open" in c: # Open a file.
			open_story(c["open"])
		elif "quit" in c: # Quit.
			quit()
		elif "save" in c: # Save the file.
			save()
		elif "undo" in c: # Revert changes.
			undo(c["undo"])
			if context[1] == "STORY":
				context[0] = "\"{0}\"".format(storyfile.data[-1]["info"]["name"])
			elif context[1] == "SCENE":
				context[0] = "Scene: \"{0}\"".format(
					storyfile.get_scene_by_id(c["context"][1])[1]
				)
	else:
		body = usage(cc)
Esempio n. 2
0
def command_handler(cmd, cmdlist):
    global body, context
    if cmd[0][:3] in cmdlist and \
       (cmd[0] == cmd[0][:3] or cmd[0] in commands.fullnames): # Three character command.
        c = commands.commands[cmd[0][:3]](cmd[1:], context)
        cc = cmd[0][:3]
    elif cmd[0][:2] in cmdlist and \
         (cmd[0] == cmd[0][:2] or cmd[0] in commands.fullnames): # Two character command.
        c = commands.commands[cmd[0][:2]](cmd[1:], context)
        cc = cmd[0][:2]
    elif cmd[0][:1] in cmdlist and \
         (cmd[0] == cmd[0][:1] or cmd[0] in commands.fullnames): # One character command.
        c = commands.commands[cmd[0][:1]](cmd[1:], context)
        cc = cmd[0][:1]
    elif not len(cmd[0]):
        clear()
        return
    else:
        clear()
        body = "Command unknown or out of context."
        return
    if c:  # Process returned control hooks.
        if "body" in c:  # Set the interface body text.
            body = c["body"]
        if "context" in c:  # Modify context.
            if c["context"][0] == "SCENE":
                print c["context"][1]
                context[0] = "Scene: \"{0}\"".format(
                    storyfile.get_scene_by_id(c["context"][1])[1])
            context[1] = c["context"][0]
            context[2] = c["context"][1]
        elif "back" in c:  # Move to STORY menu.
            context[0] = "\"{0}\"".format(storyfile.data[-1]["info"]["name"])
            context[1] = "STORY"
            context[2] = None
        elif "close" in c:  # Close the file.
            close()
        elif "name" in c:  # Change the story/scene's name.
            context[0] = c["name"]
        elif "open" in c:  # Open a file.
            open_story(c["open"])
        elif "quit" in c:  # Quit.
            quit()
        elif "save" in c:  # Save the file.
            save()
        elif "undo" in c:  # Revert changes.
            undo(c["undo"])
            if context[1] == "STORY":
                context[0] = "\"{0}\"".format(
                    storyfile.data[-1]["info"]["name"])
            elif context[1] == "SCENE":
                context[0] = "Scene: \"{0}\"".format(
                    storyfile.get_scene_by_id(c["context"][1])[1])
    else:
        body = usage(cc)
Esempio n. 3
0
def cmd_list(args, context):
    if len(args) > 1:
        return False
    if len(args) == 0:  # List all scenes.
        scenes = sf.get_all_scenes_by_id()
    elif len(args) == 1:  # Range is supplied.
        scene_range = args[0].split("-")
        if not len(scene_range) in [1, 2]:  # Range must be one or two numbers.
            return False
        try:  # Convert range to integers, check for non-integers.
            scene_range[0] = int(scene_range[0])
            if len(scene_range) == 2:
                scene_range[1] = int(scene_range[1])
        except (ValueError):
            return False
        if len(scene_range) == 1:  # Get single scene.
            scenes = (sf.get_scene_by_id(scene_range[0]),)
            print scenes
        elif len(scene_range) == 2:  # Get range of scenes.
            if scene_range[0] > scene_range[1]:  # Check for backwards range.
                return False
            scenes = sf.get_scenes_by_id_range(scene_range[0], scene_range[1])
    body = "Scene listing:"
    for scene in scenes:
        body += "\n"
        body += "({0}) {1}".format(str(scene[0]), scene[1])
    return {"body": body}
Esempio n. 4
0
def cmd_list(args, context):
    if len(args) > 1:
        return False
    if len(args) == 0:  # List all scenes.
        scenes = sf.get_all_scenes_by_id()
    elif len(args) == 1:  # Range is supplied.
        scene_range = args[0].split('-')
        if not len(scene_range) in [1, 2]:  # Range must be one or two numbers.
            return False
        try:  # Convert range to integers, check for non-integers.
            scene_range[0] = int(scene_range[0])
            if len(scene_range) == 2:
                scene_range[1] = int(scene_range[1])
        except (ValueError):
            return False
        if len(scene_range) == 1:  # Get single scene.
            scenes = (sf.get_scene_by_id(scene_range[0]), )
            print scenes
        elif len(scene_range) == 2:  # Get range of scenes.
            if scene_range[0] > scene_range[1]:  # Check for backwards range.
                return False
            scenes = sf.get_scenes_by_id_range(scene_range[0], scene_range[1])
    body = "Scene listing:"
    for scene in scenes:
        body += "\n"
        body += "({0}) {1}".format(str(scene[0]), scene[1])
    return {"body": body}
Esempio n. 5
0
def cmd_text(args, context):
    if len(args) != 0:
        return False
    contents = sf.text_edit(sf.get_scene_by_id(context[2])[2])
    if not contents:
        body = "Error processing tempfile."
        return {"body": body}
    sf.set_scene(context[2], "contents", contents)
    body = "Scene content updated."
    return {"body": body}
Esempio n. 6
0
def cmd_text(args, context):
    if len(args) != 0:
        return False
    contents = sf.text_edit(sf.get_scene_by_id(context[2])[2])
    if not contents:
        body = "Error processing tempfile."
        return {"body": body}
    sf.set_scene(context[2], "contents", contents)
    body = "Scene content updated."
    return {"body": body}
Esempio n. 7
0
def cmd_name(args, context):
    if context[1] == "STORY":
        if len(args) == 0:  # Show story name.
            body = "Story Name: " + sf.data[-1]["info"]["name"]
        else:  # Change story name.
            sf.new_revision()
            sf.set_info("name", " ".join(args))
            body = "Story name updated."
            c = ""
    elif context[1] == "SCENE":
        if len(args) == 0:  # Show scene name.
            body = "Scene Name: " + sf.get_scene_by_id(context[2])[1]
        else:  # Change scene name.
            sf.new_revision()
            sf.set_scene(context[2], "name", " ".join(args))
            body = "Scene name updated."
            c = "Scene: "
    if len(args) != 0:
        return {"body": body, "name": '{0}"{1}"'.format(c, " ".join(args))}
    else:
        return {"body": body}
Esempio n. 8
0
def cmd_name(args, context):
    if context[1] == "STORY":
        if len(args) == 0:  # Show story name.
            body = "Story Name: " + sf.data[-1]["info"]["name"]
        else:  # Change story name.
            sf.new_revision()
            sf.set_info("name", ' '.join(args))
            body = "Story name updated."
            c = ""
    elif context[1] == "SCENE":
        if len(args) == 0:  # Show scene name.
            body = "Scene Name: " + sf.get_scene_by_id(context[2])[1]
        else:  # Change scene name.
            sf.new_revision()
            sf.set_scene(context[2], "name", ' '.join(args))
            body = "Scene name updated."
            c = "Scene: "
    if len(args) != 0:
        return {"body": body, "name": "{0}\"{1}\"".format(c, ' '.join(args))}
    else:
        return {"body": body}