Advertisement
Guest User

PythonClass

a guest
Sep 1st, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.25 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import os
  5.  
  6. from xbmc import executebuiltin
  7. from xbmc import sleep
  8. from xbmc import getLocalizedString
  9. from xbmc import Player
  10. from xbmc import getInfoLabel
  11.  
  12. from xbmcgui import WindowXML
  13. from xbmcgui import ListItem
  14.  
  15. from xbmcgui import ACTION_PREVIOUS_MENU
  16. from xbmcgui import ACTION_NAV_BACK
  17. from xbmcgui import KEY_ASCII
  18. from xbmcgui import KEY_UNICODE
  19.  
  20. class SearchWindow(WindowXML):
  21.     def __init__(self, xmlFilename, scriptPath, library=None, defaultSkin='PromoTV', defaultRes='720p'):
  22.         super(SearchWindow, self).__init__(xmlFilename, scriptPath, defaultSkin, defaultRes)
  23.         self.__library = library
  24.         self.__list = None
  25.  
  26.     def setDefaultFocus(self):
  27.         self.setFocus(self.getControl(10))
  28.  
  29.     def onInit(self):
  30.         self.__edit = self.getControl(10)
  31.         self.__list = self.getControl(80)
  32.  
  33. #    def onAction(self, action):
  34. #        if (action == ACTION_PREVIOUS_MENU) or (action == ACTION_NAV_BACK):
  35. #            print 'CLOSED FOCUS'
  36. #            #if self.getFocusId() != 20:
  37. #            self.setFocusId(11)
  38. #            #self.removeControl(self.getControl(31))
  39. #            print 'CLOSED ABOUT'
  40. #            self.close()
  41. #            print 'CLOSED ALL'
  42.                                
  43.     def onClick(self, control):
  44.         if control == 61:
  45.             if getInfoLabel('Skin.String(numeric)') != 'true':
  46.                 executebuiltin('Skin.SetString(numeric, true)')
  47.                 self.setFocusId(61)
  48.             else:
  49.                 executebuiltin('Skin.SetString(numeric, false)')
  50.                 self.setFocusId(61)
  51.         elif control == 11:
  52.             print 'BEGIN START'
  53.             self.search()
  54.             print 'SEARCH ENDED'
  55.         elif control == 80:
  56.             item = self.getControl(control).getSelectedItem()
  57.             path = item.getProperty('path')
  58.             Player().play(path, item)
  59.             if self.getControl(control).getSelectedItem().getProperty('type') == "audio":
  60.                 executebuiltin('Action(fullscreen)')
  61.  
  62.     def search(self):
  63.         self.__list.reset()
  64.         search_text = self.getControl(10).getText()
  65.        
  66.         results = self.__library.librarySearch(search_text)
  67.         for movie in results['movies']:
  68.             title, path = movie
  69.             type_ = "video"
  70.             self.__list.addItem(self.createListItem(title, 'DefaultMovies.png', path, type_))
  71.         for tvshow in results['tvshows']:
  72.             title, path = tvshow
  73.             type_ = "video"
  74.             self.__list.addItem(self.createListItem(title, 'DefaultTvShows.png', path, type_))
  75.         for musicvideo in results['musicvideos']:
  76.             title, path = musicvideo
  77.             type_ = "video"
  78.             self.__list.addItem(self.createListItem(title, 'DefaultMusicVideos.png', path, type_))
  79.         for song in results['songs']:
  80.             title, path = song
  81.             type_ = "audio"
  82.             self.__list.addItem(self.createListItem(title, 'DefaultMusicSongs.png', path, type_))
  83.  
  84.     def createListItem(self, label, icon, path, type_):
  85.         item = ListItem(label, iconImage=icon, thumbnailImage=icon)
  86.         item.setProperty('path', path)
  87.         item.setProperty('type', type_)
  88.         return item
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement