X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=muff%2Fmuffmenu.py;fp=lib%2Fmuff%2Fmuffmenu.py;h=c9023a282cf1cbaa181ae7fbd877c1f473b7c645;hp=daf65125dd323c7cf0944567f65749833cc61cd1;hb=fecd4c0fc49593052697b8cf199603cf1fac2b61;hpb=724736a86ae223448f90a6d3a15adacd035feaa5 diff --git a/lib/muff/muffmenu.py b/muff/muffmenu.py similarity index 68% rename from lib/muff/muffmenu.py rename to muff/muffmenu.py index daf6512..c9023a2 100644 --- a/lib/muff/muffmenu.py +++ b/muff/muffmenu.py @@ -11,26 +11,6 @@ import muff for module in muff.__all__: exec("import " + module) -# see if the menupath can be retrieved from muffconf -try: - if muffconf.get("files", "menus"): pass - -# otherwise, reload muffconf -except AttributeError: - reload(muffconf) - -# now we can safely nab the menu path setting and build a list of data files -menu_path = muffconf.get("files", "menus") -menu_files_index = ConfigParser.SafeConfigParser() -menu_files_index.read(menu_path + "/index") -menu_files = [] -for each_file in menu_files_index.get("index", "files").split(): - menu_files.append(menu_path + "/" + each_file) - -# read the menu files -menu_data = ConfigParser.SafeConfigParser() -menu_data.read(menu_files) - def get_menu(state, error=None, echoing=True, choices={}): """Show the correct menu text to a user.""" @@ -57,10 +37,7 @@ def get_menu(state, error=None, echoing=True, choices={}): def menu_echo_on(state): """True if echo is on, false if it is off.""" - try: - return menu_data.getboolean(state, "echo") - except: - return True + return muffuniv.universe.categories["menu"][state].getboolean("echo", True) def get_echo_sequence(state, echoing): """Build the appropriate IAC ECHO sequence as needed.""" @@ -83,10 +60,8 @@ def get_echo_message(state): def get_default_menu_choice(state): """Return the default choice for a menu.""" - try: - return menu_data.get(state, "default") - except: - return "" + return muffuniv.universe.categories["menu"][state].get("default") + def get_formatted_default_menu_choice(state): """Default menu choice foratted for inclusion in a prompt string.""" default = get_default_menu_choice(state) @@ -101,39 +76,34 @@ def get_menu_description(state, error): # try to get an error message matching the condition # and current state - try: - return "$(red)" + menu_data.get(state, "error_" + error) + "$(nrm)$(eol)$(eol)" - - # otherwise, use a generic one - except: - return "$(red)That is not a valid choice...$(nrm)$(eol)$(eol)" + description = muffuniv.universe.categories["menu"][state].get("error_" + error) + if not description: description = "That is not a valid choice..." + description = "$(red)" + description + "$(nrm)" # there was no error condition else: # try to get a menu description for the current state - try: - return menu_data.get(state, "description") + "$(eol)$(eol)" + description = muffuniv.universe.categories["menu"][state].get("description") - # otherwise, leave it blank - except: - return "" + # return the description or error message + if description: description += "$(eol)$(eol)" + return description def get_menu_prompt(state): """Try to get a prompt, if it was defined.""" - try: - return menu_data.get(state, "prompt") + " " - except: - return "" + prompt = muffuniv.universe.categories["menu"][state].get("prompt") + if prompt: prompt += " " + return prompt def get_menu_choices(user): """Return a dict of choice:meaning.""" choices = {} - for option in menu_data.options(user.state): - if option.startswith("choice_"): - choices[option.split("_", 2)[1]] = menu_data.get(user.state, option) - elif option.startswith("create_"): - choices[option.split("_", 2)[1]] = eval(menu_data.get(user.state, option)) + for facet in muffuniv.universe.categories["menu"][user.state].facets(): + if facet.startswith("choice_"): + choices[facet.split("_", 2)[1]] = muffuniv.universe.categories["menu"][user.state].get(facet) + elif facet.startswith("create_"): + choices[facet.split("_", 2)[1]] = eval(muffuniv.universe.categories["menu"][user.state].get(facet)) return choices def get_formatted_menu_choices(state, choices): @@ -149,20 +119,14 @@ def get_formatted_menu_choices(state, choices): def get_menu_branches(state): """Return a dict of choice:branch.""" branches = {} - try: - for option in menu_data.options(state): - if option.startswith("branch_"): - branches[option.split("_", 2)[1]] = menu_data.get(state, option) - except: - pass + for facet in muffuniv.universe.categories["menu"][state].facets(): + if facet.startswith("branch_"): + branches[facet.split("_", 2)[1]] = muffuniv.universe.categories["menu"][state].get(facet) return branches def get_default_branch(state): """Return the default branch.""" - try: - return menu_data.get(state, "branch") - except: - return "" + return muffuniv.universe.categories["menu"][state].get("branch") def get_choice_branch(user, choice): """Returns the new state matching the given choice.""" @@ -175,20 +139,14 @@ def get_choice_branch(user, choice): def get_menu_actions(state): """Return a dict of choice:branch.""" actions = {} - try: - for option in menu_data.options(state): - if option.startswith("action_"): - actions[option.split("_", 2)[1]] = menu_data.get(state, option) - except: - pass + for facet in muffuniv.universe.categories["menu"][state].facets(): + if facet.startswith("action_"): + actions[facet.split("_", 2)[1]] = muffuniv.universe.categories["menu"][state].get(facet) return actions def get_default_action(state): """Return the default action.""" - try: - return menu_data.get(state, "action") - except: - return "" + return muffuniv.universe.categories["menu"][state].get("action") def get_choice_action(user, choice): """Run any indicated script for the given choice."""