没有添加时间的Kivy图像没有显示

时间:2016-03-13 23:45:54

标签: image python-3.x raspberry-pi kivy raspbian

此应用程序的摘要:

  • Raspberry Pi运行Raspbian Jessie并输出到电视
  • Python 3.4
  • Kivy 1.9.1
  • 通过SOAP请求提取宠物信息
  • 解析信息
  • 创建一个kivy窗口并显示宠物信息 在显示下一个宠物信息之前设置间隔

问题:

  • 每只宠物都有一张图像(通常每张20-60kB)多次未显示
  • 最初我使用异步加载来拉取图像并直接从它的网址
  • 显示它
  • 现在我在开始显示序列之前将每个图像下载到USB驱动器,但具有相同的问题
  • 预先加载的图片在应用程序外打开
  • 当从网络上直接拉出图像时,图像显示(或不显示)需要大约一秒钟
  • 现在首先下载图像,图像几乎立即出现(或不出现)
  • 我可以保证每张图片都能显示的唯一方法是将宠物之间的时间间隔设置为20秒或更长时间(无论是直接来自网络还是从USB记忆棒中拔出)
  • 我尝试使用并且不使用异步加载存储在USB记忆棒上的图像,但无论如何都没有成功
  • 我看过USB记忆棒上的文件夹,可以看到图像以每秒约1-3幅图像的速度加载(总共大约110张图像)
  • 我尝试在没有运气的情况下下载/保存每张图片之间添加延迟
  • 前7张图片总是成功,与任何宠物列表无关
  • 在前7张图像之后,它是随机的,成功率取决于显示的宠物之间的时间间隔
  • 我无法弄清楚为什么所有图像都需要增加时间才能显示图像相当小而且显示的图像几乎立即出现

的Python

import kivy
import sys
import os
import time
import requests
kivy.require('1.9.1')
import xml.etree.ElementTree as ET
from datetime import datetime
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.floatlayout import FloatLayout
from kivy.clock import Clock

# from kivy.loader import Loader
# image = Loader.image('nophoto.png')
# Loader.error_image = 'nophoto.png'

# SET ADDRESS FOR SOAP
from suds.client import Client
url = 'http://qag.petpoint.com/webservices/AdoptableSearch.asmx?WSDL'
client = Client(url)

# DELETES PRELOADED IMAGES TO START WITH AN EMPTY USB FOLDER
for ea_file in os.listdir('/media/pi/PRELOAD'):
    thedress = '/media/pi/PRELOAD' + '/' + ea_file
    os.remove(thedress)

# PUSHES DYNAMIC INFO TO SCROLLER.KV
class TheBox(FloatLayout):
    def update(self, *args):
        global date_now, which_petL, which_petR, total_count, Lname, Lsex, Lbreed, Lage, Lphoto, Rname, Rsex, Rbreed, Rage, Rphoto
        quantity = len(ans_lists[0]) - 1

        ans_particular = feeder()
        Lname = ans_particular[0]
        Lsex = ans_particular[1]
        Lbreed = ans_particular[2]
        Lage = ans_particular[3]
        Lphoto = ans_particular[4]
        Rname = ans_particular[5]
        Rsex = ans_particular[6]
        Rbreed = ans_particular[7]
        Rage = ans_particular[8]
        Rphoto = ans_particular[9]

        self.ids.Start_Time.text = '%02d  %02d    %05d' % (date_now.day, date_now.hour, total_count)

        if (total_count % 2) == 0: 
            if which_petL < quantity:
                which_petL += 1
            else:
                which_petL = 0

            self.ids.PetL_name.text = str.upper(Lname)
            self.ids.PetL_sex.text = str(Lsex)
            self.ids.PetL_breed.text = str(Lbreed)
            self.ids.PetL_age.text = str(Lage)
            self.ids.PetL_photo.source = str(Lphoto)

        else:
            if which_petR < quantity:
                which_petR += 1
            else:
                which_petR = 0

            self.ids.PetR_name.text = str.upper(Rname)
            self.ids.PetR_sex.text = str(Rsex)
            self.ids.PetR_breed.text = str(Rbreed)
            self.ids.PetR_age.text = str(Rage)
            self.ids.PetR_photo.source = str(Rphoto)

# SOAP RESPONSE IS CONVERTED TO XML FORMAT
def reformat_soap():    
    result = client.service.adoptableSearch('0', 'A', 'All', 'not4u')

    ..

    root = ET.fromstring(closeit)
    return root

# ITERATES THE SOAP RESPONSE TO ASSIGN DATA TO LISTS
def pull_data(ans_root):
    lpetid = []
    lname = []
    lsex = []
    lbreed = []
    lage = []
    lphoto = []

    for child in ans_root.iter('pet_id'):

        ..

        iphoto = child.find('pet_photo').text

        # WEB ADDRESSES FOR IMAGES ARE USED TO CREATE LOCAL ADDRESSES
        local_name = iphoto.replace('http://sms.petpoint.com/sms/photos/615/','/media/pi/PRELOAD/')
        ghost_pet = local_name.replace('http://sms.petpoint.com/sms3/emails/images/','/media/pi/PRELOAD/')
        lphoto.extend([ghost_pet])

        # IMAGES ARE DOWNLOADED FROM THE WEB AND SAVED LOCALLY
        photo_cache = open(ghost_pet, 'wb')
        photo_cache.write(requests.get(iphoto).content)
#       time.sleep(2)
        photo_cache.close()

    return(lname, lsex, lbreed, lage, lphoto)

# ASSEMBLES PET DATA PRIOR TO PUSH
def feeder():
    global which_petL, which_petR, cname, csex, cbreed, cage, cphoto
    pname = cname[which_petL]
    psex = csex[which_petL]
    pbreed = cbreed[which_petL]
    page = cage[which_petL]
    pphoto = cphoto[which_petL]
    qname = cname[which_petR]
    qsex = csex[which_petR]
    qbreed = cbreed[which_petR]
    qage = cage[which_petR]
    qphoto = cphoto[which_petR]    
    return(pname, psex, pbreed, page, pphoto, qname, qsex, qbreed, qage, qphoto) 

ans_root = reformat_soap()
ans_lists = pull_data(ans_root)
which_petR = int(len(ans_lists[0]) / 2)

cname = ans_lists[0]
csex = ans_lists[1]
cbreed = ans_lists[2]
cage = ans_lists[3]
cphoto = ans_lists[4]

# DEFINES THE KIVY APP, INTERVAL BETWEEN PET DISPLAYS, AND TIES TO SCROLLER.KV
class ScrollerApp(App):

    def build(self):
        self.load_kv('Scroller.kv')
        x = TheBox()
        x.update()
        Clock.schedule_interval(x.update, 10)
        return(x)

# KIVY WINDOW CREATION
if __name__ == '__main__':
    ScrollerApp().run()

