【发布时间】:2019-08-18 05:22:49
【问题描述】:
我正在调整 kivy 的展示面板。主要有 kv 文件,通过 screenmanager 定义一个单独的屏幕。
我的目标是创建一个屏幕 (DiashowApp),用于启动 kivy 应用轮播 (https://kivy.org/doc/stable/api-kivy.uix.carousel.html)。因此我设置了两个类,加载轮播和显示图像,它们在 kv 文件 (diashowapp.kv) 中定义。
请帮助我运行代码。
问候 斯蒂芬
不要让类运行,带有打印语句的调试例程告诉我,没有执行两个新类的代码。
from time import time
from kivy.app import App
from os.path import dirname, join
from kivy.lang import Builder
from kivy.properties import NumericProperty, StringProperty, BooleanProperty,\
ListProperty
from kivy.clock import Clock
from kivy.animation import Animation
from kivy.uix.screenmanager import Screen
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage
from subprocess import call
import subprocess
from kivy.logger import Logger
import random
Logger.info('title: This is a info message.')
Logger.debug('title: This is a debug message.')
skript_axis_all = "data/screens_axis.sh"
skript_kill_axis = "data/screens_kill_axis.sh"
skript_axis_01 = "data/screens_axis01.sh"
skript_axis_02 = "data/screens_axis02.sh"
skript_axis_03 = "data/screens_axis03.sh"
skript_axis_04 = "data/screens_axis04.sh"
class CarouselApp(Carousel):
def __init__(self, **kwargs):
super(CarouselApp, self).__init__(**kwargs)
self.direction = "right"
bilderliste = []
cmd2 = ['find', '/home/pi/Bilder/', '-maxdepth', '2', '-type', 'f', '-name', '*.JPG']
proc2 = subprocess.Popen(cmd2, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
o2, e2 = proc2.communicate()
#print('Output: ' + o2.decode('utf-8'))
#print('Error: ' + e2.decode('utf-8'))
#print('code: ' + str(proc2.returncode))
o2_zeilen = o2.split('\n')
counter = 0
for zeile2 in o2_zeilen:
bilderliste.append(zeile2.replace('\n',''))
random.shuffle(bilderliste, random.random)
for bildpfad in bilderliste:
if counter < 50:
counter = counter + 1
print(counter)
src = "%s" % bildpfad
print type(bildpfad)
if bildpfad is not None:
print('Bildpfad ist: %s') % src
image = AsyncImage(source = src, keep_ratio = True, allow_stretch = True)
try:
self.add_widget(image)
except Exception:
Logger.exception('Something happened in the add.widget!')
else:
pass
self.loop = True
Clock.schedule_interval(self.load_next, 5)
#print(self.slides)
class ShowcaseScreen(Screen):
fullscreen = BooleanProperty(False)
def add_widget(self, *args):
if 'content' in self.ids:
return self.ids.content.add_widget(*args)
return super(ShowcaseScreen, self).add_widget(*args)
class ShowcaseApp(App):
index = NumericProperty(-1)
current_title = StringProperty()
time = NumericProperty(0)
show_sourcecode = BooleanProperty(False)
sourcecode = StringProperty()
screen_names = ListProperty([])
hierarchy = ListProperty([])
def build(self):
self.title = 'hello world'
Clock.schedule_interval(self._update_clock, 1 / 60.)
self.screens = {}
self.available_screens = sorted([
'CarouselApp', 'Carousel', 'Scatter', 'Cameras'])
self.screen_names = self.available_screens
curdir = dirname(__file__)
self.available_screens = [join(curdir, 'data', 'screens',
'{}.kv'.format(fn).lower()) for fn in self.available_screens]
self.go_next_screen()
carouselapp.kv
ShowcaseScreen:
name: 'CarouselApp'
fullscreen: True
CarouselApp:
预期: 自动旋转的显示屏。
实际: 图片显示正确,手动刷卡也正常。
【问题讨论】:
-
嗨 Stefan,欢迎来到 stackoverflow。请花几分钟阅读how to ask a good question。我不完全确定你在这里实际问的是什么,所以我建议你修改和改进你的问题。
-
你的应用类甚至不是应用类,而是屏幕类。
-
...更改为“class DiashowApp(App)”,但没有效果。我误解了你的评论吗,el3ien?
-
@Stefan 将
Carousel:更改为Diashow: -
@eyllanesc 我将
Carousel:更改为Diashow:,但没有定期 load_next()。
标签: python kivy kivy-language