Search code examples
pythonpython-2.7xbmc

python error: the parameter "pControls" must be either a Tuple or a List


I need some help as I have got a problem with my code.

I'm trying to get the control with each id to find the controls I'm looking for then remove the controls.

When I try this:

def clearEPG(self):
    program_button = [elem.control for elem in self.program_buttons]

    program_id = list()
    position_X = list()
    position_Y = list()
    for elem in program_button:
        program_id.append(elem.getId())
        position_X.append(elem.getX())
        position_Y.append(elem.getY())
    program_id = map(str, program_id)
    pos_X = map(str, position_X)
    pos_Y = map(str, position_Y)

    try:
        for pos_X, pos_Y, prog_id in zip(pos_X, pos_Y, program_id):
            if int(pos_Y) == 315:
               #print type(prog_id)
               program_button = self.getControl(int(prog_id))
               #print type(program_id)
               self.removeControls(program_button)
    except RuntimeError:
        for elem in self.program_buttons:
            print program_id

            try:
                pass
                #self.removeControl(elem.control)
            except RuntimeError:
                pass

It show the error: TypeError: the parameter "pControls" must be either a Tuple or a List.

The error is highlight on this line:

self.removeControls(program_button)

Here is the list for prog_id output:

NOTICE: 3002
NOTICE: 3003
NOTICE: 3004
NOTICE: 3005

And here is the type for prog_id:

NOTICE: <type 'str'>
NOTICE: <type 'str'>
NOTICE: <type 'str'>
NOTICE: <type 'str'>

Can you please help me with what I need to do to fix the problem?


Solution

  • You should use removeControl if you only intend to remove a single control.

    self.removeControl(program_button)
    

    You would use removeControls to remove a group of controls, hence why the function expects a list or tuple.

    Edit

    One thing I find strange is that at the start of this code you do assign a list to program_button (bad name should probably be program_buttons?)

    program_button = [elem.control for elem in self.program_buttons]
    

    but later you overwrite it with a singular value

    program_button = self.getControl(int(prog_id))
    

    Which would cause the issue you see.