/// <summary> /// Returns a thumb cache filename. /// </summary> /// <param name="path"></param> /// <returns></returns> public static string getCacheThumbName(string path) { return(PythonInterop.CallFunction( new PyFunction(PyModule.Xbmc, "getCacheThumbName"), path )); }
public static void Add(IList <ListItem> items) { var list = PyVariableManager.NewVariable(); string listCode = "["; for (int i = 0; i < items.Count; i++) { listCode += string.Format("({0},{1},{2})", PythonInterop.EscapeArgument(items[i].Url), items[i].Instance.PyName, items[i].IsFolder ); if (i + 1 < items.Count) { listCode += ","; } } listCode += "]"; PyVariable listVar = PyVariableManager.NewVariable(flags: PyVariableFlags.Object); listVar.Value = listCode; PythonInterop.CallFunction( new PythonFunction(PyModule.XbmcPlugin, "addDirectoryItems"), new List <object> { KodiBridge.RunningAddon.Handle, listVar, items.Count } ); }
/// <summary> /// Returns a legal filename or path as a string. /// </summary> /// <param name="filename"></param> /// <param name="fatX"></param> /// <returns></returns> public static string makeLegalFilename(string filename, bool fatX = false) { return(PythonInterop.CallFunction( new PyFunction(PyModule.Xbmc, "makeLegalFilename"), filename, fatX )); }
/// <summary> /// Calls the specified function and assigns the result to this variable /// </summary> /// <param name="function"></param> /// <param name="arguments"></param> /// <param name="escapeMethod"></param> /// <returns></returns> public dynamic CallAssign( PyFunction function, List <object> arguments = null, EscapeFlags escapeMethod = EscapeFlags.Quotes | EscapeFlags.StripNullItems, PyVariable target = null ) { string argumentsText = ""; if (arguments != null) { List <string> textArguments = PythonInterop.EscapeArguments(arguments, escapeMethod); argumentsText = string.Join(", ", textArguments); } if (target == null) { target = this; } PythonInterop.EvalToVar(target, "{0}({1})", new List <object> { function.ToString(), argumentsText }, EscapeFlags.None); return(this.Value); }
public static void StartAndroidActivity( string package, string intent = null, string dataType = null, string dataUri = null ) { List <string> arguments = new List <string> { package }; if (intent != null) { arguments.Add(intent); } if (dataType != null) { arguments.Add(dataType); } if (dataType != null) { arguments.Add(dataType); } PythonInterop.CallBuiltin("StartAndroidActivity", arguments); }
public bool Remove(string key) { key = PythonInterop.EscapeArgument(key, EscapeFlags.Quotes); PythonInterop.Eval($"del {Instance.PyName}[{key}]"); Keys.Remove(key); return(!ContainsKey(key)); }
/// <summary> /// Returns the validated path. /// </summary> /// <param name="path"></param> /// <returns></returns> public static string validatePath(string path) { return(PythonInterop.CallFunction( new PyFunction(PyModule.Xbmc, "validatePath"), path )); }
/// <summary> /// Runs the python script. /// You must specify the full path to the script. /// As of 2007/02/24, all extra parameters are passed to the script as arguments and can be accessed by python using sys.argv /// </summary> /// <param name="script"> the URL to the python script. </param> /// <param name="args"></param> public static void RunScript(string script, params object[] args) { object[] builtinArgs = new object[args.Length + 1]; builtinArgs[0] = script; Array.Copy(args, 0, builtinArgs, 1, args.Length); PythonInterop.CallBuiltin("RunScript", script, args); }
/// <summary> /// Executes the specified script given its addon-id /// </summary> /// <param name="addonId">the addon-ID to the script add-on</param> /// <param name="args"></param> public static void RunScript(int addonId, params object[] args) { object[] builtinArgs = new object[args.Length + 1]; builtinArgs[0] = addonId; Array.Copy(args, 0, builtinArgs, 1, args.Length); PythonInterop.CallBuiltin("RunScript", addonId, args); }
public string ToPythonCode() { return(string.Format("({0},{1},{2})", PythonInterop.EscapeArgument(Url), Instance.PyName, IsFolder )); }
public static void StartAndroidActivity( string package, string intent = null, string dataType = null, string dataUri = null ) { PythonInterop.CallBuiltin("StartAndroidActivity", package, intent, dataType, dataUri); }
/// <summary> /// Returns the validated path. /// </summary> /// <param name="path"></param> /// <returns></returns> public static string validatePath(string path) { return(PythonInterop.CallFunction( new PythonFunction(PyModule.Xbmc, "validatePath"), new List <object> { path } )); }
/// <summary> /// Returns a thumb cache filename. /// </summary> /// <param name="path"></param> /// <returns></returns> public static string getCacheThumbName(string path) { return(PythonInterop.CallFunction( new PythonFunction(PyModule.Xbmc, "getCacheThumbName"), new List <object> { path } )); }
public string CallFunction( PythonFunction function, string argumentsBody ) { return(PythonInterop.EvalToResult(string.Format("{0}.{1}({2})", this.PyName, function.Function, argumentsBody )).Value); }
public PyVariable GetVariable(string name) { string pyName = PythonInterop.EscapeArgument(name); return(new PyVariable( evalCode: $"{Instance.PyName}[{pyName}]", basename: name )); }
public static void Show(bool succeded = true, bool updateListing = false, bool cacheToDisc = true) { PythonInterop.CallFunction( new PythonFunction(PyModule.XbmcPlugin, "endOfDirectory"), new List <object> { KodiBridge.RunningAddon.Handle, succeded, updateListing, cacheToDisc } ); }
/// <summary> /// Pops up a keyboard dialog and allows the user to input a string which can be used in a label control elsewhere in the skin /// via the info tag Skin.String(string) /// </summary> /// <param name="value">If specified the keyboard dialog does not pop up and the string is set directly.</param> public static void SetString(string setting, object value = null) { List <object> arguments = new List <object> { setting }; if (value != null) { arguments.Add(value); } PythonInterop.CallBuiltin("Skin.SetString", arguments); }
/// <summary> /// Pops up a keyboard dialog and allows the user to input a numerical. /// </summary> /// <param name="value">If specified the keyboard dialog does not pop up and the numeric value is set directly.</param> public static void SetNumeric(object number, object value) { List <object> arguments = new List <object> { number }; if (value != null) { arguments.Add(value); } PythonInterop.CallBuiltin("Skin.SetNumeric", arguments); }
public static void Add(ListItem item) { PythonInterop.CallFunction( new PythonFunction(PyModule.XbmcPlugin, "addDirectoryItem"), new List <object> { KodiBridge.RunningAddon.Handle, item.Url, item.Instance, item.IsFolder } ); }
/// <summary> /// Pops up a folder browser and allows the user to select a folder of images to be used in a multi image control else where in the skin /// via the info tag Skin.String(string). /// </summary> /// <param name="folderpath">If specified the file browser will start in that folder</param> public static void SetPath(string setting, string folderpath = null) { List <string> arguments = new List <string> { setting }; if (folderpath != null) { arguments.Add(folderpath); } PythonInterop.CallBuiltin("Skin.SetPath", arguments); }
/// <summary> /// Takes a Screenshot. Only .png files are supported /// </summary> /// <param name="filenameAndPath">filename (including the path)</param> /// <param name="sync">whether to run synchronously</param> public static void TakeScreenshot(string filenameAndPath = null, bool?sync = null) { List <object> arguments = new List <object>(); if (filenameAndPath != null) { arguments.Add(filenameAndPath); } if (sync != null) { arguments.Add(sync); } PythonInterop.CallBuiltin("TakeScreenshot", arguments); }
public string CallFunction( PythonFunction function, List <object> arguments = null, EscapeFlags escapeMethod = EscapeFlags.Quotes | EscapeFlags.StripNullItems ) { if (arguments == null) { arguments = new List <object>(); } List <string> textArguments = PythonInterop.EscapeArguments(arguments, escapeMethod); return(CallFunction(function, string.Join(", ", textArguments))); }
public dynamic CallFunction( PyFunction function, string argumentsBody, PyVariable target = null ) { if (target == null) { target = PyVariableManager.LastResult; } return((PythonInterop.EvalToVar(target, string.Format("{0}.{1}({2})", this.PyName, function.Function, argumentsBody ))).Value); }
public string this[string key] { get { return(Instance.CallFunction("get", new List <object>() { key })); } set { string pyVal = PythonInterop.EscapeArgument(value); GetVariable(key).EvalAssign(pyVal); } }
public static string ToPythonCode <TKey, TValue>(this IDictionary <TKey, TValue> dict) { StringBuilder sb = new StringBuilder("{"); foreach (TKey key in dict.Keys) { sb.Append(string.Format("{0}:{1}", PythonInterop.EscapeArgument(key), PythonInterop.EscapeArgument(dict[key]) )); sb.Append(","); } sb.Length--; //remove last ',' sb.Append("}"); return(sb.ToString()); }
public static void Add(IList <ListItem> items) { var list = PyVariableManager.Get.NewVariable(); string listCode = items.ToPythonCode(); using (PyVariable listVar = PyVariableManager.Get.NewVariable(evalCode: listCode)) { PythonInterop.CallFunction( new PyFunction(PyModule.XbmcPlugin, "addDirectoryItems"), new List <object> { KodiBridge.RunningAddon.Handle, listVar, items.Count } ); } }
public dynamic CallFunction( PyFunction function, List <object> arguments = null, EscapeFlags escapeMethod = EscapeFlags.Quotes | EscapeFlags.StripNullItems, PyVariable target = null ) { if (arguments == null) { arguments = new List <object>(); } List <string> textArguments = PythonInterop.EscapeArguments(arguments, escapeMethod); return(CallFunction(function, string.Join(", ", textArguments), target: target)); }
/// <summary> /// Will display a notification dialog with the specified header and message /// </summary> /// <param name="header"></param> /// <param name="message"></param> /// <param name="duration">length of time in milliseconds</param> /// <param name="iconPath">icon image</param> public static void Notification(string header = "", string message = "", TimeSpan?duration = null, string iconPath = null) { List <string> arguments = new List <string> { header, message }; if (duration != null) { arguments.Add(duration.Value.TotalMilliseconds.ToString()); } if (iconPath != null) { arguments.Add(iconPath); } PythonInterop.CallBuiltin("Notification", arguments); }
public static string ToPythonCode(this ICollection <string> array) { StringBuilder sb = new StringBuilder("["); var iter = array.GetEnumerator(); while (iter.MoveNext()) { string value = PythonInterop.EscapeArgument(iter.Current.ToString()); sb.Append(value + ","); } sb.Length--; sb.Append("]"); return(sb.ToString()); }
/// <summary> /// Pops up a file browser and allows the user to select an image file to be used in an image control elsewhere in the skin /// via the info tag Skin.String(string). /// </summary> /// <param name="value">If specified the keyboard dialog does not pop up and the image path is set directly.</param> /// <param name="folderpath">If specified the file browser will start in that folder</param> public static void SetImage(string setting, object value = null, string folderpath = null) { List <object> arguments = new List <object> { setting }; if (value != null) { arguments.Add(value); } if (folderpath != null) { arguments.Add(folderpath); } PythonInterop.CallBuiltin("Skin.SetImage", arguments); }