(2015-12-12, 23:54)ronie Wrote: here you go:
Code:
# import required libraries
import xbmcgui
class Main:
def __init__( self ):
#get the arguments passed to the script
self._parse_argv()
#get the current window
self._get_window()
#get the focussed control
self._get_control()
#add an animation to the control
self._set_anim()
def _parse_argv( self ):
#split arguments by delimiters and add them to a dict
try:
params = dict( arg.split( '=' ) for arg in sys.argv[ 1 ].split( '&' ) )
#catch exception in case no arguments are provided
except:
params = {}
#get the transaction argument and fall back to 'window' if none provided
self.transition = params.get( 'transition', 'window' )
#get the time parameter and fall back to 3000 if none provided
self.time = params.get( 'time', 3000 )
def _get_window( self ):
#get the window id
if self.transition == 'window':
wid = xbmcgui.getCurrentWindowId()
#or get the dialog id
else:
wid = xbmcgui.getCurrentWindowDialogId()
#get the window
self.win = xbmcgui.Window(wid)
def _get_control( self ):
#get the id of the focussed control
cid = self.win.getFocusId()
#get the control
self.ctrl = self.win.getControl(cid)
#get posx
self.ctrl_x = self.ctrl.getX()
#get posy
self.ctrl_y = self.ctrl.getY()
#get width
self.ctrl_width = self.ctrl.getWidth()
#get height
self.ctrl_heigth = self.ctrl.getHeight()
def _set_anim( self ):
#calcutate the center of the control
centerx= int(self.ctrl_x + self.ctrl_width/2)
centery= int(self.ctrl_y + self.ctrl_heigth/2)
#add an animation to the control
self.ctrl.setAnimations([('conditional', 'effect=zoom start=100 end=500 center=%i,%i time=%i condition=true' % (centerx, centery, int(self.time)),)])
#entry point of the script
if ( __name__ == "__main__" ):
#init the main class
Main()
reference manual: http://mirrors.xbmc.org/docs/python-docs...mcgui.html
the proper way to call the script from the skin:
Code:
RunScript(script.whambamyourewelcome,transition=window&time=3000)
That *kind of* does what I'm looking for. It doesn't seem to respect the window/dialog variable, and complains about no window with that ID existing. I skipped the variable temporarily and just told it that self.win = xbmcgui.getCurrentWindow(). Now that I'm reading over it again, maybe it just needs to be self.win = wid?
Either way, I change that. Then, it will make the entire grouplist zoom forward, centered on the x/y of the entire grouplist.
What I need it to do is take another png (circle-512.png), create an image control of that. Color it to a specific color which I can pass in. Make it draw on the center x/y of the focused
listitem being clicked/selected, and expand to fill the whole screen.
I did some changes and came up with the following, which doesn't really work:
Code:
# import required libraries
import os
import xbmc
import xbmcgui
import xbmcaddon
_ADDON_NAME = 'script.leanbackhelper'
_addon = xbmcaddon.Addon(id=_ADDON_NAME)
_addon_path = _addon.getAddonInfo('path')
try:
_images = os.path.join(_addon_path, 'textures')
except TypeError:
# Needed for unit testing with xbmcstubs
_images = os.path.join(os.path.dirname(__file__), 'textures')
class Main:
def __init__( self ):
#get the arguments passed to the script
self._parse_argv()
#get the current window
self._get_window()
#get the focussed control
self._get_control()
#create an image
self._set_image()
def _parse_argv( self ):
#split arguments by delimiters and add them to a dict
try:
params = dict( arg.split( '=' ) for arg in sys.argv[ 1 ].split( '&' ) )
#catch exception in case no arguments are provided
except:
params = {}
#get the transaction argument and fall back to 'window' if none provided
self.transition = params.get( 'transition', 'window' )
#get the time parameter and fall back to 3000 if none provided
self.time = params.get( 'time', 3000 )
def _get_window( self ):
#get the window id
self.win = xbmcgui.Window (xbmcgui.getCurrentWindowId())
def _get_control( self ):
#get the id of the focused control
cid = self.win.getFocusId()
#get the control
self.ctrl = self.win.getControl(cid)
#get the listitem
self.listitem = self.ctrl.getSelectedItem()
#get posx
self.ctrl_x = self.ctrl.getX()
#get posy
self.ctrl_y = self.ctrl.getY()
#get width
self.ctrl_width = self.ctrl.getWidth()
#get height
self.ctrl_heigth = self.ctrl.getHeight()
def _set_image( self):
centerx= int(self.ctrl_x + self.ctrl_width/2)
centery= int(self.ctrl_y + self.ctrl_heigth/2)
self.anim_img = os.path.join(_images, 'Circle-512.png')
self.image = xbmcgui.ControlImage (centerx, centery, 20, 20, self.anim_img, aspectRatio=2)
#add an animation to the control
self.image.setAnimations([('conditional', 'effect=zoom start=100 end=5000 center=%i,%i time=%i condition=true' % (centerx, centery, int(self.time)),)])
self.win.addControl(self.image)
#entry point of the script
if ( __name__ == "__main__" ):
#init the main class
Main()
So, is successful in getting some x/y coords and drawing a 20x20 white circle on those coords. It looks like it's always at 600,370 in the screen grid...
The container I'm testing this on is itself in a grouplist, which may be part of the issue. But, if I run the command from a regular old button which sits at about 750,750 on the screen, it will draw the white circle at 190,880 on the screen.
Point being, it doesn't quite make sense to me where these coordinates are coming from. I'm not sure if the script is using their positions before they're animated by a grouplist or window open transition or what, but it seems odd.
Also, what would be the trick to logging the calculated coords, or anything else? I tried just doing a log(self.center_x) or adding a message in ''s before, but it throws an error...