import kivy import sys import os import time import requests kivy.require('1.9.1') import xml.etree.ElementTree as ET from datetime import datetime from kivy.app import App from kivy.core.window import Window from kivy.uix.floatlayout import FloatLayout from kivy.clock import Clock # from kivy.loader import Loader # image = Loader.image('nophoto.png') # Loader.error_image = 'nophoto.png' # SET ADDRESS FOR SOAP from suds.client import Client url = 'http://qag.petpoint.com/webservices/AdoptableSearch.asmx?WSDL' client = Client(url) # DELETES PRELOADED IMAGES TO START WITH AN EMPTY USB FOLDER for ea_file in os.listdir('/media/pi/PRELOAD'): thedress = '/media/pi/PRELOAD' + '/' + ea_file os.remove(thedress) # PUSHES DYNAMIC INFO TO SCROLLER.KV class TheBox(FloatLayout): def update(self, *args): global date_now, which_petL, which_petR, total_count, Lname, Lsex, Lbreed, Lage, Lphoto, Rname, Rsex, Rbreed, Rage, Rphoto quantity = len(ans_lists[0]) - 1 ans_particular = feeder() Lname = ans_particular[0] Lsex = ans_particular[1] Lbreed = ans_particular[2] Lage = ans_particular[3] Lphoto = ans_particular[4] Rname = ans_particular[5] Rsex = ans_particular[6] Rbreed = ans_particular[7] Rage = ans_particular[8] Rphoto = ans_particular[9] self.ids.Start_Time.text = '%02d %02d %05d' % (date_now.day, date_now.hour, total_count) if (total_count % 2) == 0: if which_petL < quantity: which_petL += 1 else: which_petL = 0 self.ids.PetL_name.text = str.upper(Lname) self.ids.PetL_sex.text = str(Lsex) self.ids.PetL_breed.text = str(Lbreed) self.ids.PetL_age.text = str(Lage) self.ids.PetL_photo.source = str(Lphoto) else: if which_petR < quantity: which_petR += 1 else: which_petR = 0 self.ids.PetR_name.text = str.upper(Rname) self.ids.PetR_sex.text = str(Rsex) self.ids.PetR_breed.text = str(Rbreed) self.ids.PetR_age.text = str(Rage) self.ids.PetR_photo.source = str(Rphoto) # SOAP RESPONSE IS CONVERTED TO XML FORMAT def reformat_soap(): result = client.service.adoptableSearch('0', 'A', 'All', 'not4u') .. root = ET.fromstring(closeit) return root # ITERATES THE SOAP RESPONSE TO ASSIGN DATA TO LISTS def pull_data(ans_root): lpetid = [] lname = [] lsex = [] lbreed = [] lage = [] lphoto = [] for child in ans_root.iter('pet_id'): .. iphoto = child.find('pet_photo').text # WEB ADDRESSES FOR IMAGES ARE USED TO CREATE LOCAL ADDRESSES local_name = iphoto.replace('http://sms.petpoint.com/sms/photos/615/','/media/pi/PRELOAD/') ghost_pet = local_name.replace('http://sms.petpoint.com/sms3/emails/images/','/media/pi/PRELOAD/') lphoto.extend([ghost_pet]) # IMAGES ARE DOWNLOADED FROM THE WEB AND SAVED LOCALLY photo_cache = open(ghost_pet, 'wb') photo_cache.write(requests.get(iphoto).content) # time.sleep(2) photo_cache.close() return(lname, lsex, lbreed, lage, lphoto) # ASSEMBLES PET DATA PRIOR TO PUSH def feeder(): global which_petL, which_petR, cname, csex, cbreed, cage, cphoto pname = cname[which_petL] psex = csex[which_petL] pbreed = cbreed[which_petL] page = cage[which_petL] pphoto = cphoto[which_petL] qname = cname[which_petR] qsex = csex[which_petR] qbreed = cbreed[which_petR] qage = cage[which_petR] qphoto = cphoto[which_petR] return(pname, psex, pbreed, page, pphoto, qname, qsex, qbreed, qage, qphoto) ans_root = reformat_soap() ans_lists = pull_data(ans_root) which_petR = int(len(ans_lists[0]) / 2) cname = ans_lists[0] csex = ans_lists[1] cbreed = ans_lists[2] cage = ans_lists[3] cphoto = ans_lists[4] # DEFINES THE KIVY APP, INTERVAL BETWEEN PET DISPLAYS, AND TIES TO SCROLLER.KV class ScrollerApp(App): def build(self): self.load_kv('Scroller.kv') x = TheBox() x.update() Clock.schedule_interval(x.update, 10) return(x) # KIVY WINDOW CREATION if __name__ == '__main__': ScrollerApp().run()

Kivy语言



1 个答案:

答案 0 :(得分:0)

在这种相关性上对此并不积极,但似乎有道理。我将Raspberry Pi的GPU内存从64位增加到128MB,现在该应用程序能够以更小的图像间隔间隔成功显示图像。