Making A slide show App using Signal/Slot mechanism

Hi… Sorry for very long post… I hope you will go till the end. I am developing a very simple image viewer which , reads a Pixel- and corresponding counts data from binary file. Converts them to TH2Poly and displays them in a window. I have just modified the ‘stand alone simple example’ given in User guide (Chapter 25, Writting the GUI). Now it works. However I want to add a button to it like ‘Slide show’ that will :

  1. Show the images consecutively with some time pause 2. It will toggle its label from ‘Slide’ to ‘Stop’ when clicked
  2. Same button shall be used to stop the slide show & when it is stopped it should toggle the label back to Slide. (Basically I want it to work like windows photo viewer) .
    Now I have managed to do first 2 things.
    However I am unable to do the 3rd thing. Basic problem I face is that, The function SlideShow() has a while loop in it, which goes on calling the function NextImage() that displays the next image stored in file. As long as this while loop is on (i.e. basically till the end of the file) fuction SlideShow() does not ‘return’ and hence even if I click the ‘Stop’ button , ‘Slot’ connected to it doesn’t get executed. In fact all the buttons are inactive until SlideShow() ‘return’ s the control . What is the way out of it ??
    My class looks like this : [code]class MyMainFrame : public TGMainFrame {
    private:

string Camera_file ;

Camera cam ;

TRootEmbeddedCanvas *fEcanvas;

TGHorizontalFrame *hframe ;

TGTextButton *draw, *exit, *slide ;

TH2Poly* image ;

bool slide_on ;

int sernum ; // Holds the serial number of the image to be displayed
public:
MyMainFrame(const char* CamFile, int mode ,const TGWindow *p,UInt_t w,UInt_t h);
virtual ~MyMainFrame() ;
int DrawImage(int num) ;
int NextImage() ;
void ChangeButtonState();
void SlideShow() ;
ClassDef(MyMainFrame,0)
};
[/code]
The constructor has

slide = new TGTextButton(hframe,"&Slide Show "); slide->SetState(kButtonUp) ; slide->Connect("Clicked()","MyMainFrame",this,"ChangeButtonState()") ; slide->Connect("Clicked()","MyMainFrame",this,"SlideShow()");
SlideShow() looks like :

void MyMainFrame::SlideShow() { sernum = 1 ; if(!slide_on) return ; else { while(NextImage() == 0 && slide_on) sleep(2); } // ChangeButtonState() ; }
I hoped that clicking on ‘Stop’ will modify slide_on variable by calling ChangeButtonState() and that way while loop will be terminated. But thats not working.

Hi,

Try to simply add “gSystem->ProcessEvents();” in your while loop.

Cheers, Bertrand.

Thanks!!.. :slight_smile: