Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add WPF sample that uses an embedded IronPython.

  • Loading branch information...
commit 2d22ef5c8c5ee5298b6cf14ede8e81e83d095fe7 1 parent 28b8b20
Jeff Hardy authored April 03, 2012
12  IronPythonSamples.sln
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsSample", "WinFormsS
15 15
 EndProject
16 16
 Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "PyWpfSample", "PyWpfSample\PyWpfSample.pyproj", "{2F62608C-652C-406B-9775-4CE34E151D45}"
17 17
 EndProject
  18
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfSample", "WpfSample\WpfSample.csproj", "{0399791B-E075-4F41-AD68-4EA4A5602B00}"
  19
+EndProject
18 20
 Global
19 21
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
20 22
 		Debug|Any CPU = Debug|Any CPU
@@ -57,6 +59,16 @@ Global
57 59
 		{2F62608C-652C-406B-9775-4CE34E151D45}.Release|Any CPU.ActiveCfg = Release|Any CPU
58 60
 		{2F62608C-652C-406B-9775-4CE34E151D45}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
59 61
 		{2F62608C-652C-406B-9775-4CE34E151D45}.Release|x86.ActiveCfg = Release|Any CPU
  62
+		{0399791B-E075-4F41-AD68-4EA4A5602B00}.Debug|Any CPU.ActiveCfg = Debug|x86
  63
+		{0399791B-E075-4F41-AD68-4EA4A5602B00}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
  64
+		{0399791B-E075-4F41-AD68-4EA4A5602B00}.Debug|Mixed Platforms.Build.0 = Debug|x86
  65
+		{0399791B-E075-4F41-AD68-4EA4A5602B00}.Debug|x86.ActiveCfg = Debug|x86
  66
+		{0399791B-E075-4F41-AD68-4EA4A5602B00}.Debug|x86.Build.0 = Debug|x86
  67
+		{0399791B-E075-4F41-AD68-4EA4A5602B00}.Release|Any CPU.ActiveCfg = Release|x86
  68
+		{0399791B-E075-4F41-AD68-4EA4A5602B00}.Release|Mixed Platforms.ActiveCfg = Release|x86
  69
+		{0399791B-E075-4F41-AD68-4EA4A5602B00}.Release|Mixed Platforms.Build.0 = Release|x86
  70
+		{0399791B-E075-4F41-AD68-4EA4A5602B00}.Release|x86.ActiveCfg = Release|x86
  71
+		{0399791B-E075-4F41-AD68-4EA4A5602B00}.Release|x86.Build.0 = Release|x86
60 72
 	EndGlobalSection
61 73
 	GlobalSection(SolutionProperties) = preSolution
62 74
 		HideSolutionNode = FALSE
8  WpfSample/App.xaml
... ...
@@ -0,0 +1,8 @@
  1
+<Application x:Class="WpfSample.App"
  2
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4
+             StartupUri="WpfFlippingGame.xaml">
  5
+    <Application.Resources>
  6
+         
  7
+    </Application.Resources>
  8
+</Application>
14  WpfSample/App.xaml.cs
... ...
@@ -0,0 +1,14 @@
  1
+using System;
  2
+using System.Collections.Generic;
  3
+using System.Configuration;
  4
+using System.Data;
  5
+using System.Linq;
  6
+using System.Windows;
  7
+
  8
+namespace WpfSample {
  9
+    /// <summary>
  10
+    /// Interaction logic for App.xaml
  11
+    /// </summary>
  12
+    public partial class App : Application {
  13
+    }
  14
+}
55  WpfSample/Properties/AssemblyInfo.cs
... ...
@@ -0,0 +1,55 @@
  1
+using System.Reflection;
  2
+using System.Resources;
  3
+using System.Runtime.CompilerServices;
  4
+using System.Runtime.InteropServices;
  5
+using System.Windows;
  6
+
  7
+// General Information about an assembly is controlled through the following 
  8
+// set of attributes. Change these attribute values to modify the information
  9
+// associated with an assembly.
  10
+[assembly: AssemblyTitle("WpfSample")]
  11
