[SOLVED] tv guide button controls issue

Discussion of plugin / script development for XBMC4Xbox
Post Reply
chris0147
Posts: 24
Joined: Thu Jun 19, 2014 4:48 pm

[SOLVED] tv guide button controls issue

Post by chris0147 »

Hi guys

I need your help, I have got a problem with the button controls. I'm using the button controls to add the list of programs in the tv guide, but the buttons will not get separate from the other button controls.

Here is the screenshot.

Image


Here is the code I use:

Code: Select all

#Pull the data from the database
channelList = list()
database_path = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', 'source.db'))

if os.path.exists(database_path):
   #get the channels list
   cur.execute('SELECT channel FROM programs WHERE channel GROUP BY channel')

   for row in cur:
        channels = row[0].encode('ascii')
        channelList.append(channels)

        # set the channels text
        for index in range(0, CHANNELS_PER_PAGE):
             channel = channelList[index]
             channel_index = index

             if channel is not None:
                self.getControl(4110 + index).setLabel(channel)

             #get the programs list
             cur.execute('SELECT channel, title, start_date, stop_date FROM programs WHERE channel=?', [channel])
             programList = list()
             programs = cur.fetchall()

             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])

                  # find nearest half hour
                  viewStartDate = datetime.datetime.now()
                  viewStartDate -= datetime.timedelta(minutes = viewStartDate.minute % 30, seconds = viewStartDate.second)

                  try:
                      start_time = datetime.datetime.strptime(program_start_date, "%Y%m%d%H%M%S")
                      stop_time = datetime.datetime.strptime(program_end_date, "%Y%m%d%H%M%S")
                  except TypeError:
                      start_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(program_start_date, "%Y%m%d%H%M%S")))
                      stop_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(program_end_date, "%Y%m%d%H%M%S")))

                      #print start_time
                      startDelta = start_time - viewStartDate
                      stopDelta = stop_time - viewStartDate
                      program_start = self.secondsToXposition(startDelta.seconds)

                      #program_start is the size or after program
                      #print program_start

                      if startDelta.days < 0:
                          program_start = self.epgView.left
                      #print program_start
                      program_width_size = self.secondsToXposition(stopDelta.seconds) - program_start

                      if program_start + program_width_size > self.epgView.right:
                         program_width_size = self.epgView.right - program_start

                      idx = channel_index
                      program_notification = program

                      #workout the duration times to get the program time
                      program_duration = stop_time - start_time

                      #convert the datetime object between start_date and end_date
                      startDelta = start_time - viewStartDate
                      stopDelta = stop_time - viewStartDate
                      program_width = 0

                      if datetime.timedelta(minutes = 10) <= program_duration <= datetime.timedelta(minutes = 30):
                            program_width = 350

                      elif datetime.timedelta(hours = 1) <= program_duration <= datetime.timedelta(hours = 1.29):
                            program_width = 700

                      elif datetime.timedelta(hours = 1.30) <= program_duration <= datetime.timedelta(hours = 1.45):
                            program_width = 1050

                      elif datetime.timedelta(hours = 1.46) <= program_duration <= datetime.timedelta(hours = 2):
                            program_width = 1400

                      elif datetime.timedelta(hours = 2) <= program_duration <= datetime.timedelta(hours = 2.30):
                            program_width = 1750

                      elif datetime.timedelta(hours = 2.30) <= program_duration <= datetime.timedelta(hours = 3):
                            program_width = 2100

                      elif datetime.timedelta(hours = 3) <= program_duration <= datetime.timedelta(hours = 3.30):
                            program_width = 2450

                      elif datetime.timedelta(hours = 3.30) <= program_duration <= datetime.timedelta(hours = 4):
                            program_width = 2800

                      elif datetime.timedelta(hours = 4) <= program_duration <= datetime.timedelta(hours = 4.30):
                            program_width = 3150

                      elif datetime.timedelta(hours = 4.30) <= program_duration <= datetime.timedelta(hours = 5):
                            program_width = 3500

                      elif datetime.timedelta(hours = 5) <= program_duration <= datetime.timedelta(hours = 5.30):
                            program_width = 3850

                      elif datetime.timedelta(hours = 5.30) <= program_duration <= datetime.timedelta(hours = 6):
                             program_width = 4200

                      elif datetime.timedelta(hours = 6) <= program_duration <= datetime.timedelta(hours = 6.30):
                            program_width = 3250

                      elif datetime.timedelta(hours = 6.30) <= program_duration <= datetime.timedelta(hours = 7):
                            program_width = 4550

                      elif datetime.timedelta(hours = 7) <= program_duration <= datetime.timedelta(hours = 7.30):
                          program_width = 4900

                      elif datetime.timedelta(hours = 7.30) <= program_duration <= datetime.timedelta(hours = 8):
                          program_width = 5250


                      if program_width > 1:
                         if program_notification:
                             button_nofocus = 'channels_bar1.png'
                             button_focus = 'channels_yellow.png'
                         else:
                             button_nofocus = 'channels_bar1.png'
                             button_focus = 'channels_yellow.png'

                         if program_width < 65:
                             program_title = ''
                         else:
                             program_title = title
                             program_start = int(program_width) + 40
                             program_height = 35
                             program_top = 315 + 37.5 * idx

                             if not program_top % 1.0:
                                 program_top = int(program_top)
                             print program_title

                             program_controls = xbmcgui.ControlButton(
                                 program_start, 
                                 program_top, 
                                 program_width, 
                                 program_height, 
                                 program_title, 
                                 focusTexture = button_focus, 
                                 noFocusTexture = button_nofocus
                             )
                         focusFunction = None
                         # add program controls
                         if focusFunction is None:
                             focusFunction = self.findControlAt
                         focusControl = focusFunction(self.focusPoint)
                         self.addControl(program_controls)
                 cur.close()

