TextCtrl with multiple dynamic autocompletion

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

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.

https://groups.google.com/d/msg/wxpython-users/UpzLt8cDoqA/MkEcxxDpssAJ

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

http://wiki.wxpython.org/TextCtrlAutoComplete

···

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

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.

···

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

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:

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.

https://groups.google.com/d/msg/wxpython-users/UpzLt8cDoqA/MkEcxxDpssAJ

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

http://wiki.wxpython.org/TextCtrlAutoComplete

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 (1.08 KB)

···

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?

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:

···

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
    
  and the Phoenix doc:

wxpython.org/Phoenix/docs/html/TextEntry.html
Werner
http://wxwidgets.blogspot.com/2011/04/using-dynamic-auto-completion-in-text.html

Great. That helped. Thank you.

···

On Monday, September 15, 2014 4:15:07 PM UTC-7, Nathan McCorkle wrote:

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.