I use ROOT 5.6/00 with Windows XP.
I followed the example given in Guitest (ROOTSYS/tutorials/gui/guitest.C) to form my tool bar with two menus File and Help. Under the sub menu File I have Save and Print.
When I click on save, the save window of ROOT opens. what enables me to introduce the name of the file to be saved.
After having clicked on the button save, the window is closed, but the file is not saved.
I beg who can help me to check my code for to see why I can’t save the file on the disc.
This is my code . and in attachement there is the photo of the widget.
[code]#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGWindow.h>
#include <TGLabel.h>
#include <TGNumberEntry.h>
#include <TString.h>
#include “Riostream.h”
enum EMenuIds {
M_FILE_OPEN,
M_FILE_SAVE,
M_FILE_SAVEAS,
M_FILE_PRINT,
M_FILE_PRINTSETUP,
M_FILE_EXIT,
M_FILE_CLOSE,
M_HELP_CONTENTS,
};
const char filetypes1[] = { “All files”, "",
“ROOT files”, “.root",
“ROOT macros”, ".C”,
“Text files”, “*.[tT][xX][tT]”,
0, 0 };
const char filetypes2[] = { “All files”, "",
“ROOT files”, “.root",
“ROOT macros”, ".C”,
“Text files”, “*.[tT][xX][tT]”,
0, 0 };
const char *editortxt1 =“This is the text Editor\n”;
class Editor {
private:
TGTransientFrame *fMain; // main frame of this widget
TGTextEdit *fEdit; // text edit widget
TGTextButton *fOK; // OK button
TGLayoutHints *fL1; // layout of TGTextEdit
TGLayoutHints *fL2; // layout of OK button
public:
Editor(const TGWindow *main, UInt_t w, UInt_t h);
virtual ~Editor();
void LoadFile(const char *file);
void LoadBuffer(const char *buffer);
void AddBuffer(const char *buffer);
TGTextEdit *GetEditor() const { return fEdit; }
void SetTitle();
void Popup();
// slots
void CloseWindow();
void DoOK();
void DoOpen();
void DoSave();
void DoClose();
};
class MyMainFrame : public TGMainFrame {
private:
TGGroupFrame *fGroupFrame515 ;
TGPopupMenu *fMenuFile;
TGPopupMenu * fMenuHelp;
TGMenuBar *fMenuBar;
TRootEmbeddedCanvas *fRootEmbeddedCanvas528;
TCanvas *c123;
TGStatusBar *fStatusBar;
public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MyMainFrame();
ClassDef(MyMainFrame, 0)
};
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
: TGMainFrame(p, w, h)
{
// a popup menu
fMenuFile = new TGPopupMenu(gClient->GetRoot());
fMenuHelp = new TGPopupMenu(gClient->GetRoot());
// adding help menu entries
fMenuHelp->AddEntry("&Editor…",M_HELP_CONTENTS);
// adding file menu entries
fMenuFile->AddEntry("&Open…",M_FILE_OPEN);
fMenuFile->AddEntry("&Save",M_FILE_SAVE);
fMenuFile->AddEntry(“S&ave as…”,M_FILE_SAVEAS);
fMenuFile->AddEntry("&Close", M_FILE_CLOSE);
// adding separator
fMenuFile->AddSeparator();
// next group of menu entries
fMenuFile->AddEntry("&Print",M_FILE_PRINT);
fMenuFile->AddEntry(“P&rint setup…”,M_FILE_PRINTSETUP);
fMenuFile->AddSeparator();
fMenuFile->AddEntry(“E&xit”,M_FILE_EXIT);
// menu message are handled by the class’ HandleMenu() method
fMenuFile->Connect(“Activated(Int_t)”, “MyMainFrame”, this,“HandleMenuFile(Int_t)”);
fMenuHelp->Connect(“Activated(Int_t)”, “MyMainFrame”, this,“HandleMenuHelp(Int_t)”);
// menu bar item layout hints
fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
// menu bar
fMenuBar = new TGMenuBar(this,1,1,kHorizontalFrame);
// adding popup menus
fMenuBar->AddPopup("&File",fMenuFile,fMenuBarItemLayout);
fMenuBar->AddPopup("&Help",fMenuHelp,fMenuBarHelpLayout);
this->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
// “” group frame
fGroupFrame515 = new TGGroupFrame(this,"");
fGroupFrame515->SetLayoutBroken(kTRUE);
// embedded canvas
fRootEmbeddedCanvas528 = new TRootEmbeddedCanvas(0,fGroupFrame515,280,126);
Int_t wfRootEmbeddedCanvas528 = fRootEmbeddedCanvas528->GetCanvasWindowId();
c123 = new TCanvas(“c123”, 10, 10, wfRootEmbeddedCanvas528);
fRootEmbeddedCanvas528->AdoptCanvas(c123);
fGroupFrame515->AddFrame(fRootEmbeddedCanvas528, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
fRootEmbeddedCanvas528->MoveResize(18,18,280,126);
fGroupFrame515->SetLayoutManager(new TGVerticalLayout(fGroupFrame515));
fGroupFrame515->Resize(316,162);
this->AddFrame(fGroupFrame515, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
fGroupFrame515->MoveResize(8,24,316,162);
this->MapSubwindows();
this->Resize(fGroupFrame515->GetDefaultSize());
this->MapWindow();
this->Resize(343,191);
}
void MyMainFrame::HandleMenuHelp(Int_t id)
{
// Handle menuu items.
switch (id) {
case M_HELP_CONTENTS:
{
Editor *ed = new Editor(this, 600, 400);
ed->LoadBuffer(editortxt1);
ed->Popup();
}
break;
}
}
void MyMainFrame::HandleMenuFile(Int_t id)
{
// Handle menu items.
switch (id) {
case M_FILE_OPEN:
{
static TString dir(".");
TGFileInfo fi;
fi.fFileTypes = filetypes1;
fi.fIniDir = StrDup(dir);
//printf("fIniDir = %s\n", fi.fIniDir);
new TGFileDialog(gClient->GetRoot(),this, kFDOpen, &fi);
//printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
dir = fi.fIniDir;
}
break;
case M_FILE_SAVE:
static TString dir(".");
TGFileInfo fi;
fi.fFileTypes = filetypes2;
fi.fIniDir = StrDup(dir);
//printf("fIniDir = %s\n", fi.fIniDir);
new TGFileDialog(gClient->GetRoot(),this, kFDSave, &fi);
printf("Save file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
dir = fi.fIniDir;
//printf("M_FILE_SAVE\n");
break;
case M_FILE_PRINT:
printf("M_FILE_PRINT\n");
printf("Hiding itself, select \"Print Setup...\" to enable again\n");
fMenuFile->HideEntry(M_FILE_PRINT);
break;
case M_FILE_PRINTSETUP:
printf("M_FILE_PRINTSETUP\n");
printf("Enabling \"Print\"\n");
fMenuFile->EnableEntry(M_FILE_PRINT);
break;
case M_FILE_EXIT:
CloseWindow(); // terminate theApp no need to use SendCloseMessage()
break;
default:
break;
}
}
Editor::Editor(const TGWindow *main, UInt_t w, UInt_t h)
{
// Create an editor in a dialog.
fMain = new TGTransientFrame(gClient->GetRoot(), main, w, h);
fMain->Connect(“CloseWindow()”, “Editor”, this, “CloseWindow()”);
fMain->DontCallClose(); // to avoid double deletions.
fMain->SetWindowName(“HELP”);
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
fEdit = new TGTextEdit(fMain, w, h, kSunkenFrame | kDoubleBorder);
fL1 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3);
fMain->AddFrame(fEdit, fL1);
// set selected text colors
Pixel_t pxl;
gClient->GetColorByName("#ccccff", pxl);
fEdit->SetSelectBack(pxl);
fEdit->SetSelectFore(TGFrame::GetBlackPixel());
fOK = new TGTextButton(fMain, " &OK ");
fOK->Connect(“Clicked()”, “Editor”, this, “CloseWindow()”);
fL2 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
fMain->AddFrame(fOK, fL2);
fMain->MapSubwindows();
fMain->Resize();
// editor covers right half of parent window
fMain->CenterOnParent(kTRUE, TGTransientFrame::kRight);
}
Editor::~Editor()
{
// Delete editor dialog.
fMain->DeleteWindow(); // deletes fMain
}
void Editor::Popup()
{
// Show editor.
fMain->MapWindow();
}
void Editor::LoadBuffer(const char *buffer)
{
// Load a text buffer in the editor.
fEdit->LoadBuffer(buffer);
}
void Editor::CloseWindow()
{
// Called when closed via window manager action.
delete this;
}
void Editor::DoOpen()
{
SetTitle();
}
void Editor::DoSave()
{
SetTitle();
}
void Editor::DoClose()
{
// Handle close button.
CloseWindow();
}
void test()
{
new MyMainFrame(0,10,10);
}
[/code]
test.doc (740 KB)