Re: [ROOT] Unable to call methods in GUI constructor!

From: cstrato (cstrato@aon.at)
Date: Sun Feb 16 2003 - 16:09:53 MET


Dear Damir

I cannot believe it, you are right! Now my macro works!
(I consider this a severe bug!)

Sorrowly, it does not solve my other problem, the compilation
of the macro. Maybe, if you have time, I am sending you the
relevant files. It would be great if you could test it.

Thank you already for these good news.
(BTW, I am using "this->" in order to distinguish methods
defined in the current class from inherited methods)

Best regards
Christian



Damir Buskulic wrote:

> Hi Christian and Fons,
> 
> I just tried it and Christian's script doesn't work neither on MacOSX
> However, if I replace the line 321 :
> 
> this->Test(1);
> 
> simply by
> 
> Test(1)
> 
> which is usual, everything works fine. So maybe there is an interpreter
> issue here, which is not limited to GUI. But I'm not able to investigate
> more. Hope it helps.
> 
> Cheers
> 
> Damir
> 
> =====================================================================
> | Damir Buskulic                  | Universite de Savoie/LAPP       |
> |                                 | Chemin de Bellevue, B.P. 110    |
> | Tel : +33 (0)450091600          | F-74941 Annecy-le-Vieux Cedex   |
> | e-mail: buskulic@lapp.in2p3.fr  | FRANCE                          |
> =====================================================================
> mailto:buskulic@lapp.in2p3.fr
> 
> On Sun, 16 Feb 2003, Fons Rademakers wrote:
> 
> 
>>Hi Christian,.
>>
>>  this might very well be a 10.1 problem. I have this week no access
>>to my Mac so I can not verify the behaviour on Mac OS X 10.2. Maybe Damir
>>can try?
>>
>>Cheers, Fons.
>>
>>
>>
>>On Sat, Feb 15, 2003 at 06:33:11PM +0100, cstrato wrote:
>>
>>>Dear Rooters
>>>
>>>The enclosed macro ".x mygui.C" contains two classes,
>>>called MyFrame and SubFrame.
>>>
>>>In the constructor of MyFrame I am able to call methods,
>>>however, in the constructor of SubFrame I am unable to
>>>call any method. Even calling the simple method "Test(1)"
>>>(see line 321) causes ROOT to crash with:
>>>
>>>root [7] .x mygui.C
>>>---TEST - 1
>>>  *** Break *** segmentation violation
>>>Root > Function mygui() busy flag cleared
>>>Function MyFrame() busy flag cleared
>>>Function CreateShutterFrames() busy flag cleared
>>>Function SubFrame() busy flag cleared
>>>Function Test() busy flag cleared
>>>
>>>Can anybody tell me, why I am not able to call a
>>>method in the SubFrame constructor??
>>>
>>>Note: Yesterday, I could run a similar macro in root
>>>for about 50 times without problems, until root finally
>>>crashed with the error described above. Since then, it
>>>is no longer possible to call a method from the constructor.
>>>
>>>I am using root 3.05/02 on MacOS X 10.1.2
>>>
>>>Thank you in advance.
>>>
> 
> 
> 



// File created: 15/02/2003                          last modified: 15/02/2003

/******************************************************************************
* Copyright(c) 2000-2003, Dr. Christian Stratowa, Vienna, Austria.            *
* Author: Christian Stratowa.                                                 *
******************************************************************************/

#ifndef __MYGUI__
#define __MYGUI__

#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>

#include "RQ_OBJECT.h"
#include "TGFrame.h"
#include "TGMenu.h"
#include "TGButton.h"
#include "TGLayout.h"
#include "TG3DLine.h"
#include "TGShutter.h"
#include "TGPicture.h"

#include "TList.h"

class SubFrame;

struct ShutterData_t {
   const char *sPixmap_name;
   const char *sTip_text;
   Int_t       sId;
   TGButton   *sButton;
};

class MyFrame {

   RQ_OBJECT("MyFrame")

   private:
      TGMainFrame        *fMain;

