コード例 #1
0
 /// <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
                ));
 }
コード例 #2
0
        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
            }
                );
        }
コード例 #3
0
 /// <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
                ));
 }
コード例 #4
0
ファイル: PyVariable.cs プロジェクト: blessingshawn/KodiSharp
        /// <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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: PyDict.cs プロジェクト: xiaoxiongnpu/KodiSharp
 public bool Remove(string key)
 {
     key = PythonInterop.EscapeArgument(key, EscapeFlags.Quotes);
     PythonInterop.Eval($"del {Instance.PyName}[{key}]");
     Keys.Remove(key);
     return(!ContainsKey(key));
 }
コード例 #7
0
 /// <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
                ));
 }
コード例 #8
0
ファイル: Addon.cs プロジェクト: xiaoxiongnpu/KodiSharp
        /// <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);
        }
コード例 #9
0
ファイル: Addon.cs プロジェクト: xiaoxiongnpu/KodiSharp
        /// <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);
        }
コード例 #10
0
 public string ToPythonCode()
 {
     return(string.Format("({0},{1},{2})",
                          PythonInterop.EscapeArgument(Url),
                          Instance.PyName,
                          IsFolder
                          ));
 }
コード例 #11
0
ファイル: Android.cs プロジェクト: xiaoxiongnpu/KodiSharp
 public static void StartAndroidActivity(
     string package,
     string intent   = null,
     string dataType = null,
     string dataUri  = null
     )
 {
     PythonInterop.CallBuiltin("StartAndroidActivity", package, intent, dataType, dataUri);
 }
コード例 #12
0
 /// <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
     }
                ));
 }
コード例 #13
0
 /// <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
     }
                ));
 }
コード例 #14
0
ファイル: PyVariable.cs プロジェクト: devna13/KodiSharp
 public string CallFunction(
     PythonFunction function,
     string argumentsBody
     )
 {
     return(PythonInterop.EvalToResult(string.Format("{0}.{1}({2})",
                                                     this.PyName, function.Function, argumentsBody
                                                     )).Value);
 }
コード例 #15
0
        public PyVariable GetVariable(string name)
        {
            string pyName = PythonInterop.EscapeArgument(name);

            return(new PyVariable(
                       evalCode: $"{Instance.PyName}[{pyName}]",
                       basename: name
                       ));
        }
コード例 #16
0
 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
     }
         );
 }
コード例 #17
0
ファイル: Skin.cs プロジェクト: mediabuff/KodiSharp
        /// <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);
        }
コード例 #18
0
ファイル: Skin.cs プロジェクト: mediabuff/KodiSharp
        /// <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);
        }
コード例 #19
0
 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
     }
         );
 }
コード例 #20
0
ファイル: Skin.cs プロジェクト: mediabuff/KodiSharp
        /// <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);
        }
コード例 #21
0
        /// <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);
        }
コード例 #22
0
ファイル: PyVariable.cs プロジェクト: devna13/KodiSharp
        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)));
        }
コード例 #23
0
ファイル: PyVariable.cs プロジェクト: blessingshawn/KodiSharp
        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);
        }
コード例 #24
0
ファイル: PyDict.cs プロジェクト: xiaoxiongnpu/KodiSharp
        public string this[string key]
        {
            get
            {
                return(Instance.CallFunction("get", new List <object>()
                {
                    key
                }));
            }

            set
            {
                string pyVal = PythonInterop.EscapeArgument(value);
                GetVariable(key).EvalAssign(pyVal);
            }
        }
コード例 #25
0
        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());
        }
コード例 #26
0
        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
                }
                    );
            }
        }
コード例 #27
0
ファイル: PyVariable.cs プロジェクト: blessingshawn/KodiSharp
        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));
        }
コード例 #28
0
ファイル: UI.cs プロジェクト: xiaoxiongnpu/KodiSharp
        /// <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);
        }
コード例 #29
0
        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());
        }
コード例 #30
0
ファイル: Skin.cs プロジェクト: mediabuff/KodiSharp
        /// <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);
        }