Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 16 files changed
  • 0 commit comments
  • 1 contributor
View
20 IronPythonSamples.sln
@@ -13,6 +13,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleSample", "ConsoleSam
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsSample", "WinFormsSample\WinFormsSample.csproj", "{1940BB9C-9F27-417B-A227-2E69C0A8C172}"
EndProject
+Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "PyWpfSample", "PyWpfSample\PyWpfSample.pyproj", "{2F62608C-652C-406B-9775-4CE34E151D45}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfSample", "WpfSample\WpfSample.csproj", "{0399791B-E075-4F41-AD68-4EA4A5602B00}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -49,6 +53,22 @@ Global
{1940BB9C-9F27-417B-A227-2E69C0A8C172}.Release|Mixed Platforms.Build.0 = Release|x86
{1940BB9C-9F27-417B-A227-2E69C0A8C172}.Release|x86.ActiveCfg = Release|x86
{1940BB9C-9F27-417B-A227-2E69C0A8C172}.Release|x86.Build.0 = Release|x86
+ {2F62608C-652C-406B-9775-4CE34E151D45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2F62608C-652C-406B-9775-4CE34E151D45}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {2F62608C-652C-406B-9775-4CE34E151D45}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {2F62608C-652C-406B-9775-4CE34E151D45}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2F62608C-652C-406B-9775-4CE34E151D45}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {2F62608C-652C-406B-9775-4CE34E151D45}.Release|x86.ActiveCfg = Release|Any CPU
+ {0399791B-E075-4F41-AD68-4EA4A5602B00}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {0399791B-E075-4F41-AD68-4EA4A5602B00}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {0399791B-E075-4F41-AD68-4EA4A5602B00}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {0399791B-E075-4F41-AD68-4EA4A5602B00}.Debug|x86.ActiveCfg = Debug|x86
+ {0399791B-E075-4F41-AD68-4EA4A5602B00}.Debug|x86.Build.0 = Debug|x86
+ {0399791B-E075-4F41-AD68-4EA4A5602B00}.Release|Any CPU.ActiveCfg = Release|x86
+ {0399791B-E075-4F41-AD68-4EA4A5602B00}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {0399791B-E075-4F41-AD68-4EA4A5602B00}.Release|Mixed Platforms.Build.0 = Release|x86
+ {0399791B-E075-4F41-AD68-4EA4A5602B00}.Release|x86.ActiveCfg = Release|x86
+ {0399791B-E075-4F41-AD68-4EA4A5602B00}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
78 PyWpfSample/PyWpfSample.py
@@ -0,0 +1,78 @@
+import wpf
+
+import FlippingGame
+
+from System.Windows import Application, Window, Visibility
+from System.Windows.Media import Brushes
+
+class WpfSampleWindow(Window):
+ def __init__(self):
+ wpf.LoadComponent(self, 'PyWpfSample.xaml')
+ self.game = FlippingGame.FlippingGame()
+
+ def flipButton_Click(self, sender, e):
+ wager = self._getWager()
+ if not wager:
+ return
+
+ guess = "H" if self.guessHeadsButton.IsChecked else "T"
+ won, toss = self.game.flip(guess, wager)
+
+ self._showToss(won, toss)
+ self._showBankroll()
+ self._maybeEndGame()
+
+ def Window_Loaded(self, sender, e):
+ self._showBankroll()
+
+ def _getWager(self):
+ try:
+ wager = int(self.wagerBox.Text)
+ except ValueError as v:
+ self.wagerBox.Foreground = Brushes.Red
+ self._showError("Wager must be a number.")
+ return
+ else:
+ self._hideError()
+ self.wagerBox.Foreground = Brushes.Black
+
+ if wager < 1:
+ self.wagerBox.Foreground = Brushes.Red
+ self._showError("Wager must be at least 1 credit.")
+ return
+
+ if wager > self.game.bankroll:
+ self.wagerBox.Foreground = Brushes.Red
+ self._showError("Wager cannot be more than your bankroll.")
+ return
+
+ return wager
+
+ def _showError(self, error):
+ self.errorLabel.Content = error
+ self.errorLabel.Visibility = Visibility.Visible
+
+ def _hideError(self):
+ self.errorLabel.Visibility = Visibility.Collapsed
+
+ def _showToss(self, won, toss):
+ self.resultLabel.Content = toss
+ self.resultLabel.Foreground = Brushes.Green if won else Brushes.Red
+
+ def _showBankroll(self):
+ self.bankrollLabel.Content = str(self.game.bankroll)
+
+ def _maybeEndGame(self):
+ if self.game.bankroll <= 0:
+ self._showToss(False, 'X')
+
+ self.flipButton.IsEnabled = False
+ self.wagerBox.IsEnabled = False
+ self.guessHeadsButton.IsEnabled = False
+ self.guessTailsButton.IsEnabled = False
+
+ def wagerBox_GotFocus(self, sender, e):
+ sender.Foreground = Brushes.Black
+
+if __name__ == '__main__':
+ Application().Run(WpfSampleWindow())
View
52 PyWpfSample/PyWpfSample.pyproj
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{2f62608c-652c-406b-9775-4ce34e151d45}</ProjectGuid>
+ <ProjectHome>.</ProjectHome>
+ <StartupFile>PyWpfSample.py</StartupFile>
+ <SearchPath>..\FlippingGame\</SearchPath>
+ <WorkingDirectory>.</WorkingDirectory>
+ <IsWindowsApplication>True</IsWindowsApplication>
+ <InterpreterId>dc002bdb-400d-4430-b1a8-b419d62bd6ef</InterpreterId>
+ <LaunchProvider>IronPython (.NET) launcher</LaunchProvider>
+ <InterpreterVersion>2.7</InterpreterVersion>
+ <OutputPath>.</OutputPath>
+ <Name>PyWpfSample</Name>
+ <RootNamespace>PyWpfSample</RootNamespace>
+ <CommandLineArguments />
+ <InterpreterPath />
+ <DebugStdLib>False</DebugStdLib>
+ <InterpreterArguments>-X:Debug</InterpreterArguments>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <DebugSymbols>true</DebugSymbols>
+ <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+ <DebugSymbols>true</DebugSymbols>
+ <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
+ </PropertyGroup>
+ <ItemGroup>
+ <None Include="PyWpfSample.py" />
+ <None Include="PyWpfSample.xaml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="FlippingGame\" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="C:\Users\Jeff\Documents\Repositories\IronPythonSamples\FlippingGame\FlippingGame.py">
+ <Link>FlippingGame\FlippingGame.py</Link>
+ </Compile>
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
+ <Name>PresentationCore</Name>
+ <AssemblyName>PresentationCore.dll</AssemblyName>
+ <HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
+</Project>
View
42 PyWpfSample/PyWpfSample.xaml
@@ -0,0 +1,42 @@
+<Window
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ Title="Coin Flipping" Loaded="Window_Loaded" ResizeMode="CanMinimize">
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ </Grid.RowDefinitions>
+ <Grid HorizontalAlignment="Left" VerticalAlignment="Top">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition Width="Auto" />
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="*" />
+ </Grid.RowDefinitions>
+ <Grid HorizontalAlignment="Left" VerticalAlignment="Top">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition Width="Auto" />
+ </Grid.ColumnDefinitions>
+ <Label Content="Bankroll:" HorizontalAlignment="Right" VerticalAlignment="Center" />
+ <Label Content="Wager:" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center" />
+ <Label Content="Guess:" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" />
+ <RadioButton Content="Heads" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" IsChecked="True" GroupName="guessButtons" Name="guessHeadsButton" />
+ <RadioButton Content="Tails" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="55,0,0,0" GroupName="guessButtons" Name="guessTailsButton" />
+ <Label Content="?" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Name="bankrollLabel" />
+ <TextBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Center" Width="95" Name="wagerBox" GotFocus="wagerBox_GotFocus" Text="50" TextAlignment="Right" Margin="0,2" />
+ </Grid>
+ <Button Content="Flip!" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Name="flipButton" MinHeight="28" MinWidth="75" Click="flipButton_Click" Margin="8,0" />
+ </Grid>
+ <Label Content="?" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" FontWeight="Bold" Name="resultLabel" />
+ <Label Content="Error" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="Red" Visibility="Collapsed" Name="errorLabel"></Label>
+ </Grid>
+</Window>
View
4 WinFormsSample/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="IronPython" version="2.7.2-final1" />
+</packages>
View
8 WpfSample/App.xaml
@@ -0,0 +1,8 @@
+<Application x:Class="WpfSample.App"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ StartupUri="WpfFlippingGame.xaml">
+ <Application.Resources>
+
+ </Application.Resources>
+</Application>
View
14 WpfSample/App.xaml.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Linq;
+using System.Windows;
+
+namespace WpfSample {
+ /// <summary>
+ /// Interaction logic for App.xaml
+ /// </summary>
+ public partial class App : Application {
+ }
+}
View
55 WpfSample/Properties/AssemblyInfo.cs
@@ -0,0 +1,55 @@
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("WpfSample")]
+[assembly: AssemblyDescription("IronPython WPF Sample")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("WpfSample")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+//In order to begin building localizable applications, set
+//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
+//inside a <PropertyGroup>. For example, if you are using US english
+//in your source files, set the <UICulture> to en-US. Then uncomment
+//the NeutralResourceLanguage attribute below. Update the "en-US" in
+//the line below to match the UICulture setting in the project file.
+
+//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
+
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
62 WpfSample/Properties/Resources.Designer.cs
@@ -0,0 +1,62 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.261
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace WpfSample.Properties {
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if ((resourceMan == null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfSample.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
View
117 WpfSample/Properties/Resources.resx
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root>
View
26 WpfSample/Properties/Settings.Designer.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.261
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace WpfSample.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+ }
+}
View
7 WpfSample/Properties/Settings.settings
@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
+ <Profiles>
+ <Profile Name="(Default)" />
+ </Profiles>
+ <Settings />
+</SettingsFile>
View
42 WpfSample/WpfFlippingGame.xaml
@@ -0,0 +1,42 @@
+<Window x:Class="WpfSample.WpfFlippingGame"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ Title="Coin Flipping" Loaded="Window_Loaded" ResizeMode="CanMinimize">
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ </Grid.RowDefinitions>
+ <Grid HorizontalAlignment="Left" VerticalAlignment="Top">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition Width="Auto" />
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="*" />
+ </Grid.RowDefinitions>
+ <Grid HorizontalAlignment="Left" VerticalAlignment="Top">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition Width="Auto" />
+ </Grid.ColumnDefinitions>
+ <Label Content="Bankroll:" HorizontalAlignment="Right" VerticalAlignment="Center" />
+ <Label Content="Wager:" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center" />
+ <Label Content="Guess:" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" />
+ <RadioButton Content="Heads" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" IsChecked="True" GroupName="guessButtons" Name="guessHeadsButton" />
+ <RadioButton Content="Tails" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="55,0,0,0" GroupName="guessButtons" Name="guessTailsButton" />
+ <Label Content="?" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Name="bankrollLabel" />
+ <TextBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Center" Width="95" Name="wagerBox" GotFocus="wagerBox_GotFocus" Text="50" TextAlignment="Right" Margin="0,2" />
+ </Grid>
+ <Button Content="Flip!" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Name="flipButton" MinHeight="28" MinWidth="75" Click="flipButton_Click" Margin="8,0" />
+ </Grid>
+ <Label Content="?" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" FontWeight="Bold" Name="resultLabel" />
+ <Label Content="Error" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="Red" Visibility="Collapsed" Name="errorLabel"></Label>
+ </Grid>
+</Window>
View
141 WpfSample/WpfFlippingGame.xaml.cs
@@ -0,0 +1,141 @@
+using System.Windows;
+using System.Windows.Media;
+using IronPython.Hosting;
+using Microsoft.Scripting.Hosting;
+
+namespace WpfSample {
+ /// <summary>
+ /// Interaction logic for MainWindow.xaml
+ /// </summary>
+ public partial class WpfFlippingGame : Window {
+ ScriptEngine engine;
+ ScriptScope scope;
+ dynamic game;
+
+ public WpfFlippingGame() {
+ InitializeComponent();
+
+ this.engine = Python.CreateEngine();
+ this.engine.SetSearchPaths(new[] { "FlippingGame" });
+ this.scope = this.engine.CreateScope();
+ }
+
+ private void Window_Loaded(object sender, RoutedEventArgs e) {
+ this.scope.ImportModule("FlippingGame");
+ this.engine.Execute("game = FlippingGame.FlippingGame()", this.scope);
+ this.game = this.scope.GetVariable("game");
+
+ ConstrainWager();
+ ShowBankroll();
+
+ ShowResult();
+ }
+
+ private void flipButton_Click(object sender, RoutedEventArgs e) {
+ var wager = GetWager();
+ if (wager <= 0)
+ return;
+
+ var guess = guessHeadsButton.IsChecked.Value ? "H" : "T";
+
+ var result = game.flip(guess, wager);
+ var won = result[0];
+ var toss = result[1];
+
+ SetToss(toss.ToString(), (bool)won);
+ ShowResult();
+
+ ConstrainWager();
+ ShowBankroll();
+
+ //ShowSpinner();
+
+ //var timer = new Timer() { Interval = rand.Next(350, 1000) };
+ //timer.Tick += (t_sender, t_e) => {
+ // flippingBox.Visible = false;
+ // SetToss(toss.ToString(), (bool)won);
+ // ShowResult();
+
+ // ConstrainWager();
+ // ShowBankroll();
+
+ // ((Timer)t_sender).Stop();
+ //};
+
+ //timer.Start();
+ }
+
+ private void wagerBox_GotFocus(object sender, RoutedEventArgs e) {
+ wagerBox.Foreground = Brushes.Black;
+ }
+
+ private int GetWager() {
+ int wager;
+ if (!int.TryParse(wagerBox.Text, out wager)) {
+ wagerBox.Foreground = Brushes.Red;
+ ShowError("Wager must be a number.");
+
+ return -1;
+ }
+
+ if (wager < 1) {
+ wagerBox.Foreground = Brushes.Red;
+ ShowError("Wager must be at least one credit.");
+
+ return -1;
+ }
+
+ if (wager > game.bankroll) {
+ wagerBox.Foreground = Brushes.Red;
+ ShowError("Wager cannot be more than your bankroll.");
+
+ return -1;
+ }
+
+ HideError();
+ return wager;
+ }
+
+ private void ShowError(string error) {
+ errorLabel.Content = error;
+ errorLabel.Visibility = System.Windows.Visibility.Visible;
+ }
+
+ private void HideError() {
+ errorLabel.Visibility = System.Windows.Visibility.Collapsed;
+ }
+
+ private void ShowBankroll() {
+ bankrollLabel.Content = game.bankroll.ToString();
+ }
+
+ private void ShowResult() {
+ //resultLabel.Visible = true;
+ //flippingBox.Visible = false;
+ }
+
+ private void ShowSpinner() {
+ //resultLabel.Visible = false;
+ //flippingBox.Visible = true;
+ }
+
+ private void SetToss(string toss, bool won) {
+ //resultLabel.Visibility = Visibility.Visible;
+ resultLabel.Content = toss;
+ resultLabel.Foreground = won ? Brushes.Green : Brushes.Red;
+ }
+
+ private void ConstrainWager() {
+ var bankroll = game.bankroll;
+
+ if (bankroll <= 0) {
+ wagerBox.IsEnabled = false;
+ flipButton.IsEnabled = false;
+ guessHeadsButton.IsEnabled = guessTailsButton.IsEnabled = false;
+
+ SetToss("X", false);
+ ShowResult();
+ }
+ }
+ }
+}
View
126 WpfSample/WpfSample.csproj
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{0399791B-E075-4F41-AD68-4EA4A5602B00}</ProjectGuid>
+ <OutputType>WinExe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>WpfSample</RootNamespace>
+ <AssemblyName>WpfSample</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <WarningLevel>4</WarningLevel>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\IronPythonSamples\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="IronPython">
+ <HintPath>..\packages\IronPython.2.7.2-final1\lib\Net40\IronPython.dll</HintPath>
+ </Reference>
+ <Reference Include="IronPython.Modules">
+ <HintPath>..\packages\IronPython.2.7.2-final1\lib\Net40\IronPython.Modules.dll</HintPath>
+ </Reference>
+ <Reference Include="IronPython.Wpf">
+ <HintPath>..\packages\IronPython.2.7.2-final1\lib\Net40\IronPython.Wpf.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Dynamic">
+ <HintPath>..\packages\IronPython.2.7.2-final1\lib\Net40\Microsoft.Dynamic.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Scripting">
+ <HintPath>..\packages\IronPython.2.7.2-final1\lib\Net40\Microsoft.Scripting.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="System.Xaml">
+ <RequiredTargetFramework>4.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="WindowsBase" />
+ <Reference Include="PresentationCore" />
+ <Reference Include="PresentationFramework" />
+ </ItemGroup>
+ <ItemGroup>
+ <ApplicationDefinition Include="App.xaml">
+ <Generator>MSBuild:Compile</Generator>
+ <SubType>Designer</SubType>
+ </ApplicationDefinition>
+ <Page Include="WpfFlippingGame.xaml">
+ <Generator>MSBuild:Compile</Generator>
+ <SubType>Designer</SubType>
+ </Page>
+ <Compile Include="App.xaml.cs">
+ <DependentUpon>App.xaml</DependentUpon>
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="WpfFlippingGame.xaml.cs">
+ <DependentUpon>WpfFlippingGame.xaml</DependentUpon>
+ <SubType>Code</SubType>
+ </Compile>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="Properties\Resources.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Resources.resx</DependentUpon>
+ </Compile>
+ <Compile Include="Properties\Settings.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DependentUpon>Settings.settings</DependentUpon>
+ <DesignTimeSharedInput>True</DesignTimeSharedInput>
+ </Compile>
+ <EmbeddedResource Include="Properties\Resources.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
+ <None Include="..\FlippingGame\FlippingGame.py">
+ <Link>FlippingGame\FlippingGame.py</Link>
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
+ <None Include="packages.config" />
+ <None Include="Properties\Settings.settings">
+ <Generator>SettingsSingleFileGenerator</Generator>
+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+ </None>
+ <AppDesigner Include="Properties\" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
4 WpfSample/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="IronPython" version="2.7.2-final1" />
+</packages>

No commit comments for this range

Something went wrong with that request. Please try again.