Page 1 of 1
how to use progress dialog for label control?
Posted: Thu Jun 19, 2014 4:54 pm
by chris0147
Hi all,
I need some help with my code, I want to to set up the progress dialog like start from 0% to 100% for the label control when I'm downloading the xml file using with urllib2.
Here is the label control id that i want to use with the progress dialog:
Here is the code:
Code: Select all
#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 called main_loading_time_left to set up the progress dialog to start from 0%, 2%, 4%, 6%, 8% and so on when I send the request to the url to get the response and download the xml file until it get finish to 100%?
Thanks in advance
Re: how to use progress dialog for label control?
Posted: Fri Jun 20, 2014 4:38 pm
by chris0147
24 hours and no one is reply, does anyone know?
Re: how to use progress dialog for label control?
Posted: Fri Jun 20, 2014 5:39 pm
by Dom DXecutioner
Please be patient; this is not a big forum like main line xbmc and we don't have many devs.
With that said, you can read the following links to give you and idea on how to use the progress bar:
http://romanvm.github.io/xbmcstubs/docs ... gress.html
http://wiki.xbmc.org/index.php?title=Ho ... rogressbar
http://mirrors.xbmc.org/docs/python-doc ... ogProgress
Re: how to use progress dialog for label control?
Posted: Sat Jun 21, 2014 5:10 pm
by chris0147
Thank you for your reply Dom DXecutioner. Sorry this is not what I'm looking for. I'm looking for a function to make the percent to update the values in the setLabel function, example: Set up the values in the setLabel function "1%", "10%, "20%", "30%", "40%" and so on until I get "100%".
However, there is a bit of problem. When I run the code, it will update the value in the setLabel, but it will not allow me to update the values in the setLabel more than once.
Code: Select all
#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)+"%")
Do you know how I can set up the values more than once in the setLabel function?
Re: how to use progress dialog for label control?
Posted: Sun Jun 22, 2014 11:55 am
by Dan Dar3
What type of control is getControl(4202)? Shows us your window XML please.
If that is a DialogProgress you want update() method.
http://mirrors.xbmc.org/docs/python-doc ... ess-update
If you have used XBMC4Xbox Installer (in my signature) it updates the DialogProgress with download progress - even if not necessarily exactly what you want to do, in your case you might want to update the text as you loop through your files, the point is that you can.
https://code.google.com/p/xbmc4xbox-add ... install.py
Re: how to use progress dialog for label control?
Posted: Sun Jun 22, 2014 1:23 pm
by chris0147
There you go Dan:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<window type="dialog">
<allowoverlay>no</allowoverlay>
<coordinates>
<system>1</system>
<posx>0</posx>
<posy>0</posy>
</coordinates>
<controls>
<control type="image" id="1">
<posx>0</posx>
<posy>0</posy>
<width>1280</width>
<height>720</height>
<texture>background-defeat.png</texture>
<animation effect="fade" start="0" end="100" time="6500">WindowOpen</animation>
</control>
<control type="image" id="2">
<description>Tv Guide Blue Box</description>
<posx>306.5</posx>
<posy>7</posy>
<width>154</width>
<height>95</height>
<visible>true</visible>
<texture>tvguide_blue.png</texture>
</control>
<control type="label" id="4202">
<description>loading time left</description>
<posx>70</posx>
<posy>50</posy>
<width>600</width>
<height>50</height>
<aligny>center</aligny>
<font>font13</font>
<textcolor>ffffffff</textcolor>
<visible>true</visible>
<label>0%</label>
</control>
</controls>
</window>
Re: how to use progress dialog for label control?
Posted: Mon Jun 23, 2014 6:01 pm
by Dom DXecutioner
By the looks of it, tho I can be wrong, it's updating; however, it appears that it's passing the same value over and over... I don't see a real value being calculated.
You may need to get the total channels and use that as your target, then do the math to update your percentage... You'll need to move the update calculations to the channel iteration.
You might have to upload you entire code to paste bin for someone to test it out.
Re: how to use progress dialog for label control?
Posted: Fri Jun 27, 2014 5:41 pm
by Dan Dar3
Hey chris0147,
I just got your PM:
I am waiting for your answer, please fucking reply...
viewtopic.php?f=7&t=2913
to which my first reaction was
"hey dumb-ass, Dom DXecutioner already answered your problem, you're setting the same fucking value in the loop!", but I'm going to try and be civil here.
See these lines of code? you wrote them:
Code: Select all
secondsLeft = 20 * (100 - 10) / 100
secondsLeft -= secondsLeft % 10
self.getControl(4202).setLabel(str(secondsLeft)+"%")
The first line of code assigns secondsLeft with 18, and the next line practically assigns 18 - 8 = 10. And then you set that to the label, yes, same value on each FOR iteration.
Here, if you don't believe us, run it yourself here - feel free to run it as many times as you want, it will still print "10%".
http://repl.it/languages/Python
Code: Select all
secondsLeft = 20 * (100 - 10) / 100
secondsLeft -= secondsLeft % 10
print str(secondsLeft)+"%"
Useful tip, if you are going to write stupid code as I'm sure you will for a while till you learn to check your values, like we all did at some point, try printing your values using "print" statements. They will go xbmc.log and then you'll see them before pinning the blame on the wrong things. It will save you tons of time and frustration, and possible others as well. For a more elegant approach use xbmc.log(), see
http://mirrors.xbmc.org/docs/python-doc ... .html#-log
Another tip, for free again, this time about social interaction - don't use the word "fuck" with people you're not close to, and from whom you practically expect a favor - it might catch them at the wrong time and they will not appreciate the tone, even if accompanied by "please".
And now with my rant over, we can get back to our sheep...
Re: how to use progress dialog for label control?
Posted: Sat Jun 28, 2014 12:29 am
by BuZz