+[assembly: AssemblyDescription("IronPython WPF Sample")]
  12
+[assembly: AssemblyConfiguration("")]
  13
+[assembly: AssemblyCompany("")]
  14
+[assembly: AssemblyProduct("WpfSample")]
  15
+[assembly: AssemblyCopyright("Copyright ©  2012")]
  16
+[assembly: AssemblyTrademark("")]
  17
+[assembly: AssemblyCulture("")]
  18
+
  19
+// Setting ComVisible to false makes the types in this assembly not visible 
  20
+// to COM components.  If you need to access a type in this assembly from 
  21
+// COM, set the ComVisible attribute to true on that type.
  22
+[assembly: ComVisible(false)]
  23
+
  24
+//In order to begin building localizable applications, set 
  25
+//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
  26
+//inside a <PropertyGroup>.  For example, if you are using US english
  27
+//in your source files, set the <UICulture> to en-US.  Then uncomment
  28
+//the NeutralResourceLanguage attribute below.  Update the "en-US" in
  29
+//the line below to match the UICulture setting in the project file.
  30
+
  31
+//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
  32
+
  33
+
  34
+[assembly: ThemeInfo(
  35
+    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
  36
+    //(used if a resource is not found in the page, 
  37
+    // or application resource dictionaries)
  38
+    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
  39
+    //(used if a resource is not found in the page, 
  40
+    // app, or any theme specific resource dictionaries)
  41
+)]
  42
+
  43
+
  44
+// Version information for an assembly consists of the following four values:
  45
+//
  46
+//      Major Version
  47
+//      Minor Version 
  48
+//      Build Number
  49
+//      Revision
  50
+//
  51
+// You can specify all the values or you can default the Build and Revision Numbers 
  52
+// by using the '*' as shown below:
  53
+// [assembly: AssemblyVersion("1.0.*")]
  54
+[assembly: AssemblyVersion("1.0.0.0")]
  55
+[assembly: AssemblyFileVersion("1.0.0.0")]
62  WpfSample/Properties/Resources.Designer.cs
... ...
@@ -0,0 +1,62 @@
  1
+//------------------------------------------------------------------------------
  2
+// <auto-generated>
  3
+//     This code was generated by a tool.
  4
+//     Runtime Version:4.0.30319.261
  5
+//
  6
+//     Changes to this file may cause incorrect behavior and will be lost if
  7
+//     the code is regenerated.
  8
+// </auto-generated>
  9
+//------------------------------------------------------------------------------
  10
+
  11
+namespace WpfSample.Properties {
  12
+
  13
+
  14
+    /// <summary>
  15
+    ///   A strongly-typed resource class, for looking up localized strings, etc.
  16
+    /// </summary>
  17
+    // This class was auto-generated by the StronglyTypedResourceBuilder
  18
+    // class via a tool like ResGen or Visual Studio.
  19
+    // To add or remove a member, edit your .ResX file then rerun ResGen
  20
+    // with the /str option, or rebuild your VS project.
  21
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
  22
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  23
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
  24
+    internal class Resources {
  25
+
  26
+        private static global::System.Resources.ResourceManager resourceMan;
  27
+
  28
+        private static global::System.Globalization.CultureInfo resourceCulture;
  29
+
  30
+        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
  31
+        internal Resources() {
  32
+        }
  33
+
  34
+        /// <summary>
  35
+        ///   Returns the cached ResourceManager instance used by this class.
  36
+        /// </summary>
  37
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
  38
+        internal static global::System.Resources.ResourceManager ResourceManager {
  39
+            get {
  40
+                if ((resourceMan == null)) {
  41
+                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfSample.Properties.Resources", typeof(Resources).Assembly);
  42
+                    resourceMan = temp;
  43
+                }
  44
+                return resourceMan;
  45
+            }
  46
+        }
  47
+
  48
+        /// <summary>
  49
+        ///   Overrides the current thread's CurrentUICulture property for all
  50
+        ///   resource lookups using this strongly typed resource class.
  51
+        /// </summary>
  52
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
  53
+        internal static global::System.Globalization.CultureInfo Culture {
  54
+            get {
  55
+                return resourceCulture;
  56
+            }
  57
+            set {
  58
+                resourceCulture = value;
  59
+            }
  60
+        }
  61
+    }
  62
+}
117  WpfSample/Properties/Resources.resx
... ...
@@ -0,0 +1,117 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<root>
  3
