Re: GUI portability

From: Fons Rademakers <Fons.Rademakers_at_cern.ch>
Date: Sun, 24 Jul 2005 12:03:36 +0200


Hi Irene,

   you have to use TGLVEntry::GetTitle() to get the name of the object in the file list. This was also wrong in the guitest.C program. See the one line change in your code below:

void TestFileList::OnDoubleClick(TGLVEntry* f, Int_t btn) {

    // handle double click

    if (btn!=kButton1) return;

    TString name(f->GetTitle()); // <---- WAS GetName()

    const char* fname = (const char*)f->GetUserData();

    if (name.EndsWith(".root")) {

        filename =  name ;
        fMainL->SendCloseMessage();

    }
    if (name.EndsWith(".txt")) {
        filename =  name ;
        fMainL->SendCloseMessage();

    }
    else {

        DisplayDirectory(name);
    }
}

Cheers, Fons.

Irene Niessen wrote:
> Dear ROOT Users
>
> I am trying to write a GUI in which I want to select a file. The program
> I have works on a Windows computer, but not with Linux. I have attached
> a test program with the same problem: if I double-click on a file or
> directory, it doesn't respond.
> The program is setup so that it should return at least the filename, but
> I get nothing on double-click, not even an error.
> Does anyone have an idea what the problem could be (and how to solve
> it)? I am working with CERN scientific Linux, Gnome desktop, metacity
> windows manager, and ROOT version 4.02.
>
> Thanks in advance for any help.
>
> Irene Niessen
>
>
> ------------------------------------------------------------------------
>
> /////////////////////////////////////////////////////////////////////
> //
> // test
> //
> // author: I. Niessen
> //
> // Disclaimer:
> //
> /////////////////////////////////////////////////////////////////////
>
> #include <TGClient.h>
> #include <TCanvas.h>
> #include <TGButton.h>
> #include <TGFrame.h>
> #include <RQ_OBJECT.h>
> #include <TGMsgBox.h>
> #include <TGFileDialog.h>
> #include <TRootEmbeddedCanvas.h>
> #include <fstream.h>
> #include <iostream.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> class MyMainFrame {
>
> RQ_OBJECT("MyMainFrame")
>
> private:
> TGMainFrame *fMain;
> TGListView *lv ;
> TString filename;
> Bool_t fClose;
>
> public:
> MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h);
> virtual ~MyMainFrame();
> void readfiles();
> };
>
> class TestFileList {
>
> RQ_OBJECT("TestFileList")
>
> protected:
> TGMainFrame *fMainL;
> TGFileContainer *fContents;
>
> virtual void DisplayDirectory(const TString &fname);
>
> public:
> TString filename;
> TestFileList(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
> virtual ~TestFileList();
> // slots
> virtual void OnDoubleClick(TGLVEntry*,Int_t);
> virtual void DoMenu(Int_t);
> void DoClose();
> char ReturnFileName();
> };
>
> MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h)
> {
>
> // Crate Main frame
>
> fMain = new TGMainFrame(p,w,h);
> fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
>
> fL21 = new TGLayoutHints(kLHintsTop , 10, 10, 10, 10);
>
> TGTextButton *open_file = new TGTextButton(fMain,"&Open file");
> fMain->AddFrame(open_file, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,10,10,3,4));
> open_file->Connect("Clicked()","MyMainFrame",this,"readfiles()");
>
> TGTextButton *exit = new TGTextButton(fMain,"&Exit","gApplication->Terminate(0)");
> fMain->AddFrame(exit, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,10,10,3,4));
>
> fMain->SetWindowName("Main window");
>
> fMain->MapSubwindows();
>
> fMain->Resize(300,200);
>
> fMain->MapWindow();
>
> }
>
>
> void MyMainFrame::readfiles()
> {
> TestFileList *rf = new TestFileList(gClient->GetRoot(), fMain, 400, 200);
> cout << "Filename -->>>> " << rf->ReturnFileName() << endl;
> filename = rf->ReturnFileName();
> }
>
> MyMainFrame::~MyMainFrame()
> {
> fMain->Cleanup();
> delete fMain;
> }
>
> void test()
> {
> MyMainFrame *mf = new MyMainFrame(gClient->GetRoot(),200,200);
> }
>
>
> TestFileList::TestFileList(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h)
> {
> // Create transient frame containing a filelist widget.
>
> TGLayoutHints *lo;
>
> fMainL = new TGTransientFrame(p, main, w, h);
>
> TGMenuBar* mb = new TGMenuBar(fMainL);
> lo = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1);
> fMainL->AddFrame(mb, lo);
>
> TGPopupMenu *menu = mb->AddPopup("&View");
> menu->AddEntry("&Close", 10);
> menu->Connect("Activated(Int_t)","TestFileList",this,"DoMenu(Int_t)");
>
> TGListView* lv = new TGListView(fMainL, w, h);
> lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
> fMainL->AddFrame(lv,lo);
>
> Pixel_t white;
> gClient->GetColorByName("white",white);
> fContents = new TGFileContainer(lv,kSunkenFrame,white);
>
> fContents->Connect("DoubleClicked(TGFrame*,Int_t)","TestFileList",this,"OnDoubleClick(TGLVEntry*,Int_t)");
>
> fMainL->SetWindowName("File List");
> fMainL->MapSubwindows();
> fMainL->MapWindow();
> fContents->SetDefaultHeaders();
> fContents->DisplayDirectory();
> fContents->AddFile(".."); // up level directory
> fContents->Resize();
> fMainL->Resize();
> }
>
> TestFileList::~TestFileList()
> {
> // dtor.
>
> delete fContents;
> fMainL->Cleanup();
> delete fMainL;
> }
>
> void TestFileList::DoMenu(Int_t mode)
> {
> // switch view mode
> if (mode<10) {
> fContents->SetViewMode((EListViewMode)mode);
> } else {
> delete this;
> }
> }
>
> void TestFileList::DisplayDirectory(const TString &fname)
> {
> // display content of directory
>
> fContents->SetDefaultHeaders();
> gSystem->ChangeDirectory(fname);
> fContents->ChangeDirectory(fname);
> fContents->DisplayDirectory();
> fContents->AddFile(".."); // up level directory
> fMainL->Resize();
> }
>
>
> void TestFileList::OnDoubleClick(TGLVEntry* f, Int_t btn)
> {
> // handle double click
>
> if (btn!=kButton1) return;
>
> TString name(f->GetName());
>
> const char* fname = (const char*)f->GetUserData();
>
> if (name.EndsWith(".root")) {
> filename = name ;
> fMainL->SendCloseMessage();
> }
> if (name.EndsWith(".txt")) {
> filename = name ;
> fMainL->SendCloseMessage();
> }
> else {
> DisplayDirectory(name);
> }
> }
>
> TString TestFileList::ReturnFileName()
> {
> return filename ;
> }
>

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers_at_cern.ch              Phone: +41 22 7679248
WWW:    http://www.rademakers.org/fons/      Fax:   +41 22 7679480
Received on Sun Jul 24 2005 - 12:03:32 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:10 MET