HOW-TO:HelloWorld addon: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
>Martijn
>Martijn
Line 13: Line 13:




==Using xbmc modules & JSON-RPC==
==Using xbmc modules & JSON-RPC API==


More info on JSON-RPC API can be found here: [[JSON-RPC_API]]


<source lang="xml">
<source lang="xml">
Line 25: Line 26:
         'params': {
         'params': {
             'image': 'D:\\heartagram.jpg',
             'image': 'D:\\heartagram.jpg',
             'line1': 'Line 1',
             'line1': 'Hello World',
             'line2': 'Line 2',
             'line2': 'Showing this message using',
             'line3': 'Line 3',
             'line3': 'Combination of XBMC python modules and',
             'line4': 'Line 4',
             'line4': 'JSON-RPC API interface',
             'line5': 'Line 5',
             'line5': 'Have fun coding',
         }
         }
     }
     }

Revision as of 09:51, 9 January 2013

Template:DevsHeader

Introduction

This How To will explain several ways on showing a "Hello World" opup on screen

Examples

Using xbmc modules

Using JSON-RPC

Using xbmc modules & JSON-RPC API

More info on JSON-RPC API can be found here: JSON-RPC_API

{
    'jsonrpc': '2.0',
    'id': 0,
    'method': 'Addons.ExecuteAddon',
    'params': {
        'addonid': 'script.popup',
        'params': {
            'image': 'D:\\heartagram.jpg',
            'line1': 'Hello World',
            'line2': 'Showing this message using',
            'line3': 'Combination of XBMC python modules and',
            'line4': 'JSON-RPC API interface',
            'line5': 'Have fun coding',
        }
    }
}


import xbmcgui
import sys
import urlparse

class PopupWindow(xbmcgui.WindowDialog):
    def __init__(self, image, line1, line2, line3, line4, line5):
        self.addControl(xbmcgui.ControlImage(x=25, y=25, width=150, height=150, filename=image[0]))
        self.addControl(xbmcgui.ControlLabel(x=190, y=25, width=500, height=25, label=line1[0]))
        self.addControl(xbmcgui.ControlLabel(x=190, y=50, width=500, height=25, label=line2[0]))
        self.addControl(xbmcgui.ControlLabel(x=190, y=75, width=500, height=25, label=line3[0]))
        self.addControl(xbmcgui.ControlLabel(x=190, y=100, width=500, height=25, label=line4[0]))
        self.addControl(xbmcgui.ControlLabel(x=190, y=125, width=500, height=25, label=line5[0]))

if __name__ == '__main__':
    params = urlparse.parse_qs('&'.join(sys.argv[1:]))
    window = PopupWindow(**params)
    window.show()
    xbmc.sleep(5000)
    window.close()
    del window

See also

Development: