The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by CnnC »

Good day!

Found a compatibility problem of the method of the Autocomplete and events wxEVT_TEXT applicable for the same object wxTextCtrl. The idea is to implement auto-completion of a text field with constant changes in the text array when entering text into this field.

Please tell me how to solve this problem.

Below is the program code that reveals the essence of the problem. The first text box works correctly, as in the autocomplete method is added unchanged text array in the constructor. But with the second test field there was a problem.

Code: Select all

#include <wx/wx.h>

class Window : public wxFrame {
public:
    const int ID_TC_CURRECT = 1;
    const int ID_TC_UNCURRECT = 2;
    wxPanel *panel = new wxPanel(this);
    wxBoxSizer *box_vertical = new wxBoxSizer(wxVERTICAL);
    wxTextCtrl *tc_currect = new wxTextCtrl(panel, ID_TC_CURRECT);
    wxTextCtrl *tc_uncurrect = new wxTextCtrl(panel, ID_TC_UNCURRECT);
    wxArrayString *arr = new wxArrayString();
    Window (
        wxWindow *parent,
        wxWindowID id,
        const wxString &title,
        const wxPoint &pos=wxDefaultPosition,
        const wxSize &size=wxDefaultSize,
        long style=wxDEFAULT_FRAME_STYLE,
        const wxString &name=wxFrameNameStr) :
    wxFrame (
        parent,
        id,
        title,
        pos,
        size,
        style,
        name
    ) {
        box_vertical->Add(tc_currect);
        box_vertical->Add(tc_uncurrect);
        panel->SetSizer(box_vertical);
        /*Complete for example*/
        arr->Add(wxT("111222333"));
        arr->Add(wxT("22334455"));
        arr->Add(wxT("543"));
        arr->Add(wxT("12"));
        arr->Add(wxT("23"));
        arr->Add(wxT("34422"));
        arr->Add(wxT("154"));
        tc_currect->AutoComplete(*arr);   
        
        Bind(wxEVT_TEXT, m_textprint, this, ID_TC_UNCURRECT);
    }
    void m_textprint(wxCommandEvent & event);
};

void Window::m_textprint(wxCommandEvent & event) {
    /*Here, a string array is formed when the xml document is parsed, 
    * which is added as an argument for the text field autocomplete method. 
    * Each time you enter a new letter, the array changes. 
    * For simple autocomplete method is added to an immutable array. 
    * Going on the fact that autocomplete is not working properly - 
    * automatically fills the text box and does not gives you the opportunity to change it.*/
    Window::tc_uncurrect->AutoComplete(*(Window::arr));
}

class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};

IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
	Window *window = new Window(NULL, wxID_ANY, wxT("Simple Window"));
    window->Show(true);
    return true;
}
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by doublemax »

Which platform and wxWidgets version are you using?

This sounds like this bug http://trac.wxwidgets.org/ticket/12613 which was fixed 5 months ago.

So you probably need wx 3.0.4 or the latest version from GIT.
Use the source, Luke!
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by CnnC »

Good afternoon.

I use wxWidgets 3.1.1, Windows 7 operating system, IDE CodeLite.

Problem description: I type in the wxtextctrl object, one of the options in the autocomplete list is automatically selected, the input field goes to the end of the line, the selected text is not erased "backspace", and again this only option is automatically selected.

In the attached program, the problem occurs in the second loop of wxTextCtrl.
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by CnnC »

Attached screenshots of the working and non-working element
Attachments
Good.png
Good.png (12.31 KiB) Viewed 3173 times
Bad.png
Bad.png (11.72 KiB) Viewed 3173 times
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by ONEEYEMAN »

Hi,
So it is not the wxEVT_TEXT event problem then?

Please describe the scenario for which the problem occurs and what do you expect to see. It's hard to understand of what you are looking for (no offense intended).
Also, while you are at it, try to reproduce it in the widgets sample which contains the "autocomplete" feature for the text control.

And finally see if upgrading to the latest Git sources will fix the issue.

Thank you.
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by CnnC »

Good evening!

The problem is to combine the autocomplete and the wxEVT_TEXT event for the same wxTextCtrl element. In the code I put at the very beginning of the topic, the object:

Code: Select all

wxTextCtrl *tc_currect = new wxTextCtrl(panel, ID_TC_CURRECT);
works nomally.

And for the object:

Code: Select all

wxTextCtrl *tc_uncurrect = new wxTextCtrl(panel, ID_TC_UNCURRECT);
in addition to the autocomplete, there is also an event wxEVT_TEXT that is triggered when you enter each character.

Yes, the event fires normally, as in the reference description, the problem with the autocomplete method. A field with a list of choices available in the text array is not displayed. It immediately appears and disappears. One of the options is selected automatically, and the resulting row is not changed, because it is automatically selected again and again.

Thanks for your help.
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by CnnC »

In the second screenshot, if you type the numbers sequentially, the selection will be made automatically.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by ONEEYEMAN »

Hi,
So, if I understand you correctly, you launch the program and in the text control you type "1", which will display the autocomplete listbox, which then immediately disappear.
Am I correct?
Or is it scenario #2: You launch a program, type "1", but there is no wxEVT_TEXT event fired, the autocomplete list is displayed and stays waiting for another character.

Or is there scenario #3?

Thank you.
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by CnnC »

In the text element No. 1 I enter 1 and a list with possible variations is displayed. All is well.

In the test element No. 2, I enter in order 1 1 1 2 and the element is automatically filled. At the same time a list of possible options appears for a moment.

Text element number 1 - control. The problem is implemented in text element number 2.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by ONEEYEMAN »

Hi,
What happens after you type "1" in the text control #2?

Is there a different options supplied when you created both controls?

Also it looks like you problem does not related to the wxEVT_TEXT.

Finally can you reproduce the issue in the widgets sample? Also, I presume it is under Windows? Which version?

Thank you.
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by CnnC »

What happens after you type "1" in the text control #2?
If I enter "1" and "1" (i.e. "11") again, then the line will automatically fill "111222333" with no choice.
Is there a different options supplied when you created both controls?

Also it looks like you problem does not related to the wxEVT_TEXT.

Finally can you reproduce the issue in the widgets sample? Also, I presume it is under Windows? Which version?
I will remove the wxTextCtrl № 1 element from the code, as it works without problems. I'll just leave element № 2.

Code: Select all

#include <wx/wx.h>

class Window : public wxFrame {
public:
    const int ID_TC_UNCURRECT = 1;
    wxPanel *panel = new wxPanel(this);
    wxBoxSizer *box_vertical = new wxBoxSizer(wxVERTICAL);
    wxTextCtrl *tc_uncurrect = new wxTextCtrl(panel, ID_TC_UNCURRECT);
    wxArrayString *arr = new wxArrayString();
    Window (
        wxWindow *parent,
        wxWindowID id,
        const wxString &title,
        const wxPoint &pos=wxDefaultPosition,
        const wxSize &size=wxDefaultSize,
        long style=wxDEFAULT_FRAME_STYLE,
        const wxString &name=wxFrameNameStr) :
    wxFrame (
        parent,
        id,
        title,
        pos,
        size,
        style,
        name
    ) {
        box_vertical->Add(tc_uncurrect);
        panel->SetSizer(box_vertical);
        /*Complete for example*/
        arr->Add(wxT("111222333"));
        arr->Add(wxT("22334455"));
        arr->Add(wxT("543"));
        arr->Add(wxT("12"));
        arr->Add(wxT("23"));
        arr->Add(wxT("34422"));
        arr->Add(wxT("154"));
        
        Bind(wxEVT_TEXT, m_textprint, this, ID_TC_UNCURRECT);
    }
    void m_textprint(wxCommandEvent & event);
};

void Window::m_textprint(wxCommandEvent & event) {
    /*Here, a string array is formed when the xml document is parsed, 
    * which is added as an argument for the text field autocomplete method. 
    * Each time you enter a new letter, the array changes. 
    * For simple autocomplete method is added to an immutable array. 
    * Going on the fact that autocomplete is not working properly - 
    * automatically fills the text box and does not gives you the opportunity to change it.*/
    Window::tc_uncurrect->AutoComplete(*(Window::arr));
}

class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};

IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
   Window *window = new Window(NULL, wxID_ANY, wxT("Simple Window"));
    window->Show(true);
    return true;
}
Finally can you reproduce the issue in the widgets sample?
I don't understand what "widgets sample"means. I put the application code focused on the problem. Sorry, I don't quite understand.
Also, I presume it is under Windows? Which version?
Woindows 7 and Windows 10, wxWidgets 3.1.1, IDE Codelite

