best way to move items from one list control to another?
#1
Hello,

I need to move items from one list to another.
Like in a select scenario
not selected list >> select list

I get that there is no remove items so I probably have to reload the lists for each select and try to put back the scrolling.

Is there any better way?

I can of course add items but that works kind a strange

Code:
if controlId == self.control_list_id:
            position = self.list.getSelectedPosition()
            
            #get select item
            item = self.list.getSelectedItem()
            
            #self.list.removeItem(position)
            self.list2.addItem(item)

This will add the item, BUT the item is only visible when the same item in list is selected! What is up with that?
Reply
#2
My first thoughts as a workaround quick fix...
Ain't exactly optimal, but...

pastebin code

Code:
""" Proof of concept / Pseudo code (not tested) """

import xbmcgui


class proof_of_concept:

    left_ref  = []
    right_ref = []

    def __init__(self):
        self.left_list  = xbmcgui.ControlList()
        self.right_list = xbmcgui.ControlList()


    # Private methods ...

    def _fill_list(self, list, refs):
        list.reset()
        list.addItems(refs)

    def _add_item(self, list, refs, item):
        refs.append(item)
        list.addItem(item)

    def _remove_item(self, list, refs, index):
        del refs[index]
        self._fill_list(list, refs)

    def _move_selected(self, source_list, source_refs, target_list, target_refs):
        index = source_list.getSelectedPosition()
        item  = source_list.getListItem(index)
        item.select(False)
        self._remove_item(source_list, source_refs, index)
        self._addItem(target_list, target_refs, item)


    # Public methods ...

    def add_to_left(self, list_item):
        self.left_ref.append(list_item)
        self.left_list.addItem(list_item)

    def add_to_right(self, list_item):
        self.right_ref.append(list_item)
        self.right_list.addItem(list_item)

    def move_selected_from_right_to_left(self):
        self._move_selected( self.right_list, self.right_refs,
                             self.left_list, self.left_refs )
Reply

Logout Mark Read Team Forum Stats Members Help
best way to move items from one list control to another?0