How to refresh and expand TGListTree?

Dear Rooters

To explain my problems I am attaching macro “guiSelectFile.C”:

  • You can create a new root file with trees using menu File->New.
  • You can browse the trees in a root file in two ways:
    a, Press the “Browse” button in Tab Select and open a root file.
    b, Expand TGListTree and click on a root file. If a root file
    contains directories, double-click on the root file.

Here are my questions:
1, If TGListTree is expanded and I create a new root file, the
newly created file is not displayed in TGListTree.
How can I implement the possibility to refresh TGListTree?

2, When I press the “Browse” button to select a root file, I want
TGListTree to be expanded automatically to show the selected file.
How can I implement that TGListTree is expanded automatically and
the correct root file highlighted?

Thank you in advance for your help.
Best regards
Christian
guiSelectFile.C (20.8 KB)

Hi Christian,

[quote]1, If TGListTree is expanded and I create a new root file, the
newly created file is not displayed in TGListTree.
How can I implement the possibility to refresh TGListTree?[/quote]
The next lines of code could help if you include them in the method XFrame::DoNewFile():

[code]//-------------------
TGListTreeItem *pitem, *item;
pitem = fListTree->GetSelected()->GetParent();
item = fListTree->AddItem(pitem,gSystem->BaseName(fi.fFilename), fRootIcon, fRootIcon);
fListTree->AdjustPosition(item);
gClient->NeedRedraw(fListTree);
fMain->Layout();

fListTree->ClearHighlighted();
if (NewFile(fname) == 0) {
fTxtO->SetText(fname);
DisplayTrees(fname);
}//if
fListTree->HighlightItem(item);
}//DoNewFile
[/code]

[quote]2, When I press the “Browse” button to select a root file, I want
TGListTree to be expanded automatically to show the selected file.
How can I implement that TGListTree is expanded automatically and
the correct root file highlighted? [/quote]
The next lines of code could help:

fListTree->ClearHighlighted(); TGListTreeItem *item = fListTree->FindFindChild/SiblingByName(...); fListTree->HighlightItem(item);
But you need to write additional code for finding the TGListTreeItem according to the selected file name shown in the fTxtO.

Cheers, Ilka

Dear Ilka

Sorrowly, I realized that I cannot solve my first problem w/o solving the second problem first.
However, I have the problem that I cannot simulate double-clicking with the mouse on fListTree.
The following code does not work:

   fListTree->HighlightItem(fListLevel);
   fListTree->DoubleClicked(fListLevel, kButton1);
//   DoTreeDoubleClicked(fListLevel, kButton1);
   gClient->NeedRedraw(fListTree);
   fMain->Layout();
   fListTree->HighlightItem(fListLevel);

Do you know how to simulate double-clicking in order to expand fListTree?

Thank you
Christian

Hi Christian,

Use :

fListTree->HighlightItem(fListLevel); fListTree->OpenItem(fListLevel); gClient->NeedRedraw(fListTree);
Cheers,
Bertrand.

Dear Ilka, dear Bertrand

Thank you for your helpful suggestions. Enclosed I am attaching the final
macro “guiSelectFile.C” where I have implemented automatic expansion of
TGListTree. There is only one minor problem left: Sometimes the new root
file name is displayed twice in the selected directory, especially when
compiled with ACLiC?

Please allow me to make the following suggestions:
1, Maybe it is possible to add method ExpandPath() to TGListTree. I have
already added the code in my macro, see:
TGListTreeItem *TGListTree::ExpandPath(const char *path)
Sorrowly, I could not test it, however since it is adapted from method
TGListTreeItem *TGListTree::FindItemByPathname(const char *path)
anyhow, I suppose that it will work.

2, There are a lot of useful macros in the “tutorials” directory. Sorrowly,
there is only one pretty complex gui example. Let me suggest to add a new
directory “guitutorials” and move guitest.C to this directory. Maybe, it
is possible to add more gui macros to this directory, from simple ones to
more complex ones. If you want you could add my macro guiSelectFile.C to
this directory. I am sure other root users have also some simple gui macros,
which they may be willing to share.

Best regards
Christian
guiSelectFile.C (26.4 KB)

Hi Christian,

Thank you for your proposal. The same idea was discussed already and it will take place with some planned changed of the tutorials directory that needs to be structured for easy use. I agree that we need more examples of GUIs, including the simple ones in parallel with the guitest. Your contribution is very welcome.

We will test your code tomorrow and will answer your questions.

Best regards, Ilka

Hi Christian,

Using the attached macro I do not see the new file name if I do:

  • 2-click on an existing .root file to display the tree (the File field shows the name and the tree is displayed);
  • select File menu / New ==> Open dialog appears ==> write a new file name as aa.root ==> click on Open buton

After these steps the file dialog closes, the File field shows the entered new file name (aa.root), but the list tree is not updated. Here is the printouts of your macro:
------XFrame::DoMenu------
------XFrame::DoNewFile------
------XFrame::NewFile------
------XFrame::DisplayTrees------

What steps should I follow to see the list tree updated with the new file name? Or to reproduce the case when it appears twice?

Thank you, Ilka

Dear Ilka

Thank you for testing my macro. Meanwhile I have found that the root file
appears twice due to a mistake on line 545, which should be replaced by:
fitem = fListTree->FindChildByName(ditem, gSystem->BaseName(filename));
I have now replaced the corresponding code in DoNewFile() and DoSelectOpenFile()
by method ExpandPath2File(), see the enclosed macro.
Selecting File->New opens a dialogbox where I type “aaa”, which creates a new
file “aaa.root” in my home directory and expands TGListTree to show the file.
The new file is displayed at the bottom of the expanded directory.
(BTW, it takes some time until the file is created and the tree expanded.)

I have tested different combinations of opening an old file with “Browse”
button or by 2-clicking TGListBox, and creating a new file. At the moment
everything seems to work, at least on my Mac.

Best regards
Christian
guiSelectFile.C (26.6 KB)

Hi Christian,

The last macro works as expected. The only problem (seen on linux) is when a new file is added and the File menu/ Exit is used. This causes SegV.

Best regards, Ilka

Dear Ilka

Good to hear that the macro works as expected. Regarding File->Exit, I have
tested it again with CINT and ACLiC, at least on the Mac the macro closes
w/o problem. (However, in other cases, I had often this problem, too. It
appeared when a created object was not deleted.)

Best regards
Christian