Here is the title log: http://xbmclogs.com/show.php?id=290053

Here is the program width log: http://xbmclogs.com/show.php?id=290056


Do you know how to make the button controls to make get separate from the other button controls?
User avatar
sahib12
Posts: 285
Joined: Wed Jan 02, 2013 3:13 pm
Location: Liberty City
Has thanked: 8 times
Been thanked: 16 times
Contact:

Re: tv guide button controls issue

Post by sahib12 »

hey, is this an addon? if so whats its name?
Image
chris0147
Posts: 24
Joined: Thu Jun 19, 2014 4:48 pm

Re: tv guide button controls issue

Post by chris0147 »

this is my own addon. why you ask me?
User avatar
byron
Posts: 582
Joined: Wed Jul 04, 2012 9:26 pm
Location: Illinois
Has thanked: 27 times
Been thanked: 96 times

Re: tv guide button controls issue

Post by byron »

From a skinning standpoint, you would maybe have this in a (possibly a couple) grouplist control...and then you could have an </itemgap> of whatever you like. Perhaps that might help?
User avatar
Dom DXecutioner
Posts: 585
Joined: Thu Jul 05, 2012 11:59 pm
Location: California
Has thanked: 249 times
Been thanked: 219 times
Contact:

tv guide button controls issue

Post by Dom DXecutioner »

chris0147 wrote:Hi guys

I need your help, I have got a problem with the button controls. I'm using the button controls to add the list of programs in the tv guide, but the buttons will not get separate from the other button controls.

Do you know how to make the button controls to make get separate from the other button controls?
You need to be more specific when it comes to things like this; however, I'll assume that when you say "the buttons will not get separate from the other button controls," you're referring a gap from left/right and not top/bottom.

Sounds like you need to have an offset variable with the gap's width and then add/subtract from the final width or left position whichever route you decide to take:

Code: Select all

offset = 4
program_width - offset

Code: Select all

offset = 4
program_start + offset
Image
User avatar
cashonly
Posts: 181
Joined: Thu Jul 19, 2012 5:12 pm
Has thanked: 20 times
Been thanked: 32 times

