Hi guys

I need a bit of your help. I've created the variables that I want to store a list of arrays outside the for loop. I have got a problem with the code that I currently using.

When I try this:

import xbmc
import xbmcgui
import xbmcaddon

class ProgramControls(object):
     def __init__(self, control, program):
         self.control = control
         self.program = program

class MyClass(xbmcgui.WindowXML):

     def __init__(self):
         self.program_buttons = list()
         self.button_focus = 'programs_yellow.png'
         self.button_nofocus = 'channels_bar1.png'

 program_controls = xbmcgui.ControlButton(
        int(position_start), 
        int(position_top), 
        int(program_width), 
        int(program_height), 
        program_title, 
        focusTexture = path + self.button_focus, 
        noFocusTexture = path + self.button_nofocus,
        textColor ='0xFFFFFFFF',
        focusedColor ='0xFF000000'
    )
    self.program_buttons.append(ProgramControls(program_controls, program))
programs_button = [elem.control for elem in self.program_buttons]
program_id = list()
program_width = list()

for elem in programs_button:
    program_id = elem.getId()
print program_id
self.addcontrols(programs_button)

It will give me the error: AttributeError: 'MyClass' object has no attribute 'programs_button'

The error are jumping on this line:

for elem in self.programs_button:

Can you please help me how I can fix this?

Recommended Answers

All 4 Replies

for elem in self.programs_button:

That statement is not in the code you posted.

Try self.program_buttons

There may be indention issues in your code. What is the self at lines 28 and 36 for example? Also avoid to have two different variables program_buttons and programs_button in the same file.

@Gribouillis: In line 28 it is using for the add the list of buttons where I'm stored in the arrays and the addcontrols is the control that I can add the list of buttons. So I have solved the issued by changed from for elem in self.programs_button: to for elem in programs_button:.

Now it works :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.