Ad imagefile to XBMC python script
#1
I am fairly new to XBMC script writing so I apologize if this is a ridiculous question. I am having trouble adding a custom picture or image to my xbmc python script. When I place a .png or .jpg into the root folder my script will not load the image when I run the script. The stock pictures that came with the pyxbmct demo work fine. I want to load a picture when I click on a button. Is this possible?
Reply
#2
This sounds like a pyxbmct specific question but I can answer the official recommendation:
Any media should be placed in "your.addon.dir/resources/media/". If you define your own XML-based gui, the media should be placed in the skin subfolder of your addon: "your.addon.dir/resources/skins/default/media/". But in both cases you need absolute paths or XBMC-special paths. Here is a code snippet I use for this:

PHP Code:
addon xbmcaddon.Addon()

ADDON_PATH addon.getAddonInfo('path').decode('utf-8')
MEDIA_PATH os.path.join(
    
xbmc.translatePath(ADDON_PATH),
    
'resources',
    
'skins',
    
'default',
    
'media'
)

def get_image(filename):
    return 
os.path.join(MEDIA_PATHfilename

But again, I have no idea if there is a special or recommended way when using pyxbmct
My GitHub. My Add-ons:
Image
Reply
#3
(2014-03-23, 23:35)sphere Wrote: But again, I have no idea if there is a special or recommended way when using pyxbmct

No special recommendations, a full path to an image file is needed.
Reply
#4
Thank you for the info but I am still troubled. Maybe its my ignorance of programing?? I have saved my .png file in the thumbnail folder in my add-on folder. I then zipped the entire add-on folder and used XBMC to upload the zip file. What am I doing wrong?

[# -*- coding: utf-8 -*-
# Licence: GPL v.3 http://www.gnu.org/licenses/gpl.html
# This is an XBMC addon for demonstrating the capabilities
# and usage of PyXBMCt framework.

import os
import xbmc, xbmcaddon, xbmcgui
from pyxbmct.addonwindow import *

_addon = xbmcaddon.Addon()
_addon_path = _addon.getAddonInfo('path').decode('utf-8')
_media_path = os.path.join(xbmc.translatePath(_addon_path),
'thumbnail')

class MyAddon(AddonDialogWindow):

def __init__(self, title=''):
"""Class constructor"""
# Call the base class' constructor.
super(MyAddon, self).__init__(title)
# Set width, height and the grid parameters
self.setGeometry(600, 400, 10, 3)
# Call set controls method
self.set_controls()
# Call set navigation method.
self.set_navigation()
# Connect Backspace button to close our addon.
self.connect(ACTION_NAV_BACK, self.close)

def set_controls(self):
"""Set up UI controls"""
# Image control
def get_image('slider.png'):
return os.path.join[/php](_media_path, 'slider.png')
self.placeControl(image, 0, 0, rowspan=2, columnspan=2)

# Text label left
label_left = Label('Left Ballast')
self.placeControl(label_left, 2, 0)
# Text label center
label_center = Label('Center Ballast')
self.placeControl(label_center, 2, 1)
# Text label right
label_right = Label('Right Ballast')
self.placeControl(label_right, 2, 2)

# Button Increase Left
self.increasel_buton = Button('Increase')
self.placeControl(self.increasel_buton, 3, 0)
# Button Increase Center
self.increasec_buton = Button('Increase')
self.placeControl(self.increasec_buton, 3, 1)
# Button Increase Left
self.increaser_buton = Button('Increase')
self.placeControl(self.increaser_buton, 3, 2)

# Button Decrease Left
self.decreasel_buton = Button('Decrease')
self.placeControl(self.decreasel_buton, 7, 0)
# Button Decrease Center
self.decreasec_buton = Button('Decrease')
self.placeControl(self.decreasec_buton, 7, 1)
# Button Decrease Right
self.decreaser_buton = Button('Decrease')
self.placeControl(self.decreaser_buton, 7, 2)

# Image control slider
image_a = Image('slider.png')
self.placeControl(image_a, 4, 0, rowspan=1, columnspan=1)
# Image control slider
image_b = Image('slider.png')
self.placeControl(image_b, 5, 0, rowspan=1, columnspan=1)
# Image control slider
image_c = Image('slider.png')
self.placeControl(image_c, 6, 0, rowspan=1, columnspan=1)


# Conect Increase Left Button


# Text edit control
self.name_field = Edit('')
self.placeControl(self.name_field, 8, 2)
# Close button
self.close_button = Button('Close')
self.placeControl(self.close_button, 8, 0)
# Connect close button
self.connect(self.close_button, self.close)
# Hello button.
self.hello_buton = Button('Hello')
self.placeControl(self.hello_buton, 3, 1)
# Connect Hello button.
self.connect(self.hello_buton, lambda:
xbmc.executebuiltin('Notification(Hello %s!, Welcome to PyXBMCt.)' %
self.name_field.getText()))

def set_navigation(self):
"""Set up keyboard/remote navigation between controls."""
self.name_field.controlUp(self.hello_buton)
self.name_field.controlDown(self.hello_buton)
self.close_button.controlLeft(self.hello_buton)
self.close_button.controlRight(self.hello_buton)

self.hello_buton.setNavigation(self.name_field, self.name_field, self.close_button, self.close_button)
# Set initial focus.
self.setFocus(self.name_field)

def slider_update(self):
# Update slider value label when the slider nib moves
try:
if self.getFocus() == self.slider:
self.slider_value.setLabel('%.1f' % self.slider.getPercent())
except (RuntimeError, SystemError):
pass

if __name__ == '__main__':
addon = MyAddon('PyXBMCt Example')
addon.doModal()
]
Reply
#5
Please use proper code tags and formatting or paste your code to pastebin.com. Your code is not readable.
Reply
#6
Roman, sorry about that previous post. I have saved my .png file in the thumbnail folder in my add-on folder. I then zipped the entire add-on folder and used XBMC to upload the zip file. What am I doing wrong?
Where exactly do I need to place my .png file and how do I write my absolute path? Sorry for such an elementary question.
Thanks

Code:
# -*- coding: utf-8 -*-
# Licence: GPL v.3 http://www.gnu.org/licenses/gpl.html
# This is an XBMC addon for demonstrating the capabilities
# and usage of PyXBMCt framework.

import os
import xbmc, xbmcaddon, xbmcgui
from pyxbmct.addonwindow import *

addon = xbmcaddon.Addon()
addon_path = addon.getAddonInfo('path').decode('utf-8')


class MyAddon(AddonDialogWindow):
    
    def __init__(self, title=''):
        """Class constructor"""
        # Call the base class' constructor.
        super(MyAddon, self).__init__(title)
        # Set width, height and the grid parameters
        self.setGeometry(600, 400, 10, 3)
        # Call set controls method
        self.set_controls()
        # Call set navigation method.
        self.set_navigation()
        # Connect Backspace button to close our addon.
        self.connect(ACTION_NAV_BACK, self.close)
        
    def set_controls(self):
        """Set up UI controls"""
        # Image control
        image = Image('slider.png')
        self.placeControl(image, 0, 0, rowspan=2, columnspan=2)

        # Text label left
        label_left = Label('Left Ballast')
        self.placeControl(label_left, 2, 0)
        # Text label center
        label_center = Label('Center Ballast')
        self.placeControl(label_center, 2, 1)
        # Text label right
        label_right = Label('Right Ballast')
        self.placeControl(label_right, 2, 2)

        # Button Increase Left
        self.increasel_buton = Button('Increase')
        self.placeControl(self.increasel_buton, 3, 0)
        # Button Increase Center
        self.increasec_buton = Button('Increase')
        self.placeControl(self.increasec_buton, 3, 1)
        # Button Increase Left
        self.increaser_buton = Button('Increase')
        self.placeControl(self.increaser_buton, 3, 2)

        # Button Decrease Left
        self.decreasel_buton = Button('Decrease')
        self.placeControl(self.decreasel_buton, 7, 0)
        # Button Decrease Center
        self.decreasec_buton = Button('Decrease')
        self.placeControl(self.decreasec_buton, 7, 1)
        # Button Decrease Right
        self.decreaser_buton = Button('Decrease')
        self.placeControl(self.decreaser_buton, 7, 2)

        # Image control slider
        image_a = Image('slider.png')
        self.placeControl(image_a, 4, 0, rowspan=1, columnspan=1)
        # Image control slider
        image_b = Image('slider.png')
        self.placeControl(image_b, 5, 0, rowspan=1, columnspan=1)
        # Image control slider
        image_c = Image('slider.png')
        self.placeControl(image_c, 6, 0, rowspan=1, columnspan=1)

        
        # Conect Increase Left Button
        
        
        # Text edit control
        self.name_field = Edit('')
        self.placeControl(self.name_field, 8, 2)
        # Close button
        self.close_button = Button('Close')
        self.placeControl(self.close_button, 8, 0)
        # Connect close button
        self.connect(self.close_button, self.close)
        # Hello button.
        self.hello_buton = Button('Hello')
        self.placeControl(self.hello_buton, 3, 1)
        # Connect Hello button.
        self.connect(self.hello_buton, lambda:
                     xbmc.executebuiltin('Notification(Hello %s!, Welcome to PyXBMCt.)' %
self.name_field.getText()))
        
    def set_navigation(self):
        """Set up keyboard/remote navigation between controls."""
        self.name_field.controlUp(self.hello_buton)
        self.name_field.controlDown(self.hello_buton)
        self.close_button.controlLeft(self.hello_buton)
        self.close_button.controlRight(self.hello_buton)
  
        self.hello_buton.setNavigation(self.name_field, self.name_field, self.close_button, self.close_button)
        # Set initial focus.
        self.setFocus(self.name_field)

    def slider_update(self):
        # Update slider value label when the slider nib moves
        try:
            if self.getFocus() == self.slider:
                self.slider_value.setLabel('%.1f' % self.slider.getPercent())
        except (RuntimeError, SystemError):
            pass

if __name__ == '__main__':
    addon = MyAddon('PyXBMCt Example')
    addon.doModal()
Reply
#7
(2014-04-01, 21:07)ral6639 Wrote: Where exactly do I need to place my .png file


Basally, wherever you like. It can be a root addon folder or a sub-folder inside it.

Quote:and how do I write my absolute path?

First, you need to get your addon path. getAddonInfo('path') is a preferable method. Then you need to combine a full path, including filename, using Python's os.path.join() function. In fact, the PyXBMCt demo addon does include an example how to use Image control with a path to an image file.
Only one remark: you don't need to decode your addon path to utf-8 if you are using it to create paths to image files to display in your addon.
So instead of
PHP Code:
addon_path addon.getAddonInfo('path').decode('utf-8'
you need to use
PHP Code:
addon_path addon.getAddonInfo('path'

xbmcgui.ControlImage does not accept Windows paths with non-ASCII characters decoded to utf-8. I guess it has its own mechanism of normalizing path encoding on Windows.
Reply
#8
I am still having trouble with this issue. Can you look at my code and provide advice. Thanks


PHP Code:
# -*- coding: utf-8 -*-
# Licence: GPL v.3 http://www.gnu.org/licenses/gpl.html
# This is an XBMC addon for demonstrating the capabilities
# and usage of PyXBMCt framework.

import os
import sys
import time
import xbmc
xbmcaddonxbmcgui
from pyxbmct
.addonwindow import *
from pylibftdi import BitBangDevice



addon 
xbmcaddon.Addon()
addon_path addon.getAddonInfo('path')
image os.path.join(addon_path,'pyxbmct''textures''default')


class 
MyAddon(AddonDialogWindow):
    
    
def __init__(selftitle=''):
        
"""Class constructor"""
        
# Call the base class' constructor.
        
super(MyAddonself).__init__(title)
        
# Set width, height and the grid parameters
        
self.setGeometry(600400103)
        
# Call set controls method
        
self.set_controls()
        
# Call set navigation method.
        
self.set_navigation()
        
# Connect Backspace button to close our addon.
        
self.connect(ACTION_NAV_BACKself.close)

    
        
    
def set_controls(self):
        
"""Set up UI controls"""
        
# Image control
        
image Image('xbmc-slide.png')
        
self.placeControl(image00rowspan=2columnspan=2
Reply
#9
What are these two lines supposed to do?

image = os.path.join(addon_path,'pyxbmct', 'textures', 'default')
...
image = Image('xbmc-slide.png')
Reply
#10
(2014-05-29, 08:27)ral6639 Wrote: I am still having trouble with this issue. Can you look at my code and provide advice. Thanks

Sorry, but I don't understand what you are trying to achieve with this code. At first glance it makes no sense.
Reply
#11
I am still trying to add a image file (.png) to the addon I am creating. I have tried the process you mentioned below but did not have success.


Quote:First, you need to get your addon path. getAddonInfo('path') is a preferable method. Then you need to combine a full path, including filename, using Python's os.path.join() function. In fact, the PyXBMCt demo addon does include an example how to use Image control with a path to an image file.
Only one remark: you don't need to decode your addon path to utf-8 if you are using it to create paths to image files to display in your addon.

I amsure that I am not typing something in correctly. I do not completely understand the os.path.join function. Can I place my image file in the pyxbmct/textures/default folder? Then how to I call this location to load the image? I am currently working on the program in windows but once it has been perfected, I will transfer the addon program to my raspberry pi. Can you provide me an example code of how to perform this task?
Thanks in advance.
Reply
#12
(2014-05-29, 17:46)ral6639 Wrote: I am still trying to add a image file (.png) to the addon I am creating. I have tried the process you mentioned below but did not have success.


Quote:First, you need to get your addon path. getAddonInfo('path') is a preferable method. Then you need to combine a full path, including filename, using Python's os.path.join() function. In fact, the PyXBMCt demo addon does include an example how to use Image control with a path to an image file.
Only one remark: you don't need to decode your addon path to utf-8 if you are using it to create paths to image files to display in your addon.

I amsure that I am not typing something in correctly. I do not completely understand the os.path.join function. Can I place my image file in the pyxbmct/textures/default folder? Then how to I call this location to load the image? I am currently working on the program in windows but once it has been perfected, I will transfer the addon program to my raspberry pi. Can you provide me an example code of how to perform this task?
Thanks in advance.


Sorry, but you do have all answers and examples already, and I cannot add anything to that. PyXBMCt demo does include the example of using an image file in the addon folder. PyXBMCt itself does show how to use texture image files located in addon subfolders.

I understand that you might not be very familiar with Python itself. In that case I would recommend to start with basics and to read some beginner's Python textbook in English or your native language. Personally, I've started from this book: http://www.amazon.com/Learning-Python-Ed...1449355730. IMO it is very good.
Reply

Logout Mark Read Team Forum Stats Members Help
Ad imagefile to XBMC python script0