mirror of
https://github.com/evennia/evennia.git
synced 2026-04-02 14:07:16 +02:00
Updated HTML docs
This commit is contained in:
parent
86fb09d6bf
commit
86c930be7a
1221 changed files with 76528 additions and 29095 deletions
|
|
@ -30,6 +30,7 @@
|
|||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 1.0-dev</a> »</li>
|
||||
<li class="nav-item nav-item-this"><a href="">evennia.utils.evmenu</a></li>
|
||||
</ul>
|
||||
<div class="develop">develop branch</div>
|
||||
</div>
|
||||
|
||||
<div class="document">
|
||||
|
|
@ -39,9 +40,10 @@
|
|||
|
||||
<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>
|
||||
<p>EvMenu</p>
|
||||
<p>This implements a full menu system for Evennia.</p>
|
||||
<p>To start the menu, just import the EvMenu class from this module.
|
||||
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>
|
||||
|
|
@ -51,8 +53,8 @@
|
|||
</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
|
||||
cmdset while using the Menu. The menu_module_path 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>
|
||||
|
|
@ -78,7 +80,7 @@ command definition too) with function definitions:</p>
|
|||
<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
|
||||
<p>Where caller 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
|
||||
|
|
@ -92,50 +94,43 @@ deleted when the menu is exited.</p>
|
|||
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><dl class="simple">
|
||||
<dt><strong>text</strong> (str, tuple or None): Text shown at this node. If a tuple, the</dt><dd><p>second element in the tuple is a help text to display at this
|
||||
node when the user enters the menu help command there.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</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>
|
||||
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
|
||||
<li><p><strong>key</strong> (str or tuple, optional): What to enter to choose this option.
|
||||
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>
|
||||
will not be displayed in the list.</p></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
|
||||
<li><p><strong>goto</strong> (str, tuple or callable): If string, should be the name of node to go to
|
||||
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
|
||||
is the callable and the second is a dict with the <strong>**kwargs</strong> 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
|
||||
None or the empty string, the current node will be revisited.</p></li>
|
||||
<li><p><strong>exec</strong> (str, callable or tuple, optional): This takes the same input as <strong>goto</strong> above
|
||||
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>
|
||||
If an exec callable returns the empty string (only), the current node is re-run.</p></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<p>If key is not given, the option will automatically be identified by
|
||||
<p>If <strong>key</strong> 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>
|
||||
|
|
@ -189,9 +184,8 @@ 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>
|
||||
<p>For a menu demo, import <strong>CmdTestMenu</strong> 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
|
||||
|
|
@ -281,9 +275,9 @@ allowed, these will be added to the <strong>**kwargs</strong> going into the cal
|
|||
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>
|
||||
<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">
|
||||
|
|
@ -366,6 +360,11 @@ commands the caller can use.</p>
|
|||
<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>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.CmdEvMenuNode.search_index_entry">
|
||||
<code class="sig-name descname">search_index_entry</code><em class="property"> = {'aliases': '__nomatch_command', 'category': 'menu', 'key': '__noinput_command', 'tags': '', 'text': '\n Menu options.\n '}</em><a class="headerlink" href="#evennia.utils.evmenu.CmdEvMenuNode.search_index_entry" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py class">
|
||||
|
|
@ -497,14 +496,12 @@ menu will <em>not</em> be using this same session anymore after a reload.</p></l
|
|||
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>
|
||||
<li><p><strong>**kwargs</strong> – All kwargs will become initialization variables on <strong>caller.ndb._menutree</strong>,
|
||||
to be available at run.</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>
|
||||
<dt class="field-even">Raises</dt>
|
||||
<dd class="field-even"><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>
|
||||
|
|
@ -604,11 +601,9 @@ 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>
|
||||
<li><p><strong>**kwargs</strong> – Extra arguments to goto callables.</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>
|
||||
|
||||
|
|
@ -753,34 +748,49 @@ prepending those options added in the node.</p>
|
|||
<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>
|
||||
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 a kwarg mapping the option keys to the choices
|
||||
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>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">select</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="n">selection</span><span class="p">,</span> <span class="n">available_choices</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||||
<span class="s1">'''</span>
|
||||
<span class="s1"> Args:</span>
|
||||
<span class="s1"> caller (Object or Account): User of the menu.</span>
|
||||
<span class="s1"> selection (str): What caller chose in the menu</span>
|
||||
<span class="s1"> available_choices (list): The keys of elements available on the *current listing</span>
|
||||
<span class="s1"> page*.</span>
|
||||
<span class="s1"> **kwargs: Kwargs passed on from the node.</span>
|
||||
<span class="s1"> Returns:</span>
|
||||
<span class="s1"> tuple, str or None: A tuple (nextnodename, **kwargs) or just nextnodename. Return</span>
|
||||
<span class="s1"> **None** to go back to the listnode.</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>
|
||||
<span class="s1"> # (do something with **selection** here)</span>
|
||||
|
||||
<span class="s1"> return "nextnode", **kwargs</span>
|
||||
|
||||
<span class="s1">@list_node(['foo', 'bar'], select)</span>
|
||||
<span class="s1">def node_index(caller):</span>
|
||||
<span class="s1"> text = "describing the list"</span>
|
||||
|
||||
<span class="s1"> # optional extra options in addition to the list-options</span>
|
||||
<span class="s1"> extra_options = []</span>
|
||||
|
||||
<span class="s1"> return text, extra_options</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>
|
||||
<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 ‘available_choices’
|
||||
injected. These are the ordered list of named options (descs) visible
|
||||
on the current node page.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py class">
|
||||
|
|
@ -814,6 +824,11 @@ options (descs) visible on the current node page.</p>
|
|||
<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>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.CmdGetInput.search_index_entry">
|
||||
<code class="sig-name descname">search_index_entry</code><em class="property"> = {'aliases': '__noinput_command', 'category': 'general', 'key': '__nomatch_command', 'tags': '', 'text': '\n Enter your data and press return.\n '}</em><a class="headerlink" href="#evennia.utils.evmenu.CmdGetInput.search_index_entry" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py class">
|
||||
|
|
@ -867,44 +882,29 @@ options (descs) visible on the current node page.</p>
|
|||
<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>
|
||||
<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>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>
|
||||
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>
|
||||
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>any</em>) – Extra arguments to pass to <strong>callback</strong>. To utilise <strong>*args</strong>
|
||||
(and <strong>**kwargs</strong>), a value for the <strong>session</strong> argument must also be
|
||||
provided.</p></li>
|
||||
<li><p><strong>**kwargs</strong> (<em>any</em>) – Extra kwargs to pass to <strong>callback</strong>.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
<dt class="field-even">Raises</dt>
|
||||
|
|
@ -912,23 +912,160 @@ and the callback function must take <strong>*args</strong> and
|
|||
</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>
|
||||
<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.</p>
|
||||
<p>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>.
|
||||
This is why the <strong>session</strong> is required as input.</p>
|
||||
<p>It’s not recommended to ‘chain’ <strong>get_input</strong> into a sequence of
|
||||
questions. This will result in the caller stacking ever more instances
|
||||
of InputCmdSets. While 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 class">
|
||||
<dt id="evennia.utils.evmenu.CmdYesNoQuestion">
|
||||
<em class="property">class </em><code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">CmdYesNoQuestion</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#CmdYesNoQuestion"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.CmdYesNoQuestion" 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>Handle a prompt for yes or no. Press [return] for the default choice.</p>
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.CmdYesNoQuestion.key">
|
||||
<code class="sig-name descname">key</code><em class="property"> = '__noinput_command'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdYesNoQuestion.key" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.CmdYesNoQuestion.aliases">
|
||||
<code class="sig-name descname">aliases</code><em class="property"> = ['__nomatch_command', 'y', 'yes', 'n', 'a', 'abort', 'no']</em><a class="headerlink" href="#evennia.utils.evmenu.CmdYesNoQuestion.aliases" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.CmdYesNoQuestion.arg_regex">
|
||||
<code class="sig-name descname">arg_regex</code><em class="property"> = re.compile('^$', re.IGNORECASE)</em><a class="headerlink" href="#evennia.utils.evmenu.CmdYesNoQuestion.arg_regex" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt id="evennia.utils.evmenu.CmdYesNoQuestion.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#CmdYesNoQuestion.func"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.CmdYesNoQuestion.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.CmdYesNoQuestion.help_category">
|
||||
<code class="sig-name descname">help_category</code><em class="property"> = 'general'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdYesNoQuestion.help_category" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.CmdYesNoQuestion.lock_storage">
|
||||
<code class="sig-name descname">lock_storage</code><em class="property"> = 'cmd:all();'</em><a class="headerlink" href="#evennia.utils.evmenu.CmdYesNoQuestion.lock_storage" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.CmdYesNoQuestion.search_index_entry">
|
||||
<code class="sig-name descname">search_index_entry</code><em class="property"> = {'aliases': '__nomatch_command y yes n a abort no', 'category': 'general', 'key': '__noinput_command', 'tags': '', 'text': '\n Handle a prompt for yes or no. Press [return] for the default choice.\n\n '}</em><a class="headerlink" href="#evennia.utils.evmenu.CmdYesNoQuestion.search_index_entry" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py class">
|
||||
<dt id="evennia.utils.evmenu.YesNoQuestionCmdSet">
|
||||
<em class="property">class </em><code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">YesNoQuestionCmdSet</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#YesNoQuestionCmdSet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.YesNoQuestionCmdSet" 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.YesNoQuestionCmdSet.key">
|
||||
<code class="sig-name descname">key</code><em class="property"> = 'yes_no_question_cmdset'</em><a class="headerlink" href="#evennia.utils.evmenu.YesNoQuestionCmdSet.key" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.YesNoQuestionCmdSet.priority">
|
||||
<code class="sig-name descname">priority</code><em class="property"> = 1</em><a class="headerlink" href="#evennia.utils.evmenu.YesNoQuestionCmdSet.priority" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.YesNoQuestionCmdSet.mergetype">
|
||||
<code class="sig-name descname">mergetype</code><em class="property"> = 'Replace'</em><a class="headerlink" href="#evennia.utils.evmenu.YesNoQuestionCmdSet.mergetype" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.YesNoQuestionCmdSet.no_objs">
|
||||
<code class="sig-name descname">no_objs</code><em class="property"> = True</em><a class="headerlink" href="#evennia.utils.evmenu.YesNoQuestionCmdSet.no_objs" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.YesNoQuestionCmdSet.no_exits">
|
||||
<code class="sig-name descname">no_exits</code><em class="property"> = True</em><a class="headerlink" href="#evennia.utils.evmenu.YesNoQuestionCmdSet.no_exits" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py attribute">
|
||||
<dt id="evennia.utils.evmenu.YesNoQuestionCmdSet.no_channels">
|
||||
<code class="sig-name descname">no_channels</code><em class="property"> = False</em><a class="headerlink" href="#evennia.utils.evmenu.YesNoQuestionCmdSet.no_channels" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt id="evennia.utils.evmenu.YesNoQuestionCmdSet.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#YesNoQuestionCmdSet.at_cmdset_creation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.YesNoQuestionCmdSet.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.YesNoQuestionCmdSet.path">
|
||||
<code class="sig-name descname">path</code><em class="property"> = 'evennia.utils.evmenu.YesNoQuestionCmdSet'</em><a class="headerlink" href="#evennia.utils.evmenu.YesNoQuestionCmdSet.path" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py function">
|
||||
<dt id="evennia.utils.evmenu.ask_yes_no">
|
||||
<code class="sig-prename descclassname">evennia.utils.evmenu.</code><code class="sig-name descname">ask_yes_no</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><span class="o">=</span><span class="default_value">'Yes or No {options}?'</span></em>, <em class="sig-param"><span class="n">yes_action</span><span class="o">=</span><span class="default_value">'Yes'</span></em>, <em class="sig-param"><span class="n">no_action</span><span class="o">=</span><span class="default_value">'No'</span></em>, <em class="sig-param"><span class="n">default</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">allow_abort</span><span class="o">=</span><span class="default_value">False</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#ask_yes_no"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.evmenu.ask_yes_no" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A helper question for asking a simple yes/no question. This will cause
|
||||
the system to pause and wait for input from the player.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>prompt</strong> (<em>str</em>) – The yes/no question to ask. This takes an optional formatting
|
||||
marker <strong>{options}</strong> which will be filled with ‘Y/N’, ‘[Y]/N’ or
|
||||
‘Y/[N]’ depending on the setting of <strong>default</strong>. If <strong>allow_abort</strong> is set,
|
||||
then the ‘A(bort)’ option will also be available.</p></li>
|
||||
<li><p><strong>yes_action</strong> (<em>callable</em><em> or </em><em>str</em>) – If a callable, this will be called
|
||||
with <strong>(caller, *args, **kwargs)</strong> when the Yes-choice is made.
|
||||
If a string, this string will be echoed back to the caller.</p></li>
|
||||
<li><p><strong>no_action</strong> (<em>callable</em><em> or </em><em>str</em>) – If a callable, this will be called
|
||||
with <strong>(caller, *args, **kwargs)</strong> when the No-choice is made.
|
||||
If a string, this string will be echoed back to the caller.</p></li>
|
||||
<li><p><strong>default</strong> (<em>str optional</em>) – This is what the user will get if they just press the
|
||||
return key without giving any input. One of ‘N’, ‘Y’, ‘A’ or <strong>None</strong>
|
||||
for no default (an explicit choice must be given). If ‘A’ (abort)
|
||||
is given, <strong>allow_abort</strong> kwarg is ignored and assumed set.</p></li>
|
||||
<li><p><strong>allow_abort</strong> (<em>bool</em><em>, </em><em>optional</em>) – If set, the ‘A(bort)’ option is available
|
||||
(a third option meaning neither yes or no but just exits the prompt).</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._yes_no_question.session</strong>.</p></li>
|
||||
<li><p><strong>*args</strong> – Additional arguments passed on into callables.</p></li>
|
||||
<li><p><strong>**kwargs</strong> – Additional keyword args passed on into callables.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
<dt class="field-even">Raises</dt>
|
||||
<dd class="field-even"><p><strong>RuntimeError</strong><strong>, </strong><strong>FooError</strong> – If default and <strong>allow_abort</strong> clashes.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<p class="rubric">Example</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># just returning strings</span>
|
||||
<span class="n">ask_yes_no</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="s2">"Are you happy </span><span class="si">{options}</span><span class="s2">?"</span><span class="p">,</span>
|
||||
<span class="s2">"you answered yes"</span><span class="p">,</span> <span class="s2">"you answered no"</span><span class="p">)</span>
|
||||
<span class="c1"># trigger callables</span>
|
||||
<span class="n">ask_yes_no</span><span class="p">(</span><span class="n">caller</span><span class="p">,</span> <span class="s2">"Are you sad </span><span class="si">{options}</span><span class="s2">?"</span><span class="p">,</span>
|
||||
<span class="n">_callable_yes</span><span class="p">,</span> <span class="n">_callable_no</span><span class="p">,</span> <span class="n">allow_abort</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py function">
|
||||
|
|
@ -1032,7 +1169,6 @@ Must be on the form <strong>callable(caller, raw_string, **kwargs)</strong>.</p>
|
|||
<li><a href="../../0.9.5/api/evennia.utils.evmenu.html">0.9.5 (v0.9.5 branch)</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
|
|
@ -1049,6 +1185,7 @@ Must be on the form <strong>callable(caller, raw_string, **kwargs)</strong>.</p>
|
|||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 1.0-dev</a> »</li>
|
||||
<li class="nav-item nav-item-this"><a href="">evennia.utils.evmenu</a></li>
|
||||
</ul>
|
||||
<div class="develop">develop branch</div>
|
||||
</div>
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2020, The Evennia developer community.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue