How to create a text control with autocomplete (Phoenix)
Keywords : TextCtrl, AutoComplete, Autocompletion.
Contents
Demonstrating :
Tested py3.x, wx4.x and Win10.
Are you ready to use some samples ?
Test, modify, correct, complete, improve and share your discoveries !
Autocomplete 1
ICON file : wxwin.ico
1 # sample_one.py
2
3 import os
4 import wx
5
6 # class MyClassCompleterSimple
7 # class MyClassCompleter
8 # class MyMainFrame
9 # class MyApp
10
11 szClasses = [
12 'wxAboutDialogInfo',
13 'wxAcceleratorEntry',
14 'wxAcceleratorTable',
15 'wxAccessible',
16 'wxActivateEvent',
17 'wxActiveXContainer',
18 'wxAddRemoveCtrl',
19 'wxAffineMatrix2D',
20 'wxAffineMatrix2DBase',
21 'wxAnimation',
22 'wxAnimationCtrl',
23 'wxAny',
24 'wxAnyButton',
25 'wxAnyValueBuffer',
26 'wxAnyValueType',
27 'wxApp',
28 'wxAppConsole',
29 'wxAppProgressIndicator',
30 'wxAppTraits',
31 'wxArchiveClassFactory',
32 'wxArchiveEntry',
33 'wxArchiveFSHandler',
34 'wxArchiveInputStream',
35 'wxArchiveIterator',
36 'wxArchiveNotifier',
37 'wxArchiveOutputStream',
38 'wxArray<',
39 'wxArrayString',
40 'wxArrayStringProperty',
41 'wxArtProvider',
42 'wxAuiDefaultDockArt',
43 'wxAuiDefaultTabArt',
44 'wxAuiDefaultToolBarArt',
45 'wxAuiDockArt',
46 'wxAuiDockInfo',
47 'wxAuiDockUIPart',
48 'wxAuiFloatingFrame',
49 'wxAuiManager',
50 'wxAuiManagerEvent',
51 'wxAuiMDIChildFrame',
52 'wxAuiMDIClientWindow',
53 'wxAuiMDIParentFrame',
54 'wxAuiNotebook',
55 'wxAuiNotebookEvent',
56 'wxAuiNotebookPage',
57 'wxAuiPaneButton',
58 'wxAuiPaneInfo',
59 'wxAuiSimpleTabArt',
60 'wxAuiTabArt',
61 'wxAuiTabContainer',
62 'wxAuiTabContainerButton',
63 'wxAuiToolBar',
64 'wxAuiToolBarArt',
65 'wxAuiToolBarEvent',
66 'wxAuiToolBarItem',
67 'wxAutoBufferedPaintDC',
68 'wxAutomationObject',
69 'wxBannerWindow',
70 'wxBitmap',
71 'wxBitmapButton',
72 'wxBitmapComboBox',
73 'wxBitmapDataObject',
74 'wxBitmapHandler',
75 'wxBitmapToggleButton',
76 'wxBookCtrlBase',
77 'wxBookCtrlEvent',
78 'wxBoolProperty',
79 'wxBoxSizer',
80 'wxBrush',
81 'wxBrushList',
82 'wxBufferedDC',
83 'wxBufferedInputStream',
84 'wxBufferedOutputStream',
85 'wxBufferedPaintDC',
86 'wxBusyCursor',
87 'wxBusyInfo',
88 'wxBusyInfoFlags',
89 'wxButton',
90 'wxCalculateLayoutEvent',
91 'wxCalendarCtrl',
92 'wxCalendarDateAttr',
93 'wxCalendarEvent',
94 'wxCaret',
95 'wxCharBuffer',
96 'wxCharTypeBuffer',
97 'wxCheckBox',
98 'wxCheckListBox',
99 'wxChildFocusEvent',
100 'wxChoice',
101 'wxChoicebook',
102 'wxClassInfo',
103 'wxClient',
104 'wxClientData',
105 'wxClientDataContainer',
106 'wxClientDC',
107 'wxClipboard',
108 'wxClipboardTextEvent',
109 'wxCloseEvent',
110 'wxCmdLineArg',
111 'wxCmdLineArgs',
112 'wxCmdLineEntryDesc',
113 'wxCmdLineParser',
114 'wxCollapsibleHeaderCtrl',
115 'wxCollapsiblePane',
116 'wxCollapsiblePaneEvent',
117 'wxColour',
118 'wxColourData',
119 'wxColourDatabase',
120 'wxColourDialog',
121 'wxColourPickerCtrl',
122 'wxColourPickerEvent',
123 'wxColourProperty',
124 'wxColourPropertyValue',
125 'wxComboBox',
126 'wxComboCtrl',
127 'wxComboCtrlFeatures',
128 'wxComboPopup',
129 'wxCommand',
130 'wxCommandEvent',
131 'wxCommandLinkButton',
132 'wxCommandProcessor',
133 'wxCondition',
134 'wxConfigBase',
135 'wxConfigPathChanger',
136 'wxConnection',
137 'wxConnectionBase',
138 'wxContextHelp',
139 'wxContextHelpButton',
140 'wxContextMenuEvent',
141 'wxControl',
142 'wxControlWithItems',
143 'wxConvAuto',
144 'wxCountingOutputStream',
145 'wxCriticalSection',
146 'wxCriticalSectionLocker',
147 'wxCSConv',
148 'wxCursor',
149 'wxCursorProperty',
150 'wxCustomBackgroundWindow',
151 'wxCustomDataObject',
152 'wxDataFormat',
153 'wxDatagramSocket',
154 'wxDataInputStream',
155 'wxDataObject',
156 'wxDataObjectComposite',
157 'wxDataObjectSimple',
158 'wxDataOutputStream',
159 'wxDataViewBitmapRenderer',
160 'wxDataViewCheckIconTextRenderer',
161 'wxDataViewChoiceByIndexRenderer',
162 'wxDataViewChoiceRenderer',
163 'wxDataViewColumn',
164 'wxDataViewCtrl',
165 'wxDataViewCustomRenderer',
166 'wxDataViewDateRenderer',
167 'wxDataViewEvent',
168 'wxDataViewIconText',
169 'wxDataViewIconTextRenderer',
170 'wxDataViewIndexListModel',
171 'wxDataViewItem',
172 'wxDataViewItemAttr',
173 'wxDataViewListCtrl',
174 'wxDataViewListModel',
175 'wxDataViewListStore',
176 'wxDataViewModel',
177 'wxDataViewModelNotifier',
178 'wxDataViewProgressRenderer',
179 'wxDataViewRenderer',
180 'wxDataViewSpinRenderer',
181 'wxDataViewTextRenderer',
182 'wxDataViewToggleRenderer',
183 'wxDataViewTreeCtrl',
184 'wxDataViewTreeStore',
185 'wxDataViewValueAdjuster',
186 'wxDataViewVirtualListModel',
187 'wxDateEvent',
188 'wxDatePickerCtrl',
189 'wxDateProperty',
190 'wxDateSpan',
191 'wxDateTime',
192 'TimeZone',
193 'Tm',
194 'wxDateTimeHolidayAuthority',
195 'wxDateTimeWorkDays',
196 'wxDC',
197 'wxDCBrushChanger',
198 'wxDCClipper',
199 'wxDCFontChanger',
200 'wxDCOverlay',
201 'wxDCPenChanger',
202 'wxDCTextColourChanger',
203 'wxDDEClient',
204 'wxDDEConnection',
205 'wxDDEServer',
206 'wxDebugContext',
207 'wxDebugReport',
208 'wxDebugReportCompress',
209 'wxDebugReportPreview',
210 'wxDebugReportPreviewStd',
211 'wxDebugReportUpload',
212 'wxDelegateRendererNative',
213 'wxDialog',
214 'wxDialogLayoutAdapter',
215 'wxDialUpEvent',
216 'wxDialUpManager',
217 'wxDir',
218 'wxDirDialog',
219 'wxDirFilterListCtrl',
220 'wxDirPickerCtrl',
221 'wxDirProperty',
222 'wxDirTraverser',
223 'wxDisplay',
224 'wxDisplayChangedEvent',
225 'wxDocChildFrame',
226 'wxDocManager',
227 'wxDocMDIChildFrame',
228 'wxDocMDIParentFrame',
229 'wxDocParentFrame',
230 'wxDocTemplate',
231 'wxDocument',
232 'wxDragImage',
233 'wxDropFilesEvent',
234 'wxDropSource',
235 'wxDropTarget',
236 'wxDynamicLibrary',
237 'wxDynamicLibraryDetails',
238 'wxEditableListBox',
239 'wxEditEnumProperty',
240 'wxEncodingConverter',
241 'wxEnumProperty',
242 'wxEraseEvent',
243 'wxEvent',
244 'wxEventBlocker',
245 'wxEventFilter',
246 'wxEventLoopActivator',
247 'wxEventLoopBase',
248 'wxEvtHandler',
249 'wxExecuteEnv',
250 'wxExtHelpController',
251 'wxFFile',
252 'wxFFileInputStream',
253 'wxFFileOutputStream',
254 'wxFFileStream',
255 'wxFile',
256 'wxFileConfig',
257 'wxFileCtrl',
258 'wxFileCtrlEvent',
259 'wxFileDataObject',
260 'wxFileDialog',
261 'wxFileDirPickerEvent',
262 'wxFileDropTarget',
263 'wxFileHistory',
264 'wxFileInputStream',
265 'wxFileName',
266 'wxFileOutputStream',
267 'wxFilePickerCtrl',
268 'wxFileProperty',
269 'wxFileStream',
270 'wxFileSystem',
271 'wxFileSystemHandler',
272 'wxFileSystemWatcher',
273 'wxFileSystemWatcherEvent',
274 'wxFileTranslationsLoader',
275 'wxFileType',
276 'MessageParameters',
277 'wxFileTypeInfo',
278 'wxFilterClassFactory',
279 'wxFilterFSHandler',
280 'wxFilterInputStream',
281 'wxFilterOutputStream',
282 'wxFindDialogEvent',
283 'wxFindReplaceData',
284 'wxFindReplaceDialog',
285 'wxFlagsProperty',
286 'wxFlexGridSizer',
287 'wxFloatingPointValidator',
288 'wxFloatProperty',
289 'wxFocusEvent',
290 'wxFont',
291 'wxFontData',
292 'wxFontDialog',
293 'wxFontEnumerator',
294 'wxFontInfo',
295 'wxFontList',
296 'wxFontMapper',
297 'wxFontMetrics',
298 'wxFontPickerCtrl',
299 'wxFontPickerEvent',
300 'wxFontProperty',
301 'wxFrame',
302 'wxFSFile',
303 'wxFSInputStream',
304 'wxFSVolume',
305 'wxFTP',
306 'wxGauge',
307 'wxGBPosition',
308 'wxGBSizerItem',
309 'wxGBSpan',
310 'wxGCDC',
311 'wxGDIObject',
312 'wxGenericAboutDialog',
313 'wxGenericDirCtrl',
314 'wxGenericProgressDialog',
315 'wxGenericValidator',
316 'wxGestureEvent',
317 'wxGIFHandler',
318 'wxGLAttribsBase',
319 'wxGLAttributes',
320 'wxGLCanvas',
321 'wxGLContext',
322 'wxGLContextAttrs',
323 'wxGraphicsBitmap',
324 'wxGraphicsBrush',
325 'wxGraphicsContext',
326 'wxGraphicsFont',
327 'wxGraphicsGradientStop',
328 'wxGraphicsGradientStops',
329 'wxGraphicsMatrix',
330 'wxGraphicsObject',
331 'wxGraphicsPath',
332 'wxGraphicsPen',
333 'wxGraphicsPenInfo',
334 'wxGraphicsRenderer',
335 'wxGrid',
336 'wxGridBagSizer',
337 'wxGridCellAttr',
338 'wxGridCellAttrProvider',
339 'wxGridCellAutoWrapStringEditor',
340 'wxGridCellAutoWrapStringRenderer',
341 'wxGridCellBoolEditor',
342 'wxGridCellBoolRenderer',
343 'wxGridCellChoiceEditor',
344 'wxGridCellCoords',
345 'wxGridCellDateTimeRenderer',
346 'wxGridCellEditor',
347 'wxGridCellEnumEditor',
348 'wxGridCellEnumRenderer',
349 'wxGridCellFloatEditor',
350 'wxGridCellFloatRenderer',
351 'wxGridCellNumberEditor',
352 'wxGridCellNumberRenderer',
353 'wxGridCellRenderer',
354 'wxGridCellStringRenderer',
355 'wxGridCellTextEditor',
356 'wxGridColumnHeaderRenderer',
357 'wxGridColumnHeaderRendererDefault',
358 'wxGridCornerHeaderRenderer',
359 'wxGridCornerHeaderRendererDefault',
360 'wxGridEditorCreatedEvent',
361 'wxGridEvent',
362 'wxGridHeaderLabelsRenderer',
363 'wxGridRangeSelectEvent',
364 'wxGridRowHeaderRenderer',
365 'wxGridRowHeaderRendererDefault',
366 'wxGridSizeEvent',
367 'wxGridSizer',
368 'wxGridSizesInfo',
369 'wxGridStringTable',
370 'wxGridTableBase',
371 'wxGridTableMessage',
372 'wxGridUpdateLocker',
373 'wxGUIEventLoop',
374 'wxHashMap',
375 'wxHashSet',
376 'wxHashTable',
377 'wxHeaderButtonParams',
378 'wxHeaderColumn',
379 'wxHeaderColumnSimple',
380 'wxHeaderCtrl',
381 'wxHeaderCtrlEvent',
382 'wxHeaderCtrlSimple',
383 'wxHelpController',
384 'wxHelpControllerBase',
385 'wxHelpControllerHelpProvider',
386 'wxHelpEvent',
387 'wxHelpProvider',
388 'wxHScrolledWindow',
389 'wxHtmlBookRecord',
390 'wxHtmlCell',
391 'wxHtmlCellEvent',
392 'wxHtmlColourCell',
393 'wxHtmlContainerCell',
394 'wxHTMLDataObject',
395 'wxHtmlDCRenderer',
396 'wxHtmlEasyPrinting',
397 'wxHtmlFilter',
398 'wxHtmlFontCell',
399 'wxHtmlHelpController',
400 'wxHtmlHelpData',
401 'wxHtmlHelpDataItem',
402 'wxHtmlHelpDialog',
403 'wxHtmlHelpFrame',
404 'wxHtmlHelpWindow',
405 'wxHtmlLinkEvent',
406 'wxHtmlLinkInfo',
407 'wxHtmlListBox',
408 'wxHtmlModalHelp',
409 'wxHtmlParser',
410 'wxHtmlPrintout',
411 'wxHtmlRenderingInfo',
412 'wxHtmlRenderingState',
413 'wxHtmlRenderingStyle',
414 'wxHtmlSelection',
415 'wxHtmlTag',
416 'wxHtmlTagHandler',
417 'wxHtmlTagsModule',
418 'wxHtmlWidgetCell',
419 'wxHtmlWindow',
420 'wxHtmlWindowInterface',
421 'wxHtmlWinParser',
422 'wxHtmlWinTagHandler',
423 'wxHtmlWordCell',
424 'wxHtmlWordWithTabsCell',
425 'wxHTTP',
426 'wxHVScrolledWindow',
427 'wxHyperlinkCtrl',
428 'wxHyperlinkEvent',
429 'wxIcon',
430 'wxIconBundle',
431 'wxIconizeEvent',
432 'wxIconLocation',
433 'wxIdleEvent',
434 'wxIdManager',
435 'wxIFFHandler',
436 'wxImage',
437 'HSVValue',
438 'RGBValue',
439 'wxImageFileProperty',
440 'wxImageHandler',
441 'wxImageHistogram',
442 'wxImageList',
443 'wxIndividualLayoutConstraint',
444 'wxInfoBar',
445 'wxInitDialogEvent',
446 'wxInitializer',
447 'wxInputStream',
448 'wxIntegerValidator',
449 'wxInternetFSHandler',
450 'wxIntProperty',
451 'wxIPaddress',
452 'wxIPV4address',
453 'wxItemAttr',
454 'wxItemContainer',
455 'wxItemContainerImmutable',
456 'wxJoystick',
457 'wxJoystickEvent',
458 'wxJPEGHandler',
459 'wxKeyboardState',
460 'wxKeyEvent',
461 'wxLanguageInfo',
462 'wxLayoutAlgorithm',
463 'wxLayoutConstraints',
464 'wxLinuxDistributionInfo',
465 'wxList<',
466 'wxListbook',
467 'wxListBox',
468 'wxListCtrl',
469 'wxListEvent',
470 'wxListItem',
471 'wxListView',
472 'wxLocale',
473 'wxLog',
474 'wxLogBuffer',
475 'wxLogChain',
476 'wxLogFormatter',
477 'wxLogGui',
478 'wxLogInterposer',
479 'wxLogInterposerTemp',
480 'wxLogNull',
481 'wxLogRecordInfo',
482 'wxLogStderr',
483 'wxLogStream',
484 'wxLogTextCtrl',
485 'wxLogWindow',
486 'wxLongLong',
487 'wxLongPressEvent',
488 'wxLongStringProperty',
489 'wxMask',
490 'wxMatrix2D',
491 'wxMaximizeEvent',
492 'wxMBConv',
493 'wxMBConvUTF16',
494 'wxMBConvUTF32',
495 'wxMBConvUTF7',
496 'wxMBConvUTF8',
497 'wxMDIChildFrame',
498 'wxMDIClientWindow',
499 'wxMDIParentFrame',
500 'wxMediaCtrl',
501 'wxMediaEvent',
502 'wxMemoryBuffer',
503 'wxMemoryDC',
504 'wxMemoryFSHandler',
505 'wxMemoryInputStream',
506 'wxMemoryOutputStream',
507 'wxMenu',
508 'wxMenuBar',
509 'wxMenuEvent',
510 'wxMenuItem',
511 'wxMessageDialog',
512 'ButtonLabel',
513 'wxMessageOutput',
514 'wxMessageOutputBest',
515 'wxMessageOutputDebug',
516 'wxMessageOutputMessageBox',
517 'wxMessageOutputStderr',
518 'wxMessageQueue<',
519 'wxMetafile',
520 'wxMetafileDC',
521 'wxMimeTypesManager',
522 'wxMiniFrame',
523 'wxMirrorDC',
524 'wxModalDialogHook',
525 'wxModule',
526 'wxMouseCaptureChangedEvent',
527 'wxMouseCaptureLostEvent',
528 'wxMouseEvent',
529 'wxMouseEventsManager',
530 'wxMouseState',
531 'wxMoveEvent',
532 'wxMsgCatalog',
533 'wxMultiChoiceDialog',
534 'wxMultiChoiceProperty',
535 'wxMutex',
536 'wxMutexLocker',
537 'wxNativeFontInfo',
538 'wxNativeWindow',
539 'wxNavigationEnabled',
540 'wxNavigationKeyEvent',
541 'wxNode<',
542 'wxNonOwnedWindow',
543 'wxNotebook',
544 'wxNotificationMessage',
545 'wxNotifyEvent',
546 'wxNumberFormatter',
547 'wxNumericPropertyValidator',
548 'wxNumValidator',
549 'wxObject',
550 'wxObjectDataPtr<',
551 'wxObjectRefData',
552 'wxOutputStream',
553 'wxOverlay',
554 'wxOwnerDrawnComboBox',
555 'wxPageSetupDialog',
556 'wxPageSetupDialogData',
557 'wxPaintDC',
558 'wxPaintEvent',
559 'wxPalette',
560 'wxPaletteChangedEvent',
561 'wxPanel',
562 'wxPanGestureEvent',
563 'wxPasswordEntryDialog',
564 'wxPathList',
565 'wxPCXHandler',
566 'wxPen',
567 'wxPenInfo',
568 'wxPenList',
569 'wxPersistenceManager',
570 'wxPersistentBookCtrl',
571 'wxPersistentDataViewCtrl',
572 'wxPersistentObject',
573 'wxPersistentTLW',
574 'wxPersistentTreeBookCtrl',
575 'wxPersistentWindow',
576 'wxPGArrayEditorDialog',
577 'wxPGArrayStringEditorDialog',
578 'wxPGAttributeStorage',
579 'wxPGCell',
580 'wxPGCellData',
581 'wxPGCellRenderer',
582 'wxPGCheckBoxEditor',
583 'wxPGChoiceAndButtonEditor',
584 'wxPGChoiceEditor',
585 'wxPGChoiceEntry',
586 'wxPGChoices',
587 'wxPGChoicesData',
588 'wxPGComboBoxEditor',
589 'wxPGDefaultRenderer',
590 'wxPGEditor',
591 'wxPGEditorDialogAdapter',
592 'wxPGFileDialogAdapter',
593 'wxPGInDialogValidator',
594 'wxPGLongStringDialogAdapter',
595 'wxPGMultiButton',
596 'wxPGPaintData',
597 'wxPGPropArgCls',
598 'wxPGProperty',
599 'wxPGRootProperty',
600 'wxPGSpinCtrlEditor',
601 'wxPGTextCtrlAndButtonEditor',
602 'wxPGTextCtrlEditor',
603 'wxPGValidationInfo',
604 'wxPGVIterator',
605 'wxPGWindowList',
606 'wxPickerBase',
607 'wxPixelData',
608 'Iterator',
609 'wxPlatformInfo',
610 'wxPNGHandler',
611 'wxPNMHandler',
612 'wxPoint',
613 'wxPoint2DDouble',
614 'wxPoint2DInt',
615 'wxPopupTransientWindow',
616 'wxPopupWindow',
617 'wxPosition',
618 'wxPostScriptDC',
619 'wxPowerEvent',
620 'wxPowerResource',
621 'wxPowerResourceBlocker',
622 'wxPreferencesEditor',
623 'wxPreferencesPage',
624 'wxPressAndTapEvent',
625 'wxPreviewCanvas',
626 'wxPreviewControlBar',
627 'wxPreviewFrame',
628 'wxPrintAbortDialog',
629 'wxPrintData',
630 'wxPrintDialog',
631 'wxPrintDialogData',
632 'wxPrinter',
633 'wxPrinterDC',
634 'wxPrintout',
635 'wxPrintPreview',
636 'wxProcess',
637 'wxProcessEvent',
638 'wxProgressDialog',
639 'wxPropagateOnce',
640 'wxPropagationDisabler',
641 'wxPropertyCategory',
642 'wxPropertyGrid',
643 'wxPropertyGridConstIterator',
644 'wxPropertyGridEvent',
645 'wxPropertyGridHitTestResult',
646 'wxPropertyGridInterface',
647 'wxPropertyGridIterator',
648 'wxPropertyGridIteratorBase',
649 'wxPropertyGridManager',
650 'wxPropertyGridPage',
651 'wxPropertyGridPageState',
652 'wxPropertyGridPopulator',
653 'wxPropertySheetDialog',
654 'wxProtocol',
655 'wxProtocolLog',
656 'wxQuantize',
657 'wxQueryLayoutInfoEvent',
658 'wxQueryNewPaletteEvent',
659 'wxRadioBox',
660 'wxRadioButton',
661 'wxRealPoint',
662 'wxRearrangeCtrl',
663 'wxRearrangeDialog',
664 'wxRearrangeList',
665 'wxRect',
666 'wxRect2DDouble',
667 'wxRect2DInt',
668 'wxRecursionGuard',
669 'wxRecursionGuardFlag',
670 'wxRefCounter',
671 'wxRegConfig',
672 'wxRegEx',
673 'wxRegion',
674 'wxRegionIterator',
675 'wxRegKey',
676 'wxRendererNative',
677 'wxRendererVersion',
678 'wxResourceTranslationsLoader',
679 'wxRibbonArtProvider',
680 'wxRibbonAUIArtProvider',
681 'wxRibbonBar',
682 'wxRibbonBarEvent',
683 'wxRibbonButtonBar',
684 'wxRibbonButtonBarEvent',
685 'wxRibbonControl',
686 'wxRibbonGallery',
687 'wxRibbonGalleryEvent',
688 'wxRibbonMSWArtProvider',
689 'wxRibbonPage',
690 'wxRibbonPageTabInfo',
691 'wxRibbonPanel',
692 'wxRibbonPanelEvent',
693 'wxRibbonToolBar',
694 'wxRibbonToolBarEvent',
695 'wxRichMessageDialog',
696 'wxRichTextAction',
697 'wxRichTextAttr',
698 'wxRichTextBox',
699 'wxRichTextBuffer',
700 'wxRichTextBufferDataObject',
701 'wxRichTextCell',
702 'wxRichTextCharacterStyleDefinition',
703 'wxRichTextCommand',
704 'wxRichTextCompositeObject',
705 'wxRichTextContextMenuPropertiesInfo',
706 'wxRichTextCtrl',
707 'wxRichTextDrawingContext',
708 'wxRichTextDrawingHandler',
709 'wxRichTextEvent',
710 'wxRichTextField',
711 'wxRichTextFieldType',
712 'wxRichTextFieldTypeStandard',
713 'wxRichTextFileHandler',
714 'wxRichTextFontTable',
715 'wxRichTextFormattingDialog',
716 'wxRichTextFormattingDialogFactory',
717 'wxRichTextHeaderFooterData',
718 'wxRichTextHTMLHandler',
719 'wxRichTextImage',
720 'wxRichTextImageBlock',
721 'wxRichTextLine',
722 'wxRichTextListStyleDefinition',
723 'wxRichTextObject',
724 'wxRichTextObjectAddress',
725 'wxRichTextParagraph',
726 'wxRichTextParagraphLayoutBox',
727 'wxRichTextParagraphStyleDefinition',
728 'wxRichTextPlainText',
729 'wxRichTextPlainTextHandler',
730 'wxRichTextPrinting',
731 'wxRichTextPrintout',
732 'wxRichTextProperties',
733 'wxRichTextRange',
734 'wxRichTextRenderer',
735 'wxRichTextSelection',
736 'wxRichTextStdRenderer',
737 'wxRichTextStyleComboCtrl',
738 'wxRichTextStyleDefinition',
739 'wxRichTextStyleListBox',
740 'wxRichTextStyleListCtrl',
741 'wxRichTextStyleOrganiserDialog',
742 'wxRichTextStyleSheet',
743 'wxRichTextTable',
744 'wxRichTextTableBlock',
745 'wxRichTextXMLHandler',
746 'wxRichToolTip',
747 'wxRotateGestureEvent',
748 'wxSashEvent',
749 'wxSashLayoutWindow',
750 'wxSashWindow',
751 'wxScopedArray',
752 'wxScopedCharTypeBuffer',
753 'wxScopedPtr',
754 'wxScopedPtr<',
755 'wxScopedTiedPtr',
756 'wxScopeGuard',
757 'wxScreenDC',
758 'wxScrollBar',
759 'wxScrolled',
760 'wxScrollEvent',
761 'wxScrollWinEvent',
762 'wxSearchCtrl',
763 'wxSecretStore',
764 'wxSecretValue',
765 'wxSemaphore',
766 'wxServer',
767 'wxSetCursorEvent',
768 'wxSettableHeaderColumn',
769 'wxSharedPtr<',
770 'wxShowEvent',
771 'wxSimplebook',
772 'wxSimpleHelpProvider',
773 'wxSimpleHtmlListBox',
774 'wxSingleChoiceDialog',
775 'wxSingleInstanceChecker',
776 'wxSize',
777 'wxSizeEvent',
778 'wxSizer',
779 'wxSizerFlags',
780 'wxSizerItem',
781 'wxSizerXmlHandler',
782 'wxSlider',
783 'wxSockAddress',
784 'wxSocketBase',
785 'wxSocketClient',
786 'wxSocketEvent',
787 'wxSocketInputStream',
788 'wxSocketOutputStream',
789 'wxSocketServer',
790 'wxSortedArrayString',
791 'wxSound',
792 'wxSpinButton',
793 'wxSpinCtrl',
794 'wxSpinCtrlDouble',
795 'wxSpinDoubleEvent',
796 'wxSpinEvent',
797 'wxSplashScreen',
798 'wxSplitterEvent',
799 'wxSplitterRenderParams',
800 'wxSplitterWindow',
801 'wxStack<',
802 'wxStackFrame',
803 'wxStackWalker',
804 'wxStandardPaths',
805 'wxStaticBitmap',
806 'wxStaticBox',
807 'wxStaticBoxSizer',
808 'wxStaticLine',
809 'wxStaticText',
810 'wxStatusBar',
811 'wxStatusBarPane',
812 'wxStdDialogButtonSizer',
813 'wxStdInputStream',
814 'wxStdInputStreamBuffer',
815 'wxStdOutputStream',
816 'wxStdOutputStreamBuffer',
817 'wxStockPreferencesPage',
818 'wxStopWatch',
819 'wxStreamBase',
820 'wxStreamBuffer',
821 'wxStreamToTextRedirector',
822 'wxString',
823 'wxStringBuffer',
824 'wxStringBufferLength',
825 'wxStringClientData',
826 'wxStringInputStream',
827 'wxStringOutputStream',
828 'wxStringProperty',
829 'wxStringTokenizer',
830 'wxStyledTextCtrl',
831 'wxStyledTextEvent',
832 'wxSVGBitmapEmbedHandler',
833 'wxSVGBitmapFileHandler',
834 'wxSVGBitmapHandler',
835 'wxSVGFileDC',
836 'wxSymbolPickerDialog',
837 'wxSysColourChangedEvent',
838 'wxSystemColourProperty',
839 'wxSystemOptions',
840 'wxSystemSettings',
841 'wxSystemThemedControl',
842 'wxTarClassFactory',
843 'wxTarEntry',
844 'wxTarInputStream',
845 'wxTarOutputStream',
846 'wxTaskBarButton',
847 'wxTaskBarIcon',
848 'wxTaskBarIconEvent',
849 'wxTaskBarJumpList',
850 'wxTaskBarJumpListCategory',
851 'wxTaskBarJumpListItem',
852 'wxTCPClient',
853 'wxTCPConnection',
854 'wxTCPServer',
855 'wxTempFile',
856 'wxTempFileOutputStream',
857 'wxTextAttr',
858 'wxTextAttrBorder',
859 'wxTextAttrBorders',
860 'wxTextAttrDimension',
861 'wxTextAttrDimensionConverter',
862 'wxTextAttrDimensions',
863 'wxTextAttrShadow',
864 'wxTextAttrSize',
865 'wxTextBoxAttr',
866 'wxTextCompleter',
867 'wxTextCompleterSimple',
868 'wxTextCtrl',
869 'wxTextDataObject',
870 'wxTextDropTarget',
871 'wxTextEntry',
872 'wxTextEntryDialog',
873 'wxTextFile',
874 'wxTextInputStream',
875 'wxTextOutputStream',
876 'wxTextUrlEvent',
877 'wxTextValidator',
878 'wxTextWrapper',
879 'wxTGAHandler',
880 'wxThread',
881 'wxThreadEvent',
882 'wxThreadHelper',
883 'wxThumbBarButton',
884 'wxTIFFHandler',
885 'wxTimePickerCtrl',
886 'wxTimer',
887 'wxTimerEvent',
888 'wxTimerRunner',
889 'wxTimeSpan',
890 'wxTipProvider',
891 'wxTipWindow',
892 'wxToggleButton',
893 'wxToolBar',
894 'wxToolBarToolBase',
895 'wxToolbook',
896 'wxToolTip',
897 'wxTopLevelWindow',
898 'wxTrackable',
899 'wxTransform2D',
900 'wxTranslations',
901 'wxTranslationsLoader',
902 'wxTreebook',
903 'wxTreeCtrl',
904 'wxTreeEvent',
905 'wxTreeItemData',
906 'wxTreeItemId',
907 'wxTreeListCtrl',
908 'wxTreeListEvent',
909 'wxTreeListItem',
910 'wxTreeListItemComparator',
911 'wxTwoFingerTapEvent',
912 'wxUIActionSimulator',
913 'wxUIntProperty',
914 'wxULongLong',
915 'wxUniChar',
916 'wxUniCharRef',
917 'wxUpdateUIEvent',
918 'wxURI',
919 'wxURL',
920 'wxURLDataObject',
921 'wxUString',
922 'wxValidator',
923 'wxVarHScrollHelper',
924 'wxVarHVScrollHelper',
925 'wxVariant',
926 'wxVariantData',
927 'wxVariantDataCurrency',
928 'wxVariantDataErrorCode',
929 'wxVariantDataSafeArray',
930 'wxVarScrollHelperBase',
931 'wxVarVScrollHelper',
932 'wxVector<',
933 'wxVersionInfo',
934 'wxVideoMode',
935 'wxView',
936 'wxVisualAttributes',
937 'wxVListBox',
938 'wxVScrolledWindow',
939 'wxWCharBuffer',
940 'wxWeakRef<',
941 'wxWeakRefDynamic<',
942 'wxWebKitBeforeLoadEvent',
943 'wxWebKitCtrl',
944 'wxWebKitNewWindowEvent',
945 'wxWebKitStateChangedEvent',
946 'wxWebView',
947 'wxWebViewArchiveHandler',
948 'wxWebViewEvent',
949 'wxWebViewFactory',
950 'wxWebViewFSHandler',
951 'wxWebViewHandler',
952 'wxWebViewHistoryItem',
953 'wxWindow',
954 'ChildrenRepositioningGuard',
955 'wxWindowCreateEvent',
956 'wxWindowDC',
957 'wxWindowDestroyEvent',
958 'wxWindowDisabler',
959 'wxWindowModalDialogEvent',
960 'wxWindowPtr<',
961 'wxWindowUpdateLocker',
962 'wxWithImages',
963 'wxWizard',
964 'wxWizardEvent',
965 'wxWizardPage',
966 'wxWizardPageSimple',
967 'wxWrapperInputStream',
968 'wxWrapSizer',
969 'wxXLocale',
970 'wxXmlAttribute',
971 'wxXmlDoctype',
972 'wxXmlDocument',
973 'wxXmlNode',
974 'wxXmlResource',
975 'wxXmlResourceHandler',
976 'wxXPMHandler',
977 'wxZipClassFactory',
978 'wxZipEntry',
979 'wxZipInputStream',
980 'wxZipNotifier',
981 'wxZipOutputStream',
982 'wxZlibInputStream',
983 'wxZlibOutputStream',
984 'wxZoomGestureEvent'
985 ]
986
987 #---------------------------------------------------------------------------
988
989 class MyClassCompleterSimple(wx.TextCompleterSimple):
990 def __init__(self, maxResults=25):
991 wx.TextCompleterSimple.__init__(self)
992 self._iMaxResults = maxResults
993
994 def GetCompletions(self, prefix):
995 if len(prefix) < 3:
996 return []
997 res = []
998 prfx = prefix.lower()
999 for item in szClasses:
1000 if item.lower().startswith(prfx):
1001 res.append(item)
1002 # Max number of results reached ?
1003 if len(res) == self._iMaxResults:
1004 return res
1005
1006 return res
1007
1008 #---------------------------------------------------------------------------
1009
1010 class MyClassCompleter(wx.TextCompleter):
1011 def __init__(self):
1012 wx.TextCompleter.__init__(self)
1013 self._iLastReturned = wx.NOT_FOUND
1014 self._sPrefix = ''
1015
1016 def Start(self, prefix):
1017 self._sPrefix = prefix.lower()
1018 self._iLastReturned = wx.NOT_FOUND
1019 for item in szClasses:
1020 if item.lower().startswith(self._sPrefix):
1021 return True
1022 # Nothing found
1023 return False
1024
1025 def GetNext(self):
1026 for i in range(self._iLastReturned+1, len(szClasses)):
1027 if szClasses[i].lower().startswith(self._sPrefix):
1028 self._iLastReturned = i
1029 return szClasses[i]
1030 # No more corresponding item
1031 return ''
1032
1033 #---------------------------------------------------------------------------
1034
1035 class MyMainFrame(wx.Frame):
1036 def __init__(self):
1037 wx.Frame.__init__(self, None, title=wx.GetApp().GetAppName())
1038 self.SetIcon(wx.Icon('wxwin.ico'))
1039
1040 self._createControls()
1041
1042 self._connectControls()
1043
1044 def _createControls(self):
1045 # A Statusbar in the bottom of the window
1046 self.CreateStatusBar(1)
1047 sMsg = 'wxPython ' + wx.version()
1048 self.SetStatusText(sMsg)
1049
1050 # Add a panel to the frame (needed under Windows to have a nice background)
1051 pnl = wx.Panel(self, wx.ID_ANY)
1052
1053 szrMain = wx.BoxSizer(wx.VERTICAL)
1054 szrMain.AddSpacer(5)
1055
1056 stbSzr = wx.StaticBoxSizer(wx.VERTICAL, pnl, 'wxTextCompleterSimple :')
1057 stBox = stbSzr.GetStaticBox()
1058 label = wx.StaticText(stBox, wx.ID_STATIC, 'Start entering a wxWidgets class name in the wxTextCtrl below.')
1059 stbSzr.Add(label, 0, wx.LEFT|wx.RIGHT|wx.TOP, 5)
1060 stbSzr.AddSpacer(2)
1061 label = wx.StaticText(stBox, wx.ID_STATIC, 'Auto-completion should start working at the 3rd char.')
1062 stbSzr.Add(label, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
1063 self._txtEntry1 = wx.TextCtrl(stBox, -1, wx.EmptyString)
1064 stbSzr.Add(self._txtEntry1, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
1065
1066 szrMain.Add(stbSzr, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
1067
1068 stbSzr = wx.StaticBoxSizer(wx.VERTICAL, pnl, 'wxTextCompleter :')
1069 stBox = stbSzr.GetStaticBox()
1070 label = wx.StaticText(stBox, wx.ID_STATIC, 'Start entering a wxWidgets class name in the wxTextCtrl below.')
1071 stbSzr.Add(label, 0, wx.LEFT|wx.RIGHT|wx.TOP, 5)
1072 stbSzr.AddSpacer(2)
1073 label = wx.StaticText(stBox, wx.ID_STATIC, 'Auto-completion should start working at the 1rst char.')
1074 stbSzr.Add(label, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5)
1075 self._txtEntry2 = wx.TextCtrl(stBox, -1, wx.EmptyString)
1076 stbSzr.Add(self._txtEntry2, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
1077
1078 szrMain.Add(stbSzr, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, 5)
1079
1080 pnl.SetSizer(szrMain)
1081 szrMain.SetSizeHints(self)
1082
1083 self._txtEntry1.AutoComplete(MyClassCompleterSimple())
1084 self._txtEntry2.AutoComplete(MyClassCompleter())
1085
1086 def _connectControls(self):
1087 # No event handler to bind for this snippet
1088 pass
1089
1090 #---------------------------------------------------------------------------
1091
1092 class MyApp(wx.App):
1093 def OnInit(self):
1094 print('Running wxPython ' + wx.version())
1095 # Set Current directory to the one containing this file
1096 os.chdir(os.path.dirname(os.path.abspath(__file__)))
1097
1098 self.SetAppName('AutoComplete')
1099
1100 # Create the main window
1101 frm = MyMainFrame()
1102 self.SetTopWindow(frm)
1103
1104 frm.Show()
1105 return True
1106
1107 #---------------------------------------------------------------------------
1108
1109 if __name__ == '__main__':
1110 app = MyApp()
1111 app.MainLoop()
Autocomplete 2
README file : Readme.txt
ICON file : wxwin.ico
1 # sample_two.py
2
3 """
4 wxPython Custom Widget Collection 2006-02-07
5 Written By: Edward Flick (eddy -=at=- cdf-imaging -=dot=- com)
6 Michele Petrazzo (michele -=dot=- petrazzo -=at=- unipex -=dot=- it)
7 Will Sadkin (wsadkin-=at=- nameconnector -=dot=- com)
8 Copyright 2006 (c) CDF Inc. ( http://www.cdf-imaging.com )
9 Contributed to the wxPython project under the wxPython project's license.
10
11 Updated for wxPython Phoenix by Ecco.
12 """
13
14 import sys
15 import locale
16 import wx
17 from wx.lib.embeddedimage import PyEmbeddedImage
18 import wx.lib.mixins.listctrl as listmix
19
20 # class MyListCtrl
21 # class MyTxtCtrlAutoComplete
22 # class MyApp
23
24 #-------------------------------------------------------------------------------
25
26 # These images files was generated by encode_bitmaps.py
27
28 SmallUpArrow = PyEmbeddedImage(
29 b"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAADxJ"
30 b"REFUOI1jZGRiZqAEMFGke2gY8P/f3/9kGwDTjM8QnAaga8JlCG3CAJdt2MQxDCAUaOjyjKMp"
31 b"cRAYAABS2CPsss3BWQAAAABJRU5ErkJggg==")
32
33 SmallDnArrow = PyEmbeddedImage(
34 b"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAEhJ"
35 b"REFUOI1jZGRiZqAEMFGke9QABgYGBgYWdIH///7+J6SJkYmZEacLkCUJacZqAD5DsInTLhDR"
36 b"bcPlKrwugGnCFy6Mo3mBAQChDgRlP4RC7wAAAABJRU5ErkJggg==")
37
38 #-------------------------------------------------------------------------------
39
40 class MyListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
41 def __init__(self, parent, ID=-1, pos=wx.DefaultPosition,
42 size=wx.DefaultSize, style=0):
43 wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
44 listmix.ListCtrlAutoWidthMixin.__init__(self)
45
46 #-------------------------------------------------------------------------------
47
48 class MyTxtCtrlAutoComplete(wx.TextCtrl, listmix.ColumnSorterMixin):
49 def __init__ (self, parent, colNames=None, choices=None,
50 multiChoices=None, showHead=True, dropDownClick=True,
51 colFetch=-1, colSearch=0, hideOnNoMatch=True,
52 selectCallback=None, entryCallback=None, matchFunction=None,
53 **therest):
54 '''
55 Constructor works just like wx.TextCtrl except you can pass in a
56 list of choices. You can also change the choice list at any time
57 by calling setChoices.
58 '''
59 if 'style' in therest:
60 therest['style']=wx.TE_PROCESS_ENTER | therest['style']
61 else:
62 therest['style']=wx.TE_PROCESS_ENTER
63 wx.TextCtrl.__init__(self, parent, **therest)
64 # Some variables
65 self._dropDownClick = dropDownClick
66 self._colNames = colNames
67 self._multiChoices = multiChoices
68 self._showHead = showHead
69 self._choices = choices
70 self._lastinsertionpoint = 0
71 self._hideOnNoMatch = hideOnNoMatch
72 self._selectCallback = selectCallback
73 self._entryCallback = entryCallback
74 self._matchFunction = matchFunction
75 self._screenheight = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)
76 # Sort variable needed by listmix
77 self.itemDataMap = dict()
78 # Load and sort data
79 if not (self._multiChoices or self._choices):
80 raise ValueError("Pass me at least one of multiChoices OR choices")
81 # Widgets
82 self.dropdown = wx.PopupWindow(self)
83 # Control the style
84 flags = wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_SORT_ASCENDING
85 if not (showHead and multiChoices):
86 flags = flags | wx.LC_NO_HEADER
87 # Create the list and bind the events
88 self.dropdownlistbox = MyListCtrl(self.dropdown, style=flags,
89 pos=wx.Point(0, 0))
90 # Initialize the parent
91 if multiChoices: ln = len(multiChoices)
92 else: ln = 1
93 # else: ln = len(choices)
94 listmix.ColumnSorterMixin.__init__(self, ln)
95 # Load the data
96 if multiChoices: self.SetMultipleChoices(multiChoices, colSearch=colSearch, colFetch=colFetch)
97 else: self.SetChoices(choices)
98 gp = self
99 while gp != None:
100 gp.Bind(wx.EVT_MOVE , self.onControlChanged, gp)
101 gp.Bind(wx.EVT_SIZE , self.onControlChanged, gp)
102 gp = gp.GetParent()
103 self.Bind(wx.EVT_KILL_FOCUS, self.onControlChanged, self)
104 self.Bind(wx.EVT_TEXT , self.onEnteredText, self)
105 self.Bind(wx.EVT_KEY_DOWN , self.onKeyDown, self)
106 # If need drop down on left click
107 if dropDownClick:
108 self.Bind(wx.EVT_LEFT_DOWN, self.onClickToggleDown, self)
109 self.Bind(wx.EVT_LEFT_UP, self.onClickToggleUp, self)
110 self.dropdown.Bind(wx.EVT_LISTBOX, self.onListItemSelected, self.dropdownlistbox)
111 self.dropdownlistbox.Bind(wx.EVT_LEFT_DOWN, self.onListClick)
112 self.dropdownlistbox.Bind(wx.EVT_LEFT_DCLICK, self.onListDClick)
113 self.dropdownlistbox.Bind(wx.EVT_LIST_COL_CLICK, self.onListColClick)
114 self.il = wx.ImageList(16, 16)
115 self.sm_up = self.il.Add(SmallUpArrow.GetBitmap())
116 self.sm_dn = self.il.Add(SmallDnArrow.GetBitmap())
117 self.dropdownlistbox.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
118 self._ascending = True
119
120 #-- Methods called from mixin class
121 def GetSortImages(self):
122 return (self.sm_dn, self.sm_up)
123
124 def GetListCtrl(self):
125 return self.dropdownlistbox
126 # -- Event methods
127
128 def onListClick(self, evt):
129 toSel, flag = self.dropdownlistbox.HitTest(evt.GetPosition())
130 # No values on position, return
131 if toSel == -1: return
132 self.dropdownlistbox.Select(toSel)
133
134 def onListDClick(self, evt):
135 self._setValueFromSelected()
136
137 def onListColClick(self, evt):
138 col = evt.GetColumn()
139 # Reverse the sort
140 if col == self._colSearch:
141 self._ascending = not self._ascending
142 self.SortListItems(evt.GetColumn(), ascending=self._ascending)
143 self._colSearch = evt.GetColumn()
144 evt.Skip()
145
146 def onEnteredText(self, event):
147 text = event.GetString()
148 if self._entryCallback:
149 self._entryCallback()
150 if not text:
151 # Control is empty; hide dropdown if shown:
152 if self.dropdown.IsShown():
153 self._showDropDown(False)
154 event.Skip()
155 return
156 found = False
157 if self._multiChoices:
158 # Load the sorted data into the listbox
159 dd = self.dropdownlistbox
160 choices = [dd.GetItem(x, self._colSearch).GetText()
161 for x in range(dd.GetItemCount())]
162 else:
163 choices = self._choices
164 for numCh, choice in enumerate(choices):
165 if self._matchFunction and self._matchFunction(text, choice):
166 found = True
167 elif choice.lower().startswith(text.lower()):
168 found = True
169 if found:
170 self._showDropDown(True)
171 item = self.dropdownlistbox.GetItem(numCh)
172 toSel = item.GetId()
173 self.dropdownlistbox.Select(toSel)
174 break
175 if not found:
176 self.dropdownlistbox.Select(self.dropdownlistbox.GetFirstSelected(), False)
177 if self._hideOnNoMatch:
178 self._showDropDown(False)
179 self._listItemVisible()
180 event.Skip()
181
182 def onKeyDown(self, event):
183 """ Do some work when the user press on the keys:
184 up and down: move the cursor
185 left and right: move the search
186 """
187 skip = True
188 sel = self.dropdownlistbox.GetFirstSelected()
189 visible = self.dropdown.IsShown()
190 KC = event.GetKeyCode()
191 if KC == wx.WXK_DOWN:
192 if sel < self.dropdownlistbox.GetItemCount() - 1:
193 self.dropdownlistbox.Select(sel+1)
194 self._listItemVisible()
195 self._showDropDown()
196 skip = False
197 elif KC == wx.WXK_UP:
198 if sel > 0:
199 self.dropdownlistbox.Select(sel - 1)
200 self._listItemVisible()
201 self._showDropDown()
202 skip = False
203 elif KC == wx.WXK_LEFT:
204 if not self._multiChoices: return
205 if self._colSearch > 0:
206 self._colSearch -=1
207 self._showDropDown()
208 elif KC == wx.WXK_RIGHT:
209 if not self._multiChoices: return
210 if self._colSearch < self.dropdownlistbox.GetColumnCount() -1:
211 self._colSearch += 1
212 self._showDropDown()
213 if visible:
214 if event.GetKeyCode() == wx.WXK_RETURN:
215 self._setValueFromSelected()
216 skip = False
217 if event.GetKeyCode() == wx.WXK_ESCAPE:
218 self._showDropDown( False )
219 skip = False
220 if skip:
221 event.Skip()
222
223 def onListItemSelected(self, event):
224 self._setValueFromSelected()
225 event.Skip()
226
227 def onClickToggleDown(self, event):
228 self._lastinsertionpoint = self.GetInsertionPoint()
229 event.Skip()
230
231 def onClickToggleUp(self, event):
232 if self.GetInsertionPoint() == self._lastinsertionpoint:
233 self._showDropDown(not self.dropdown.IsShown())
234 event.Skip()
235
236 def onControlChanged(self, event):
237 if self.IsShown():
238 self._showDropDown(False)
239 event.Skip()
240
241 # -- Interfaces methods
242 def SetMultipleChoices(self, choices, colSearch=0, colFetch=-1):
243 ''' Set multi-column choice
244 '''
245 self._multiChoices = choices
246 self._choices = None
247 if not isinstance(self._multiChoices, list):
248 self._multiChoices = list(self._multiChoices)
249 flags = wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_SORT_ASCENDING
250 if not self._showHead:
251 flags |= wx.LC_NO_HEADER
252 self.dropdownlistbox.SetWindowStyleFlag(flags)
253 # Prevent errors on "old" systems
254 if sys.version.startswith("2.3"):
255 self._multiChoices.sort(lambda x, y: cmp(x[0].lower(), y[0].lower()))
256 else:
257 self._multiChoices.sort(key=lambda x: locale.strxfrm(x[0]).lower())
258 self._updateDataList(self._multiChoices)
259 if len(choices)<2 or len(choices[0])<2:
260 raise ValueError("You have to pass me a multi-dimension list with at least two entries")
261 # With only one entry, the dropdown artifacts
262 for numCol, rowValues in enumerate(choices[0]):
263 if self._colNames: colName = self._colNames[numCol]
264 else: colName = "Select %i" % numCol
265 self.dropdownlistbox.InsertColumn(numCol, colName)
266 self.dropdownlistbox.SetColumnWidth(0, 150)
267 self.dropdownlistbox.SetColumnWidth(1, wx.LIST_AUTOSIZE)
268 for numRow, valRow in enumerate(choices):
269 for numCol, colVal in enumerate(valRow):
270 if numCol == 0:
271 maxs = -sys.maxsize - 1
272 index = self.dropdownlistbox.InsertItem(maxs, colVal, -1)
273 self.dropdownlistbox.SetItem(index, numCol, colVal)
274 self.dropdownlistbox.SetItemData(index, numRow)
275 self._setListSize()
276 self._colSearch = colSearch
277 self._colFetch = colFetch
278
279 def SetChoices(self, choices):
280 '''
281 Sets the choices available in the popup wx.ListBox.
282 The items will be sorted case insensitively.
283 '''
284 self._choices = choices
285 self._multiChoices = None
286 flags = wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_SORT_ASCENDING | wx.LC_NO_HEADER
287 self.dropdownlistbox.SetWindowStyleFlag(flags)
288 if not isinstance(choices, list):
289 self._choices = list(choices)
290 # Prevent errors on "old" systems
291 if sys.version.startswith("2.3"):
292 self._choices.sort(lambda x, y: cmp(x.lower(), y.lower()))
293 else:
294 self._choices.sort(key=lambda x: locale.strxfrm(x).lower())
295 self._updateDataList(self._choices)
296 self.dropdownlistbox.InsertColumn(0, "")
297 for num, colVal in enumerate(self._choices):
298 maxs = -sys.maxsize - 1
299 index = self.dropdownlistbox.InsertItem(maxs, colVal, 0)
300 self.dropdownlistbox.SetItem(index, 0, colVal)
301 self.dropdownlistbox.SetItemData(index, num)
302 self._setListSize()
303 # There is only one choice for both search and fetch if setting a single column:
304 self._colSearch = 0
305 self._colFetch = -1
306
307 def GetChoices(self):
308 return self._choices or self._multiChoices
309
310 def SetSelectCallback(self, cb=None):
311 self._selectCallback = cb
312
313 def SetEntryCallback(self, cb=None):
314 self._entryCallback = cb
315
316 def SetMatchFunction(self, mf=None):
317 self._matchFunction = mf
318
319 #-- Internal methods
320 def _setValueFromSelected(self):
321 '''
322 Sets the wx.TextCtrl value from the selected wx.ListCtrl item.
323 Will do nothing if no item is selected in the wx.ListCtrl.
324 '''
325 sel = self.dropdownlistbox.GetFirstSelected()
326 if sel > -1:
327 if self._colFetch != -1: col = self._colFetch
328 else: col = self._colSearch
329 itemtext = self.dropdownlistbox.GetItem(sel, col).GetText()
330 if self._selectCallback:
331 dd = self.dropdownlistbox
332 values = [dd.GetItem(sel, x).GetText()
333 for x in range(dd.GetColumnCount())]
334 self._selectCallback(values)
335 self.SetValue(itemtext)
336 self.SetInsertionPointEnd()
337 self.SetSelection(-1, -1)
338 self._showDropDown(False)
339
340 def _showDropDown(self, show=True):
341 '''
342 Either display the drop down list (show = True) or hide it (show = False).
343 '''
344 if show:
345 size = self.dropdown.GetSize()
346 width, height = self.GetSize()
347 x, y = self.ClientToScreen(0, height)
348 if size.GetWidth() != width:
349 size.SetWidth(width)
350 self.dropdown.SetSize(size)
351 self.dropdownlistbox.SetSize(self.dropdown.GetClientSize())
352 if y + size.GetHeight() < self._screenheight:
353 self.dropdown.SetPosition(wx.Point(x, y))
354 else:
355 self.dropdown.SetPosition(wx.Point(x, y - height - size.GetHeight()))
356 self.dropdown.Show(show)
357
358 def _listItemVisible(self):
359 '''
360 Moves the selected item to the top of the list ensuring it is always visible.
361 '''
362 toSel = self.dropdownlistbox.GetFirstSelected()
363 if toSel == -1: return
364 self.dropdownlistbox.EnsureVisible(toSel)
365
366 def _updateDataList(self, choices):
367 # Delete, if need, all the previous data
368 if self.dropdownlistbox.GetColumnCount() != 0:
369 self.dropdownlistbox.DeleteAllColumns()
370 self.dropdownlistbox.DeleteAllItems()
371 # And update the dict
372 if choices:
373 for numVal, data in enumerate(choices):
374 self.itemDataMap[numVal] = data
375 else:
376 numVal = 0
377 self.SetColumnCount(numVal)
378
379 def _setListSize(self):
380 if self._multiChoices:
381 choices = self._multiChoices
382 else:
383 choices = self._choices
384 longest = 0
385 for choice in choices:
386 longest = max(len(choice), longest)
387 longest += 3
388 itemcount = min(len(choices), 7) + 2
389 charheight = self.dropdownlistbox.GetCharHeight()
390 charwidth = self.dropdownlistbox.GetCharWidth()
391 self.popupsize = wx.Size(charwidth*longest, charheight*itemcount)
392 self.dropdownlistbox.SetSize(self.popupsize)
393 self.dropdown.SetClientSize(self.popupsize)
394
395 #-------------------------------------------------------------------------------
396
397 class MyTest:
398 def __init__(self):
399 args = {}
400 if True:
401 args["colNames"] = ("Col 1", "Col 2")
402 args["multiChoices"] = [("Zoey", "WOW"), ("Alpha", "wxPython"),
403 ("Ceda", "Is"), ("Beta", "fantastic"),
404 ("zoebob", "!!")]
405 args["colFetch"] = 1
406 else:
407 args["choices"] = ["123", "cs", "cds", "Bob", "Marley", "Alpha"]
408 args["selectCallback"] = self.selectCallback
409 self.dynamic_choices = [
410 'aardvark', 'abandon', 'acorn', 'acute', 'adore',
411 'aegis', 'ascertain', 'asteroid',
412 'beautiful', 'bold', 'classic',
413 'daring', 'dazzling', 'debonair', 'definitive',
414 'effective', 'elegant',
415 'http://python.org', 'http://www.google.com',
416 'fabulous', 'fantastic', 'friendly', 'forgiving', 'feature',
417 'sage', 'scarlet', 'scenic', 'seaside', 'showpiece', 'spiffy',
418 'www.wxPython.org', 'www.osafoundation.org'
419 ]
420 app = wx.App()
421 frm = wx.Frame(None, -1, "Test", style=wx.TAB_TRAVERSAL|wx.DEFAULT_FRAME_STYLE)
422 frm.SetIcon(wx.Icon('wxwin.ico'))
423 panel = wx.Panel(frm)
424 sizer = wx.BoxSizer(wx.VERTICAL)
425 self._ctrl = MyTxtCtrlAutoComplete(panel, **args)
426 but = wx.Button(panel, label="Set other multi-choice")
427 but.Bind(wx.EVT_BUTTON, self.onBtMultiChoice)
428 but2 = wx.Button(panel, label="Set other one-colum choice")
429 but2.Bind(wx.EVT_BUTTON, self.onBtChangeChoice)
430 but3 = wx.Button(panel, label="Set the starting choices")
431 but3.Bind(wx.EVT_BUTTON, self.onBtStartChoices)
432 but4 = wx.Button(panel, label="Enable dynamic choices")
433 but4.Bind(wx.EVT_BUTTON, self.onBtDynamicChoices)
434 sizer.Add(but, 0, wx.EXPAND, 0)
435 sizer.Add(but2, 0, wx.EXPAND, 0)
436 sizer.Add(but3, 0, wx.EXPAND, 0)
437 sizer.Add(but4, 0, wx.EXPAND, 0)
438 sizer.Add(self._ctrl, 0, wx.EXPAND, 0)
439 panel.SetAutoLayout(True)
440 panel.SetSizer(sizer)
441 sizer.Fit(panel)
442 sizer.SetSizeHints(panel)
443 panel.Layout()
444 app.SetTopWindow(frm)
445 frm.Show()
446 but.SetFocus()
447 app.MainLoop()
448
449 def onBtChangeChoice(self, event):
450 # Change the choices
451 self._ctrl.SetChoices(["123", "cs", "cds", "Bob", "Marley", "Alpha"])
452 self._ctrl.SetEntryCallback(None)
453 self._ctrl.SetMatchFunction(None)
454
455 def onBtMultiChoice(self, event):
456 # Change the choices
457 self._ctrl.SetMultipleChoices([("Test", "Hello"), ("Other word", "World"),
458 ("Yes!", "it work?") ],
459 colFetch = 1)
460 self._ctrl.SetEntryCallback(None)
461 self._ctrl.SetMatchFunction(None)
462
463 def onBtStartChoices(self, event):
464 # Change the choices
465 self._ctrl.SetMultipleChoices([("Zoey", "WOW"), ("Alpha", "wxPython"),
466 ("Ceda", "Is"), ("Beta", "fantastic"),
467 ("zoebob", "!!")],
468 colFetch = 1)
469 self._ctrl.SetEntryCallback(None)
470 self._ctrl.SetMatchFunction(None)
471
472 def onBtDynamicChoices(self, event):
473 '''
474 Demonstrate dynamic adjustment of the auto-complete list, based on what's
475 been typed so far:
476 '''
477 self._ctrl.SetChoices(self.dynamic_choices)
478 self._ctrl.SetEntryCallback(self.setDynamicChoices)
479 self._ctrl.SetMatchFunction(self.match)
480
481 def match(self, text, choice):
482 '''
483 Demonstrate "smart" matching feature, by ignoring http:// and www. when doing
484 matches.
485 '''
486 t = text.lower()
487 c = choice.lower()
488 if c.startswith(t): return True
489 if c.startswith(r'http://'): c = c[7:]
490 if c.startswith(t): return True
491 if c.startswith('www.'): c = c[4:]
492 return c.startswith(t)
493
494 def setDynamicChoices(self):
495 ctrl = self._ctrl
496 text = ctrl.GetValue().lower()
497 current_choices = ctrl.GetChoices()
498 choices = [choice for choice in self.dynamic_choices if self.match(text, choice)]
499 if choices != current_choices:
500 ctrl.SetChoices(choices)
501
502 def selectCallback(self, values):
503 """ Simply function that receive the row values when the
504 user select an item
505 """
506 print("Select Callback called...:", values)
507
508 #-------------------------------------------------------------------------------
509
510 if __name__ == "__main__":
511 MyTest()
Download source
Additional Information
Link :
https://pypi.org/project/wxautocompletectrl/
https://stackoverflow.com/questions/50978627/combobox-with-autocomplete-wxpython
- - - - -
https://wiki.wxpython.org/TitleIndex
Thanks to
Xaviou (sample_one.py coding), Edward Flick / Michele Petrazzo / Will Sadkin (sample_two.py coding), the wxPython community...
About this page
Date (d/m/y) Person (bot) Comments :
14/03/18 - Ecco (Created page for wxPython Phoenix).
17/08/19 - Ecco (Updated example for wxPython Phoenix (sample_two.py coding).
Comments
- blah, blah, blah....