   // MenuBar Frame
      TGPopupMenu        *fMenuFile;
      TGMenuBar          *fMenuBar;
      TGHorizontal3DLine *fLineH1;

   // Shutter Frame
      TGHorizontalFrame  *fHF1;
      TGShutter           *fShutter;
      const TGPicture     *fDefaultPic;
      SubFrame           *fSubFrame;

   // Layout hints
      TGLayoutHints      *fMenuBarLayout;
      TGLayoutHints      *fMenuBarItemLayout;
      TGLayoutHints      *fMenuBarHelpLayout;
      TGLayoutHints      *fLineLayout;
      TGLayoutHints      *fLayout;

      TList    *fTrash;

   public:
      MyFrame(const TGWindow *window, UInt_t w, UInt_t h);
      virtual ~MyFrame();

//      void AddShutterItem(const char *name, Int_t id, ShutterData_t *data);
      void AddShutterItem(const char *name, Int_t id, ShutterData_t data[]);

   // Slots
      void DoCloseWindow();
      void DoShutter(Int_t id = -1);

   private:
      void CreateMenuBar();
      void DeleteMenuBar();
      void CreateShutter();
      void DeleteShutter();
      void CreateShutterFrames();
      void DeleteShutterFrames();

      ClassDef(MyFrame,0) //MainFrame
};

class SubFrame {

   RQ_OBJECT("SubFrame")

   private:
      MyFrame            *fMyFrame;
      TGCompositeFrame   *fShutterFrame;
      TGCompositeFrame    *fFrameA;
      TGGroupFrame         *fFG1;

      TList    *fTrash;

   public:
      SubFrame() {}
      SubFrame(TGCompositeFrame *parent, MyFrame *main, UInt_t w, UInt_t h);
      virtual ~SubFrame();

      void HandleShutter(Int_t id = -1);

   private:
      void Test(Int_t k) {cout << "---TEST - " << k << endl;}
      void CreateFrameA();
      void DeleteFrameA();

      ClassDef(SubFrame,0) //SubFrame
};

#endif


// File created: 15/02/2003                          last modified: 15/02/2003

/******************************************************************************
* Copyright(c) 2000-2003, Dr. Christian Stratowa, Vienna, Austria.            *
* Author: Christian Stratowa.                                                 *
******************************************************************************/

#include "TROOT.h"
#include "TApplication.h"
#include "TVirtualX.h"

#include "MyGui.h"

// Menu commands
enum EMenuCommands {
   M_FILE,
   M_FILE_NEW,
};

// Shutter commands
enum EShutterCommands {
   S_SHUT1 = 1001,
   S_SHUT1_A,
   S_SHUT1_B,

   S_SHUT2 = 1001,
   S_SHUT2_A,
   S_SHUT2_B,
};

const char *xpm_names[] = {
    "Folder.xpm",
    "Folder.xpm",
    0
};
const char *kShutterName[] = {
    "Shutter1",
    "Shutter2",
    0
};

ShutterData_t kItems1[] = {
   { "folder_s.xpm", "xxx", S_SHUT1_A, 0 },
   { "folder_s.xpm", "xxx", S_SHUT1_B, 0 },
   { 0,               0,    0,         0 }
};

ShutterData_t kItems2[] = {
   { "folder_s.xpm", "xxx", S_SHUT2_A, 0 },
   { "folder_s.xpm", "xxx", S_SHUT2_B, 0 },
   { 0,               0,    0,         0 }
};

//debug: print function names
const Bool_t kCS  = 1; 

ClassImp(MyFrame);
ClassImp(SubFrame);

//______________________________________________________________________________
MyFrame::MyFrame(const TGWindow *window, UInt_t w, UInt_t h)
{
   if(kCS) cout << "------MyFrame::MyFrame------" << endl;

   fTrash = new TList();

   fMain = new TGMainFrame(window, w, h);
   fMain->Connect("CloseWindow()", "MyFrame", this, "DoCloseWindow()");

// Create menus
   CreateMenuBar();
//   this->CreateMenuBar();

// Basic frame layout
   fLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
   fHF1 = new TGHorizontalFrame(fMain, 20, 20);
   fMain->AddFrame(fHF1, fLayout);

// Create shutter
   CreateShutter();
   CreateShutterFrames();
//   this->CreateShutter();
//   this->CreateShutterFrames();

// Main settings
   fMain->SetWindowName("MyGui");
   fMain->MapSubwindows();
   fMain->Resize(fMain->GetDefaultSize());
   fMain->MapWindow();
   fMain->Move(20, 20);
}//Constructor