+  <!-- 
  4
+    Microsoft ResX Schema 
  5
+    
  6
+    Version 2.0
  7
+    
  8
+    The primary goals of this format is to allow a simple XML format 
  9
+    that is mostly human readable. The generation and parsing of the 
  10
+    various data types are done through the TypeConverter classes 
  11
+    associated with the data types.
  12
+    
  13
+    Example:
  14
+    
  15
+    ... ado.net/XML headers & schema ...
  16
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
  17
+    <resheader name="version">2.0</resheader>
  18
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
  19
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
  20
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
  21
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
  22
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
  23
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
  24
+    </data>
  25
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
  26
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
  27
+        <comment>This is a comment</comment>
  28
+    </data>
  29
+                
  30
+    There are any number of "resheader" rows that contain simple 
  31
+    name/value pairs.
  32
+    
  33
+    Each data row contains a name, and value. The row also contains a 
  34
+    type or mimetype. Type corresponds to a .NET class that support 
  35
+    text/value conversion through the TypeConverter architecture. 
  36
+    Classes that don't support this are serialized and stored with the 
  37
+    mimetype set.
  38
+    
  39
+    The mimetype is used for serialized objects, and tells the 
  40
+    ResXResourceReader how to depersist the object. This is currently not 
  41
+    extensible. For a given mimetype the value must be set accordingly:
  42
+    
  43
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
  44
+    that the ResXResourceWriter will generate, however the reader can 
  45
+    read any of the formats listed below.
  46
+    
  47
+    mimetype: application/x-microsoft.net.object.binary.base64
  48
+    value   : The object must be serialized with 
  49
+            : System.Serialization.Formatters.Binary.BinaryFormatter
  50
+            : and then encoded with base64 encoding.
  51
+    
  52
+    mimetype: application/x-microsoft.net.object.soap.base64
  53
+    value   : The object must be serialized with 
  54
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
  55
+            : and then encoded with base64 encoding.
  56
+
  57
+    mimetype: application/x-microsoft.net.object.bytearray.base64
  58
+    value   : The object must be serialized into a byte array 
  59
+            : using a System.ComponentModel.TypeConverter
  60
+            : and then encoded with base64 encoding.
  61
+    -->
  62
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  63
+    <xsd:element name="root" msdata:IsDataSet="true">
  64
+      <xsd:complexType>
  65
+        <xsd:choice maxOccurs="unbounded">
  66
+          <xsd:element name="metadata">
  67
+            <xsd:complexType>
  68
+              <xsd:sequence>
  69
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
  70
+              </xsd:sequence>
  71
+              <xsd:attribute name="name" type="xsd:string" />
  72
+              <xsd:attribute name="type" type="xsd:string" />
  73
+              <xsd:attribute name="mimetype" type="xsd:string" />
  74
+            </xsd:complexType>
  75
+          </xsd:element>
  76
+          <xsd:element name="assembly">
  77
+            <xsd:complexType>
  78
+              <xsd:attribute name="alias" type="xsd:string" />
  79
+              <xsd:attribute name="name" type="xsd:string" />
  80
+            </xsd:complexType>
  81
+          </xsd:element>
  82
+          <xsd:element name="data">
  83
+            <xsd:complexType>
  84
+              <xsd:sequence>
  85
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
  86
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
  87
+              </xsd:sequence>
  88
+              <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
  89
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
  90
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
  91
+            </xsd:complexType>
  92
+          </xsd:element>
  93
+          <xsd:element name="resheader">
  94
+            <xsd:complexType>
  95
+              <xsd:sequence>
  96
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
  97
+              </xsd:sequence>
  98
+              <xsd:attribute name="name" type="xsd:string" use="required" />
  99
+            </xsd:complexType>
  100
+          </xsd:element>
  101
+        </xsd:choice>
  102
+      </xsd:complexType>
  103
+    </xsd:element>
  104
+  </xsd:schema>
  105
+  <resheader name="resmimetype">
  106
+    <value>text/microsoft-resx</value>
  107
+  </resheader>
  108
+  <resheader name="version">
  109
+    <value>2.0</value>
  110
+  </resheader>
  111
+  <resheader name="reader">
  112
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  113
+  </resheader>
  114
+  <resheader name="writer">
  115
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  116
+  </resheader>
  117
+</root>
26  WpfSample/Properties/Settings.Designer.cs
... ...
@@ -0,0 +1,26 @@
  1
+//------------------------------------------------------------------------------
  2
+// <auto-generated>
  3
+//     This code was generated by a tool.
  4
+//     Runtime Version:4.0.30319.261
  5
+//
  6
+//     Changes to this file may cause incorrect behavior and will be lost if
  7
+//     the code is regenerated.
  8
+// </auto-generated>
  9
+//------------------------------------------------------------------------------
  10
+
  11
+namespace WpfSample.Properties {
  12
+
  13
+
  14
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
  15
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
  16
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
  17
+
  18
+        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
  19
+
  20
+        public static Settings Default {
  21
+            get {
  22
+                return defaultInstance;
  23
+            }
  24
+        }
  25
+    }
  26
+}
7  WpfSample/Properties/Settings.settings
... ...
@@ -0,0 +1,7 @@
  1
+<?xml version='1.0' encoding='utf-8'?>
  2
+<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
  3
+  <Profiles>
  4
+    <Profile Name="(Default)" />
  5
+  </Profiles>
  6
+  <Settings />
  7
+</SettingsFile>
42  WpfSample/WpfFlippingGame.xaml
... ...
@@ -0,0 +1,42 @@
  1
+<Window x:Class="WpfSample.WpfFlippingGame"
  2
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4
+        Title="Coin Flipping" Loaded="Window_Loaded" ResizeMode="CanMinimize">
  5
+    <Grid>
  6
+        <Grid.RowDefinitions>
  7
+            <RowDefinition Height="Auto" />
  8
+            <RowDefinition Height="Auto" />
  9
+            <RowDefinition Height="Auto" />
  10
+        </Grid.RowDefinitions>
  11
+        <Grid HorizontalAlignment="Left" VerticalAlignment="Top">
  12
+            <Grid.ColumnDefinitions>
  13
+                <ColumnDefinition Width="Auto" />
  14
+                <ColumnDefinition Width="Auto" />
  15
+            </Grid.ColumnDefinitions>
  16
+            <Grid.RowDefinitions>
  17
+                <RowDefinition Height="*" />
  18
+            </Grid.RowDefinitions>
  19
+            <Grid HorizontalAlignment="Left" VerticalAlignment="Top">
  20
+                <Grid.RowDefinitions>
  21
+                    <RowDefinition Height="Auto" />
  22
+                    <RowDefinition Height="Auto" />
  23
+                    <RowDefinition Height="Auto" />
  24
+                </Grid.RowDefinitions>
  25
+                <Grid.ColumnDefinitions>
  26
+                    <ColumnDefinition Width="Auto" />
  27
+                    <ColumnDefinition Width="Auto" />
  28
+                </Grid.ColumnDefinitions>
  29
+                <Label Content="Bankroll:" HorizontalAlignment="Right" VerticalAlignment="Center" />
  30
+                <Label Content="Wager:" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center" />
  31
+                <Label Content="Guess:" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" />
  32
+                <RadioButton Content="Heads" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" IsChecked="True" GroupName="guessButtons" Name="guessHeadsButton" />
  33
+                <RadioButton Content="Tails" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="55,0,0,0" GroupName="guessButtons" Name="guessTailsButton" />
  34
+                <Label Content="?" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Name="bankrollLabel" />
  35
+                <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" />
  36
+            </Grid>
  37
+            <Button Content="Flip!" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Name="flipButton" MinHeight="28" MinWidth="75" Click="flipButton_Click" Margin="8,0" />
  38
+        </Grid>
  39
