Script hangs on onControl
#1
Hi there,

perhaps someone can point out my mistake. My script hangs when i enter onControl. Menu doesn't work anymore and I have to restart the xbox. I'm sure it's something trivial ...

Mighty Bombero

Here's the code:

Code:
import xbmc, xbmcgui, re, urllib2

try: Emulating = xbmcgui.Emulating

except: Emulating = False

DEBUG = True



ACTION_UNKNOWN = 0            #'Y', black

ACTION_MOVE_LEFT = 1        #Dpad Left

ACTION_MOVE_RIGHT = 2        #Dpad Right

ACTION_MOVE_UP = 3            #Dpad Up

ACTION_MOVE_DOWN = 4        #Dpad Down

ACTION_SKIP_NEXT = 5         #Left trigger

ACTION_SKIP_PREVIOUS = 6     #Right trigger

ACTION_SELECT = 7            #'A'

ACTION_BACK = 9                #'B'

ACTION_MENU = 10            #'Back'

ACTION_STOP = 13            #'Start'

ACTION_DISPLAY = 18            #'X'



RootDir = "Q:\\scripts\\karambolage"    # Add the folder name of your script to the end of RootDir (i.e. "Q:\\scripts\\XMovieGuide\\")

url_list = {}
base_url = "http://www.arte.tv/de/wissen-entdeckung/karambolage/1529146.html"



class MyClass(xbmcgui.Window):
    

    def __init__(self):

        if Emulating: xbmcgui.Window.__init__(self)



        # Begin setting up the GUI

#        self.pic = xbmcgui.ControlImage(0,0,0,0, RootDir + "background.png")    # (0,0,0,0) Makes it draw the image full size, starting at the top left

#        self.addControl(self.pic)
        page = self.retrievePage()
        if page: url_list = self.parsePage(page)

        self.list = xbmcgui.ControlList(200, 150, 300, 300)
        self.addControl(self.list)
        for i in url_list.values():
            self.list.addItem(i)
            #xbmc.Player().play(i)
        self.setFocus(self.list)




    def onAction(self, action):

        print "Action button:", action

        if action == ACTION_MENU:

            self.close()


    def onControl(self, control):

        if DEBUG: print "onControl"

        if control == self.list:
            item = self.list.getSelectedItem()
            self.message("You selected : " + item)
            #self.setFocus(self.list)
            #self.setFocus(self.list)
            #if DEBUG: print "URL: %s" %url_list[item.getLabel]
            xbmc.Player().play(item.getLabel)

    def message(self, message):
        dialog = xbmcgui.Dialog()
        dialog.ok(" My message title", message)

            
    def retrievePage(self):
        if DEBUG: print "dlSourcePage"        
        try:

            get = urllib2.urlopen(base_url)

            return get

        except:

            if DEBUG: print "Could not retrieve file %s,check Internet connection and URL" %webfile

            return

    def parsePage(self, page):
        if DEBUG: print "parsing Page"
        url_list = {}
        for line in page:
            exp = re.compile('<a href="http://sonix.*?</a>')
            m = exp.findall(line)
            #if DEBUG: print "Regex: %s" %m
            #if DEBUG: print "Analysierte Zeile: %s" %line
            if m:
                if DEBUG: print "Liste hat ein Element"
                for match in m:
                    if DEBUG: print "Match: %s" %match
                    exp = re.compile('http://.*\.rm')
                    stream = exp.search(match).group()
                    exp = re.compile('Sonntag.*200[0-9]{1}')
                    sendung = exp.search(match).group()
                    if DEBUG: print sendung + stream
                    url_list[sendung] = stream
                break
        if DEBUG: print url_list
        return url_list

            



win = MyClass()

win.doModal()

del win
Reply
#2
Quote:if page: url_list = self.parsePage(page)

are you sure page exists? If it doesn't it will error at the for loop. just a headsup.

Your problem is
Code:
self.message("You selected : " + item)

item is not a string, it's a listitem.

Code:
self.message("You selected : " + item.getLabel())
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#3
Nuka1195 Wrote:are you sure page exists? If it doesn't it will error at the for loop. just a headsup.

Yes page exists and properly populates my ControlList.


Nuka1195 Wrote:Your problem is
Code:
self.message("You selected : " + item)

item is not a string, it's a listitem.

Code:
self.message("You selected : " + item.getLabel())


Fixed that but it wasn't causing the problem. Thanks anyway ...
Reply
#4
did you fixed that as well :
you did :
Code:
xbmc.Player().play(item.getLabel)

try this :
Code:
xbmc.Player().play(item.getLabel())
Reply
#5
solexalex Wrote:did you fixed that as well :
you did :
Code:
xbmc.Player().play(item.getLabel)

try this :
Code:
xbmc.Player().play(item.getLabel())


I figure I was way too tired. That did it indeed. Thanks!

Mighty Bombero
Reply

Logout Mark Read Team Forum Stats Members Help
Script hangs on onControl0