//______________________________________________________________________________
MyFrame::~MyFrame()
{
   if(kCS) cout << "------MyFrame::~MyFrame------" << endl;

   DeleteMenuBar();
   DeleteShutterFrames();
   DeleteShutter();
//   this->DeleteMenuBar();
//   this->DeleteShutterFrames();
//   this->DeleteShutter();

   delete fHF1; 
   delete fMain;

   delete fLayout;

   fTrash->Delete();
   delete fTrash;
}//Destructor

//______________________________________________________________________________
void MyFrame::CreateMenuBar()
{
   if(kCS) cout << "------MyFrame::CreateMenuBar------" << endl;

// File menu
   fMenuFile = new TGPopupMenu(gClient->GetRoot());
   fMenuFile->AddEntry("&New...",  M_FILE_NEW);

// Create menubar layout hints
   fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1);
   fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
   fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);

// Add menus to MenuBar
   fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame);
   fMenuBar->AddPopup("&File",        fMenuFile, fMenuBarItemLayout);

   fMain->AddFrame(fMenuBar, fMenuBarLayout);

// Line to separate menubar
   fLineH1 = new TGHorizontal3DLine(fMain);
   fLineLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX);
   fMain->AddFrame(fLineH1, fLineLayout);
   fLineH1->DrawBorder();
}//CreateMenuBar

//______________________________________________________________________________
void MyFrame::DeleteMenuBar()
{
   if(kCS) cout << "------MyFrame::DeleteMenuBar------" << endl;

   delete fLineH1; 
   delete fMenuBar;
   delete fMenuFile; 

   delete fMenuBarLayout;
   delete fMenuBarItemLayout;
   delete fMenuBarHelpLayout;
   delete fLineLayout;
}//DeleteMenuBar

//______________________________________________________________________________
void MyFrame::CreateShutter()
{
   if(kCS) cout << "------MyFrame::CreateShutter------" << endl;

   fDefaultPic = gClient->GetPicture("folder_s.xpm");
   fShutter = new TGShutter(fHF1, kSunkenFrame | kFixedWidth | kDoubleBorder);

   AddShutterItem(kShutterName[0], 5001, kItems1);
   AddShutterItem(kShutterName[1], 5002, kItems2);
//   this->AddShutterItem(kShutterName[0], S_SHUT1, kItems1);
//   this->AddShutterItem(kShutterName[1], S_SHUT2, kItems2);

   TGLayoutHints *hint = 0;
   hint = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY);
   fTrash->Add(hint);
   fHF1->AddFrame(fShutter, hint);
   fShutter->Resize(100, 400);
}//CreateShutter

//______________________________________________________________________________
void MyFrame::DeleteShutter()
{
   if(kCS) cout << "------MyFrame::DeleteShutter------" << endl;

   delete fShutter;
}//DeleteShutter

//______________________________________________________________________________
void MyFrame::CreateShutterFrames()
{
   if(kCS) cout << "------MyFrame::CreateShutterFrames------" << endl;

//   fSubFrame = new SubFrame(fHF1, this, 0, 0);
}//CreateShutterFrames

//______________________________________________________________________________
void MyFrame::DeleteShutterFrames()
{
   if(kCS) cout << "------MyFrame::DeleteShutterFrames------" << endl;

   delete fSubFrame;
}//DeleteShutterFrames

//______________________________________________________________________________
//void MyFrame::AddShutterItem(const char *name, Int_t id, ShutterData_t *data)
void MyFrame::AddShutterItem(const char *name, Int_t id, ShutterData_t data[])
{
   if(kCS) cout << "------MyFrame::AddShutterItem------" << endl;

   TGShutterItem    *item;
   TGCompositeFrame *container;
   TGButton         *button;
   const TGPicture  *buttonpic;
   TGLayoutHints    *hint;

   hint = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 0);
   fTrash->Add(hint);

   item = new TGShutterItem(fShutter, new TGHotString(name), id);
   fTrash->Add(item);
   container = (TGCompositeFrame*)item->GetContainer();

   for (Int_t i=0; data[i].sPixmap_name != 0; i++) {
      buttonpic = gClient->GetPicture(data[i].sPixmap_name);
      if (!buttonpic) {
         printf("Shutter: missing pixmap \"%s\", using default",
                data[i].sPixmap_name);
         buttonpic = fDefaultPic;
      }//if

      button = new TGPictureButton(container, buttonpic, data[i].sId);
      fTrash->Add(button);
      button->Connect("Clicked()", "MyFrame", this, "DoShutter()");
      button->SetToolTipText(data[i].sTip_text);
      data[i].sButton = button;
      container->AddFrame(button, hint);
   }//for_i

   fShutter->AddItem(item);
}//AddShutterItem

//______________________________________________________________________________
void MyFrame::DoCloseWindow()
{
   if(kCS) cout << "------MyFrame::DoCloseWindow------" << endl;

//   delete this;  //does not exit root
   gApplication->Terminate(0);  //exit root, needed for standalone App
}//DoCloseWindow

//______________________________________________________________________________
void MyFrame::DoShutter(Int_t id)
{
   if(kCS) cout << "------MyFrame::DoShutter------" << endl;

}//DoShutter


//______________________________________________________________________________
//______________________________________________________________________________
SubFrame::SubFrame(TGCompositeFrame *parent, MyFrame *main, UInt_t w, UInt_t h)
{
   if(kCS) cout << "------SubFrame::SubFrame------" << endl;

   fMyFrame = main;
   fTrash = new TList();

// Subframe for frame containing different shutter frames
   TGLayoutHints *hint = 0;
   hint = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
   fTrash->Add(hint);
   fShutterFrame = new TGCompositeFrame(parent, w, h);
   parent->AddFrame(fShutterFrame, hint);

//THIS DOES WORK!!
   fFrameA = new TGCompositeFrame(fShutterFrame,0,0, kHorizontalFrame);
   fShutterFrame->AddFrame(fFrameA, hint);
   fFG1 = new TGGroupFrame(fFrameA, "Group frame for A", kVerticalFrame);
   fFrameA->AddFrame(fFG1, hint);

// Create shutter subframes
//   this->Test(1);
//THIS DOES NOT WORK!!
//   this->CreateFrameA();
//   this->Test(2);

// Show first frame
   fShutterFrame->ShowFrame(fFrameA);
}//Constructor

//______________________________________________________________________________
SubFrame::~SubFrame()
{
   if(kCS) cout << "------SubFrame::~SubFrame------" << endl;

   DeleteFrameA();
//   this->DeleteFrameA();

   fTrash->Delete();
   delete fTrash;

   fMyFrame = 0;
}//Destructor

//______________________________________________________________________________
void SubFrame::HandleShutter(Int_t id)
{
   if(kCS) cout << "------SubFrame::HandleShutter------" << endl;

}//HandleShutter

//______________________________________________________________________________
void SubFrame::CreateFrameA()
{
   if(kCS) cout << "------SubFrame::CreateFrameA------" << endl;

   TGLayoutHints *hint1 = 0;
   hint1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
   fTrash->Add(hint1);

   fFrameA = new TGCompositeFrame(fShutterFrame,0,0, kHorizontalFrame);
   fShutterFrame->AddFrame(fFrameA, hint1);
   fFG1 = new TGGroupFrame(fFrameA, "Group frame for A", kVerticalFrame);
   fFrameA->AddFrame(fFG1, hint1);

   fShutterFrame->HideFrame(fFrameA);
}//CreateFrameA

