How to : Synchronise 2 lists
#1
hi everybody !

maybe i'm not the first to find this trick, it is not the question, but i found a way to synchronise 2 lists... (or more)

you 'browse' items of one of the list, and the other one move in the same time. that way, item number x of the 1st list is always  in front of item number x of 2nd list !!

this can be very helpfull for drawing arrays on xbmc screen...

it is very simple to do, anyway, mismatch can happen when using pad triggers to move fast inside the list...
have a look in it and just tell me. this example shows in a 1st list the sum of 2 numbers and in a second list the result for each sum...
here is a link : http://xbmc-scripts.gx-mod.com/documents...o_lists.py
and here is the code (not sure it will look correctly indented here) :

Quote:#this simple script example will show you how to
# 'synchronize' several lists together
#it can be very interesting to draw some boards on your xbmc
# or to align some datas together in a kind of multitab list

#sorry for my explanations as they may appear not very understandable
# but hey ! i'm french;)
#
# alexsolex[a]gmail.com

import xbmc, xbmcgui

class main(xbmcgui.window):
   def (self):
       self.setcoordinateresolution(6)

       #background
       self.addcontrol(xbmcgui.controlimage(0,0,720,576, 'background.png'))

       #1st list
       self.list_1=xbmcgui.controllist(200,110,200,430,'font13','0xffffffff')
       self.addcontrol(self.list_1)
       self.list_1.setpagecontrolvisible(false)

       #s2nd list
       self.list_2=xbmcgui.controllist(300,110,200,430,'font13','0xffffffff')
       self.addcontrol(self.list_2)
       self.list_2.setpagecontrolvisible(false)

       #fill 1st list with datas
       for number in range(60):
           self.list_1.additem('%s + %s = '%(number,number))

       #fill 2nd list with datas
       for number in range(60):
           self.list_2.additem(str(number+number))

       #note that you have to be sure both lists have the same length !!
           
       self.setfocus(self.list_1)


   
   def oncontrol(self,control):
       #do your oncontrol as you need to...
       #for example :
       if control==self.list_1:
           print "a list_1 item has been selected"
       elif control == self.list_2:
           print "a list_2 item has been selected"



   def onaction(self, action):
       #here we will check every pad inputs to move both lists together as one

       #first catch control list item selected :
       item = self.list_1.getselectedposition()
       #then focus the same item in the second list :
       self.list_2.selectitem(item)

       #finally do your oncontrol as you need
       #for example :
       if action == action_back:
           self.close()

m = main()
m.domodal()
del m
Reply
#2
ohh i get it so this is like a poor man's table control with each list as a column.... pretty clever..

actually this doesnt look like it would take into account scrolling. i know that when using scroll events the selection in a list stays near the center but when using move events the selection is near the edge. page up/down doesnt move the selection (just the scroll amount).

i don't know how selectitem works though (it was added after the table i implemented for the stock script). but i don't think it could replicate that behavior? it seems like you would need a way to get/set scroll amount to do this...

am i missing something maybe?



Reply
#3
so it just selects the same list item number as the one selected each time u press a key?
read the xbmc online-manual, faq and search the forums before posting! do not e-mail the xbmc-team asking for support!
read/follow the forum rules! note! team-xbmc never have and never will host or distribute ms-xdk binaries/executables!
Reply
#4
hi !
i'm not sure to understand what asteron says (sorry...) but diagdave is right :
Quote:it just selects the same list item number as the one selected each time u press a key
exactly.
anyway,maybe it is not a real trick for advanced xbmc python scripters, but it can be very useful
Reply

Logout Mark Read Team Forum Stats Members Help
How to : Synchronise 2 lists0