ironpython

IronPython & WPF: Binding a checkbox's IsChecked property to a class member variable

岁酱吖の 提交于 2019-12-04 13:19:41
I've seen many similar questions on how to get data binding working with a checkbox, but all of the examples I've seen are in C# and I can't seem to make the leap to convert it to IronPython. I have a checkbox defined in a window thusly: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="Test" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <DockPanel> <CheckBox Name="bindtest" IsChecked="{Binding Path

Natural language parser for dates (.NET)?

混江龙づ霸主 提交于 2019-12-04 12:16:17
问题 I want to be able to let users enter dates (including recurring dates) using natural language (eg "next friday", "every weekday"). Much like the examples at http://todoist.com/Help/timeInsert I found this post, but it's a bit old and offered only one solution that I'm not entirely content with. I thought I'd resurrect this question and see: are there any other .NET libraries out there that do this kind of date parsing? 回答1: I know it's not an optimal solution but you can also try to port the

Python .net framework reference argument Double[]&

≡放荡痞女 提交于 2019-12-04 10:55:31
Using the Python for .Net framework I'm trying to call a method from a C# .dll file. This method has the following arguments: public static void ExternalFunction( String Arg1, ref Double[]& Arg2, ); I understood the .Net framework converts Python floats to doubles. Now I would like to know how to make an array (double) and pass this as a reference to the external method. I've the following code: import clr clr.AddReference("MyDll") from MyLib import MyClass myName = "Benjamin" r = MyClass.ExternalFunction(myName, 0.0); print "Result: %s"%r You can call this method by providing a list (or tuple

Setting and getting variables in .Net hosted IronPython script

♀尐吖头ヾ 提交于 2019-12-04 10:48:52
I'm trying to prototype a validation rules engine using IronPython hosted in a .Net console application. I've stripped the script right down to what I believe is the basics var engine = Python.CreateEngine(); engine.Execute("from System import *"); engine.Runtime.Globals.SetVariable("property_value", "TB Test"); engine.Runtime.Globals.SetVariable("result", true); var sourceScope = engine.CreateScriptSourceFromString("result = property_value != None and len(property_value) >= 3"); sourceScope.Execute(); bool result = engine.Runtime.Globals.GetVariable("result"); engine.Runtime.Shutdown(); It

How do I bind to a ListBox in IronPython?

人盡茶涼 提交于 2019-12-04 10:41:11
I am just starting out using IronPython with WPF and I don't quiet understand how binding is supposed to be done. Normally in WPF I would just do something like this: <ListBox Name="MyListBox"> <ListBox.Resources> <Style TargetType="ListBoxItem"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <DockPanel> <TextBlock Text="{Binding Path=From}" /> <TextBlock Text="{Binding Path=Subject}" /> </DockPanel> </DataTemplate> </Setter.Value> </Setter> </Style> </ListBox.Resources> </ListBox> Then in my code behind: MyListBox.ItemsSource = new ObservableCollection<Email>() But in

BOO Vs IronPython

爱⌒轻易说出口 提交于 2019-12-04 10:11:37
问题 What is the difference between IronPython and BOO? Is there a need for 2 Python-like languages? 回答1: IronPython is designed to be a faithful implementation of Python on the .NET platform. Version 1 targets Python 2.4 for compatibility, and version 2 targets version 2.5 (although most of the Python standard library modules implemented in C aren't supported). Boo's stated aim is to be a "wrist-friendly [dynamic] language for the CLI." It takes a lot of inspiration from Python, but diverges on

Embedding IronPython in a C# application - import error on urllib

拥有回忆 提交于 2019-12-04 10:01:02
I have a Python file with as content: import re import urllib class A(object): def __init__(self, x): self.x = x def getVal(self): return self.x def __str__(self): return "instance of A with value '%s'" % (self.getVal()) I also have a simple C# console project with the following code: engine = Python.CreateEngine(); ScriptSource source = engine.CreateScriptSourceFromFile("test.py"); ScriptScope scope = engine.CreateScope(); ObjectOperations op = engine.Operations; source.Execute(scope); // class object created object klaz = scope.GetVariable("A"); // get the class object object instance = op

Why can't I import my C# type into IronPython?

你。 提交于 2019-12-04 09:33:03
I have some types in a C# library I wrote, e.g.: namespace SprocGenerator.Generators { public class DeleteGenerator : GeneratorBase { public DeleteGenerator(string databaseName, string tableName) : base(databaseName, tableName) I want to use them in an IronPython script: import clr import sys clr.AddReferenceToFile("SprocGenerator.dll") # problem happens here: from SprocGenerator.Generators import * generator = DeleteGenerator("a", "b") When the line below the comment happens, I get: ImportError: No module named Generators I have verified that the file I am loading is what I expect by renaming

Use Python alongside C# in Windows UWP app

怎甘沉沦 提交于 2019-12-04 07:35:15
I started writing an application in Python, but I now want to switch to C# and UWP. I know that you cannot write a UWP app in Python, but I am trying to see if I can write some code in Python and access that code from C#. For example, writing a class in Python that C# code can access as well. Is that possible? And if so, can Python access Microsoft's UWP APIs? The main code will not be written in Python; that would be impossible. But can interoperability between C# and Python exist, perhaps with IronPython (.NET's Python)? And how would I set up such a Visual Studio project? I have Python

Python equivalent to C#'s using statement [duplicate]

天大地大妈咪最大 提交于 2019-12-04 06:21:18
Possible Duplicate: What is the equivalent of the C# “using” block in IronPython? I'm writing some IronPython using some disposable .NET objects, and wondering whether there is a nice "pythonic" way of doing this. Currently I have a bunch of finally statements (and I suppose there should be checks for None in each of them too - or will the variable not even exist if the constructor fails?) def Save(self): filename = "record.txt" data = "{0}:{1}".format(self.Level,self.Name) isf = IsolatedStorageFile.GetUserStoreForApplication() try: isfs = IsolatedStorageFileStream(filename, FileMode.Create,