Display two message one after another in a label in single event

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

2 posts / 0 new
Last post
Display two message one after another in a label in single event

 

Hi,

My form contains scroll window with two label's to display error and status message and  two buttons i.e, "Generate" and "Cancel".

Whenever I click on "Generate" buttons I have to get a status message saying "Kit generate process is in Progress" and when the process is complete display a message in same status label saying "Kit Is Created Successfully." and return from the event. This whole process is happening in a single event. The issue is application is giving  the last message in the status label before the return from the event . No intermediate messages are being displayed.

Code Snippet:

Below is the code snippet for "Generate" Buttons.

//The below method is to register the application callbacks for "Cancel" and "Generate" Button Form Elements.

Logical CreateDbKit::register_application_callbacks( )

{

    bool status = dispatch.map( fe_Cancel, &CreateDbKit::KitCancel )

               && dispatch.map( fe_Generate, &CreateDbKit::Generate );

    return status;

}

 

//This method is called when the user clicks on the Generate button.

 

Logical CreateDbKit::Generate( const FormEvent& event )

{

   bool status = true;

   _errormsg = "Kit Is Created Successfully.";

  message( format_msg( KitInProgress ) ); -----------------------------------> Not being printed In the status label

  message( format_msg( KitGenerated, _errormsg.c_str( ) ) ); ----------> Only final message is being printed in the status label

  unlock();

return status;

}

End Code Snippet:

Below are the lists of approaches tried so far. But no luck.

 

1)  Adding sleep(10) in between two message like below.

 

   message( format_msg( KitInProgress ) ); -----------------------------------> Not being printed In the status label

   sleep(10);

  message( format_msg( KitGenerated, _errormsg.c_str( ) ) ); ----------> Only final message is being printed in the status label

 

2) Calling extra "message(...)" function call like below.

     

  message( format_msg( KitInProgress ) ); ------------------------------------> Not being printed In the status label

  sleep(10);

  _errormsg = "Kit Created Failed.";

  message( format_msg( KitGenFailed, _errormsg.c_str( ) ) ); ----------> Still not being printed In the status label

  sleep(10);

  message( format_msg( KitGenerated, _errormsg.c_str( ) ) ); ----------> Only final message is being printed in the status label

 

3) If I call This function i.e "graph_db->process_pending_events( );" in between every messages then it works for 2-3 times then only.like Below.

     

    message( format_msg( KitInProgress ) ); ------------------------------------> printed In the status label only 2-3 times then only.

    graph_db->process_pending_events( );

  _errormsg = "Kit Created Failed.";

  message( format_msg( KitGenFailed, _errormsg.c_str( ) ) ); ----------> Still not being printed In the status label

  graph_db->process_pending_events( );

  message( format_msg( KitGenerated, _errormsg.c_str( ) ) ); ----------> Only final message is being printed in the status label

     

  Definition of this function is below:

 

  inline void Graphic_DB::process_pending_events( ) 

 {

     XtInputMask input_mask;

    while ( (input_mask = XtAppPending( Graphic_DB::app_context )) )

    {

        XtAppProcessEvent( Graphic_DB::app_context, input_mask );

    }

}

 

Please Please Advise me, as I am very new to this Motif world.

An example

Please find below a sample demonstrating how to update widgets during long-time operations. This is just one of possible implementations assumed you use only one thread.

 

#include <stdio.h>
#include <stdlib.h>
#include <Xm/XmAll.h>

XtAppContext  app_context;


void ButtonCallback(Widget wd, XtPointer client_data, XtPointer call_data)
  { static int ExecutionControl=0;

    // Multiple callback entering control
    if (ExecutionControl > 0)
      { printf("Multiple entering to callback function is denied\n");
        return;
      }
    ExecutionControl++;

    // Initial message about long-time operation
    XmString xmsg = XmStringCreateLocalized("Executing long time operation ...");
    XtVaSetValues(wd, XmNlabelString, xmsg,NULL);
    XmStringFree(xmsg);

    int i=0;
    char Str[30];
    const int CountItems=10;
    // Simulation of long-time processing operation
    for (i=0; i< CountItems; i++)
        {
          // Processing Motif event loop
          while (XtAppPending(app_context))
            { XEvent event;
              XtAppNextEvent(app_context, &event);
              XtDispatchEvent(&event);
            }
          // simulation processing operation
          sleep(1);
          // Output of intermediate results of operation
          sprintf(Str, "Processed %d %%", 100*(i+1)/CountItems);
          xmsg = XmStringCreateLocalized(Str);
          XtVaSetValues(wd, XmNlabelString, xmsg);
          XmStringFree(xmsg);
        }
    sleep(1);

    // Operation is finished!
    xmsg = XmStringCreateLocalized("Processing finished!");
    XtVaSetValues(wd, XmNlabelString, xmsg);
    XmStringFree(xmsg);

    ExecutionControl--;
  }


int main(int argc, char *argv[])
 { Widget Label,  Button, rc1;
   Widget toplevel, MainWindow;
   Arg args[10];
   Cardinal ac;

   XtSetLanguageProc(NULL, NULL, NULL);

   toplevel = XtVaOpenApplication(&app_context, "SampleApp_shell", NULL, 0, &argc,
                argv, NULL,sessionShellWidgetClass,NULL);

   ac=0;
   MainWindow = XmCreateMainWindow(toplevel, "SampleApp_main_window", args, ac);

   // RowColumn creating
   ac=0;
   XtSetArg(args[ac], XmNrowColumnType, XmWORK_AREA); ac++;
   XtSetArg(args[ac], XmNorientation, XmVERTICAL); ac++;
   rc1 = XmCreateRowColumn(MainWindow, "rc1", args , ac);
   XtVaSetValues(MainWindow, XmNworkWindow, rc1, NULL);

   // Label creating
   ac=0;
   XmString xmstr = XmStringCreateLocalized("Press button:");
   Label = XmCreateLabel(rc1, "label", args, ac);
   XtVaSetValues(Label, XmNlabelType, XmSTRING, XmNlabelString, xmstr, NULL);
   XtManageChild(Label);
   XmStringFree(xmstr);

   // Button creating
   ac=0;
   xmstr = XmStringCreateLocalized("Execute long operation...             ");
   Button = XmCreatePushButton(rc1, "execute_button", args, ac);
   XtVaSetValues(Button, XmNlabelString, xmstr, NULL);
   XtManageChild(Button);
   XmStringFree(xmstr);

   // Calback for Add Host button
   XtAddCallback(Button, XmNactivateCallback, ButtonCallback, (XtPointer)NULL);

   XtManageChild(rc1);
   XtManageChild(MainWindow);
   XtRealizeWidget(toplevel);
   XtAppMainLoop(app_context);

  return 0;
 }