2014-01-11 5 views
3

나는 내 자신의 파이썬 스크립트로 4 개의 이미지를 실행하기 위해 xbmc에서 작업 중이다. 키보드의 왼쪽 화살표를 누를 때 파이썬에서 이미지를 변경하려면 keymap.xml을 사용하여 키보드 컨트롤을 설정했습니다.파이썬에서 이미지를 변경하는 방법

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"> 
     <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>Image 2</description> 
     <posx>307</posx> 
     <posy>7</posy> 
     <width>154</width> 
     <height>95</height> 
     <visible>true</visible> 
     <texture>Image 2.png</texture> 
     <animation effect="fade" start="0" end="100" time="1500">WindowOpen</animation> 
    </control>  

    <control type="image" id="3"> 
     <description>Image 3</description> 
     <posx>460</posx> 
     <posy>7</posy> 
     <width>188</width> 
     <height>95</height> 
     <visible>true</visible> 
     <texture>Image 3.png</texture> 
     <animation effect="fade" start="0" end="100" time="1500">WindowOpen</animation> 
    </control> 

    <control type="image" id="4"> 
     <description>Image 4</description> 
     <posx>648.5</posx> 
     <posy>7</posy> 
     <width>165</width> 
     <height>95</height> 
     <visible>true</visible> 
     <texture>Image 4.png</texture> 
     <animation effect="fade" start="0" end="100" time="1500">WindowOpen</animation> 
    </control> 
</controls> 
</window> 

는 파이썬 스크립트입니다 : 여기

은 내가 사용하는 XML 파일의

import xbmc 
import xbmcgui 
import os 

#get actioncodes from keymap.xml 
ACTION_MOVE_LEFT = 1 
ACTION_MOVE_RIGHT = 2 
ACTION_MOVE_UP = 3 
ACTION_MOVE_DOWN = 4 
ACTION_PREVIOUS_MENU = 10 
ACTION_BACKSPACE = 110 

class MyClass(xbmcgui.WindowXML): 
    def onAction(self, action): 

    if action == ACTION_PREVIOUS_MENU: 
     self.close() 

    if action == ACTION_BACKSPACE: 
     self.close() 


    if action == ACTION_MOVE_LEFT: 
     if os.path.exists(xbmc.translatePath("special://home/addons/script.tvguide/resources/skins/Default/media/Image 2.png")): 
      self.strAction = xbmcgui.ControlLabel(300, 200, 600, 200, '', 'font14', '0xFF00FF00') 
      self.addControl(self.strAction) 
      self.strAction.setLabel('you are pressing on the left button. Now let change the image') 

나는 키보드의 왼쪽 화살표 버튼을 누르면, 내가 만약에 통과 얻을 수 있습니다 문이 이미지로 Image 2.png 존재합니다. 이제 이미지를 이미지 2.png에서 이미지 3.png로 변경하고 싶습니다.

내가 어떻게 할 수 있는지 아는 사람이 있습니까?

답변

1

(XML에 정의 된 ID로) ImageControl을 제어 개체로 가져오고 setImage() 메서드를 사용하여 텍스처를 변경해야합니다.

예제 코드 :

if action == ACTION_MOVE_LEFT: 
    image_control = self.getControl(4) 
    image_control.setImage("special://home/addons/script.tvguide/resources/skins/Default/media/Image 2.png") 

당신은 정말 읽어야합니다 xbmcgui 워드 프로세서 : http://mirrors.xbmc.org/docs/python-docs/12.2-frodo/xbmcgui.html