home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / xbmc-9.11.exe / scripts / AppleMovieTrailers / resources / lib / chooser.py < prev    next >
Encoding:
Python Source  |  2008-09-14  |  3.3 KB  |  82 lines

  1. """
  2. helper module for settings
  3.  
  4. Nuka1195
  5. """
  6.  
  7. import sys
  8. import os
  9. import xbmcgui
  10. import xbmc
  11.  
  12. from utilities import *
  13.  
  14. _ = sys.modules[ "__main__" ].__language__
  15. __scriptname__ = sys.modules[ "__main__" ].__scriptname__
  16. __version__ = sys.modules[ "__main__" ].__version__
  17. __svn_revision__ = sys.modules[ "__main__" ].__svn_revision__
  18.  
  19.  
  20. class GUI( xbmcgui.WindowXMLDialog ):
  21.     """ Settings module: used for changing settings """
  22.     def __init__( self, *args, **kwargs ):
  23.         xbmcgui.WindowXMLDialog.__init__( self, *args, **kwargs )
  24.         self.controlId = 0
  25.         self.base_path = os.path.join( BASE_RESOURCE_PATH, "skins" )
  26.         self.choices = kwargs[ "choices" ]
  27.         self.descriptions = kwargs[ "descriptions" ]
  28.         self.original = kwargs[ "original" ]
  29.         self.selection = kwargs[ "selection" ]
  30.         self.list_control = kwargs[ "list_control" ]
  31.         self.title = kwargs[ "title" ]
  32.         self.doModal()
  33.  
  34.     def onInit( self ):
  35.         self.show_chooser()
  36.  
  37.     def show_chooser( self ):
  38.         self.getControl( 500 ).setLabel( self.title )
  39.         #self.getControl( 502 ).setLabel( _( 231 ) )
  40.         self._setup_list()
  41.         if ( self.list_control == 0 and self.descriptions[ 0 ] == "" ):
  42.             self._get_thumb( self.choices[ self.getControl( 503 ).getSelectedPosition() ] )
  43.  
  44.     def _setup_list( self ):
  45.         xbmcgui.lock()
  46.         self.getControl( 502 ).setVisible( False )
  47.         self.getControl( 503 ).setVisible( self.list_control == 0 )
  48.         self.getControl( 504 ).setVisible( self.list_control == 1 )
  49.         self.getControl( 505 ).setVisible( self.list_control == 0 and self.descriptions[ 0 ] != "" )
  50.         self.getControl( 503 + self.list_control ).reset()
  51.         for count, choice in enumerate( self.choices ):
  52.             listitem = xbmcgui.ListItem( choice, self.descriptions[ count ] )
  53.             self.getControl( 503 + self.list_control ).addItem( listitem )
  54.             if ( count == self.original ):
  55.                 self.getControl( 503 + self.list_control ).selectItem( count )
  56.                 self.getControl( 503 + self.list_control ).getSelectedItem().select( True )
  57.         self.getControl( 503 + self.list_control ).selectItem( self.selection )
  58.         self.setFocus( self.getControl( 503 + self.list_control ) )
  59.         xbmcgui.unlock()
  60.  
  61.     def _get_thumb( self, choice ):
  62.         xbmc.executebuiltin( "Skin.SetString(AMT-chooser-thumbfolder,%s)" % ( os.path.join( self.base_path, choice, "media", "thumbs" ), ) )
  63.         self.getControl( 502 ).setVisible( os.path.isfile( os.path.join( self.base_path, choice, "warning.txt" ) ) )
  64.  
  65.     def _close_dialog( self, selection=None ):
  66.         #xbmc.sleep( 5 )
  67.         self.selection = selection
  68.         self.close()
  69.  
  70.     def onClick( self, controlId ):
  71.         if ( controlId in ( 503, 504, ) ):
  72.             self._close_dialog( self.getControl( controlId ).getSelectedPosition() )
  73.  
  74.     def onFocus( self, controlId ):
  75.         self.controlId = controlId
  76.  
  77.     def onAction( self, action ):
  78.         if ( action in ACTION_CANCEL_DIALOG ):
  79.             self._close_dialog()
  80.         elif ( self.list_control == 0 and self.descriptions[ 0 ] == "" ):
  81.             self._get_thumb( self.choices[ self.getControl( 503 ).getSelectedPosition() ] )
  82.