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 / context_menu.py < prev    next >
Encoding:
Python Source  |  2008-08-09  |  3.6 KB  |  89 lines

  1. """
  2. Context menu module
  3.  
  4. Nuka1195
  5. """
  6.  
  7. import sys
  8. import xbmcgui
  9.  
  10. from utilities import *
  11.  
  12. _ = sys.modules[ "__main__" ].__language__
  13. __scriptname__ = sys.modules[ "__main__" ].__scriptname__
  14. __version__ = sys.modules[ "__main__" ].__version__
  15. __svn_revision__ = sys.modules[ "__main__" ].__svn_revision__
  16.  
  17.  
  18. class GUI( xbmcgui.WindowXMLDialog ):
  19.     def __init__( self, *args, **kwargs ):
  20.         xbmcgui.WindowXMLDialog.__init__( self, *args, **kwargs )
  21.         self.area = kwargs[ "area" ]
  22.         self.labels = kwargs[ "labels" ]
  23.         xbmcgui.lock()
  24.         self.doModal()
  25.  
  26.     def onInit( self ):
  27.         self.show_context_menu()
  28.         xbmcgui.unlock()
  29.  
  30.     def show_context_menu( self ):
  31.         self._hide_buttons()
  32.         self._setup_menu()
  33.         self.setFocus( self.getControl( 1001 ) )
  34.  
  35.     def _hide_buttons( self ):
  36.         for button in range( 1001, 1009 ):
  37.             self.getControl( button ).setVisible( False )
  38.  
  39.     def _setup_menu( self ):
  40.         """ centers the context_menu within an area """
  41.         # get positions and dimensions
  42.         button_height = self.getControl( 1001 ).getHeight()
  43.         button_posx, button_posy = self.getControl( 1001 ).getPosition()
  44.         dialog_width = self.getControl( 997 ).getWidth()
  45.         dialog_top_height = self.getControl( 997 ).getHeight()
  46.         dialog_bottom_height = self.getControl( 999 ).getHeight()
  47.         dialog_top_posx, dialog_top_posy = self.getControl( 997 ).getPosition()
  48.         dialog_middle_posy = self.getControl( 998 ).getPosition()[ 1 ]
  49.         dialog_middle_offsety = dialog_middle_posy - dialog_top_posy
  50.         # calculate position
  51.         button_offsetx = button_posx - dialog_top_posx
  52.         button_offsety = button_posy - dialog_top_posy
  53.         button_gap = 2
  54.         dialog_middle_height = ( ( len( self.labels ) * ( button_height + button_gap ) ) - button_gap ) - 2 * ( dialog_top_height - ( button_posy - dialog_top_posy ) )
  55.         dialog_height = dialog_middle_height + dialog_top_height + dialog_bottom_height
  56.         dialog_posx = int( float( self.area[ 2 ] - dialog_width ) / 2 ) + self.area[ 0 ]
  57.         if ( dialog_posx + dialog_width > 700 ):
  58.             dialog_posx = 700 - dialog_width
  59.         elif ( dialog_posx < 20 ):
  60.             dialog_posx = 20
  61.         dialog_posy = int( float( self.area[ 3 ] - dialog_height ) / 2 ) + self.area[ 1 ]
  62.         button_posx = dialog_posx + button_offsetx
  63.         button_posy = dialog_posy + button_offsety
  64.         # position and size menu
  65.         self.getControl( 998 ).setHeight( dialog_middle_height )
  66.         self.getControl( 997 ).setPosition( dialog_posx, dialog_posy )
  67.         self.getControl( 998 ).setPosition( dialog_posx, dialog_posy + dialog_middle_offsety )
  68.         self.getControl( 999 ).setPosition( dialog_posx, dialog_posy + dialog_middle_offsety + dialog_middle_height )
  69.         # position buttons and set labels
  70.         for button in range( len( self.labels ) ):
  71.             self.getControl( button + 1001 ).setPosition( button_posx, button_posy + ( ( button_height + button_gap ) * button ) )
  72.             self.getControl( button + 1001 ).setLabel( self.labels[ button ] )
  73.             self.getControl( button + 1001 ).setVisible( True )
  74.             self.getControl( button + 1001 ).setEnabled( True )
  75.  
  76.     def _close_dialog( self, selection=None ):
  77.         self.selection = selection
  78.         self.close()
  79.  
  80.     def onClick( self, controlId ):
  81.         self._close_dialog( controlId - 1001 )
  82.  
  83.     def onFocus( self, controlId ):
  84.         pass
  85.  
  86.     def onAction( self, action ):
  87.         if ( action in ( ACTION_CANCEL_DIALOG + ACTION_CONTEXT_MENU ) ):
  88.             self._close_dialog()
  89.