Thank you.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by ONEEYEMAN »

Hi,
CnnC wrote:
What happens after you type "1" in the text control #2?
If I enter "1" and "1" (i.e. "11") again, then the line will automatically fill "111222333" with no choice.
Well I didn't ask to type "11", did I?
CnnC wrote:
Is there a different options supplied when you created both controls?

Also it looks like you problem does not related to the wxEVT_TEXT.

Finally can you reproduce the issue in the widgets sample? Also, I presume it is under Windows? Which version?
I will remove the wxTextCtrl № 1 element from the code, as it works without problems. I'll just leave element № 2.
My first question should've given you a clue - what is different between the code for text #1 and text #2. Just compare that code and see.
Also, please check the syntax for the Bind() - I don't think it is correct.
CnnC wrote:
Finally can you reproduce the issue in the widgets sample?
I don't understand what "widgets sample"means. I put the application code focused on the problem. Sorry, I don't quite understand.
Open the folder wxWidgets-3.1.1\samples\widgets and issue exactly the same command you used for building wxWidgets. Then run "./widgets". You are running "widgets" sample.
There are many more samples available for you to explore, but autocompletion is demonstrated in widgets sample.
CnnC wrote:
Also, I presume it is under Windows? Which version?
Woindows 7 and Windows 10, wxWidgets 3.1.1, IDE Codelite

Thank you.
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by CnnC »

What happens after you type "1" in the text control #2?
Nothing. In the text field, the symbol "1" is displayed, the bark will stand behind this symbol with readiness for further selection of sigils.
Is there a different options supplied when you created both controls?
Yes. Both elements were created in the constructor. The difference is in the place of adding the autocomplete method. For the first element - in the constructor, for the second - in the function, caused by the event handler.
Finally can you reproduce the issue in the widgets sample?
Open the folder wxWidgets-3.1.1\samples\widgets and issue exactly the same command you used for building wxWidgets. Then run "./widgets". You are running "widgets" sample.
Forgive my misunderstanding. I was able to compile the C application: /wxWidgets-3.1.1/samples/widgets/gcc_mswu/widgets.exe. I launched it. But I did not find an example with autocomplete. And I do not understand what it means:
Also, while you are at it, try to reproduce it in the widgets, which contains the" autocomplete "feature for the text control.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by ONEEYEMAN »

Hi,
When you open the widgets sample on the left side there will be a tree with the different controls. Choose the native text control.
Then in the menu there will be different options for autocompletion. Select all of them one by one and try to type something in the control.

Finally, I strongly suggest to try with the latest Git sources. There was a bug about autocompletion with the wxEVT_TEXT event which was fixed fairly recently. So just for the test tryo to grab latest sources, compile them and build you test. Will this work?

Thank you.
CnnC
Knows some wx things
Knows some wx things
Posts: 31
Joined: Thu Mar 08, 2018 7:40 am

Re: The simultaneous use of autocomplete and wxEVT_TEXT to wxTextCtrl

Post by CnnC »

Hi.
Thank you for your patience and responsiveness.

Started: С:/wxWidgets3.1.1/samples/widgets/gcc_mswu/widgets.exe. I moved on to Text testing. Then I used the instruction described in the first answer to this topic http://trac.wxwidgets.org/ticket/12613. Left all the "Set textctrl parameters" options as default. I press "Enter" in the text field on the right, nothing happens, the cursor remains in place. In the log appears the inscription "Text entered: ...". When I uncheck the "Process Enter" parameter, pressing "Enter" will move the cursor to a new line. The log says "text ctrl value change". I don't know if the application works correctly. But the cursor does not move to a new line with default parameters.

Now in the horizontal menu, select Text- > Fixed-list auto-completion. The "Process Enter" option is enabled. Press "Enter". Line gets selected. The cursor does not move, stands still. The log says "Text entered:' Hello Universe!'" . Interestingly, I return the settings Text->Disable auto-completion, then pressing "Enter" again highlighted a line in the text field.
It seems that the behavior of the example differs from what is written in http://trac.wxwidgets.org/ticket/12613.

The source files of the library were taken from the source: https://github.com/wxWidgets/wxWidgets/ ... s-3.1.1.7z. Kind of like the latest version of the library. Maybe I do not understand something.

I'm sorry for being thorough. Thanks.
Post Reply