How to set up the calculate progress
#1
Hello,

I need some help with my code, I want to to set up the calculate progress from 0% to 100% for the label control to see how far I'm going when I send the request to url to get the response and then to store the data in a database.

Here is the label control that i want to use:

Code:
main_loading_time_left = 4202


Here is the code:

Code:
#DOWNLOAD THE XML SOURCE HERE
url = ADDON.getSetting('url')
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read()
response.close()
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))

if os.path.exists(profilePath):
   profilePath = profilePath + 'source.db'
   con = database.connect(profilePath)
   cur = con.cursor()
   cur.execute('CREATE TABLE programs(channel TEXT, title TEXT, start_date TIMESTAMP, stop_date TIMESTAMP, description TEXT)')
   con.commit()
   con.close
   tv_elem = ElementTree.parse(StringIO.StringIO(data)).getroot()
   profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
   profilePath = profilePath + 'source.db'
   con = sqlite3.connect(profilePath)
   cur = con.cursor()
   channels = OrderedDict()

   # Get the loaded data
   for channel in tv_elem.findall('channel'):
       channel_name = channel.find('display-name').text
       for program in channel.findall('programme'):
           title = program.find('title').text
           start_time = program.get("start")
           stop_time = program.get("stop")
           cur.execute("INSERT INTO programs(channel, title, start_date, stop_date)" + " VALUES(?, ?, ?, ?)", [channel_name, title, start_time, stop_time])
           con.commit()


Does anyone know how I can use the label control `main_loading_time_left` to set up the calculate progress that start from 0% to 100% when I send the request to the url to get the response and then store the data into the database?

Thanks in advance
Reply
#2
24 hours and no one is reply, does anyone know how I can use the label to display the progress?
Reply
#3
Firstly, there's no rule that people need to reply to your post within a certain time, so please don't get impatient..

Secondly, I've read your post three times now and I still haven't got a clue what you're trying to do.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#4
I understand what you are saying but I would like to get this done asap. I would like to apology for being impatient.

Ok, what I'm trying to do is I want to set up the progress dialog like start from 0%, 2%, 4%, 6%, 8% and so on until when it finish it will be 100%. Hope you get what I mean?

The label control I want to use to set up the progress dialog using the variable id is main_loading_time_left.
Reply
#5
first create the dialog
http://mirrors.xbmc.org/docs/python-docs...sBG-create

then start updating it
http://mirrors.xbmc.org/docs/python-docs...sBG-update

after done, close it
http://mirrors.xbmc.org/docs/python-docs...ssBG-close

This uses the background dialog so you can continue using XBMC.
For the blocking dialog, use
http://mirrors.xbmc.org/docs/python-docs...ogProgress
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#6
Thank you Martijn. How I can use the variable of main_loading_time_left to work with the progress dialog and the urllib2?

Here is the one I want to use:

Code:
main_loading_time_left = 4202
url = ADDON.getSetting('allchannels.url')
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read()
response.close()
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
progress = xbmcgui.DialogProgressBG()
progress.create('Progress', 'This is a progress bar.')

i = 0
while i < 10:
    percent = int( ( i / 10.0 ) * 100)
    message = "Message " + str(i) + " out of 10"
    progress.update(percent, "", message, "")
    print "Message " + str(i) + " out of 10"

    if progress.iscanceled():
       break
    i = i + 1
progress.close()
Reply
#7
Maybe I'm being stupid but I don't see anything in your code that links that variable to the progress of your download. You need to work that out first (which isn't an xbmc issue) and then use the progress dialog to display the progress.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#8
Well I am sure you know what I want to achieve. Sorry for confused you, but I'm set up the label text and I want to call the setLabel with the percent string.

When I try this:

Code:
percent = 1
progressStartTime = datetime.datetime.now()
delta = datetime.datetime.now() - progressStartTime
secondsLeft = int(delta.seconds) / float(percent) * (100.0 - percent)
secondsLeft -= secondsLeft % 10
self.getControl(4202).setLabel(secondsLeft + "%")

I'm getting an error: TypeError: unsupported operand type(s) for +: 'float' and 'str'

The error are jumping on this line:

Code:
self.getControl(4202).setLabel(secondsLeft + "%")

I don't understand why I'm getting an error.

Do you know why I'm getting the error and do you know how to fix it?
Reply
#9
secondsLeft is a float, and "%" is a string. You can't concatenate a float and a string.

If you don't need any of the decimal points, I think you can just do str(secondsLef) + "%". If you want to get that into something like 98.22%, I think you may have to do a little googling.
Reply
#10
Thank you for your help pkscuot. I have a little trouble with updating the percent in a setLabel function.

It can only be updating once the value is set in the label.

This is where I'm stuck at right now:

Code:
#DOWNLOAD THE XML SOURCE HERE
url = ADDON.getSetting('allchannels.url')
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read()
response.close()
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
self.getControl(4202).setLabel("1%")


if os.path.exists(profilePath):
   profilePath = profilePath + 'source.db'
   con = database.connect(profilePath)
   cur = con.cursor()
   cur.execute('CREATE TABLE programs(channel TEXT, title TEXT, start_date TIMESTAMP, stop_date TIMESTAMP, description TEXT)')
   con.commit()
   con.close
   tv_elem = ElementTree.parse(StringIO.StringIO(data)).getroot()
   channels = OrderedDict()

   # Get the loaded data
   for channel in tv_elem.findall('channel'):
       channel_name = channel.find('display-name').text
       for program in channel.findall('programme'):
            title = program.find('title').text
            start_time = program.get("start")
            stop_time = program.get("stop")
            cur.execute("INSERT INTO programs(channel, title, start_date, stop_date)" + " VALUES(?, ?, ?, ?)", [channel_name, title, start_time, stop_time])
            con.commit()
            con.close
            secondsLeft = 20 * (100 - 10) / 100
            secondsLeft -= secondsLeft % 10

            self.getControl(4202).setLabel(str(secondsLeft)+"%")


If there is possible to updating the setLabel function more than once, I would love to know how Smile
Reply
#11
Sorry, I think it was me who may have been unclear.

My confusion was that I didn't see anything in your code that calculated how much of the download was remaining. That code you referred to is a loop that just counts to 10 and has nothing to do with the state of your download.

Once you've worked out how you're calculating the progress, we can then tell you how to implement it into your code. E.g. if the relevant progress based on the number of programmes you've processed?
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#12
That's okay.

Yes, I want to counts to 10 in the loop, but the trouble is it will only allow me to update the value in the setLabel function only once at a time.

If you know a way how to update the values in the setLabel function with counting the number to 10, I will be very grateful Smile
Reply
#13
ok - but counting to 10 against what? Sorry, if I'm being dumb - but I just don't see the point of sticking in an arbitrary counting to 10. The progress bar should be meaningful, i.e. if your xml file has 100 programmes, then I'd base the status text on how many of those 100 programmes had been processed.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply

Logout Mark Read Team Forum Stats Members Help
How to set up the calculate progress0