Getting selection in TGListView

Hello,

I am trying to get the currently selected item in TGListView. I found only a TGLVContainer::GetSelectedItems() method which seems to does it. Unfortunately the returned list is just a list string of the names of the items, so in case when the names (first column) is not unique, it is useless. Is there any way to get the TGLVEntry object of the currently selected item?

Hi,

See TGContainer::GetNextSelected(void** current)

Cheers, Bertrand.

What do I provide as the current? 0?

Yes, if you want the first TGLVEntry (or if the multiple selection is not enabled)

Cheers, Bertrand.

A little bit different question. How to properly activate an entry?

The entry seems to be activated when I use TGLVEntry::Activate , IsActive() returns true, the entry is selected in the list. However when I, after this Activate(), press the button on the list, which invokes a KeyPressed event, the entry that I am getting from the event is a null pointer. If I click the entry first, everything is OK. So it seems clicking makes a “deeper” activation than Activate(). How do I make similar activation as when clicking?

In general, I am trying to be able to delete items from the list with keyboard. Currently I am unable to delete the second item after I deleted the first, because the second item is not fully “activated”.

Did you try TGLVContainer:ActivateItem(TGFrameElement* el)?

Yes. I’m trying it in PyROOT and it crashes.

Could you post a running macro reproducing the problem?

That is always a nasty question, when one has to produce a long macro building gui, events, filling the list, etc. But I’ll try :wink:

Somehow it does not crash in the attached macro, but just reports that there is no such thing as ActivateItem() for the container (true, because it is protected).

Just click on any of the entries and press delete.
etos_dispatcher.C (898 Bytes)
triggerwindow.py (4.86 KB)

Hi,

Could you try with this modified script?
triggerwindow.py (4.65 KB)(and sorry for the delay, I had to fix ROOT & Python on Windows first…)

Cheers, Bertrand.

Thanks, works, but… I understand that:

self.eventlist_container.FindFrameByName(self.elements[i].GetItemName().GetString())

means that the container finds the item by its name. The problem is, that it is not just an internal name like in case of a histogram, but a string that appears in the first column of the list. Therefore it is often non-unique which would render this method not working. And such is my original case (I want to have pixel x coordinates in first column, so it will be repeated even for different pixels).

OK, I see… I don’t know why ActivateItem() is protected, but here is a possible (and dirty) workaround. Replace the original: self.elements.remove(self.elements[i]) self.elements[i].Activate(True) print self.elements[i+1].IsActive() self.elements[i].SetCheckedEntry(True) self.eventlist_container.ActivateItem(self.elements[i])by something like: self.elements.remove(self.elements[i]) for num in range(0,i): self.eventlist_container.LineDown(True) self.elements[i].SetCheckedEntry(True)
Cheers, Bertrand.

Works, thanks! However, could you make ActivateItem() public in the patches?

Also some GetSelectedItems() that returns list of actual TGLVEntries (not their GetItemName() results) would be nice. The current method of getting currently selected item was probably not intended to do that (and for sure is not documented). Some kind of GetFirstSelectedItem() returning first selected TGLVEntry or just the selected TGLVEntry in case of single selection would also be very convenient. I guess this is 5 minutes of coding for all those methods…

The following methods have been added in the master and in the v5-34-00-patches branch:

virtual void SelectEntry(TGLVEntry *item) TList *GetSelectedEntries();
Allowing to use it in your python code:

And IMHO there is no need of GetFirstSelectedItem(), GetNextSelected(void** current) is enough (I’ll update the doc)

Cheers, Bertrand.

Thanks!

You’re welcome. And the the documentation of TGContainer::GetNextSelected(void **current) has just been updated

I came back to this issue, trying to use SelectEntry(). It seems it works… to some extend. When I invoke it, specified entry is select, but the previously selected entry is not deselected, even if the multiple selection if off for the containter.

Also, it would be nice to have public DeselectEntry() function, since DeactivateItem is also protected.

In addition, I am not sure if it is a matter of this accidental multiple selection or not, but when selecting another entry, the listview is not scrolled to this entry. Is there a way to scroll it?

Can you post a running macro showing the problem?

Here you are. Select any event >3 and then press right arrow. On right arrow the element “2” is selected, but the previous is not deselected, also list is not scrolling back.
list_select.py (2.2 KB) etos_dispatcher.C (853 Bytes)

(I needed to add the C file, for I don’t know how to init a class using ProcessLine, nor if the dispatcher problem for lists was already fixed in ROOT 6)