//______________________________________________________________________________
void SubFrame::DeleteFrameA()
{
   if(kCS) cout << "------SubFrame::DeleteFrameA------" << endl;

   delete fFG1; delete fFrameA;
}//DeleteFrameA


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// Main program                                                         //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

TROOT root("MyApp", "GUI Application");

int main(int argc, char **argv)
{
   TApplication theApp("App", &argc, argv);

   if (gROOT->IsBatch()) {
      fprintf(stderr, "%s: Cannot run in batch mode\n", argv[0]);
      return 1;
   }

   new MyFrame(gClient->GetRoot(), 400, 220);
//   MyFrame *myApp = new MyFrame(gClient->GetRoot(), 400, 220);

   theApp.Run();

//   delete myApp;
   return 0;
}//main


#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class MyFrame+;
#pragma link C++ class SubFrame+;

#endif


#---------------------------------------------
# Makefile for MyGui.
# shell: gmake -f Makefile4MyApp

#ARCH          = linuxppcegcs
ARCH          = macosx

CXX           =
ObjSuf        = o
SrcSuf        = cxx
ExeSuf        =
DllSuf        = so
OutPutOpt     = -o

LPATH         = .
MYLIB    = -L$(LPATH)
#MYLIB    = -L$(LPATH) -lMyClassB -lMyClassA

ROOTCFLAGS   := $(shell root-config --cflags)
ROOTLIBS     := $(shell root-config --libs)
ROOTGLIBS    := $(shell root-config --glibs)


ifeq ($(ARCH),linuxegcs)
# Linux with egcs (>= RedHat 5.2)
CXX           = g++
CXXFLAGS      = -O -Wall -fPIC
LD            = g++
LDFLAGS       = -O
SOFLAGS       = -shared
endif

ifeq ($(ARCH),linuxppcegcs)
# MkLinux with egcs/glibc
CXX           = g++
CXXFLAGS      = -O -Wall -fPIC
LD            = g++
LDFLAGS       = -O
SOFLAGS       = -shared 
endif

ifeq ($(ARCH),macosx)
# MacOS X with cc (GNU cc 2.95.2)
CXX           = c++
CXXFLAGS      = -O -pipe -Wall
LD            = c++
LDFLAGS       = -O -Xlinker -bind_at_load -flat_namespace
# The SOFLAGS will be used to create the .dylib; the .so will
# be created separately
DllSuf        = dylib
SOFLAGS       = -dynamiclib -flat_namespace -undefined suppress
endif

CXXFLAGS     += $(ROOTCFLAGS)
LIBS          = $(ROOTLIBS) $(SYSLIBS)
GLIBS         = $(ROOTGLIBS) $(SYSLIBS)

#------------------------------------------------------------------------------

GUIO      = MyGui.$(ObjSuf) MyGuiDict.$(ObjSuf)
GUIS      = MyGui.$(SrcSuf) MyGuiDict.$(SrcSuf)
GUI       = MyApp$(ExeSuf)

OBJS          = $(GUIO)

PROGRAMS      = $(GUI)

#------------------------------------------------------------------------------

.SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf)

all:            $(PROGRAMS)

$(GUI):     $(GUIO)
#	$(LD) $(LDFLAGS) $(OutPutOpt) $(GUI) $(GUIO) $(GLIBS)
	$(LD) $(LDFLAGS) $(OutPutOpt) $(GUI) $(GUIO) $(MYLIB) $(GLIBS)
	@echo "$@ done"

clean:
	@rm -f $(OBJS) core

distclean:      clean
	@rm -f $(PROGRAMS) $(GUIO) *Dict.* *.def *.exp \
		*.root *.ps *.so .def so_locations
#  @rm -rf cxx_repository

.SUFFIXES: .$(SrcSuf)

###

MyGui.$(ObjSuf): MyGui.h
MyGuiDict.$(SrcSuf): MyGui.h MyGuiLinkDef.h
	@echo "Generating dictionary $@..."
	@rootcint -f $@ -c $^

.$(SrcSuf).$(ObjSuf):
	$(CXX) $(CXXFLAGS) -c $<



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:09 MET