Re: tv guide button controls issue

Post by cashonly »

cand we download this addon?
These pretzels are making me thirsty!
User avatar
sahib12
Posts: 285
Joined: Wed Jan 02, 2013 3:13 pm
Location: Liberty City
Has thanked: 8 times
Been thanked: 16 times
Contact:

Re: tv guide button controls issue

Post by sahib12 »

chris0147 wrote:this is my own addon. why you ask me?
I ask because your addon looks intresting. Were you plannning on sharing this addon? Its cool if you don't want to as you do own it.
Image
chris0147
Posts: 24
Joined: Thu Jun 19, 2014 4:48 pm

Re: tv guide button controls issue

Post by chris0147 »

Dom DXecutioner wrote:
chris0147 wrote:Hi guys

I need your help, I have got a problem with the button controls. I'm using the button controls to add the list of programs in the tv guide, but the buttons will not get separate from the other button controls.

Do you know how to make the button controls to make get separate from the other button controls?
You need to be more specific when it comes to things like this; however, I'll assume that when you say "the buttons will not get separate from the other button controls," you're referring a gap from left/right and not top/bottom.

Sounds like you need to have an offset variable with the gap's width and then add/subtract from the final width or left position whichever route you decide to take:

Code: Select all

offset = 4
program_width - offset

Code: Select all

offset = 4
program_start + offset

Thank you very much for your help. Where do i need to input this code?

Code: Select all

offset = 4
program_width - offset

Code: Select all

offset = 4
program_start + offset

how i can make the gaps for widths and then add/subtract from the final width on the right position?
chris0147
Posts: 24
Joined: Thu Jun 19, 2014 4:48 pm

Re: tv guide button controls issue

Post by chris0147 »

sahib12 wrote:
chris0147 wrote:this is my own addon. why you ask me?
I ask because your addon looks intresting. Were you plannning on sharing this addon? Its cool if you don't want to as you do own it.
Thank you. i might release it if alot of people really want this as if they don't have this one. ;)


cashonly wrote:cand we download this addon?

this is my own addon i have made.
User avatar
Dom DXecutioner
Posts: 585
Joined: Thu Jul 05, 2012 11:59 pm
Location: California
Has thanked: 249 times
Been thanked: 219 times
Contact:

tv guide button controls issue

Post by Dom DXecutioner »

@chris0147,

I haven't really looked at your code but if you have written it yourself, you shouldn't have a problem figuring it out...

If you're gonna use the "offset" or gap, if you prefer, variable, then that goes at the top near the imports... You then perform the calculations before adding the button control for the "program".

I'm not gonna look any further than this until you at least try it on your own; the code you have pasted, assuming is yours, tells me that you shouldn't have much problems figuring this out.
Image
chris0147
Posts: 24
Joined: Thu Jun 19, 2014 4:48 pm

Re: tv guide button controls issue

Post by chris0147 »

Dom DXecutioner wrote:@chris0147,

I haven't really looked at your code but if you have written it yourself, you shouldn't have a problem figuring it out...

If you're gonna use the "offset" or gap, if you prefer, variable, then that goes at the top near the imports... You then perform the calculations before adding the button control for the "program".

I'm not gonna look any further than this until you at least try it on your own; the code you have pasted, assuming is yours, tells me that you shouldn't have much problems figuring this out.

Well I still have a problem with the pixel, I'm adding the button controls in the pixel area, the area you know where the tv guide programs will display. When I added the button controls in the pixel area, it will add the buttons but most of the buttons will not calculating in the pixel area to get it separate with other button controls.

Here is the screenshot:

Image


Here is the code

