TextCtrl with multiple dynamic autocompletion

284 views
Skip to first unread message

kruvva

unread,
Sep 15, 2014, 1:45:26 PM9/15/14
to wxpytho...@googlegroups.com
Hello,

I have the following code snippet:

console = wx.TextControl(parent, -1, style = wx.TE_PROCESS_ENTER|wx.TE_MULTILINE)
console.Bind(wx.EVT_TEXT_ENTER, self.ConsoleEvents)
console.Bind(wx.EVT_KEY_DOWN, self.ConsoleEvents) #To handle the Enter key
console.AutoComplete((Draw, Move, Rotate, Zoom))

def ConsoleEvents(self)
   if e.GetKeyCode() == 44 #Comma
      console.AutoComplete((Rectangle, Circle, triangle))
   elif
      ...
      ...

I would like to enter commands which is a set of arguments. While I enter the arguments, each argument comes from a predefined set of items. So I would like to call AutoComplete(items) before each argument selection.

For example, I have a tree of depth two to simplify the problem. 
Commands(
   (Draw, [Rectangle, Circle, Triangle]),
   (Move, [AlongX, AlongY, Both]),
   (Rotate, [CW, CCW]),
   (Zoom, [In, Out, Fit]),
   etc
)

I would like to choose my first argument from (Draw, Move, Rotate, Zoom, etc). So, initially I call console.AutoComplete((Draw, Move, Rotate, Zoom))
If I choose Move as my first argument, I would like to call console.AutoComplete( (AlongX, AlongY, Both)). This can go deeper depending on the command.


The above code only helps me selecting the first argument. But I don't know how and where to call the next AutoComplete(...). BTW, I want to separate the arguments with a delimeter, e.g comma.

If there is an example that would help me too.

Thanks
Kotesh


Nathan McCorkle

unread,
Sep 15, 2014, 3:53:36 PM9/15/14
to wxpytho...@googlegroups.com


On Monday, September 15, 2014 10:45:26 AM UTC-7, kruvva wrote:
Hello,

I have the following code snippet:

console = wx.TextControl(parent, -1, style = wx.TE_PROCESS_ENTER|wx.TE_MULTILINE)
console.Bind(wx.EVT_TEXT_ENTER, self.ConsoleEvents)
console.Bind(wx.EVT_KEY_DOWN, self.ConsoleEvents) #To handle the Enter key
console.AutoComplete((Draw, Move, Rotate, Zoom))

def ConsoleEvents(self)
   if e.GetKeyCode() == 44 #Comma
      console.AutoComplete((Rectangle, Circle, triangle))
   elif
      ...
      ...


I would first change console to self.console... then try to access it in ConsoleEvents with self.console

If changing AutoComplete there doesn't work, you might just have to implement autocomplete yourself. I did basically this for a drop-down box a few weeks ago, to mimic the Google-chrome web-browser dropdown search, except that I wanted to filter the results rather than just select the match.

And this is similar but uses a different approach (I specifically used a VListBox so that it would support newlines in entry choices)

 

Nathan McCorkle

unread,
Sep 15, 2014, 3:54:44 PM9/15/14
to wxpytho...@googlegroups.com


On Monday, September 15, 2014 12:53:36 PM UTC-7, Nathan McCorkle wrote:


On Monday, September 15, 2014 10:45:26 AM UTC-7, kruvva wrote:
Hello,

I have the following code snippet:

console = wx.TextControl(parent, -1, style = wx.TE_PROCESS_ENTER|wx.TE_MULTILINE)
console.Bind(wx.EVT_TEXT_ENTER, self.ConsoleEvents)
console.Bind(wx.EVT_KEY_DOWN, self.ConsoleEvents) #To handle the Enter key
console.AutoComplete((Draw, Move, Rotate, Zoom))

def ConsoleEvents(self)
   if e.GetKeyCode() == 44 #Comma
      console.AutoComplete((Rectangle, Circle, triangle))
   elif
      ...
      ...


I would first change console to self.console... then try to access it in ConsoleEvents with self.console

P.S. I couldn't tell if you'd tried this approach already or not.
Also, from the docs, AutoComplete wants a list, not a tuple.

kruvva

unread,
Sep 15, 2014, 5:39:18 PM9/15/14
to wxpytho...@googlegroups.com
Nathan, you are right. It was self.console.
It works with tuples too. I tested.

How do I implement my own AutoComplete() method? Basically, I need different sets of items available to choose from as I select one after the other on the same textctrl line. I have all this information in a tree structured element but I am looking for a way to implement this.
e.g it will look on the console like this: 
1. draw circle fill redColor dashLine
2. draw rectangle noFill solidLine

On Monday, September 15, 2014 12:53:36 PM UTC-7, Nathan McCorkle wrote:

Nathan McCorkle

unread,
Sep 15, 2014, 7:15:07 PM9/15/14
to wxpytho...@googlegroups.com


On Monday, September 15, 2014 2:39:18 PM UTC-7, kruvva wrote:
Nathan, you are right. It was self.console.
It works with tuples too. I tested.

How do I implement my own AutoComplete() method?

I hadn't heard of the AutoComplete method/ability until today... so much in wxPython is like this it seems (not sure if I fail at reading the docs, or if the fact that super-class methods aren't included in all sub-class pages)... but I can't comment on how to make your own function, you'll have to search the web to see if others have done this. I posted the code in my last post for how I handled auto-complete, basically any text that comes into the textbox I use to create a regular expression, then use it to search each entry in my list of choices, and re-populate the list with just the matches. AutoComplete looks simpler and maybe pretty much what I wanted though, so I recommend playing with it some more before giving up on it.

I put together a sample program that seems to do what you want. See attached.
 
testautocomplete.py

Werner

unread,
Sep 16, 2014, 2:02:19 AM9/16/14
to wxpytho...@googlegroups.com
Hi,


On 9/15/2014 23:39, kruvva wrote:
Nathan, you are right. It was self.console.
It works with tuples too. I tested.

How do I implement my own AutoComplete() method? Basically, I need different sets of items available to choose from as I select one after the other on the same textctrl line. I have all this information in a tree structured element but I am looking for a way to implement this.
e.g it will look on the console like this: 
1. draw circle fill redColor dashLine
2. draw rectangle noFill solidLine
Have not used AutoComplete myself, but got curious reading this thread.

Maybe the following helps, unless you have already seen that.
There is this on blogspot:
http://wxwidgets.blogspot.com/2011/04/using-dynamic-auto-completion-in-text.html

and the Phoenix doc:
wxpython.org/Phoenix/docs/html/TextEntry.html

Werner

kruvva

unread,
Sep 16, 2014, 12:14:11 PM9/16/14
to wxpytho...@googlegroups.com
Great. That helped. Thank you.

Cesar Tabares

unread,
Apr 4, 2020, 10:34:55 PM4/4/20
to wxPython-users
Dude,
I was about to give up, your example save my life, long live to you!, works perfectly , plus I could made the autocomplete txtctrl linked to an autocomplete places google's API
Thanks!!
Reply all
Reply to author
Forward
0 new messages