Attachment 'Readme.txt'

Download

   1 (Note: this code does not currently run on Mac, since wxMAC does not yet support PopupWindow.)
   2 
   3 (Will Sadkin 8/05/2008: This may no longer be true-- see below.)
   4 
   5 (Daniel Levine 7/10/2010: This is still not supported on Macs as of wxPython 2.8.10.1)
   6 
   7 Michele Petrazzo modified the code for use '''wxList{{{}}}Ctrl''' instead of '''wxList{{{}}}Box''', so now TextCtrlAutoComplete can handle more than one column, has column sorting, can fetch the data on the column you want and at the end, can call a "callback" function when an item are select.
   8 
   9 Will Sadkin modified the code to allow dynamic generation of the select list based on what's typed, added an argument to hide the dropdown if no match, added an option to set a match function, and enhanced the demo to show how you can now do dynamic list updates based on what is typed.
  10 
  11 ------------------ Comments -----------------
  12 
  13 == Comment by Franz Steinhaeusler ==
  14 If I replace the init line of the textctrl,
  15  . wx.Text''''''Ctrl.__init__( self , parent , style = wx.TE_PROCESS_ENTER, **therest )
  16 when the Enter Key seems to be processed accordingly.
  17 
  18 I see, your implementation to this is much better than mine. :)
  19 
  20 == Comment by Edward Flick ==
  21 Thanks Franz I think we just about tied for the solution to that.  I had just added the TE_PROCESS_ENTER dynamically in the init section.
  22 Either way :-).  So do you have any idea on how to fix the Popup''''''Window issue?
  23 
  24 == Comment by Franz Steinhaeusler ==
  25 No, sorry. I will ask in the wxPython mailing list.
  26 
  27 Michele Petrazzo posted a solution using a List''''''Ctrl instead of a List''''''Box.
  28 
  29 http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi?11:mss:47543:200602:jjhfcaoagldbfbigklnf
  30 
  31 == Comment by Michele Petrazzo ==
  32 New class uploaded
  33 
  34 == Comment by Michele Petrazzo ==
  35 Add two interface methods: '''setMultiple{{{}}}Choices''' and '''set{{{}}}Choices''' that permit to modify the list after the initialization.
  36 
  37 == Comment by Edward Flick ==
  38 Changed __init__ to support single column list of choices (was broken).  Also, changed the sort function to locale specific sort (as is used in the mixin).  Commented out the  mixin sort called at the beginning, since its unnecessary.
  39 
  40 == Comment by Michele Petrazzo ==
  41 Change the sort methods for prevent the old (python 2.3) sort method that not accepting arguments
  42 
  43 == Comment by Will Sadkin ==
  44 Fixed bug in design that could leave fetch column set to a non-existent column if you switched from a multi-choice to a single choice list, causing the control not to autocomplete.
  45 
  46 Instead, '''.set{{{}}}Choices()''' now automatically sets colSearch and colFetch to 0 and -1, respectively, (as there's only one choice), and '''.setMultiple{{{}}}Choices()''' now takes ''colSearch'' and ''colFetch'' as arguments.  (I also changed fetchCol to colFetch, to be consistent with colSearch and colNames.)
  47 
  48 I also made the behavior more consistent with the Firefox address bar behavior, so that when the control is empty(ied), the dropdown is hidden, and added a constructor argument, ''hideOn{{{}}}No{{{}}}Match'' (by default True), so that when a user is typing, if nothing in the choice list matches, the dropdown is hidden as well.
  49 
  50 (Finally, I fixed this wiki page to not put wiki links in where none were meant to be.)
  51 
  52 == Comment by Will Sadkin ==
  53  * Fixed another bug with case-sensitive sorting in choice list, but case-insensitive sorting in '''List{{{}}}Ctrl''', causing incorrect selection from the list when auto-completing.
  54  * Changed single-column display to not show an empty header in the dropdown, to better match address bar look and feel, and to make the control look right when the choice list is empty.
  55  * Renamed existing callBack argument to selectCallback, added entryCallback, added matchFunction, and setters for each of these.
  56  * Changed the Mixed{{{}}}Case format of the control's public methods to match rest of wx.Python.
  57  * Changed '''Set{{{}}}Choices''' and '''Set{{{}}}Multiple{{{}}}Choices''' to not auto-clear the text control when the list changes, so you can do dynamic updates of the list based on what is typed.
  58  * Added button in demo to demonstrate both dynamic list generation and "smart" matching via match function-- Click the '''Enable dynamic choices''' button, and then try typing 'as' or 'www', and see what happens!
  59  * Attached a working copy of the source for easier extension by others, (so they don't have to cut & paste from the above and then remove the trailing whitespaces in the bitmaps.)
  60 
  61 == Comment by Marc Hedlund ==
  62 
  63 This class looks great -- thanks to the people who have worked on it.  As a note so that others are aware, the class depends on Popup``Window, which is not currently (Jan 2008) implemented on Mac.  If you need something cross-platform, you'll have to look elsewhere...
  64 
  65 == Comment by Will Sadkin ==
  66 
  67 According to http://trac.wxwidgets.org/ticket/9377, as of 6/27/2008, wxWidgets was updated to support Popup``Window...  I don't know how long it will take for wxPython to incorporate this change, but someone who
  68 has access to a Mac should check this out and update this page if this restriction no longer applies.)
  69 
  70 == Comment by Marcelo Fernandez ==
  71 
  72 This widget is great! And it also works passing a cursor.fetchall() (from a SQLite DB) to the !SetMultipleChoices() method. :-)
  73 
  74 I was looking at the custom widget !TextCtrl and implementing it in a little application I'm developing. The thing is, the widget works very well overall, but I added a new method which I needed:
  75 
  76 {{{#!python
  77     def GetSelectedItems(self):
  78         ''' Returns the complete listbox item selected as a list '''
  79         dd = self.dropdownlistbox
  80         sel = dd.GetFirstSelected()
  81         if sel > -1:
  82             values = [dd.GetItem(sel, x).GetText()
  83                       for x in xrange(dd.GetColumnCount())]
  84             return values
  85         else:
  86             return None
  87 }}}
  88 
  89 It borrows a lot of code from the internal "_setValueFromSelected()" method, but its intention is to return the selected listbox item as a list.
  90 
  91 I needed it because in the "Save Form" button I wanted to know not only the !TextCtrl value, but all the !ListCtrl values selected; and I didn't want to set a callback to _selectCallback() (which adds more code).
  92 
  93 IMHO, I think this approach to get all the !ListCtrl values stored there, in any time, is cleaner.
  94 
  95 == Comment by Matthijs Sypkens Smit ==
  96 
  97 I believe to have discovered a bug in the current code (29-7-2009). In lines 101-105 ('gp = self' to 'gp = gp.GetParent()') bindings are created to catch movement and resize events for parents. However, these are never removed when the control is terminated. The problem came to light when I put the control on a custom dialog. After the dialog had been destroyed I got PyDeadObjectErrors:
  98  "wx._core.PyDeadObjectError: The C++ part of the TextCtrlAutoComplete object has been deleted, attribute access no longer allowed."
  99 
 100 The following code fixed it, at least for my case. I inserted them between line 105 and 106, but there might be
 101 
 102 {{{#!python
 103     def handler_close(evt):
 104         # unbinding...
 105         gp = self
 106         while ( gp != None ) :
 107             gp.Unbind( wx.EVT_MOVE , gp, -1, -1)
 108             gp.Unbind( wx.EVT_SIZE , gp, -1, -1)
 109             gp = gp.GetParent()
 110 
 111     self.Bind(wx.EVT_WINDOW_DESTROY, handler_close)
 112 }}}
 113 
 114 == Comment by Matthijs Sypkens Smit ==
 115 
 116 This widget does not work perfectly when placed on a modal dialog. I suspect this is because the ListBox is on a separate popup window. Doubleclick on an item in the listbox or scrolling with the scrollbars does not work on a modal dialog. Scrolling with the keyboard does work. 
 117 
 118 == Comment by James Hofmann ==
 119 
 120 16 October 2009: Clarified the exact usage of multiChoices(the test was incorrect before).
 121 
 122 == Comment by Daniel Levine ==
 123 
 124 10 July 2010: Checked with a friend who has wxPython on a Mac (wxPython 2.8.10.1) and got a non-implementation error.  This still does not work for Macs.

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2019-08-16 17:27:11, 7.9 KB) [[attachment:Readme.txt]]
  • [get | view] (2019-05-19 12:01:08, 54.9 KB) [[attachment:img_sample_one.png]]
  • [get | view] (2019-10-26 11:48:49, 57.5 KB) [[attachment:img_sample_two.png]]
  • [get | view] (2019-11-16 16:14:06, 28.2 KB) [[attachment:source.zip]]
  • [get | view] (2019-03-16 15:17:39, 21.9 KB) [[attachment:wxwin.ico]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.