【问题标题】:how do I set up the calculate progress如何设置计算进度
【发布时间】:2014-06-17 19:08:20
【问题描述】:

我正在为 xbmc 媒体应用程序编写我的 python 脚本,以将请求发送到 url 以获取响应,以便我可以将数据存储在 sqlite3 数据库中。

我想为标签控件设置从 0% 到 100% 的计算进度,以查看当我将请求发送到 url 以获取响应然后将数据存储在数据库中时我走了多远.

这是我要使用的控件 ID:

main_loading_time_left = 4202

代码如下:

#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()

有谁知道我如何使用控件 ID main_loading_time_left 来设置从 0% 到 100% 的计算进度,当我将请求发送到 url 以获取响应然后将数据存储到数据库中时.有人知道怎么做吗?

【问题讨论】:

    标签: python xbmc


    【解决方案1】:

    要显示进度,您应该有 2 个点:startcurrentend。所以,0,当前处理的数据和总数据。

    但是这里有 2 个昂贵的操作:http 查询获取和导出到 sqlite。

    要跟踪 http 查询的进度,我建议查看以下问题和答案:thisthis

    要跟踪 sql 查询进度,您只需将 tv_elem.findall('channel') 的长度设为 end

    elements = tv_elem.findall('channel')
    total = len(elements)
    for current, channel in enumerate(elements):
        ...
        setProgressBar(main_loading_time_left, float(current)/total*100)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多