Set own icon in TBrowser

Hello,
I would like to set my own icon in TBrowser. In ROOT documentation I found that I should create method GetIconName for my class but it seem to not work:

  1. if I set full path to my icon (e.g. /opt/myicon.xpm) default ROOT icon is shown (look like white piece of paper)
  2. if I set “short path” to icon that exist in ROOT (e.g. leaf_s.xpm) then icon is shown but don’t look exactly like picture that I set (looks like white piece of paper with something)
    Is there any way that allows quickly set icon for my class without changes in ROOT files?

Hi,

Try to add your class in $(ROOTSYS)/etc/root.mimes, as for example:

[root/myclass] pattern = TMyClass icon = myicon_s.xpm myicon_t.xpm action = ->Browse()
Cheers, Bertrand.

Hello,
So if I understood you well its impossible to add my own icon without overwriting ROOT files or ~/root.mimetypes?
Edit:
I found solution by adding to mimetype list during calling GetIconName. However I don’t know why it working only for some object of MyClass instead of all of them. If MyClass is inside of MyClass then icon is set properly, if MyClass is stored directly in ROOT file or TDirectory then my icon is not used. Any Ideas what can be reason? Setting “->Browse” action in MimeTypes?

Hi,

I’m note sure to really understand what you mean by “MyClass is inside of MyClass” you mean your class MyClass has a class member of type MyClass? And then? Could you give a concrete example (e.g. a running macro and a ROOT file)?

[quote=“dwielane”]Setting “->Browse” action in MimeTypes?[/quote]No, this is the action to be executed when the user double-click on the icon.

Cheers, Bertrand.

Yes if MyClass is inside of MyClass then icon is present. Example that reproduce my problem is in archive.
Maybe the reason is that icon is set when I click on MyClass.
Edit:
I noticed that using icons by some methods in class its impossible because TBrowser don’t call them during opening file and clicking inside object, so only solution is modifying root.mimes or creating own ~/.root.mimes.
temp.zip (900 Bytes)

Hi,

OK, I understand. If you execute this:

gClient->GetMimeTypeList()->AddType("root/myclass", "MyClass", "/home/wielanek/Pulpit/icons/params_int.xpm", "/home/wielanek/Pulpit/icons/params_int.xpm", "->Browse()");
Before loading the file, it should work. The icon is missing because when opening the file, only the key is read, and the mime type is not known at that time. Then, when reading the object itself, the GetIconName() method is called, adding the mime type to the list, it’s why the icon is displayed for the member. So if you want the icon being displayed when reading the key, you must register its mime beforehand.
(just try to open the file, browse your fObj member, close the file and re-open it again, you will see the icon)

Cheers, Bertrand.