带有建议的条目
我正在构建一个小型 PyGTK 应用程序,并且有一个文本输入字段(当前是 ComboBoxEntry),其中填充了用户应该能够从中选择的一些值。
我认为我想要做的是过滤掉匹配字段并仅显示这些字段,以便使用键盘箭头的用户可以选择匹配字段之一。
为了提供一些背景知识,预定义值是一堆 URL,用户应该能够从这些 URL 中进行选择或填写新的 URL。
例子: 预定义网址:
- http://www.google.com
- http://www.google.com/android
- http://www.google.com/android http:// /www.greatstuff.com
- http://www.facebook.com
当用户输入 '< a href="http://www.g" rel="noreferrer">http://www.g' 以该字符串开头的三个 URL 将在输入“http://www.goog 时显示(以某种方式) ' 以此开头的两个内容将被显示
有任何想法吗?
I'm building a small PyGTK application and I have an text input field (currently a ComboBoxEntry) which is populated with a few values that the user should be able to choose from.
I think what I want to do is to filter out the matching fields and only show those ones so the user using the keyboard arrows can choose one of the matching ones.
To give some background the predefined values are a bunch of urls and the user should be able to choose from theese or fill in a new one.
Example:
the predefined urls:
When a user types 'http://www.g'
The three URLs starting with that string is to be shown (in some way) and when typeing 'http://www.goog' the two starting with that is to be shown
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
带有
EntryCompletion
的Entry
似乎比ComboBoxEntry
更合适。一如既往,教程是一个好的开始。当预定义的 URL 列表较小且固定时,设置非常容易。
您只需要填充一个 ListStore:
用户不太可能费心输入“http://”甚至“www.”,因此您可能想要匹配 URL 的任何部分(例如,只需“og”即可!)
:将测试 ListStore 中的每个值是否匹配,因此它无法扩展到巨大的列表(我的意思是巨大;1000 就可以了)。
请务必使用 EntryCompletion 的各种选项,以配置最令人愉快的行为。
An
Entry
with anEntryCompletion
seems more appropriate than aComboBoxEntry
. As always, the tutorial is a good start.It's very easy to set up when the predefined URLs list is small and fixed.
You just need to populate a ListStore:
Users are not likely to bother typing "http://" or even "www.", so you probably want to match any part of the URL (e.g. just "og" works!):
This will test every value in the ListStore for a match, so it's not scalable to huge lists (I mean huge; a 1000 works fine).
Be sure to play with the various options of EntryCompletion, to configure the most pleasant behavior.
您可能想了解一下桌面栏小程序的
Cuemiac
做到了。You may want to look at how Deskbar Applet's
Cuemiac
does it.嗯,你显然想要处理前缀,所以你可能想要使用某种 trie。当然,还有一些问题需要处理。例如,在一个人输入了几个字母(甚至可能只是一个)后,您将希望遍历特里树的其余分支来查找建议,或者将建议存储在每个节点中。许多此类决定取决于您计划有多少可能的建议。
Well, you obviously want to deal with prefixes so you'll probably want to use some sort of trie. Of course, there are issues to deal with. For instance, after a person has typed in a few letters ( or maybe even just one) you will want to either traverse the rest of the branches of the trie to find suggestions, or have suggestions stored in each node. A lot of these sorts of decisions depend on how many possible suggestions you plan on having.