Re: [ROOT] Advice on using TGMenuBar/TGPopupMenu

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Wed Dec 20 2000 - 18:50:22 MET


Hi James,

   the code you show here is in principle correct (you must use
fClient->GetRoot() in TGPopupMenu() and not this because, as you saw,
then the MapSubwindows() call would then also map the popup menus).

Check carefully the ProcessMessage() routine. Does it get called
at all (try some prints).

For another extensive example program see $ROOTSYS/test/guitest.cxx.
And if you use the latest version of ROOT you can also use the new
signal/slot communication mechanism in the GUI (which removes the need
for very large switch statements in ProcessMessage() and which allows
you to develop the GUI entirely in the interpreter, if desired). See
$ROOTSYS/tutorials/guitest.C.

Cheers, Fons.



James Peachey wrote:
> 
> Hi,
> 
> Since this is my first time writing to roottalk, let me start by
> saying thank you for making available such a great software system!
> I very much enjoy using Root, and I'm very impressed at what it
> can do.
> 
> At the moment I'm using the GUI classes, and I'm having some trouble
> getting my menubar to work correctly. I based my approach on the code
> in TRootCanvas, which suggests that the following should work:
> 
>   // file menu
>   mFileMenu = new TGPopupMenu(fClient->GetRoot());
>   mFileMenu->AddEntry(new TGHotString("&Save"), kITG_ID_MENUSAVE);
>   mFileMenu->Associate(this);
> 
>   // menubar
>   mMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame | kRaisedFrame);
>   mMenuBar->AddPopup("&File", mFileMenu, TopLeftHints);
>   AddFrame(mMenuBar, TopLeftExpandXHints);
> 
> I also added code to ProcessMessage() to handle the event for the
> TGPopupMenu for parm1 == kITG_ID_MENUSAVE. I should mention that the
> code above appears in the initialization for a class derived from
> TGMainFrame.
> 
> When I do this, I get a "File" pull-down menu which pops up
> a "Save" option when it is clicked -- so far so good. However, it
> is impossible actually to *select* the "Save" option, that is, the
> code in ProcessMessage() is never executed even when one selects
> "Save" with the mouse.
> 
> I also tried constructing the TGPopupMenu object using "this" instead
> of "fClient->GetRoot()". In that case, the code in ProcessMessage()
> is called when one selects "Save", but the menu doesn't look right
> when my application starts; the menu appears to be "pulled down"
> when the main window first pops up.
> 
> Any ideas what I am doing wrong?
> 
> Thanks,
> James

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:40 MET