.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2018 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.TextCompleterSimple:

==========================================================================================================================================
|phoenix_title|  **wx.TextCompleterSimple**
==========================================================================================================================================

A simpler base class for custom completer objects.          

This class may be simpler to use than the base :ref:`wx.TextCompleter`  as it allows to implement only a single virtual method instead of two of them (at the price of storing all completions in a temporary array). 

Here is a simple example of a custom completer that completes the names of some chess pieces. Of course, as the total list here has only four items it would have been much simpler to just specify the array containing all the completions in this example but the same approach could be used when the total number of completions is much higher provided the number of possibilities for each word is still relatively small: ::

        class MyTextCompleter(wx.TextCompleterSimple):

            def __init__(self):
                wx.TextCompleterSimple.__init__(self)

            def GetCompletions(self, prefix):
                res = []
                firstWord = prefix.split()[0]

                if firstWord == "white":
                    res.append("white pawn")
                    res.append("white rook")
                elif firstWord == "black":
                    res.append("black king")
                    res.append("black queen")
                else:
                    res.append("white")
                    res.append("black")

                return res


        # Later on...
        text = wx.TextCtrl(parent, wx.ID_ANY, 'My Text')
        text.AutoComplete(MyTextCompleter())







         



.. versionadded:: 2.9.2 
     







|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>TextCompleterSimple</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.TextCompleterSimple_inheritance.png" alt="Inheritance diagram of TextCompleterSimple" usemap="#dummy" class="inheritance"/></center>
   </div>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.TextCompleterSimple.html" title="wx.TextCompleterSimple" alt="" coords="5,83,184,112"/> <area shape="rect" id="node2" href="wx.TextCompleter.html" title="wx.TextCompleter" alt="" coords="27,5,161,35"/> </map> 
   </p>

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.TextCompleterSimple.GetCompletions`                                   Pure virtual method returning all possible completions for the given prefix.
:meth:`~wx.TextCompleterSimple.GetNext`                                          Called to retrieve the next completion.
:meth:`~wx.TextCompleterSimple.Start`                                            Function called to start iteration over the completions for the given prefix.
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.TextCompleterSimple.Next`                                             See :meth:`~wx.TextCompleterSimple.GetNext`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.TextCompleterSimple(TextCompleter)

   A simpler base class for custom completer objects.



   .. method:: GetCompletions(self, prefix)

      Pure virtual method returning all possible completions for the given prefix.                  

      The custom completer should examine the provided prefix and return all the possible completions for it in the output array `res`. 

      Please notice that the returned values should start with the prefix, otherwise they will be simply ignored, making adding them to the array in the first place useless. 

      Notice that this function may be called from thread other than main one (this is currently always the case under MSW) so the appropriate synchronization mechanism should be used to protect the shared data. 




      :param `prefix`: The possibly empty prefix that the user had already entered.   
      :type `prefix`: string








      :rtype: `res`



                  





   .. method:: GetNext(self)

      Called to retrieve the next completion.                  

      All completions returned by this function should start with the prefix passed to the last call to :meth:`Start` . 

      Notice that, as :meth:`Start` , this method is called from a worker thread context under MSW. 

                

      :rtype: `string`







      :returns: 

         The next completion or an empty string to indicate that there are no more of them.   








   .. method:: Start(self, prefix)

      Function called to start iteration over the completions for the given prefix.                  

      This function could start a database query, for example, if the results are read from a database. 

      Notice that under some platforms (currently MSW only) it is called from another thread context and so the appropriate synchronization mechanism should be used to access any data also used by the main UI thread. 




      :param `prefix`: The prefix for which completions are to be generated.   
      :type `prefix`: string






      :rtype: `bool`



                  



      :returns: 

         ``True`` to continue with calling :meth:`GetNext`   or ``False`` to indicate that there are no matches and :meth:`GetNext`   shouldn't be called at all.   








   .. attribute:: Next

      See :meth:`~wx.TextCompleterSimple.GetNext`