+        <Label Content="?" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" FontWeight="Bold" Name="resultLabel" />
  40
+        <Label Content="Error" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="Red" Visibility="Collapsed" Name="errorLabel"></Label>
  41
+    </Grid>
  42
+</Window>
141  WpfSample/WpfFlippingGame.xaml.cs
... ...
@@ -0,0 +1,141 @@
  1
+using System.Windows;
  2
+using System.Windows.Media;
  3
+using IronPython.Hosting;
  4
+using Microsoft.Scripting.Hosting;
  5
+
  6
+namespace WpfSample {
  7
+    /// <summary>
  8
+    /// Interaction logic for MainWindow.xaml
  9
+    /// </summary>
  10
+    public partial class WpfFlippingGame : Window {
  11
+        ScriptEngine engine;
  12
+        ScriptScope scope;
  13
+        dynamic game;
  14
+
  15
+        public WpfFlippingGame() {
  16
+            InitializeComponent();
  17
+
  18
+            this.engine = Python.CreateEngine();
  19
+            this.engine.SetSearchPaths(new[] { "FlippingGame" });
  20
+            this.scope = this.engine.CreateScope();
  21
+        }
  22
+
  23
+        private void Window_Loaded(object sender, RoutedEventArgs e) {
  24
+            this.scope.ImportModule("FlippingGame");
  25
+            this.engine.Execute("game = FlippingGame.FlippingGame()", this.scope);
  26
+            this.game = this.scope.GetVariable("game");
  27
+
  28
+            ConstrainWager();
  29
+            ShowBankroll();
  30
+
  31
+            ShowResult();
  32
+        }
  33
+
  34
+        private void flipButton_Click(object sender, RoutedEventArgs e) {
  35
+            var wager = GetWager();
  36
+            if (wager <= 0)
  37
+                return;
  38
+
  39
+            var guess = guessHeadsButton.IsChecked.Value ? "H" : "T";
  40
+
  41
+            var result = game.flip(guess, wager);
  42
+            var won = result[0];
  43
+            var toss = result[1];
  44
+
  45
+            SetToss(toss.ToString(), (bool)won);
  46
+            ShowResult();
  47
+
  48
+            ConstrainWager();
  49
+            ShowBankroll();
  50
+
  51
+            //ShowSpinner();
  52
+
  53
+            //var timer = new Timer() { Interval = rand.Next(350, 1000) };
  54
+            //timer.Tick += (t_sender, t_e) => {
  55
+            //    flippingBox.Visible = false;
  56
+            //    SetToss(toss.ToString(), (bool)won);
  57
+            //    ShowResult();
  58
+
  59
+            //    ConstrainWager();
  60
+            //    ShowBankroll();
  61
+
  62
+            //    ((Timer)t_sender).Stop();
  63
+            //};
  64
+
  65
+            //timer.Start();
  66
+        }
  67
+
  68
+        private void wagerBox_GotFocus(object sender, RoutedEventArgs e) {
  69
+            wagerBox.Foreground = Brushes.Black;
  70
+        }
  71
+
  72
+        private int GetWager() {
  73
+            int wager;
  74
+            if (!int.TryParse(wagerBox.Text, out wager)) {
  75
+                wagerBox.Foreground = Brushes.Red;
  76
+                ShowError("Wager must be a number.");
  77
+
  78
+                return -1;
  79
+            }
  80
+            
  81
+            if (wager < 1) {
  82
+                wagerBox.Foreground = Brushes.Red;
  83
+                ShowError("Wager must be at least one credit.");
  84
+
  85
+                return -1;
  86
+            }
  87
+            
  88
+            if (wager > game.bankroll) {
  89
+                wagerBox.Foreground = Brushes.Red;
  90
+                ShowError("Wager cannot be more than your bankroll.");
  91
+
  92
+                return -1;
  93
+            }
  94
+
  95
+            HideError();
  96
+            return wager;
  97
+        }
  98
+
  99
+        private void ShowError(string error) {
  100
+            errorLabel.Content = error;
  101
+            errorLabel.Visibility = System.Windows.Visibility.Visible;
  102
+        }
  103
+
  104
+        private void HideError() {
  105
+            errorLabel.Visibility = System.Windows.Visibility.Collapsed;
  106
+        }
  107
+
  108
+        private void ShowBankroll() {
  109
+            bankrollLabel.Content = game.bankroll.ToString();
  110
+        }
  111
+
  112
+        private void ShowResult() {
  113
+            //resultLabel.Visible = true;
  114
+            //flippingBox.Visible = false;
  115
+        }
  116
+
  117
+        private void ShowSpinner() {
  118
+            //resultLabel.Visible = false;
  119
+            //flippingBox.Visible = true;
  120
+        }
  121
+
  122
+        private void SetToss(string toss, bool won) {
  123
+            //resultLabel.Visibility = Visibility.Visible;
  124
+            resultLabel.Content = toss;
  125
+            resultLabel.Foreground = won ? Brushes.Green : Brushes.Red;
  126
+        }
  127
+
  128
+        private void ConstrainWager() {
  129
+            var bankroll = game.bankroll;
  130
+
  131
+            if (bankroll <= 0) {
  132
+                wagerBox.IsEnabled = false;
  133
+                flipButton.IsEnabled = false;
  134
+                guessHeadsButton.IsEnabled = guessTailsButton.IsEnabled = false;
  135
+
  136
+                SetToss("X", false);
  137
+                ShowResult();
  138
+            }
  139
+        }
  140
+    }
  141
+}
126  WpfSample/WpfSample.csproj
... ...
@@ -0,0 +1,126 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3
+  <PropertyGroup>
  4
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  5
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
  6
+    <ProductVersion>8.0.30703</ProductVersion>
  7
+    <SchemaVersion>2.0</SchemaVersion>
  8
+    <ProjectGuid>{0399791B-E075-4F41-AD68-4EA4A5602B00}</ProjectGuid>
  9
+    <OutputType>WinExe</OutputType>
  10
+    <AppDesignerFolder>Properties</AppDesignerFolder>
  11
+    <RootNamespace>WpfSample</RootNamespace>
  12
+    <AssemblyName>WpfSample</AssemblyName>
  13
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  14
+    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
  15
+    <FileAlignment>512</FileAlignment>
  16
+    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
  17
+    <WarningLevel>4</WarningLevel>
  18
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\IronPythonSamples\</SolutionDir>
  19
+    <RestorePackages>true</RestorePackages>
  20
+  </PropertyGroup>
  21
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
  22
+    <PlatformTarget>x86</PlatformTarget>
  23
+    <DebugSymbols>true</DebugSymbols>
  24
+    <DebugType>full</DebugType>
  25
+    <Optimize>false</Optimize>
  26
+    <OutputPath>bin\Debug\</OutputPath>
  27
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
  28
+    <ErrorReport>prompt</ErrorReport>
  29
+    <WarningLevel>4</WarningLevel>
  30
+  </PropertyGroup>
  31
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
  32
+    <PlatformTarget>x86</PlatformTarget>
  33
+    <DebugType>pdbonly</DebugType>
  34
+    <Optimize>true</Optimize>
  35
+    <OutputPath>bin\Release\</OutputPath>
  36
+    <DefineConstants>TRACE</DefineConstants>
  37
+    <ErrorReport>prompt</ErrorReport>
  38
+    <WarningLevel>4</WarningLevel>
  39
+  </PropertyGroup>
  40
+  <ItemGroup>
  41
+    <Reference Include="IronPython">
  42
+      <HintPath>..\packages\IronPython.2.7.2-final1\lib\Net40\IronPython.dll</HintPath>
  43
+    </Reference>
  44
+    <Reference Include="IronPython.Modules">
  45
+      <HintPath>..\packages\IronPython.2.7.2-final1\lib\Net40\IronPython.Modules.dll</HintPath>
  46
+    </Reference>
  47
+    <Reference Include="IronPython.Wpf">
  48
+      <HintPath>..\packages\IronPython.2.7.2-final1\lib\Net40\IronPython.Wpf.dll</HintPath>
  49
+    </Reference>
  50
