def notify(self, msg='', title=None, delay=5000, image=''): '''Displays a temporary notification message to the user. If title is not provided, the plugin name will be used. To have a blank title, pass '' for the title argument. The delay argument is in milliseconds. ''' if not msg: log.warning('Empty message for notification dialog') if title is None: title = self.addon.getAddonInfo('name') xbmc.executebuiltin('XBMC.Notification("%s", "%s", "%s", "%s")' % (msg, title, delay, image))
def notify(self, msg='', title=None, delay=5000, image=''): '''Displays a temporary notification message to the user. If title is not provided, the plugin name will be used. To have a blank title, pass '' for the title argument. The delay argument is in milliseconds. ''' if not msg: log.warning('Empty message for notification dialog') if title is None: title = self.addon.getAddonInfo('name') xbmc.executebuiltin('XBMC.Notification("%s", "%s", "%s", "%s")' % (msg, title, delay, image))
def get_setting(self, key, converter=None, choices=None): '''Returns the settings value for the provided key. If converter is str, unicode, bool or int the settings value will be returned converted to the provided type. If choices is an instance of list or tuple its item at position of the settings value be returned. .. note:: It is suggested to always use unicode for text-settings because else xbmc returns utf-8 encoded strings. :param key: The id of the setting defined in settings.xml. :param converter: (Optional) Choices are str, unicode, bool and int. :param converter: (Optional) Choices are instances of list or tuple. Examples: * ``plugin.get_setting('per_page', int)`` * ``plugin.get_setting('password', unicode)`` * ``plugin.get_setting('force_viewmode', bool)`` * ``plugin.get_setting('content', choices=('videos', 'movies'))`` ''' #TODO: allow pickling of settings items? # TODO: STUB THIS OUT ON CLI value = self.addon.getSetting(id=key) if converter is str: return value elif converter is unicode: return value.decode('utf-8') elif converter is bool: return value == 'true' elif converter is int: return int(value) elif isinstance(choices, (list, tuple)): return choices[int(value)] elif converter is None: log.warning('No converter provided, unicode should be used, ' 'but returning str value') return value else: raise TypeError('Acceptable converters are str, unicode, bool and ' 'int. Acceptable choices are instances of list ' ' or tuple.')
def get_setting(self, key, converter=None, choices=None): '''Returns the settings value for the provided key. If converter is str, unicode, bool or int the settings value will be returned converted to the provided type. If choices is an instance of list or tuple its item at position of the settings value be returned. .. note:: It is suggested to always use unicode for text-settings because else xbmc returns utf-8 encoded strings. :param key: The id of the setting defined in settings.xml. :param converter: (Optional) Choices are str, unicode, bool and int. :param converter: (Optional) Choices are instances of list or tuple. Examples: * ``plugin.get_setting('per_page', int)`` * ``plugin.get_setting('password', unicode)`` * ``plugin.get_setting('force_viewmode', bool)`` * ``plugin.get_setting('content', choices=('videos', 'movies'))`` ''' #TODO: allow pickling of settings items? # TODO: STUB THIS OUT ON CLI value = self.addon.getSetting(id=key) if converter is str: return value elif converter is unicode: return value.decode('utf-8') elif converter is bool: return value == 'true' elif converter is int: return int(value) elif isinstance(choices, (list, tuple)): return choices[int(value)] elif converter is None: log.warning('No converter provided, unicode should be used, ' 'but returning str value') return value else: raise TypeError('Acceptable converters are str, unicode, bool and ' 'int. Acceptable choices are instances of list ' ' or tuple.')
def add_to_playlist(self, items, playlist='video'): '''Adds the provided list of items to the specified playlist. Available playlists include *video* and *music*. ''' playlists = {'music': 0, 'video': 1} assert playlist in playlists.keys(), ('Playlist "%s" is invalid.' % playlist) selected_playlist = xbmc.PlayList(playlists[playlist]) _items = [] for item in items: if not hasattr(item, 'as_xbmc_listitem'): if 'info_type' in item.keys(): log.warning('info_type key has no affect for playlist ' 'items as the info_type is inferred from the ' 'playlist type.') # info_type has to be same as the playlist type item['info_type'] = playlist item = resources.lib.xbmcswift2b.ListItem.from_dict(**item) _items.append(item) selected_playlist.add(item.get_path(), item.as_xbmc_listitem()) return _items
def add_to_playlist(self, items, playlist='video'): '''Adds the provided list of items to the specified playlist. Available playlists include *video* and *music*. ''' playlists = {'music': 0, 'video': 1} assert playlist in playlists.keys(), ('Playlist "%s" is invalid.' % playlist) selected_playlist = xbmc.PlayList(playlists[playlist]) _items = [] for item in items: if not hasattr(item, 'as_xbmc_listitem'): if 'info_type' in item.keys(): log.warning('info_type key has no affect for playlist ' 'items as the info_type is inferred from the ' 'playlist type.') # info_type has to be same as the playlist type item['info_type'] = playlist item = resources.lib.xbmcswift2b.ListItem.from_dict(**item) _items.append(item) selected_playlist.add(item.get_path(), item.as_xbmc_listitem()) return _items