Sheesh - he shouldn't be PM'ing anyway - if he had bothered to read the forum rules. It's always also a good idea to not insult the moderators - especially when they are giving up their free time to try and help.
Dan: you have a lot more patience than me - I would have clicked the Ban button!
Re: how to use progress dialog for label control?
Posted: Sat Jun 28, 2014 1:20 pm
by Dan Dar3
Hey Buzz, now I feel a bit bad for making it all public display...
It's just that I was a bit peed off cause I remember back in the day when spending hours and days in the College computer lab with virtually no one to tell you how to program for that old Unix system, bashing you head and waiting for hours for the 9600 bps Internet connection to come back to access the little knowledge that was out there on the Internet, it would've never crossed my mind to go to some of the older students and tell them "hey, I asked you a question yesterday and it bugs me and I need your answer. F**k your shit, my shit is more important.". Never.
On the other hand, I know how frustrating it can be when you start coding, it can seem so easy when others do it and a world of pain when you do it - so in a way I feel bad for the guy, it's just not ok to take your frustrations out on others, whether it's an admin or anyone else. Yes, it's all faceless text, but we're still people at the end.
That being said, I don't want to push you out chris0147, if you can take it as you give it, I can gladly let it go and come back to the matter at hand.
how to use progress dialog for label control?
Posted: Sun Jul 06, 2014 10:47 am
by fxmech
Way to [censored] teach a man to fish, Dan. You [censored] showed him.
FWIW: A simple ban may serve to make life easier, but some good ol' confrontation has it's benefits, too. If nothing else, it reasserts *why* there are rules and etiquette to be followed. Dan's point of view and ways of expression made me laugh.
And to the OP, who may or may not ever come back. we have to give some credit. They at least took it upon themselves to start coding something. It is a step much further than most take, to at least *try* doing something themselves. For somebody going in the right direction, I think they've earned a bonus life if not at least to possibly stick around and become a useful member of this community.
Perhaps, one [censored] day, he will [censored] teach some other [censored] to fish!
MOD MSG
post edited for language; please refrain from using bad language
thanks!
Re: how to use progress dialog for label control?
Posted: Sun Jul 06, 2014 11:24 am
by fxmech
Dan Dar3 wrote:Hey chris0147,
I just got your PM:
I am waiting for your answer, please fucking reply...
viewtopic.php?f=7&t=2913
to which my first reaction was
"hey dumb-ass, Dom DXecutioner already answered your problem, you're setting the same fucking value in the loop!", but I'm going to try and be civil here.
...
...

I learned it from you, Dan!
--------EDIT----------
do we need censor quotes?
I find this so entertaining. Did I mutate into a troll at some point?
How to add per program in the tv guide?
Posted: Mon Jul 21, 2014 2:22 am
by chris0147
Hi guys,
I need your help, I'm working on my own skin to created my own tv guide addon.
I understand how tv guide actually works, I need to add the labels control in the skin so I can set the text in each label for each channel. I tried to find the answer on google how I can add each program and how to duration time, but I can't find the answer I'm looking for.
I still have no idea how to add the per program and how to duration time to allowed me to display them in the tv guide.
Do I need to add the label, button control for each program or what?
What about the duration time how I can workout the time?
Please advise me what I would actually need.
Thanks in advance
Re: How to add per program in the tv guide?
Posted: Mon Jul 21, 2014 5:58 pm
by whufclee
I'm a little confused, are you wanting to create your own XBMC4Xbox skin with your very own TV Guide built-in to the skin or are you creating a script but need help skinning it?
You could try twinthers original TV Guide script as a base, no idea whether or not it would work on the Xbox but it would give you a good starting point.
As for the actual listings they are heavily copyrighted which is why OnTapp had to go subscription based in order to help pay to get legal listings, I can tell you from experience that they cost thousands of dollars per month to obtain! Unfortunately OnTapp is not (currently) xbox compatible, I've not had chance to look into why this is but I'm guessing it's probably database related, also I'm not entirely convinced a stock xbox with just 64MB RAM would be up to the job of showing the TVGuide and starting off a live stream. Theoretically it should be possible to get working but that would all depend on the number of listings and the amount of eye candy you want to show.
Re: How to add per program in the tv guide?
Posted: Tue Jul 22, 2014 4:35 pm
by chris0147
I have already created my own skin built-in with my own tv guide addon.
I don't use twinthers orgional tv guide because I have my own tv guide. I can fetch the list of channels and programs to store them in a sqlite3 database which I know how to put the channels in each label control, but my trouble is i don't know what type of control that I should use to add the programs in the tv guide.
Do you know what type of control that I should use to add the programs in the tv guide?
And how I can duration the times using the control that i add the programs in the tv guide?
If you are not sure what I'm talking about, please see the skin that I have created:

Re: How to add per program in the tv guide?
Posted: Tue Jul 22, 2014 6:04 pm
by Dom DXecutioner
chris0147 wrote:Hi guys,
I need your help, I'm working on my own skin to created my own tv guide addon.
I understand how tv guide actually works, I need to add the labels control in the skin so I can set the text in each label for each channel. I tried to find the answer on google how I can add each program and how to duration time, but I can't find the answer I'm looking for.
I still have no idea how to add the per program and how to duration time to allowed me to display them in the tv guide.
Do I need to add the label, button control for each program or what?
What about the duration time how I can workout the time?
Please advise me what I would actually need.
Thanks in advance
You had already started a thread on this; please do not create multiple threads for the same issue... I have moved and merged the threads to the original since they are the same problem.
Thank you!
Now moving on... as stated before, you will need to find out the amount of channels that are being displayed, then you need to update during the iteration; something like:
Code: Select all
dialogProgress = xbmcgui.DialogProgress()
dialogProgress.create( "XBox Tv Guide", "Updating guide..." )
channels = tv_elem.findall('channel')
channelsTotal = len(channels)
channelsDone = 0
for channel in channels:
# add channel done
channelsDone += 1
# calculate percent done
percentDone = min( float(channelsDone / channelsTotal) * 100, 100 )
channel_name = channel.find('display-name').text
# update progress
dialogProgress.update( percentDone, "working.." )
# process tv programs
for program in channel.findall('programme'):
# do something meaningfull
# close dialog
dialogProgress.close()
The above code has not been tested but it gives you an idea of what needs to be done...
Re: how to use progress dialog for label control?
Posted: Tue Jul 22, 2014 7:01 pm
by chris0147
@Dom DXecutioner: Thank you very much for that, but i have already got that code in my code list which you can see it here:
Code: Select all
#Pull the data from the database
channelList = list()
programList = 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)
What I'm asking how do you put the programs in the tv guide?
what type of control i need to use to add?
And how I can duration the time using the control?
how to use progress dialog for label control?
Posted: Tue Jul 22, 2014 7:21 pm
by Dom DXecutioner
Take a look at the twinthers tv guide and see how that was done; to be honest, what you're asking is too involved for us to comment on... You'll have to predefine the layout and add the necessary labels or containers, depending on your approach, then add code to display the information based on selection.
Your best bet is to study other similar addons, build it, then if you come across specific issues, post back.