Code: Select all

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_index = channel_index
    program_start = channel_index * 60
    program_length = minutes_length
    program_notification = program
    program_minutes = minutes_length
    program_start_to_end = 100
    programs_top = 325
    program_height = 34.5
    pixels_per_minute = 1080 / minutes_length
    program_gap = 10
    position_start = program_start_to_end + (program_start * pixels_per_minute) + ((program_index - 1) * program_gap)
     position_top = programs_top + (channel_index * program_height) + ((channel_index - 1) * program_gap)
     program_width = program_length * pixels_per_minute

     if program_width > 1:
          if program_notification:
               button_nofocus = 'channels_bar1.png'
               button_focus = 'channels_yellow.png'
          else:
               button_nofocus = 'channels_bar1.png'
               button_focus = 'channels_yellow.png'

               if program_width < 1:
                   program_title = ''
               else:
                   program_title = title
 
                   program_controls = xbmcgui.ControlButton(
                         position_start, 
                         position_top, 
                         program_width, 
                         program_height, 
                         program_title, 
                         focusTexture = button_focus, 
                         noFocusTexture = button_nofocus
                   )
                   self.addControl(program_controls)
             cur.close()

Do you know how i can add the button controls in the pixel area?
chris0147
Posts: 24
Joined: Thu Jun 19, 2014 4:48 pm

Re: tv guide button controls issue

Post by chris0147 »

Hi,

I have my tv guide issue is solved.

You can see it here:

Image


So I have got some questions. Do you know how i can hide the programs?

Do you know how i can move the yellow box to get access to the programs and the channels by pressing right, left, up and down??
User avatar
Dom DXecutioner
Posts: 585
Joined: Thu Jul 05, 2012 11:59 pm
Location: California
Has thanked: 249 times
Been thanked: 219 times
Contact:

tv guide button controls issue

Post by Dom DXecutioner »

One: if you've solved your original problem, you should edit the title with a [SOLVED] or similar prefix

Two: it'd be great if you explain how you accomplish the fix so that others can benefit from your findings; also to know if we helped or otherwise

Three: if you have a new question separate from your original, you should start a new topic with a meaningful title, not just "help can't get it to work"

Four: explain what and how your doing it so that we can assist faster instead if us having to go thru your code, which in most cases we won't do
Image
tim619
Posts: 204
Joined: Sun Mar 10, 2013 10:22 am
Has thanked: 25 times
Been thanked: 59 times

Re: tv guide button controls issue

Post by tim619 »

Without source code it's hard to say, but I think you're referring to an xml file. If so you can hide using "visible" take a look at Confluence Lite -> DialogKeyboard.xml seeing an example.
If you referring to python pls provide some source code or even better full.
chris0147
Posts: 24
Joined: Thu Jun 19, 2014 4:48 pm

Re: tv guide button controls issue

Post by chris0147 »

tim619 wrote:Without source code it's hard to say, but I think you're referring to an xml file. If so you can hide using "visible" take a look at Confluence Lite -> DialogKeyboard.xml seeing an example.
If you referring to python pls provide some source code or even better full.

Hey tim619

here it is:

Code: Select all

#get actioncodes from keyboard.xml
ACTION_MOVE_LEFT = 1
ACTION_MOVE_RIGHT = 2
ACTION_MOVE_UP = 3
ACTION_MOVE_DOWN = 4

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:

for full code: please see it here: http://pastebin.com/dUJmgX9m
chris0147
Posts: 24
Joined: Thu Jun 19, 2014 4:48 pm

Re: tv guide button controls issue

Post by chris0147 »

does anyone know how i can navigate the timeline with up/down/left/right buttons in the tv guide?
User avatar
Dom DXecutioner
Posts: 585
Joined: Thu Jul 05, 2012 11:59 pm
Location: California
Has thanked: 249 times
Been thanked: 219 times
Contact:

Re: tv guide button controls issue

Post by Dom DXecutioner »

Dom DXecutioner wrote:One: if you've solved your original problem, you should edit the title with a [SOLVED] or similar prefix

Two: it'd be great if you explain how you accomplish the fix so that others can benefit from your findings; also to know if we helped or otherwise

Three: if you have a new question separate from your original, you should start a new topic with a meaningful title, not just "help can't get it to work"

Four: explain what and how your doing it so that we can assist faster instead if us having to go thru your code, which in most cases we won't do
Image
Post Reply