xbmc if图像显示语句 [英] xbmc if image display statement

查看:109
本文介绍了xbmc if图像显示语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用xml编写的图像列表,并且可以在xbmc上运行它们.

这是xml中的图像列表:

<?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">
       <description>Image1</description>
       <posx>307</posx>
       <posy>7</posy>
       <width>164</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image1_blue.jpg</texturefocus>
       <texturenofocus>image1_yellow.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>

    <control type="image" id="2">
       <description>Image2</description>
       <posx>471</posx>
       <posy>7</posy>
       <width>201</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image2_yellow.jpg</texturefocus>
       <texturenofocus>image2_blue.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>

    <control type="image" id="4">
       <description>Image3</description>
       <posx>671</posx>
       <posy>7</posy>
       <width>177</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image3_yellow.jpg</texturefocus>
       <texturenofocus>image3_blue.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>

    <control type="image" id="6">
       <description>image4</description>
       <posx>848</posx>
       <posy>7</posy>
       <width>176</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image4_yellow.jpg</texturefocus>
       <texturenofocus>image4_blue.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>
</controls>
</window>

我想知道如何在python中为xbmc编写if语句,如果存在包含ID的图像,那么我想知道如何使用ID更改图像?

解决方案

Python随附了xml模块,该模块具有有用的ElementTree,可以满足您的需要.

以下是使用方法的示例:

import xml.etree.ElementTree as ET

filename = 'name_of_the_xml_file.xml'
tree = ET.parse(filename)
root = tree.getroot()
controls = root.find('controls')

for control in controls.findall('control'):
    # Here are the image filenames, focus and nofocus.
    focus = control.find('texturefocus').text
    nofocus = control.find('texturenofocus').text
    print('texturefocus={0}, texturenofocus={1}'.format(focus, nofocus))

进一步阅读: xml.etree.ElementTree文档. >

I have the list of images that I wrote in xml and I can be able to run them on xbmc.

Here is the list of the images in the xml:

<?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">
       <description>Image1</description>
       <posx>307</posx>
       <posy>7</posy>
       <width>164</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image1_blue.jpg</texturefocus>
       <texturenofocus>image1_yellow.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>

    <control type="image" id="2">
       <description>Image2</description>
       <posx>471</posx>
       <posy>7</posy>
       <width>201</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image2_yellow.jpg</texturefocus>
       <texturenofocus>image2_blue.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>

    <control type="image" id="4">
       <description>Image3</description>
       <posx>671</posx>
       <posy>7</posy>
       <width>177</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image3_yellow.jpg</texturefocus>
       <texturenofocus>image3_blue.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>

    <control type="image" id="6">
       <description>image4</description>
       <posx>848</posx>
       <posy>7</posy>
       <width>176</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image4_yellow.jpg</texturefocus>
       <texturenofocus>image4_blue.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>
</controls>
</window>

I want to know how do you write on if statement in python for xbmc that if the image include the id is exist then I want to know how I can change the image using the id?

解决方案

Python comes with the xml module which has the useful ElementTree that will do what you need.

Here's an example of how to use it:

import xml.etree.ElementTree as ET

filename = 'name_of_the_xml_file.xml'
tree = ET.parse(filename)
root = tree.getroot()
controls = root.find('controls')

for control in controls.findall('control'):
    # Here are the image filenames, focus and nofocus.
    focus = control.find('texturefocus').text
    nofocus = control.find('texturenofocus').text
    print('texturefocus={0}, texturenofocus={1}'.format(focus, nofocus))

Further reading: xml.etree.ElementTree documentation.

这篇关于xbmc if图像显示语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