예제 #1
0
        public static IntPtr ToPython(object value)
        {
            if (value == null)
            {
                return(Py_None);
            }

            PythonObject result = PythonObject.From(value);

            if (result != null)
            {
                return(result);
            }

            if (ClrToPython.ContainsKey(value))
            {
                return((PythonObject)ClrToPython[value]);
            }

            Type        type       = value.GetType();
            PythonClass pythonType = TypeManager.ToPython(type);

            result = pythonType.CreateEmpty();
            Register(value, result);

            return(result);
        }
예제 #2
0
        private void criatabela1_Click(object sender, EventArgs e)
        {
            if (Directory.Exists(pathName.Text))
            {
                Parametros parametros = new Parametros {
                    appname = appName.Text.ToString(), tabela = tableName.Text.ToString(), caminho = pathName.Text.ToString()
                };
                List <Campos> campos = new List <Campos> {
                };

                foreach (DataGridViewRow linha in fields.Rows)
                {
                    if (linha.Cells["nome"].Value != null && linha.Cells["tipo"].Value != null && linha.Cells["format"].Value != null)
                    {
                        campos.Add(new Campos {
                            nome   = linha.Cells["nome"].Value.ToString(),
                            tipo   = linha.Cells["tipo"].Value.ToString(),
                            format = linha.Cells["format"].Value.ToString()
                        });
                    }
                }

                PythonClass.Executa(parametros, campos);
            }
            else
            {
                MessageBox.Show("Caminho inválido");
            }
        }
예제 #3
0
파일: TypeTest.cs 프로젝트: jbatonnet/PyNet
        public void Type()
        {
            string pythonModuleCode = @"class TestType:

    def get_OldProperty(self):
        return 0
    def set_OldProperty(self, value):
        pass

    @property
    def NewProperty(self):
        return 'test'
    @NewProperty.setter
    def NewProperty(self, value):
        pass";

            PythonModule pythonModule = Build(pythonModuleCode);
            PythonClass  pythonClass  = pythonModule.Dictionary.Values.OfType <PythonClass>().First();

            Type clrType = TypeManager.FromPython(pythonClass);

            PropertyInfo oldPropertyInfo = clrType.GetProperty("OldProperty");
            //Assert.IsNotNull(oldPropertyInfo);

            PropertyInfo newPropertyInfo = clrType.GetProperty("NewProperty");

            Assert.IsNotNull(newPropertyInfo);
            Assert.AreEqual(newPropertyInfo.PropertyType, typeof(object));
        }
예제 #4
0
    public static void Initialize(string name)
    {
        Py_NoSiteFlag = true;
        Py_Initialize();

        PythonModule = new PythonModule(name);

        PythonModule.AddFunction(nameof(AddReference), a => AddReference(null, a));
        PythonModule.AddFunction(nameof(Break), a => Break(null, null));

        PythonModule.SetAttribute(nameof(System), new ClrNamespace(nameof(System)));



        ClrClass = new PythonClass("clr");

        ClrClass.AddMethod(nameof(__getattr__), __getattr__);
        ClrClass.AddMethod(nameof(__str__), __str__);

        ClrClass.AddMethod(nameof(AddReference), AddReference);
        ClrClass.AddMethod(nameof(Break), Break);
        //ClrClass.AddMethod("Method", Method);
        //ClrClass.AddProperty("Property", GetProperty, SetProperty);

        ClrObject = ClrClass.Create();

        PythonModule.SetAttribute("clr", ClrObject);
    }
 public IEnumerable <CompletionData> SelfDotCompletionData(PythonClass klass)
 {
     foreach (var attr in klass.Attributes)
     {
         yield return(new CompletionData(attr.Name, s_ImgAttr, attr.Documentation));
     }
     foreach (var func in klass.Functions)
     {
         yield return(new CompletionData(func.Name, s_ImgFunc, func.Documentation));
     }
 }
예제 #6
0
        public override void BuildNode(ITreeBuilder treeBuilder,
                                       object dataObject,
                                       ref string label,
                                       ref Gdk.Pixbuf icon,
                                       ref Gdk.Pixbuf closedIcon)
        {
            PythonClass pyClass = dataObject as PythonClass;

            label = pyClass.Name;
            icon  = Context.GetIcon(MonoDevelop.Ide.Gui.Stock.Class);
        }
        public override bool Walk(ClassDefinition node)
        {
            var klass = new PythonClass()
            {
                Name          = node.Name,
                Region        = GetDomRegion(node),
                Documentation = node.Documentation
            };

            containers.Peek().Classes.Add(klass);
            containers.Push(klass);

            return(base.Walk(node));
        }
예제 #8
0
        public override void BuildChildNodes(ITreeBuilder treeBuilder,
                                             object dataObject)
        {
            PythonClass pyClass = dataObject as PythonClass;

            if (pyClass == null)
            {
                return;
            }

            foreach (PythonAttribute pyAttr in pyClass.Attributes)
            {
                treeBuilder.AddChild(pyAttr);
            }

            foreach (PythonFunction pyFunc in pyClass.Functions)
            {
                treeBuilder.AddChild(pyFunc);
            }
        }
예제 #9
0
 static ClrNamespace()
 {
     Type = new PythonClass("namespace");
     Type.AddMethod("__getattr__", __getattr__);
     Type.AddMethod("__str__", __str__);
 }
예제 #10
0
        public override string GetNodeName(ITreeNavigator thisNode, object dataObject)
        {
            PythonClass pyClass = dataObject as PythonClass;

            return(pyClass.Name);
        }
예제 #11
0
 static ClrExtensionMethod()
 {
     Type = new PythonClass("extension");
     Type.AddMethod("__call__", __call__);
 }
예제 #12
0
 public PythonMember(PythonClass parent)
 {
     this.parent = parent;
 }