示例#1
0
 public bool Remove(string key)
 {
     key = PythonInterop.EscapeArgument(key, EscapeFlags.Quotes);
     PythonInterop.Eval($"del {Instance.PyName}[{key}]");
     Keys.Remove(key);
     return(!ContainsKey(key));
 }
示例#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
 public string ToPythonCode()
 {
     return(string.Format("({0},{1},{2})",
                          PythonInterop.EscapeArgument(Url),
                          Instance.PyName,
                          IsFolder
                          ));
 }
示例#4
0
        public PyVariable GetVariable(string name)
        {
            string pyName = PythonInterop.EscapeArgument(name);

            return(new PyVariable(
                       evalCode: $"{Instance.PyName}[{pyName}]",
                       basename: name
                       ));
        }
示例#5
0
        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());
        }
示例#7
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());
        }