mirror of
https://github.com/evennia/evennia.git
synced 2026-03-18 13:56:30 +01:00
1060 lines
No EOL
76 KiB
HTML
1060 lines
No EOL
76 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
|
||
<title>evennia.utils.evmenu — Evennia 0.9.5 documentation</title>
|
||
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<script src="../_static/language_data.js"></script>
|
||
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"processClass": "tex2jax_process|mathjax_process|math|output_area"}})</script>
|
||
<link rel="shortcut icon" href="../_static/favicon.ico"/>
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
</head><body>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 0.9.5</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">evennia.utils.evmenu</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="module-evennia.utils.evmenu">
|
||
<span id="evennia-utils-evmenu"></span><h1>evennia.utils.evmenu<a class="headerlink" href="#module-evennia.utils.evmenu" title="Permalink to this headline">¶</a></h1>
|
||
<p>The EvMenu is a full in-game menu system for Evennia.</p>
|
||
<p>To start the menu, just import the EvMenu class from this module.</p>
|
||
<p>Example usage:</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia.utils.evmenu</span> <span class="kn">import</span> <span class="n">EvMenu</span>
|
||
|
||
<span class="n">EvMenu</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">menu_module_path</span><span class="p">,</span>
|
||
<span class="n">startnode</span><span class="o">=</span><span class="s2">"node1"</span><span class="p">,</span>
|
||
<span class="n">cmdset_mergetype</span><span class="o">=</span><span class="s2">"Replace"</span><span class="p">,</span> <span class="n">cmdset_priority</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
|
||
<span class="n">auto_quit</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">cmd_on_exit</span><span class="o">=</span><span class="s2">"look"</span><span class="p">,</span> <span class="n">persistent</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Where <strong>caller</strong> is the Object to use the menu on - it will get a new
|
||
cmdset while using the Menu. The <strong>menu_module_path</strong> is the python path
|
||
to a python module containing function definitions. By adjusting the
|
||
keyword options of the Menu() initialization call you can start the
|
||
menu at different places in the menu definition file, adjust if the
|
||
menu command should overload the normal commands or not, etc.</p>
|
||
<p>The <strong>persistent</strong> keyword will make the menu survive a server reboot.
|
||
It is <strong>False</strong> by default. Note that if using persistent mode, every
|
||
node and callback in the menu must be possible to be <em>pickled</em>, this
|
||
excludes e.g. callables that are class methods or functions defined
|
||
dynamically or as part of another function. In non-persistent mode
|
||
no such restrictions exist.</p>
|
||
<p>The menu is defined in a module (this can be the same module as the
|
||
command definition too) with function definitions:</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">node1</span><span class="p">(</span><span class="n">caller</span><span class="p">):</span>
|
||
<span class="c1"># (this is the start node if called like above)</span>
|
||
<span class="c1"># code</span>
|
||
<span class="k">return</span> <span class="n">text</span><span class="p">,</span> <span class="n">options</span>
|
||
|
||
<span class="k">def</span> <span class="nf">node_with_other_name</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">input_string</span><span class="p">):</span>
|
||
<span class="c1"># code</span>
|
||
<span class="k">return</span> <span class="n">text</span><span class="p">,</span> <span class="n">options</span>
|
||
|
||
<span class="k">def</span> <span class="nf">another_node</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">input_string</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||
<span class="c1"># code</span>
|
||
<span class="k">return</span> <span class="n">text</span><span class="p">,</span> <span class="n">options</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Where <strong>caller</strong> is the object using the menu and input_string is the
|
||
command entered by the user on the <em>previous</em> node (the command
|
||
entered to get to this node). The node function code will only be
|
||
executed once per node-visit and the system will accept nodes with
|
||
both one or two arguments interchangeably. It also accepts nodes
|
||
that takes <strong>**kwargs</strong>.</p>
|
||
<p>The menu tree itself is available on the caller as
|
||
<strong>caller.ndb._evmenu</strong>. This makes it a convenient place to store
|
||
temporary state variables between nodes, since this NAttribute is
|
||
deleted when the menu is exited.</p>
|
||
<p>The return values must be given in the above order, but each can be
|
||
returned as None as well. If the options are returned as None, the
|
||
menu is immediately exited and the default “look” command is called.</p>
|
||
<ul class="simple">
|
||
<li><p><strong>text</strong> (str, tuple or None): Text shown at this node. If a tuple, the
|
||
second element in the tuple is a help text to display at this
|
||
node when the user enters the menu help command there.</p></li>
|
||
<li><p><strong>options</strong> (tuple, dict or None): If <strong>None</strong>, this exits the menu.
|
||
If a single dict, this is a single-option node. If a tuple,
|
||
it should be a tuple of option dictionaries. Option dicts have
|
||
the following keys:</p>
|
||
<ul>
|
||
<li><dl class="simple">
|
||
<dt><strong>key</strong> (str or tuple, optional): What to enter to choose this option.</dt><dd><p>If a tuple, it must be a tuple of strings, where the first string is the
|
||
key which will be shown to the user and the others are aliases.
|
||
If unset, the options’ number will be used. The special key <strong>_default</strong>
|
||
marks this option as the default fallback when no other option matches
|
||
the user input. There can only be one <strong>_default</strong> option per node. It
|
||
will not be displayed in the list.</p>
|
||
</dd>
|
||
</dl>
|
||
</li>
|
||
<li><p><strong>desc</strong> (str, optional): This describes what choosing the option will do.</p></li>
|
||
<li><dl class="simple">
|
||
<dt><strong>goto</strong> (str, tuple or callable): If string, should be the name of node to go to</dt><dd><p>when this option is selected. If a callable, it has the signature
|
||
<strong>callable(caller[,raw_input][,**kwargs])</strong>. If a tuple, the first element
|
||
is the callable and the second is a dict with the kwargs to pass to
|
||
the callable. Those kwargs will also be passed into the next node if possible.
|
||
Such a callable should return either a str or a (str, dict), where the
|
||
string is the name of the next node to go to and the dict is the new,
|
||
(possibly modified) kwarg to pass into the next node. If the callable returns
|
||
None or the empty string, the current node will be revisited.</p>
|
||
</dd>
|
||
</dl>
|
||
</li>
|
||
<li><dl class="simple">
|
||
<dt><strong>exec</strong> (str, callable or tuple, optional): This takes the same input as <strong>goto</strong> above</dt><dd><p>and runs before it. If given a node name, the node will be executed but will not
|
||
be considered the next node. If node/callback returns str or (str, dict), these will
|
||
replace the <strong>goto</strong> step (<strong>goto</strong> callbacks will not fire), with the string being the
|
||
next node name and the optional dict acting as the kwargs-input for the next node.
|
||
If an exec callable returns <strong>None</strong>, the current node is re-run.</p>
|
||
</dd>
|
||
</dl>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<p>If key is not given, the option will automatically be identified by
|
||
its number 1..N.</p>
|
||
<p>Example:</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># in menu_module.py</span>
|
||
|
||
<span class="k">def</span> <span class="nf">node1</span><span class="p">(</span><span class="n">caller</span><span class="p">):</span>
|
||
<span class="n">text</span> <span class="o">=</span> <span class="p">(</span><span class="s2">"This is a node text"</span><span class="p">,</span>
|
||
<span class="s2">"This is help text for this node"</span><span class="p">)</span>
|
||
<span class="n">options</span> <span class="o">=</span> <span class="p">({</span><span class="s2">"key"</span><span class="p">:</span> <span class="s2">"testing"</span><span class="p">,</span>
|
||
<span class="s2">"desc"</span><span class="p">:</span> <span class="s2">"Select this to go to node 2"</span><span class="p">,</span>
|
||
<span class="s2">"goto"</span><span class="p">:</span> <span class="p">(</span><span class="s2">"node2"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"foo"</span><span class="p">:</span> <span class="s2">"bar"</span><span class="p">}),</span>
|
||
<span class="s2">"exec"</span><span class="p">:</span> <span class="s2">"callback1"</span><span class="p">},</span>
|
||
<span class="p">{</span><span class="s2">"desc"</span><span class="p">:</span> <span class="s2">"Go to node 3."</span><span class="p">,</span>
|
||
<span class="s2">"goto"</span><span class="p">:</span> <span class="s2">"node3"</span><span class="p">})</span>
|
||
<span class="k">return</span> <span class="n">text</span><span class="p">,</span> <span class="n">options</span>
|
||
|
||
<span class="k">def</span> <span class="nf">callback1</span><span class="p">(</span><span class="n">caller</span><span class="p">):</span>
|
||
<span class="c1"># this is called when choosing the "testing" option in node1</span>
|
||
<span class="c1"># (before going to node2). If it returned a string, say 'node3',</span>
|
||
<span class="c1"># then the next node would be node3 instead of node2 as specified</span>
|
||
<span class="c1"># by the normal 'goto' option key above.</span>
|
||
<span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Callback called!"</span><span class="p">)</span>
|
||
|
||
<span class="k">def</span> <span class="nf">node2</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||
<span class="n">text</span> <span class="o">=</span> <span class="s1">'''</span>
|
||
<span class="s1"> This is node 2. It only allows you to go back</span>
|
||
<span class="s1"> to the original node1. This extra indent will</span>
|
||
<span class="s1"> be stripped. We don't include a help text but</span>
|
||
<span class="s1"> here are the variables passed to us: </span><span class="si">{}</span><span class="s1"></span>
|
||
<span class="s1"> '''</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
|
||
<span class="n">options</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"goto"</span><span class="p">:</span> <span class="s2">"node1"</span><span class="p">}</span>
|
||
<span class="k">return</span> <span class="n">text</span><span class="p">,</span> <span class="n">options</span>
|
||
|
||
<span class="k">def</span> <span class="nf">node3</span><span class="p">(</span><span class="n">caller</span><span class="p">):</span>
|
||
<span class="n">text</span> <span class="o">=</span> <span class="s2">"This ends the menu since there are no options."</span>
|
||
<span class="k">return</span> <span class="n">text</span><span class="p">,</span> <span class="kc">None</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>When starting this menu with <strong>Menu(caller, “path.to.menu_module”)</strong>,
|
||
the first node will look something like this:</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">This</span> <span class="ow">is</span> <span class="n">a</span> <span class="n">node</span> <span class="n">text</span>
|
||
<span class="n">______________________________________</span>
|
||
|
||
<span class="n">testing</span><span class="p">:</span> <span class="n">Select</span> <span class="n">this</span> <span class="n">to</span> <span class="n">go</span> <span class="n">to</span> <span class="n">node</span> <span class="mi">2</span>
|
||
<span class="mi">2</span><span class="p">:</span> <span class="n">Go</span> <span class="n">to</span> <span class="n">node</span> <span class="mi">3</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Where you can both enter “testing” and “1” to select the first option.
|
||
If the client supports MXP, they may also mouse-click on “testing” to
|
||
do the same. When making this selection, a function “callback1” in the
|
||
same Using <strong>help</strong> will show the help text, otherwise a list of
|
||
available commands while in menu mode.</p>
|
||
<p>The menu tree is exited either by using the in-menu quit command or by
|
||
reaching a node without any options.</p>
|
||
<p>For a menu demo, import CmdTestMenu from this module and add it to
|
||
your default cmdset. Run it with this module, like <strong>testmenu
|
||
evennia.utils.evmenu</strong>.</p>
|
||
<section id="menu-generation-from-template-string">
|
||
<h2>Menu generation from template string<a class="headerlink" href="#menu-generation-from-template-string" title="Permalink to this headline">¶</a></h2>
|
||
<p>In evmenu.py is a helper function <strong>parse_menu_template</strong> that parses a
|
||
template-string and outputs a menu-tree dictionary suitable to pass into
|
||
EvMenu:</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">menutree</span> <span class="o">=</span> <span class="n">evmenu</span><span class="o">.</span><span class="n">parse_menu_template</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">menu_template</span><span class="p">,</span> <span class="n">goto_callables</span><span class="p">)</span>
|
||
<span class="n">EvMenu</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">menutree</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>For maximum flexibility you can inject normally-created nodes in the menu tree
|
||
before passing it to EvMenu. If that’s not needed, you can also create a menu
|
||
in one step with:</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">evmenu</span><span class="o">.</span><span class="n">template2menu</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">menu_template</span><span class="p">,</span> <span class="n">goto_callables</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The <strong>goto_callables</strong> is a mapping <strong>{“funcname”: callable, …}</strong>, where each
|
||
callable must be a module-global function on the form
|
||
<strong>funcname(caller, raw_string, **kwargs)</strong> (like any goto-callable). The
|
||
<strong>menu_template</strong> is a multi-line string on the following form:</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>## node start
|
||
|
||
This is the text of the start node.
|
||
The text area can have multiple lines, line breaks etc.
|
||
|
||
Each option below is one of these forms
|
||
key: desc -> gotostr_or_func
|
||
key: gotostr_or_func
|
||
>: gotostr_or_func
|
||
> glob/regex: gotostr_or_func
|
||
|
||
## options
|
||
|
||
# comments are only allowed from beginning of line.
|
||
# Indenting is not necessary, but good for readability
|
||
|
||
1: Option number 1 -> node1
|
||
2: Option number 2 -> node2
|
||
next: This steps next -> go_back()
|
||
# the -> can be ignored if there is no desc
|
||
back: go_back(from_node=start)
|
||
abort: abort
|
||
|
||
## node node1
|
||
|
||
Text for Node1. Enter a message!
|
||
<return> to go back.
|
||
|
||
## options
|
||
|
||
# Starting the option-line with >
|
||
# allows to perform different actions depending on
|
||
# what is inserted.
|
||
|
||
# this catches everything starting with foo
|
||
> foo*: handle_foo_message()
|
||
|
||
# regex are also allowed (this catches number inputs)
|
||
> [0-9]+?: handle_numbers()
|
||
|
||
# this catches the empty return
|
||
>: start
|
||
|
||
# this catches everything else
|
||
> *: handle_message(from_node=node1)
|
||
|
||
## node node2
|
||
|
||
Text for Node2. Just go back.
|
||
|
||
## options
|
||
|
||
>: start
|
||
|
||
# node abort
|
||
|
||
This exits the menu since there is no **## options** section.
|
||
</pre></div>
|
||
</div>
|
||
<p>Each menu node is defined by a <strong># node <name></strong> containing the text of the node,
|
||
followed by <strong>## options</strong> Also <strong>## NODE</strong> and <strong>## OPTIONS</strong> work. No python code
|
||
logics is allowed in the template, this code is not evaluated but parsed. More
|
||
advanced dynamic usage requires a full node-function (which can be added to the
|
||
generated dict, as said).</p>
|
||
<p>Adding <strong>(..)</strong> to a goto treats it as a callable and it must then be included in
|
||
the <strong>goto_callable</strong> mapping. Only named keywords (or no args at all) are
|
||
allowed, these will be added to the <strong>**kwargs</strong> going into the callable. Quoting
|
||
strings is only needed if wanting to pass strippable spaces, otherwise the
|
||
key:values will be converted to strings/numbers with literal_eval before passed
|
||
into the callable.</p>
|
||
<p>The “> ” option takes a glob or regex to perform different actions depending on user
|
||
input. Make sure to sort these in increasing order of generality since they
|
||
will be tested in sequence.</p>
|
||
<hr class="docutils" />
|
||
<dl class="py exception">
|
||
<dt id="evennia.utils.evmenu.EvMenuError">
|
||
<em class="property">exception </em><code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">EvMenuError</code><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenuError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenuError" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">RuntimeError</span></code></p>
|
||
<p>Error raised by menu when facing internal errors.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py exception">
|
||
<dt id="evennia.utils.evmenu.EvMenuGotoAbortMessage">
|
||
<em class="property">exception </em><code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">EvMenuGotoAbortMessage</code><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenuGotoAbortMessage"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenuGotoAbortMessage" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">RuntimeError</span></code></p>
|
||
<p>This can be raised by a goto-callable to abort the goto flow. The message
|
||
stored with the executable will be sent to the caller who will remain on
|
||
the current node. This can be used to pass single-line returns without
|
||
re-running the entire node with text and options.</p>
|
||
<p class="rubric">Example</p>
|
||
<p>raise EvMenuGotoMessage(“That makes no sense.”)</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt id="evennia.utils.evmenu.CmdEvMenuNode">
|
||
<em class="property">class </em><code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">CmdEvMenuNode</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#CmdEvMenuNode"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.CmdEvMenuNode" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <a class="reference internal" href="evennia.commands.command.html#evennia.commands.command.Command" title="evennia.commands.command.Command"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.commands.command.Command</span></code></a></p>
|
||
<p>Menu options.</p>
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.CmdEvMenuNode.key">
|
||
<code class="sig-name descname">key</code><em class="property"> = '__noinput_command'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdEvMenuNode.key" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.CmdEvMenuNode.aliases">
|
||
<code class="sig-name descname">aliases</code><em class="property"> = ['__nomatch_command']</em><a class="headerlink" href="#evennia.utils.evmenu.CmdEvMenuNode.aliases" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.CmdEvMenuNode.locks">
|
||
<code class="sig-name descname">locks</code><em class="property"> = 'cmd:all()'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdEvMenuNode.locks" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.CmdEvMenuNode.help_category">
|
||
<code class="sig-name descname">help_category</code><em class="property"> = 'menu'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdEvMenuNode.help_category" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.CmdEvMenuNode.auto_help_display_key">
|
||
<code class="sig-name descname">auto_help_display_key</code><em class="property"> = '<menu commands>'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdEvMenuNode.auto_help_display_key" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.CmdEvMenuNode.get_help">
|
||
<code class="sig-name descname">get_help</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#CmdEvMenuNode.get_help"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.CmdEvMenuNode.get_help" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Return the help message for this command and this caller.</p>
|
||
<p>By default, return self.__doc__ (the docstring just under
|
||
the class definition). You can override this behavior,
|
||
though, and even customize it depending on the caller, or other
|
||
commands the caller can use.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>caller</strong> (<em>Object</em><em> or </em><em>Account</em>) – the caller asking for help on the command.</p></li>
|
||
<li><p><strong>cmdset</strong> (<a class="reference internal" href="evennia.commands.cmdset.html#evennia.commands.cmdset.CmdSet" title="evennia.commands.cmdset.CmdSet"><em>CmdSet</em></a>) – the command set (if you need additional commands).</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><em>docstring (str)</em> – the help text to provide the caller for this command.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.CmdEvMenuNode.func">
|
||
<code class="sig-name descname">func</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#CmdEvMenuNode.func"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.CmdEvMenuNode.func" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Implement all menu commands.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.CmdEvMenuNode.lock_storage">
|
||
<code class="sig-name descname">lock_storage</code><em class="property"> = 'cmd:all()'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdEvMenuNode.lock_storage" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt id="evennia.utils.evmenu.EvMenuCmdSet">
|
||
<em class="property">class </em><code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">EvMenuCmdSet</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">cmdsetobj</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">key</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenuCmdSet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenuCmdSet" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <a class="reference internal" href="evennia.commands.cmdset.html#evennia.commands.cmdset.CmdSet" title="evennia.commands.cmdset.CmdSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.commands.cmdset.CmdSet</span></code></a></p>
|
||
<p>The Menu cmdset replaces the current cmdset.</p>
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.EvMenuCmdSet.key">
|
||
<code class="sig-name descname">key</code><em class="property"> = 'menu_cmdset'</em><a class="headerlink" href="#evennia.utils.evmenu.EvMenuCmdSet.key" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.EvMenuCmdSet.priority">
|
||
<code class="sig-name descname">priority</code><em class="property"> = 1</em><a class="headerlink" href="#evennia.utils.evmenu.EvMenuCmdSet.priority" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.EvMenuCmdSet.mergetype">
|
||
<code class="sig-name descname">mergetype</code><em class="property"> = 'Replace'</em><a class="headerlink" href="#evennia.utils.evmenu.EvMenuCmdSet.mergetype" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.EvMenuCmdSet.no_objs">
|
||
<code class="sig-name descname">no_objs</code><em class="property"> = True</em><a class="headerlink" href="#evennia.utils.evmenu.EvMenuCmdSet.no_objs" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.EvMenuCmdSet.no_exits">
|
||
<code class="sig-name descname">no_exits</code><em class="property"> = True</em><a class="headerlink" href="#evennia.utils.evmenu.EvMenuCmdSet.no_exits" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.EvMenuCmdSet.no_channels">
|
||
<code class="sig-name descname">no_channels</code><em class="property"> = False</em><a class="headerlink" href="#evennia.utils.evmenu.EvMenuCmdSet.no_channels" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenuCmdSet.at_cmdset_creation">
|
||
<code class="sig-name descname">at_cmdset_creation</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenuCmdSet.at_cmdset_creation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenuCmdSet.at_cmdset_creation" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Called when creating the set.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.EvMenuCmdSet.path">
|
||
<code class="sig-name descname">path</code><em class="property"> = 'evennia.utils.evmenu.EvMenuCmdSet'</em><a class="headerlink" href="#evennia.utils.evmenu.EvMenuCmdSet.path" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt id="evennia.utils.evmenu.EvMenu">
|
||
<em class="property">class </em><code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">EvMenu</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">caller</span></em>, <em class="sig-param"><span class="n">menudata</span></em>, <em class="sig-param"><span class="n">startnode</span><span class="o">=</span><span class="default_value">'start'</span></em>, <em class="sig-param"><span class="n">cmdset_mergetype</span><span class="o">=</span><span class="default_value">'Replace'</span></em>, <em class="sig-param"><span class="n">cmdset_priority</span><span class="o">=</span><span class="default_value">1</span></em>, <em class="sig-param"><span class="n">auto_quit</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">auto_look</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">auto_help</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">cmd_on_exit</span><span class="o">=</span><span class="default_value">'look'</span></em>, <em class="sig-param"><span class="n">persistent</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">startnode_input</span><span class="o">=</span><span class="default_value">''</span></em>, <em class="sig-param"><span class="n">session</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">debug</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
|
||
<p>This object represents an operational menu. It is initialized from
|
||
a menufile.py instruction.</p>
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.EvMenu.node_border_char">
|
||
<code class="sig-name descname">node_border_char</code><em class="property"> = '_'</em><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.node_border_char" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.__init__">
|
||
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">caller</span></em>, <em class="sig-param"><span class="n">menudata</span></em>, <em class="sig-param"><span class="n">startnode</span><span class="o">=</span><span class="default_value">'start'</span></em>, <em class="sig-param"><span class="n">cmdset_mergetype</span><span class="o">=</span><span class="default_value">'Replace'</span></em>, <em class="sig-param"><span class="n">cmdset_priority</span><span class="o">=</span><span class="default_value">1</span></em>, <em class="sig-param"><span class="n">auto_quit</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">auto_look</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">auto_help</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">cmd_on_exit</span><span class="o">=</span><span class="default_value">'look'</span></em>, <em class="sig-param"><span class="n">persistent</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">startnode_input</span><span class="o">=</span><span class="default_value">''</span></em>, <em class="sig-param"><span class="n">session</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">debug</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.__init__" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Initialize the menu tree and start the caller onto the first node.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>caller</strong> (<em>Object</em><em>, </em><em>Account</em><em> or </em><a class="reference internal" href="evennia.server.session.html#evennia.server.session.Session" title="evennia.server.session.Session"><em>Session</em></a>) – The user of the menu.</p></li>
|
||
<li><p><strong>menudata</strong> (<em>str</em><em>, </em><em>module</em><em> or </em><em>dict</em>) – The full or relative path to the module
|
||
holding the menu tree data. All global functions in this module
|
||
whose name doesn’t start with ‘_ ‘ will be parsed as menu nodes.
|
||
Also the module itself is accepted as input. Finally, a dictionary
|
||
menu tree can be given directly. This must then be a mapping
|
||
<strong>{“nodekey”:callable,…}</strong> where <strong>callable</strong> must be called as
|
||
and return the data expected of a menu node. This allows for
|
||
dynamic menu creation.</p></li>
|
||
<li><p><strong>startnode</strong> (<em>str</em><em>, </em><em>optional</em>) – The starting node name in the menufile.</p></li>
|
||
<li><p><strong>cmdset_mergetype</strong> (<em>str</em><em>, </em><em>optional</em>) – ‘Replace’ (default) means the menu
|
||
commands will be exclusive - no other normal commands will
|
||
be usable while the user is in the menu. ‘Union’ means the
|
||
menu commands will be integrated with the existing commands
|
||
(it will merge with <strong>merge_priority</strong>), if so, make sure that
|
||
the menu’s command names don’t collide with existing commands
|
||
in an unexpected way. Also the CMD_NOMATCH and CMD_NOINPUT will
|
||
be overloaded by the menu cmdset. Other cmdser mergetypes
|
||
has little purpose for the menu.</p></li>
|
||
<li><p><strong>cmdset_priority</strong> (<em>int</em><em>, </em><em>optional</em>) – The merge priority for the
|
||
menu command set. The default (1) is usually enough for most
|
||
types of menus.</p></li>
|
||
<li><p><strong>auto_quit</strong> (<em>bool</em><em>, </em><em>optional</em>) – Allow user to use “q”, “quit” or
|
||
“exit” to leave the menu at any point. Recommended during
|
||
development!</p></li>
|
||
<li><p><strong>auto_look</strong> (<em>bool</em><em>, </em><em>optional</em>) – Automatically make “looK” or “l” to
|
||
re-show the last node. Turning this off means you have to handle
|
||
re-showing nodes yourself, but may be useful if you need to
|
||
use “l” for some other purpose.</p></li>
|
||
<li><p><strong>auto_help</strong> (<em>bool</em><em>, </em><em>optional</em>) – Automatically make “help” or “h” show
|
||
the current help entry for the node. If turned off, eventual
|
||
help must be handled manually, but it may be useful if you
|
||
need ‘h’ for some other purpose, for example.</p></li>
|
||
<li><p><strong>cmd_on_exit</strong> (<em>callable</em><em>, </em><em>str</em><em> or </em><em>None</em><em>, </em><em>optional</em>) – When exiting the menu
|
||
(either by reaching a node with no options or by using the
|
||
in-built quit command (activated with <strong>allow_quit</strong>), this
|
||
callback function or command string will be executed.
|
||
The callback function takes two parameters, the caller then the
|
||
EvMenu object. This is called after cleanup is complete.
|
||
Set to None to not call any command.</p></li>
|
||
<li><p><strong>persistent</strong> (<em>bool</em><em>, </em><em>optional</em>) – Make the Menu persistent (i.e. it will
|
||
survive a reload. This will make the Menu cmdset persistent. Use
|
||
with caution - if your menu is buggy you may end up in a state
|
||
you can’t get out of! Also note that persistent mode requires
|
||
that all formatters, menu nodes and callables are possible to
|
||
<em>pickle</em>. When the server is reloaded, the latest node shown will be completely
|
||
re-run with the same input arguments - so be careful if you are counting
|
||
up some persistent counter or similar - the counter may be run twice if
|
||
reload happens on the node that does that. Note that if <strong>debug</strong> is True,
|
||
this setting is ignored and assumed to be False.</p></li>
|
||
<li><p><strong>startnode_input</strong> (<em>str</em><em> or </em><em>(</em><em>str</em><em>, </em><em>dict</em><em>)</em><em>, </em><em>optional</em>) – Send an input text to <strong>startnode</strong> as if
|
||
a user input text from a fictional previous node. If including the dict, this will
|
||
be passed as <strong>kwargs to that node. When the server reloads,
|
||
the latest visited node will be re-run as **node(caller, raw_string, **kwargs)</strong>.</p></li>
|
||
<li><p><strong>session</strong> (<a class="reference internal" href="evennia.server.session.html#evennia.server.session.Session" title="evennia.server.session.Session"><em>Session</em></a><em>, </em><em>optional</em>) – This is useful when calling EvMenu from an account
|
||
in multisession mode > 2. Note that this session only really relevant
|
||
for the very first display of the first node - after that, EvMenu itself
|
||
will keep the session updated from the command input. So a persistent
|
||
menu will <em>not</em> be using this same session anymore after a reload.</p></li>
|
||
<li><p><strong>debug</strong> (<em>bool</em><em>, </em><em>optional</em>) – If set, the ‘menudebug’ command will be made available
|
||
by default in all nodes of the menu. This will print out the current state of
|
||
the menu. Deactivate for production use! When the debug flag is active, the
|
||
<strong>persistent</strong> flag is deactivated.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Keyword Arguments</dt>
|
||
<dd class="field-even"><p><strong>any</strong> (<em>any</em>) – All kwargs will become initialization variables on <strong>caller.ndb._evmenu</strong>,
|
||
to be available at run.</p>
|
||
</dd>
|
||
<dt class="field-odd">Raises</dt>
|
||
<dd class="field-odd"><p><a class="reference internal" href="#evennia.utils.evmenu.EvMenuError" title="evennia.utils.evmenu.EvMenuError"><strong>EvMenuError</strong></a> – If the start/end node is not found in menu tree.</p>
|
||
</dd>
|
||
</dl>
|
||
<p class="rubric">Notes</p>
|
||
<p>While running, the menu is stored on the caller as <strong>caller.ndb._evmenu</strong>. Also
|
||
the current Session (from the Command, so this is still valid in multisession
|
||
environments) is available through <strong>caller.ndb._evmenu._session</strong>. The <strong>_evmenu</strong>
|
||
property is a good one for storing intermediary data on between nodes since it
|
||
will be automatically deleted when the menu closes.</p>
|
||
<p>In persistent mode, all nodes, formatters and callbacks in the menu must be
|
||
possible to be <em>pickled</em>, this excludes e.g. callables that are class methods
|
||
or functions defined dynamically or as part of another function. In
|
||
non-persistent mode no such restrictions exist.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.msg">
|
||
<code class="sig-name descname">msg</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">txt</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.msg"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.msg" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>This is a central point for sending return texts to the caller. It
|
||
allows for a central point to add custom messaging when creating custom
|
||
EvMenu overrides.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><p><strong>txt</strong> (<em>str</em>) – The text to send.</p>
|
||
</dd>
|
||
</dl>
|
||
<p class="rubric">Notes</p>
|
||
<p>By default this will send to the same session provided to EvMenu
|
||
(if <strong>session</strong> kwarg was provided to <strong>EvMenu.__init__</strong>). It will
|
||
also send it with a <strong>type=menu</strong> for the benefit of OOB/webclient.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.run_exec">
|
||
<code class="sig-name descname">run_exec</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">nodename</span></em>, <em class="sig-param"><span class="n">raw_string</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.run_exec"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.run_exec" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>NOTE: This is deprecated. Use <strong>goto</strong> directly instead.</p>
|
||
<p>Run a function or node as a callback (with the ‘exec’ option key).</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>nodename</strong> (<em>callable</em><em> or </em><em>str</em>) – A callable to run as
|
||
<strong>callable(caller, raw_string)</strong>, or the Name of an existing
|
||
node to run as a callable. This may or may not return
|
||
a string.</p></li>
|
||
<li><p><strong>raw_string</strong> (<em>str</em>) – The raw default string entered on the
|
||
previous node (only used if the node accepts it as an
|
||
argument)</p></li>
|
||
<li><p><strong>kwargs</strong> (<em>any</em>) – These are optional kwargs passed into goto</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><p><em>new_goto (str or None)</em> –</p>
|
||
<dl class="simple">
|
||
<dt>A replacement goto location string or</dt><dd><p>None (no replacement).</p>
|
||
</dd>
|
||
</dl>
|
||
</p>
|
||
</dd>
|
||
</dl>
|
||
<p class="rubric">Notes</p>
|
||
<p>Relying on exec callbacks to set the goto location is
|
||
very powerful but will easily lead to spaghetti structure and
|
||
hard-to-trace paths through the menu logic. So be careful with
|
||
relying on this.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.extract_goto_exec">
|
||
<code class="sig-name descname">extract_goto_exec</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">nodename</span></em>, <em class="sig-param"><span class="n">option_dict</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.extract_goto_exec"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.extract_goto_exec" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Helper: Get callables and their eventual kwargs.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>nodename</strong> (<em>str</em>) – The current node name (used for error reporting).</p></li>
|
||
<li><p><strong>option_dict</strong> (<em>dict</em>) – The seleted option’s dict.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><em>goto (str, callable or None)</em> – The goto directive in the option.
|
||
goto_kwargs (dict): Kwargs for <strong>goto</strong> if the former is callable, otherwise empty.
|
||
execute (callable or None): Executable given by the <strong>exec</strong> directive.
|
||
exec_kwargs (dict): Kwargs for <strong>execute</strong> if it’s callable, otherwise empty.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.goto">
|
||
<code class="sig-name descname">goto</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">nodename</span></em>, <em class="sig-param"><span class="n">raw_string</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.goto"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.goto" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Run a node by name, optionally dynamically generating that name first.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>nodename</strong> (<em>str</em><em> or </em><em>callable</em>) – Name of node or a callable
|
||
to be called as <strong>function(caller, raw_string, **kwargs)</strong> or
|
||
<strong>function(caller, **kwargs)</strong> to return the actual goto string or
|
||
a (“nodename”, kwargs) tuple.</p></li>
|
||
<li><p><strong>raw_string</strong> (<em>str</em>) – The raw default string entered on the
|
||
previous node (only used if the node accepts it as an
|
||
argument)</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Keyword Arguments</dt>
|
||
<dd class="field-even"><p><strong>any</strong> – Extra arguments to goto callables.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.run_exec_then_goto">
|
||
<code class="sig-name descname">run_exec_then_goto</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">runexec</span></em>, <em class="sig-param"><span class="n">goto</span></em>, <em class="sig-param"><span class="n">raw_string</span></em>, <em class="sig-param"><span class="n">runexec_kwargs</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">goto_kwargs</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.run_exec_then_goto"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.run_exec_then_goto" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Call ‘exec’ callback and goto (which may also be a callable) in sequence.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>runexec</strong> (<em>callable</em><em> or </em><em>str</em>) – Callback to run before goto. If
|
||
the callback returns a string, this is used to replace
|
||
the <strong>goto</strong> string/callable before being passed into the goto handler.</p></li>
|
||
<li><p><strong>goto</strong> (<em>str</em>) – The target node to go to next (may be replaced
|
||
by <strong>runexec</strong>)..</p></li>
|
||
<li><p><strong>raw_string</strong> (<em>str</em>) – The original user input.</p></li>
|
||
<li><p><strong>runexec_kwargs</strong> (<em>dict</em><em>, </em><em>optional</em>) – Optional kwargs for runexec.</p></li>
|
||
<li><p><strong>goto_kwargs</strong> (<em>dict</em><em>, </em><em>optional</em>) – Optional kwargs for goto.</p></li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.close_menu">
|
||
<code class="sig-name descname">close_menu</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.close_menu"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.close_menu" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Shutdown menu; occurs when reaching the end node or using the quit command.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.print_debug_info">
|
||
<code class="sig-name descname">print_debug_info</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">arg</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.print_debug_info"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.print_debug_info" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Messages the caller with the current menu state, for debug purposes.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><p><strong>arg</strong> (<em>str</em>) – Arg to debug instruction, either nothing, ‘full’ or the name
|
||
of a property to inspect.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.parse_input">
|
||
<code class="sig-name descname">parse_input</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">raw_string</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.parse_input"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.parse_input" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Parses the incoming string from the menu user.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><p><strong>raw_string</strong> (<em>str</em>) – The incoming, unmodified string
|
||
from the user.</p>
|
||
</dd>
|
||
</dl>
|
||
<p class="rubric">Notes</p>
|
||
<p>This method is expected to parse input and use the result
|
||
to relay execution to the relevant methods of the menu. It
|
||
should also report errors directly to the user.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.display_nodetext">
|
||
<code class="sig-name descname">display_nodetext</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.display_nodetext"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.display_nodetext" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.display_helptext">
|
||
<code class="sig-name descname">display_helptext</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.display_helptext"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.display_helptext" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.nodetext_formatter">
|
||
<code class="sig-name descname">nodetext_formatter</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">nodetext</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.nodetext_formatter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.nodetext_formatter" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Format the node text itself.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><p><strong>nodetext</strong> (<em>str</em>) – The full node text (the text describing the node).</p>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><em>nodetext (str)</em> – The formatted node text.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.helptext_formatter">
|
||
<code class="sig-name descname">helptext_formatter</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">helptext</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.helptext_formatter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.helptext_formatter" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Format the node’s help text</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><p><strong>helptext</strong> (<em>str</em>) – The unformatted help text for the node.</p>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><em>helptext (str)</em> – The formatted help text.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.options_formatter">
|
||
<code class="sig-name descname">options_formatter</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">optionlist</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.options_formatter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.options_formatter" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Formats the option block.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>optionlist</strong> (<em>list</em>) – List of (key, description) tuples for every
|
||
option related to this node.</p></li>
|
||
<li><p><strong>caller</strong> (<em>Object</em><em>, </em><em>Account</em><em> or </em><em>None</em><em>, </em><em>optional</em>) – The caller of the node.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><em>options (str)</em> – The formatted option display.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.EvMenu.node_formatter">
|
||
<code class="sig-name descname">node_formatter</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">nodetext</span></em>, <em class="sig-param"><span class="n">optionstext</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#EvMenu.node_formatter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.EvMenu.node_formatter" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Formats the entirety of the node.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>nodetext</strong> (<em>str</em>) – The node text as returned by <strong>self.nodetext_formatter</strong>.</p></li>
|
||
<li><p><strong>optionstext</strong> (<em>str</em>) – The options display as returned by <strong>self.options_formatter</strong>.</p></li>
|
||
<li><p><strong>caller</strong> (<em>Object</em><em>, </em><em>Account</em><em> or </em><em>None</em><em>, </em><em>optional</em>) – The caller of the node.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><em>node (str)</em> – The formatted node to display.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt id="evennia.utils.evmenu.list_node">
|
||
<code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">list_node</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">option_generator</span></em>, <em class="sig-param"><span class="n">select</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">pagesize</span><span class="o">=</span><span class="default_value">10</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#list_node"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.list_node" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Decorator for making an EvMenu node into a multi-page list node. Will add new options,
|
||
prepending those options added in the node.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>option_generator</strong> (<em>callable</em><em> or </em><em>list</em>) – A list of strings indicating the options, or a callable
|
||
that is called as option_generator(caller) to produce such a list.</p></li>
|
||
<li><p><strong>select</strong> (<em>callable</em><em> or </em><em>str</em><em>, </em><em>optional</em>) – Node to redirect a selection to. Its <strong>**kwargs</strong> will
|
||
contain the <strong>available_choices</strong> list and <strong>selection</strong> will hold one
|
||
of the elements in that list. If a callable, it will be called as
|
||
<strong>select(caller, menuchoice, **kwargs)</strong> where menuchoice is the
|
||
chosen option as a string and <strong>available_choices</strong> is the list of available
|
||
options offered by the option_generator. The callable whould return
|
||
the name of the target node to goto after this selection (or None to repeat the
|
||
list-node). Note that if this is not given, the decorated node
|
||
must itself provide a way to continue from the node!</p></li>
|
||
<li><p><strong>pagesize</strong> (<em>int</em>) – How many options to show per page.</p></li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<p class="rubric">Example</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">_selectfunc</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">menuchoice</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||
<span class="c1"># menuchoice would be either 'foo' or 'bar' here</span>
|
||
<span class="c1"># kwargs['available_choices'] would be the list ['foo', 'bar']</span>
|
||
<span class="k">return</span> <span class="s2">"the_next_node_to_go_to"</span>
|
||
|
||
<span class="nd">@list_node</span><span class="p">([</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">],</span> <span class="n">_selectfunc</span><span class="p">)</span>
|
||
<span class="k">def</span> <span class="nf">node_index</span><span class="p">(</span><span class="n">caller</span><span class="p">):</span>
|
||
<span class="n">text</span> <span class="o">=</span> <span class="s2">"describing the list"</span>
|
||
<span class="k">return</span> <span class="n">text</span><span class="p">,</span> <span class="p">[]</span>
|
||
</pre></div>
|
||
</div>
|
||
<p class="rubric">Notes</p>
|
||
<p>All normal <strong>goto</strong> or <strong>exec</strong> callables returned from the decorated nodes will, if they accept
|
||
<strong>**kwargs</strong>, get a new kwarg <strong>available_choices</strong> injected. This is the ordered list of named
|
||
options (descs) visible on the current node page.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt id="evennia.utils.evmenu.CmdGetInput">
|
||
<em class="property">class </em><code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">CmdGetInput</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#CmdGetInput"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.CmdGetInput" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <a class="reference internal" href="evennia.commands.command.html#evennia.commands.command.Command" title="evennia.commands.command.Command"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.commands.command.Command</span></code></a></p>
|
||
<p>Enter your data and press return.</p>
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.CmdGetInput.key">
|
||
<code class="sig-name descname">key</code><em class="property"> = '__nomatch_command'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdGetInput.key" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.CmdGetInput.aliases">
|
||
<code class="sig-name descname">aliases</code><em class="property"> = ['__noinput_command']</em><a class="headerlink" href="#evennia.utils.evmenu.CmdGetInput.aliases" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.CmdGetInput.func">
|
||
<code class="sig-name descname">func</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#CmdGetInput.func"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.CmdGetInput.func" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>This is called when user enters anything.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.CmdGetInput.help_category">
|
||
<code class="sig-name descname">help_category</code><em class="property"> = 'general'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdGetInput.help_category" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.CmdGetInput.lock_storage">
|
||
<code class="sig-name descname">lock_storage</code><em class="property"> = 'cmd:all();'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdGetInput.lock_storage" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt id="evennia.utils.evmenu.InputCmdSet">
|
||
<em class="property">class </em><code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">InputCmdSet</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">cmdsetobj</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">key</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#InputCmdSet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.InputCmdSet" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <a class="reference internal" href="evennia.commands.cmdset.html#evennia.commands.cmdset.CmdSet" title="evennia.commands.cmdset.CmdSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.commands.cmdset.CmdSet</span></code></a></p>
|
||
<p>This stores the input command</p>
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.InputCmdSet.key">
|
||
<code class="sig-name descname">key</code><em class="property"> = 'input_cmdset'</em><a class="headerlink" href="#evennia.utils.evmenu.InputCmdSet.key" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.InputCmdSet.priority">
|
||
<code class="sig-name descname">priority</code><em class="property"> = 1</em><a class="headerlink" href="#evennia.utils.evmenu.InputCmdSet.priority" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.InputCmdSet.mergetype">
|
||
<code class="sig-name descname">mergetype</code><em class="property"> = 'Replace'</em><a class="headerlink" href="#evennia.utils.evmenu.InputCmdSet.mergetype" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.InputCmdSet.no_objs">
|
||
<code class="sig-name descname">no_objs</code><em class="property"> = True</em><a class="headerlink" href="#evennia.utils.evmenu.InputCmdSet.no_objs" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.InputCmdSet.no_exits">
|
||
<code class="sig-name descname">no_exits</code><em class="property"> = True</em><a class="headerlink" href="#evennia.utils.evmenu.InputCmdSet.no_exits" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.InputCmdSet.no_channels">
|
||
<code class="sig-name descname">no_channels</code><em class="property"> = False</em><a class="headerlink" href="#evennia.utils.evmenu.InputCmdSet.no_channels" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.utils.evmenu.InputCmdSet.at_cmdset_creation">
|
||
<code class="sig-name descname">at_cmdset_creation</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#InputCmdSet.at_cmdset_creation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.InputCmdSet.at_cmdset_creation" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>called once at creation</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.utils.evmenu.InputCmdSet.path">
|
||
<code class="sig-name descname">path</code><em class="property"> = 'evennia.utils.evmenu.InputCmdSet'</em><a class="headerlink" href="#evennia.utils.evmenu.InputCmdSet.path" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt id="evennia.utils.evmenu.get_input">
|
||
<code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">get_input</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">caller</span></em>, <em class="sig-param"><span class="n">prompt</span></em>, <em class="sig-param"><span class="n">callback</span></em>, <em class="sig-param"><span class="n">session</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">*</span><span class="n">args</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#get_input"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.get_input" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>This is a helper function for easily request input from
|
||
the caller.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>caller</strong> (<em>Account</em><em> or </em><em>Object</em>) – The entity being asked
|
||
the question. This should usually be an object
|
||
controlled by a user.</p></li>
|
||
<li><p><strong>prompt</strong> (<em>str</em>) – This text will be shown to the user,
|
||
in order to let them know their input is needed.</p></li>
|
||
<li><p><strong>callback</strong> (<em>callable</em>) – A function that will be called
|
||
when the user enters a reply. It must take three
|
||
arguments: the <strong>caller</strong>, the <strong>prompt</strong> text and the
|
||
<strong>result</strong> of the input given by the user. If the
|
||
callback doesn’t return anything or return False,
|
||
the input prompt will be cleaned up and exited. If
|
||
returning True, the prompt will remain and continue to
|
||
accept input.</p></li>
|
||
<li><p><strong>session</strong> (<a class="reference internal" href="evennia.server.session.html#evennia.server.session.Session" title="evennia.server.session.Session"><em>Session</em></a><em>, </em><em>optional</em>) – This allows to specify the
|
||
session to send the prompt to. It’s usually only
|
||
needed if <strong>caller</strong> is an Account in multisession modes
|
||
greater than 2. The session is then updated by the
|
||
command and is available (for example in callbacks)
|
||
through <strong>caller.ndb.getinput._session</strong>.</p></li>
|
||
<li><p><strong>args</strong> (<em>optional</em>) – Extra arguments will be
|
||
passed to the fall back function as a list ‘args’
|
||
and all keyword arguments as a dictionary ‘kwargs’.
|
||
To utilise <strong>*args</strong> and <strong>**kwargs</strong>, a value for the
|
||
session argument must be provided (None by default)
|
||
and the callback function must take <strong>*args</strong> and
|
||
<strong>**kwargs</strong> as arguments.</p></li>
|
||
<li><p><strong>kwargs</strong> (<em>optional</em>) – Extra arguments will be
|
||
passed to the fall back function as a list ‘args’
|
||
and all keyword arguments as a dictionary ‘kwargs’.
|
||
To utilise <strong>*args</strong> and <strong>**kwargs</strong>, a value for the
|
||
session argument must be provided (None by default)
|
||
and the callback function must take <strong>*args</strong> and
|
||
<strong>**kwargs</strong> as arguments.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Raises</dt>
|
||
<dd class="field-even"><p><strong>RuntimeError</strong> – If the given callback is not callable.</p>
|
||
</dd>
|
||
</dl>
|
||
<p class="rubric">Notes</p>
|
||
<p>The result value sent to the callback is raw and not
|
||
processed in any way. This means that you will get
|
||
the ending line return character from most types of
|
||
client inputs. So make sure to strip that before
|
||
doing a comparison.</p>
|
||
<p>When the prompt is running, a temporary object
|
||
<strong>caller.ndb._getinput</strong> is stored; this will be removed
|
||
when the prompt finishes.
|
||
If you need the specific Session of the caller (which
|
||
may not be easy to get if caller is an account in higher
|
||
multisession modes), then it is available in the
|
||
callback through <strong>caller.ndb._getinput._session</strong>.</p>
|
||
<p>Chaining get_input functions will result in the caller
|
||
stacking ever more instances of InputCmdSets. Whilst
|
||
they will all be cleared on concluding the get_input
|
||
chain, EvMenu should be considered for anything beyond
|
||
a single question.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt id="evennia.utils.evmenu.parse_menu_template">
|
||
<code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">parse_menu_template</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">caller</span></em>, <em class="sig-param"><span class="n">menu_template</span></em>, <em class="sig-param"><span class="n">goto_callables</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#parse_menu_template"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.parse_menu_template" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Parse menu-template string. The main function of the EvMenu templating system.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>caller</strong> (<em>Object</em><em> or </em><em>Account</em>) – Entity using the menu.</p></li>
|
||
<li><p><strong>menu_template</strong> (<em>str</em>) – Menu described using the templating format.</p></li>
|
||
<li><p><strong>goto_callables</strong> (<em>dict</em><em>, </em><em>optional</em>) – Mapping between call-names and callables
|
||
on the form <strong>callable(caller, raw_string, **kwargs)</strong>. These are what is
|
||
available to use in the <strong>menu_template</strong> string.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><em>dict</em> – A <strong>{“node”: nodefunc}</strong> menutree suitable to pass into EvMenu.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt id="evennia.utils.evmenu.template2menu">
|
||
<code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">template2menu</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">caller</span></em>, <em class="sig-param"><span class="n">menu_template</span></em>, <em class="sig-param"><span class="n">goto_callables</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">startnode</span><span class="o">=</span><span class="default_value">'start'</span></em>, <em class="sig-param"><span class="n">persistent</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/evmenu.html#template2menu"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.template2menu" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Helper function to generate and start an EvMenu based on a menu template
|
||
string. This will internall call <strong>parse_menu_template</strong> and run a default
|
||
EvMenu with its results.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>caller</strong> (<em>Object</em><em> or </em><em>Account</em>) – The entity using the menu.</p></li>
|
||
<li><p><strong>menu_template</strong> (<em>str</em>) – The menu-template string describing the content
|
||
and structure of the menu. It can also be the python-path to, or a module
|
||
containing a <strong>MENU_TEMPLATE</strong> global variable with the template.</p></li>
|
||
<li><p><strong>goto_callables</strong> (<em>dict</em><em>, </em><em>optional</em>) – Mapping of callable-names to
|
||
module-global objects to reference by name in the menu-template.
|
||
Must be on the form <strong>callable(caller, raw_string, **kwargs)</strong>.</p></li>
|
||
<li><p><strong>startnode</strong> (<em>str</em><em>, </em><em>optional</em>) – The name of the startnode, if not ‘start’.</p></li>
|
||
<li><p><strong>persistent</strong> (<em>bool</em><em>, </em><em>optional</em>) – If the generated menu should be persistent.</p></li>
|
||
<li><p><strong>**kwargs</strong> – All kwargs will be passed into EvMenu.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><em>EvMenu</em> – The generated EvMenu.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
</section>
|
||
|
||
|
||
<div class="clearer"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<p class="logo"><a href="../index.html">
|
||
<img class="logo" src="../_static/evennia_logo.png" alt="Logo"/>
|
||
</a></p>
|
||
<div id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="../search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" />
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<script>$('#searchbox').show(0);</script>
|
||
<p><h3><a href="../index.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">evennia.utils.evmenu</a><ul>
|
||
<li><a class="reference internal" href="#menu-generation-from-template-string">Menu generation from template string</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<div role="note" aria-label="source link">
|
||
<!--h3>This Page</h3-->
|
||
<ul class="this-page-menu">
|
||
<li><a href="../_sources/api/evennia.utils.evmenu.md.txt"
|
||
rel="nofollow">Show Page Source</a></li>
|
||
</ul>
|
||
</div><h3>Links</h3>
|
||
<ul>
|
||
<li><a href="https://www.evennia.com">Home page</a> </li>
|
||
<li><a href="https://github.com/evennia/evennia">Evennia Github</a> </li>
|
||
<li><a href="http://games.evennia.com">Game Index</a> </li>
|
||
<li><a href="http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb">IRC</a> -
|
||
<a href="https://discord.gg/NecFePw">Discord</a> -
|
||
<a href="https://groups.google.com/forum/#%21forum/evennia">Forums</a>
|
||
</li>
|
||
<li><a href="http://evennia.blogspot.com/">Evennia Dev blog</a> </li>
|
||
</ul>
|
||
<h3>Versions</h3>
|
||
<ul>
|
||
<li><a href="../../1.0-dev/api/evennia.utils.evmenu.html">1.0-dev (develop branch)</a></li>
|
||
<li><a href="evennia.utils.evmenu.html">0.9.5 (v0.9.5 branch)</a></li>
|
||
</ul>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 0.9.5</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">evennia.utils.evmenu</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2020, The Evennia developer community.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
|
||
</div>
|
||
</body>
|
||
</html> |