wxTheApp->Yield Topic is solved

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.
Post Reply
stefania
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Jul 20, 2005 9:08 am

wxTheApp->Yield

Post by stefania » Mon Aug 01, 2005 1:04 pm

Hi, I have a problem with mi project in Unix.

I have a Dialog, when I press a button the function execute a while cycle and I show another dialog, the code is:

Code: Select all

void TMK_SelNom::OnButtonIniziaClick( wxCommandEvent& event )
{
    TMK_Attesa* Attesa = new TMK_Attesa(NULL, ID_DIALOG_ATTESA, _("Attendere. Elaborazione in corso!"));
    Attesa->Show(true);
    while( !l_err) {
        wxTheApp->Yield();
            if( g_sosp)
                break;
            l_totali++;
            if( (l_totali % 10) == 0) {
                sprintf( et.et_mser, "Analizzati %ld nominativi", l_totali);
               m_attesa->SetLabel( et.et_mser);
            }
    }
}
The dialog TMK_Attesa has a button, when I press this button I assign to g_sosp variable 1. In Windows works, but in Unix I do not succeed to press this button, why?

Thanks.

KevinHock
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Sat Sep 04, 2004 1:49 pm
Location: Ohio, USA
Contact:

Post by KevinHock » Mon Aug 01, 2005 1:58 pm

I don't understand why you would be processing your button events this way. Rather than an infinite loop, why not just have your TMK_Attesa class handle button click events?

geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon » Mon Aug 01, 2005 1:59 pm

My first impression is that this should not work at all, since the while-loop prevents any events to be handeled.

I am asuming that shis event is processed in the main thread.

stefania
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Jul 20, 2005 9:08 am

Post by stefania » Mon Aug 01, 2005 2:13 pm

I need to sospend this while cycle, when I press button on class TMK_Attesa

KevinHock
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Sat Sep 04, 2004 1:49 pm
Location: Ohio, USA
Contact:

Post by KevinHock » Mon Aug 01, 2005 2:28 pm

I would recommend rethinking this whole approach. You should use events for processing button events. Perhaps you could put your loop contents in an OnIdle handler?

stefania
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Jul 20, 2005 9:08 am

Post by stefania » Mon Aug 01, 2005 2:45 pm

Sorry but I do not understand why in Windows work and in Unix do not work. How can I solve it? How can I use OnIdle handler?

KevinHock
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Sat Sep 04, 2004 1:49 pm
Location: Ohio, USA
Contact:

Post by KevinHock » Mon Aug 01, 2005 3:08 pm

Because events are being processed differently in Unix and Windows, and what you are doing is somewhat an abuse of the event system.

As for idle handling, look up wxIdleEvent in the documentation.

ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

Post by ssigala » Mon Aug 01, 2005 5:57 pm

Ciao Stefania,

the main problem is that your code is "Pascal-like", where users usually write something like:

Code: Select all

repeat
    mumble_mumble;
until keypressed;
This code is also know as "cpu killer"...

If I understand correctly your code, there is one button that start some processing and you want to inform the user about the progress.

If it is so, wxProgressDialog is your friend! :o

You should rework the code as:

Code: Select all

void TMK_SelNom::OnButtonIniziaClick( wxCommandEvent& event )
{
    wxProgressDialog dlg(_("Wait"), _T(""), 100, this, wxPD_AUTO_HIDE|wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_REMAINING_TIME);

    bool cancelled = false;
    for (int i = 0; i < 10; ++i) {
        do_something();
        if (!dlg.Update(i*10, wxString::Format("Done %d percent", i*10))) {
            cancelled = true;
            break;
        }
     }
   if (cancelled)
      warn_the_user();
} 
By the way, sprintf is not as good as:

Code: Select all

wxString s;
int i = 10;
s = wxString::Format("number: %d", i);

stefania
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Jul 20, 2005 9:08 am

Post by stefania » Tue Aug 02, 2005 7:26 am

Thanks a lot! It work fine!

Now I have another problem, I do not know the maximun value of progress bar. How can I know the value to update?

Ciao Stefania

NinjaNL
Moderator
Moderator
Posts: 899
Joined: Sun Oct 03, 2004 10:33 am
Location: Oosterwolde, Netherlands

Post by NinjaNL » Tue Aug 02, 2005 7:48 am

stefania wrote:Thanks a lot! It work fine!

Now I have another problem, I do not know the maximun value of progress bar. How can I know the value to update?

Ciao Stefania
You can set the maximum value using SetRange(value), or in the constructor

You then move the display by SetValue(value)

Read Up on the wxGauge control here
Follow the development of my screenplay authoring program at http://wxscreenplaywriter.blogspot.com/

Post Reply