+    <Reference Include="Microsoft.Dynamic">
  51
+      <HintPath>..\packages\IronPython.2.7.2-final1\lib\Net40\Microsoft.Dynamic.dll</HintPath>
  52
+    </Reference>
  53
+    <Reference Include="Microsoft.Scripting">
  54
+      <HintPath>..\packages\IronPython.2.7.2-final1\lib\Net40\Microsoft.Scripting.dll</HintPath>
  55
+    </Reference>
  56
+    <Reference Include="System" />
  57
+    <Reference Include="System.Data" />
  58
+    <Reference Include="System.Xml" />
  59
+    <Reference Include="Microsoft.CSharp" />
  60
+    <Reference Include="System.Core" />
  61
+    <Reference Include="System.Xml.Linq" />
  62
+    <Reference Include="System.Data.DataSetExtensions" />
  63
+    <Reference Include="System.Xaml">
  64
+      <RequiredTargetFramework>4.0</RequiredTargetFramework>
  65
+    </Reference>
  66
+    <Reference Include="WindowsBase" />
  67
+    <Reference Include="PresentationCore" />
  68
+    <Reference Include="PresentationFramework" />
  69
+  </ItemGroup>
  70
+  <ItemGroup>
  71
+    <ApplicationDefinition Include="App.xaml">
  72
+      <Generator>MSBuild:Compile</Generator>
  73
+      <SubType>Designer</SubType>
  74
+    </ApplicationDefinition>
  75
+    <Page Include="WpfFlippingGame.xaml">
  76
+      <Generator>MSBuild:Compile</Generator>
  77
+      <SubType>Designer</SubType>
  78
+    </Page>
  79
+    <Compile Include="App.xaml.cs">
  80
+      <DependentUpon>App.xaml</DependentUpon>
  81
+      <SubType>Code</SubType>
  82
+    </Compile>
  83
+    <Compile Include="WpfFlippingGame.xaml.cs">
  84
+      <DependentUpon>WpfFlippingGame.xaml</DependentUpon>
  85
+      <SubType>Code</SubType>
  86
+    </Compile>
  87
+  </ItemGroup>
  88
+  <ItemGroup>
  89
+    <Compile Include="Properties\AssemblyInfo.cs">
  90
+      <SubType>Code</SubType>
  91
+    </Compile>
  92
+    <Compile Include="Properties\Resources.Designer.cs">
  93
+      <AutoGen>True</AutoGen>
  94
+      <DesignTime>True</DesignTime>
  95
+      <DependentUpon>Resources.resx</DependentUpon>
  96
+    </Compile>
  97
+    <Compile Include="Properties\Settings.Designer.cs">
  98
+      <AutoGen>True</AutoGen>
  99
+      <DependentUpon>Settings.settings</DependentUpon>
  100
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
  101
+    </Compile>
  102
+    <EmbeddedResource Include="Properties\Resources.resx">
  103
+      <Generator>ResXFileCodeGenerator</Generator>
  104
+      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
  105
+    </EmbeddedResource>
  106
+    <None Include="..\FlippingGame\FlippingGame.py">
  107
+      <Link>FlippingGame\FlippingGame.py</Link>
  108
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  109
+    </None>
  110
+    <None Include="packages.config" />
  111
+    <None Include="Properties\Settings.settings">
  112
+      <Generator>SettingsSingleFileGenerator</Generator>
  113
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
  114
+    </None>
  115
+    <AppDesigner Include="Properties\" />
  116
+  </ItemGroup>
  117
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  118
+  <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
  119
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
  120
+       Other similar extension points exist, see Microsoft.Common.targets.
  121
+  <Target Name="BeforeBuild">
  122
+  </Target>
  123
+  <Target Name="AfterBuild">
  124
+  </Target>
  125
+  -->
  126
+</Project>
4  WpfSample/packages.config
... ...
@@ -0,0 +1,4 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<packages>
  3
+  <package id="IronPython" version="2.7.2-final1" />
  4
+</packages>

0 notes on commit 2d22ef5

Please sign in to comment.
Something went wrong with that request. Please try again.