Hi guys,

I have added the list of buttons for the channels and programs in the xbmc skin. I have one yellow box on the channel and program box for both buttons. I want to know how I can move the yellow box to go to the next program when I press on the left and right arrow buttons of the keyboard and how i can go to the next channel when I press on the up and down arrow buttons of the keyboard.

Here is the screenshot:

http://oi62.tinypic.com/30ag8k8.jpg

Here is the code:

def Channels(self):
    for row in programs:
        program = row[1].encode('ascii'), str(row[2]), str(row[3])
        title = row[1].encode('ascii')
        program_start_date = str(row[2])
        program_end_date = str(row[3])                       

        #convert the date formats into minutes
        minutes_start = self.parseDateTimeToMinutesSinceEpoch(program_start_date)
        minutes_end = self.parseDateTimeToMinutesSinceEpoch(program_end_date)
        minutes_length = minutes_end - minutes_start

        program_length = minutes_length
        program_notification = program
        programs_top = 315
        program_height = 34.5
        program_gap = 2.5
        position_start = start_pos
        position_top = programs_top + channel_index * (program_height + program_gap)


        if 10 <= program_length < 60:
            program_width = 342.5
        elif 60 <= program_length < 90:
            program_width = 690
        elif 90 <= program_length < 105:
            program_width = 1050
        elif 105 <= program_length < 120:
            program_width = 1400
        elif 120 <= program_length < 150:
            program_width = 1750
        elif 150 <= program_length < 180:
            program_width = 2100
        elif 180 <= program_length < 210:
            program_width = 2450
        elif 210 <= program_length < 240:
            program_width = 2800
        elif 240 <= program_length < 270:
            program_width = 3150
        elif 270 <= program_length < 300:
            program_width = 3500
        elif 300 <= program_length < 330:
            program_width = 3850
        elif 330 <= program_length < 360:
            program_width = 4200
        elif 360 <= program_length < 390:
            program_width = 3250
        elif 390 <= program_length < 420:
            program_width = 4550
        elif 420 <= program_length < 450:
            program_width = 4900
        elif 450 <= program_length < 480:
            program_width = 5250

        start_pos += program_width + 2 * program_gap

        if program_width > 1:
            if yellow_flag:
                if program_notification:
                    button_nofocus = 'changelang_yellow.png'
                    button_focus = 'channels_bar1.png'
                else:
                    button_nofocus = 'changelang_yellow.png'
                    button_focus = 'channels_bar1.png'
                    yellow_flag = False
                    text_color = '0xFF000000'

            else:
                if program_notification:
                    button_nofocus = 'channels_bar1.png'
                    button_focus = 'channels_yellow.png'
                else:
                    button_nofocus = 'channels_bar1.png'
                    button_focus = 'channels_yellow.png'
                text_color = '0xFFFFFFFF'

                if program_width < 1:
                    program_title = ''
                else:
                    program_title = '[B]' + title + '[/B]'


                    program_controls = xbmcgui.ControlButton(
                            position_start, 
                            position_top, 
                            program_width, 
                            program_height, 
                            program_title,
                            textColor = text_color,
                            focusTexture = button_focus, 
                            noFocusTexture = button_nofocus
                    )
                    self.addControl(program_controls)


def onAction(self, action):
    if action == ACTION_MOVE_LEFT:



    if action == ACTION_MOVE_RIGHT:



    if action == ACTION_MOVE_UP:



    if action == ACTION_MOVE_DOWN:

Do you know how I can move the yellow box to go to the next program when I press on the left and right arrow buttons of the keyboard and how i can go to the next channel when I press on the up and down arrow buttons of the keyboard??

does anyone know how?

does anyone know how?

Are we supposed to know what you are talking about?

I assume that the OP is referring to XMBC Media Center, but I don't know enough about it myself to make sense out of the question, either. I would suggest that the OP seek help on the XMBC forums directly, as there presumably would be people familiar with the program in question.

I will recommend one other thing, as a general principle in Python programming. Rather than having the extended if-elif/else statement you have from lines 22-53, it would be better structured and more Pythonic to make a lookup table consisting of a range and a value. A simple representation might be a dictionary where the key is a tuple pairing the startpoint and endpoint of the length range, and the the second value is the width. You would then have a function to extract the values from the dictionary as needed. Something like this should work:

def get_program_width(program_length):
    width_map = {(10, 60): 342.5, (60, 90): 690, (90, 105) : 1050, 
                 (105, 120): 1400, (120, 150): 1750, (150, 180): 2100, 
                 (180, 210): 2450, (210, 240): 2800, (240, 270): 3150, 
                 (270, 300): 3500, (300, 330): 3850, (330, 360): 4200, 
                 (360, 390): 3250, (390, 420): 4550, (420, 450): 4900, 
                 (450, 480): 5250}

    keylist = width_map.keys()

    for key in keylist:
        if program_length in range(key[0] + 1, key[1] + 1):
            return width_map[key]
    return 0
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.