├── .gitignore ├── .nuget ├── nuget.config ├── nuget.exe └── nuget.targets ├── AndroidSample ├── AndroidSample.csproj ├── Assets │ ├── AboutAssets.txt │ └── FlippingGameActivity.py ├── FlippingGameActivity.cs ├── Properties │ └── AssemblyInfo.cs └── Resources │ ├── AboutResources.txt │ ├── Drawable │ └── Icon.png │ ├── Layout │ └── Main.axml │ ├── Resource.Designer.cs │ └── Values │ └── Strings.xml ├── ConsoleGame.py ├── ConsoleSample ├── ConsoleSample.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── FlippingGame ├── FlippingGame.py ├── FlippingGame.pyproj └── __init__.py ├── IronPythonSamples.sln ├── PyGtkSample └── PyGtkSample.py ├── PyWpfSample ├── PyWpfSample.py ├── PyWpfSample.pyproj └── PyWpfSample.xaml ├── README ├── WinFormsSample ├── FlippingGame.Designer.cs ├── FlippingGame.cs ├── FlippingGame.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Resources │ └── ajax-loader.gif ├── WinFormsSample.csproj └── packages.config └── WpfSample ├── App.xaml ├── App.xaml.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── WpfFlippingGame.xaml ├── WpfFlippingGame.xaml.cs ├── WpfSample.csproj └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | *.suo 2 | bin 3 | obj 4 | packages 5 | -------------------------------------------------------------------------------- /.nuget/nuget.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhardy/IronPythonSamples/ccab7c4a12f37296cf18ef42ffea626facdeb4b9/.nuget/nuget.exe -------------------------------------------------------------------------------- /.nuget/nuget.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\..\ 5 | 6 | 7 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) 8 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) 9 | $([System.IO.Path]::Combine($(SolutionDir), "packages")) 10 | 11 | 12 | $(SolutionDir).nuget 13 | packages.config 14 | $(SolutionDir)packages 15 | 16 | 17 | $(NuGetToolsPath)\nuget.exe 18 | "$(NuGetExePath)" 19 | mono --runtime=v4.0.30319 $(NuGetExePath) 20 | 21 | $(TargetDir.Trim('\\')) 22 | 23 | 24 | "" 25 | 26 | 27 | false 28 | 29 | 30 | false 31 | 32 | 33 | $(NuGetCommand) install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)" 34 | $(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols 35 | 36 | 37 | 38 | RestorePackages; 39 | $(BuildDependsOn); 40 | 41 | 42 | 43 | 44 | $(BuildDependsOn); 45 | BuildPackage; 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 57 | 58 | 61 | 62 | 63 | 64 | 66 | 67 | 70 | 71 | -------------------------------------------------------------------------------- /AndroidSample/AndroidSample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {F97F76A2-D298-488B-93B0-C4F93B63ECA5} 9 | {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10 | Library 11 | Properties 12 | AndroidSample 13 | AndroidSample 14 | 512 15 | true 16 | Resources\Resource.Designer.cs 17 | Off 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | True 28 | None 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | False 38 | SdkOnly 39 | 40 | 41 | 42 | bin\Debug\IronPython.dll 43 | 44 | 45 | bin\Debug\IronPython.Modules.dll 46 | 47 | 48 | bin\Debug\Microsoft.Dynamic.dll 49 | 50 | 51 | bin\Debug\Microsoft.Scripting.dll 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | Assets\FlippingGame\FlippingGame.py 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 90 | -------------------------------------------------------------------------------- /AndroidSample/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with you package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); -------------------------------------------------------------------------------- /AndroidSample/Assets/FlippingGameActivity.py: -------------------------------------------------------------------------------- 1 | from AndroidSample import Resource 2 | 3 | class FlippingGameActivity(object): 4 | def __init__(self, main): 5 | self.main = main 6 | self.count = 1 7 | 8 | def OnCreate(self, bundle): 9 | # Set our view from the "main" layout resource 10 | self.main.SetContentView(Resource.Layout.Main); 11 | 12 | self.resultLabel = self.main.FindViewById(Resource.Id.resultLabel) 13 | self.resultLabel.Text = str(self.count) 14 | 15 | # Get our button from the layout resource, 16 | # and attach an event to it 17 | self.flipButton = self.main.FindViewById(Resource.Id.flipButton) 18 | self.flipButton.Click += lambda sender, e: self.button_Click(sender, e) 19 | 20 | def button_Click(self, sender, e): 21 | self.count += 1 22 | self.resultLabel.Text = str(self.count) 23 | -------------------------------------------------------------------------------- /AndroidSample/FlippingGameActivity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Android.App; 4 | using Android.Content; 5 | using Android.Runtime; 6 | using Android.Views; 7 | using Android.Widget; 8 | using Android.OS; 9 | using Microsoft.Scripting.Hosting; 10 | using IronPython.Hosting; 11 | using System.IO; 12 | 13 | namespace AndroidSample { 14 | [Activity(Label = "AndroidSample", MainLauncher = true, Icon = "@drawable/icon")] 15 | public class FlippingGameActivity : Activity { 16 | int count = 1; 17 | 18 | ScriptEngine engine = Python.CreateEngine(); 19 | ScriptScope scope = null; 20 | object shadow; 21 | 22 | public FlippingGameActivity() { 23 | this.scope = this.engine.CreateScope(); 24 | this.engine.Runtime.LoadAssembly(typeof(Resource).Assembly); 25 | } 26 | 27 | protected override void OnCreate(Bundle bundle) { 28 | base.OnCreate(bundle); 29 | 30 | InitShadow(); 31 | this.engine.Operations.InvokeMember(this.shadow, "OnCreate", bundle); 32 | } 33 | 34 | private void InitShadow() { 35 | string code = null; 36 | using(var shadowStream = new StreamReader(this.Assets.Open("FlippingGameActivity.py"))) { 37 | code = shadowStream.ReadToEnd(); 38 | } 39 | 40 | this.engine.Execute(code, this.scope); 41 | 42 | object shadowClass = this.scope.GetVariable("FlippingGameActivity"); 43 | this.shadow = this.engine.Operations.CreateInstance(shadowClass, this); 44 | } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /AndroidSample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using Android.App; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("AndroidSample")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("AndroidSample")] 14 | [assembly: AssemblyCopyright("Copyright © 2012")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | [assembly: Guid("a557ce8c-9dbe-4b93-8fc4-95ffc126cf14")] 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | // You can specify all the values or you can default the Build and Revision Numbers 34 | // by using the '*' as shown below: 35 | // [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyVersion("1.0.0.0")] 37 | [assembly: AssemblyFileVersion("1.0.0.0")] 38 | 39 | // Add some common permissions, these can be removed if not needed 40 | [assembly: UsesPermission(Android.Manifest.Permission.Internet)] 41 | [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)] 42 | -------------------------------------------------------------------------------- /AndroidSample/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (Main.xml), 7 | an internationalization string table (Strings.xml) and some icons (drawable/Icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | Drawable/ 12 | Icon.png 13 | 14 | Layout/ 15 | Main.axml 16 | 17 | Values/ 18 | Strings.xml 19 | 20 | In order to get the build system to recognize Android resources, the build action should be set 21 | to "AndroidResource". The native Android APIs do not operate directly with filenames, but 22 | instead operate on resource IDs. When you compile an Android application that uses resources, 23 | the build system will package the resources for distribution and generate a class called 24 | "Resource" that contains the tokens for each one of the resources included. For example, 25 | for the above Resources layout, this is what the Resource class would expose: 26 | 27 | public class Resource { 28 | public class Drawable { 29 | public const int Icon = 0x123; 30 | } 31 | 32 | public class Layout { 33 | public const int Main = 0x456; 34 | } 35 | 36 | public class String { 37 | public const int FirstString = 0xabc; 38 | public const int SecondString = 0xbcd; 39 | } 40 | } 41 | 42 | You would then use Resource.Drawable.Icon to reference the Drawable/Icon.png file, or 43 | Resource.Layout.Main to reference the Layout/Main.axml file, or Resource.String.FirstString 44 | to reference the first string in the dictionary file Values/Strings.xml. -------------------------------------------------------------------------------- /AndroidSample/Resources/Drawable/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhardy/IronPythonSamples/ccab7c4a12f37296cf18ef42ffea626facdeb4b9/AndroidSample/Resources/Drawable/Icon.png -------------------------------------------------------------------------------- /AndroidSample/Resources/Layout/Main.axml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 14 | 19 | 24 | 29 | 30 | 35 | 40 | 45 | 46 | 51 | 56 | 62 | 67 | 68 | 73 | 82 | 83 | 88 |