Working with IronPython and WPF



Similar documents
Understanding In and Out of XAML in WPF

STEP BY STEP to Build the Application 1. Start a. Open a MvvmLight (WPF4) application and name it MvvmControlChange.

Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB)

Relationships in WPF Applications

Microsoft Virtual Labs. Building Windows Presentation Foundation Applications - C# - Part 1

ComponentOne. Windows for WPF

>


How To Insert Hyperlinks In Powerpoint Powerpoint

Async startup WPF Application

Introduction. Inserting Hyperlinks. PowerPoint 2010 Hyperlinks and Action Buttons. About Hyperlinks. Page 1

Commercial Online Banking

Create a PivotTable or PivotChart report

Implementing multi-user multi-touch scenarios using WPF in Windows* 8 Desktop Apps

WPF Viewer for Reporting Services 2008/2012 Getting Started

Custom fields validation

5.7. Quick Guide to Fusion Pro Schedule

First Time Off-Campus Remote Desktop Connection ipad Edition

Introduction to C#, Visual Studio and Windows Presentation Foundation

Introduction to Building Windows Store Apps with Windows Azure Mobile Services

Election 2012: Real- Time Monitoring of Election Results

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Windows 10 Apps Development

Envisioneer Technical Note

User Support Resource

Top Navigation menu - Tabs. User Guide 1. &

Create A Google Site. Introduction to Sites. Create, format, and customize a site. Adapted from:

First Time On-Campus Remote Desktop Connection ipad Edition

Lab - Data Backup and Recovery in Windows Vista

Dartmouth College Technical Support Document for Kronos PC version

Xamarin.Forms. Hands On

Your Salesforce account has 100 free Force.com licenses that you can activate to run thirdparty applications such as DreamTeam.

How-To: Submitting PDF forms to SharePoint from custom websites

Introduction to Windows Presentation Foundation

Data Containers. User Guide

Chapter 14 WCF Client WPF Implementation. Screen Layout

Hosted Service Tips and Troubleshooting

How to start creating a VoIP solution with Ozeki VoIP SIP SDK

The presentation explains how to create and access the web services using the user interface. WebServices.ppt. Page 1 of 14

Introduction to the BackgroundWorker Component in WPF

70-536VB:.NET Framework Application Development Foundation Course Introduction

Creating a One-line Diagram

TIBCO Spotfire Metrics Prerequisites and Installation

Guest Quick Guide PC and Mac Users Updated to version March 2015

BSU Workshop Advanced Forms

: provid.ir

CRESTRON-APP/CRESTRON-APP-PAD

A SharePoint Developer Introduction. Hands-On Lab. Lab Manual SPCHOL306 Using Silverlight with the Client Object Model VB

2009 Tutorial (DB4O and Visual Studio 2008 Express)

This tutorial has been designed for all those readers who want to learn WPF and to apply it instantaneously in different type of applications.

A SharePoint Developer Introduction. Hands-On Lab. Lab Manual HOL8 Using Silverlight with the Client Object Model C#

GapSkill User Guide Module

A Guide to Getting Started with the AmeriCorps VISTA Applicant Tracking Tool

This section provides a 'Quickstart' guide to using TestDriven.NET any version of Microsoft Visual Studio.NET

The MAC address, short for Media Access Control address, is a number in hexadecimal format that uniquely identifies every machine on a network.

Product: DQ Order Manager Release Notes

Unity Express Voice Mail Transfer Behavior

LACCD Student E Mail Getting Started Guide

IENG2004 Industrial Database and Systems Design. Microsoft Access I. What is Microsoft Access? Architecture of Microsoft Access

How to Use? SKALICLOUD DEMO

CRESTRON-APP/CRESTRON-APP-PAD Control App for Apple ios

Developing Cross-Platform.NET Apps with ArcGIS Runtime

Quick Start Guide. Microsoft Publisher 2013 looks different from previous versions, so we created this guide to help you minimize the learning curve.

A Guide to Connecting to FreePBX

Managing Your Lotus Notes Mail Database Size

How to Setup Auto Recording for MyPBX U100/200/300

Hands-On Lab. Building a Data-Driven Master/Detail Business Form using Visual Studio Lab version: Last updated: 12/10/2010.

You simply need to define your flows and triggers; Built.io Flow will do the rest for you.

Using EDA Databases: Milkyway & OpenAccess

Using OwnCloud. OwnCloud is a very easy to use file storage and sharing system that you can access anywhere you have an internet connection.

Upgrading Your PhoneTree Software

Real World IronPython

Requesting Apps for ipads

Application Domains and Contexts and Threads, Oh My!

MAS 90 Demo Guide: Accounts Payable

Special Note Ethernet Connection Problems and Handling Methods (CS203 / CS468 / CS469)

Windows Presentation Foundation

Migrating Groupwise Data

Printer Connection Manager

Microsoft Dynamics AX Windows 8 App Starter Kit. App Development Guide Version 1.0

Microsoft PowerPoint 2010 Computer Jeopardy Tutorial

WPF Shapes. WPF Shapes, Canvas, Dialogs 1

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

آموزش DataGrid در WPF به همراه صفحه بندي و جستجوي انتخابی. کلیک کن

Virtual Office Module. View Calendar. Add Personal Event. Add Global Event. View All. View Personal

Utilizing SASED OneDrive Cloud Storage

Simple Computer Backup

How to Create a Proper Meeting Invitation in Skype for Business

ARCONICS CONTENT MANAGEMENT SYSTEM FOR UL

EFORMS MANUAL FOR SHAREPOINT ONLINE

Transcription:

Working with IronPython and WPF Douglas Blank Bryn Mawr College Programming Paradigms Spring 2010 With thanks to: http://www.ironpython.info/ http://devhawk.net/

IronPython Demo with WPF >>> import clr >>> clr.addreference("presentationframework") >>> from System.Windows import * >>> window = Window() >>> window.title = "Hello" >>> window.show() >>> button = Controls.Button() >>> button.content = "Push Me" >>> panel = Controls.StackPanel() >>> window.content = panel >>> panel.children.add(button) 0 >>> app = System.Windows.Application() >>> app.run(window)

XAML Example: Main.xaml <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x="http://schemas.microsoft.com/winfx/2006/xaml" Title="TestApp" Width="640" Height="480"> <StackPanel> <Label>Iron Python and WPF</Label> <ListBox Grid.Column="0" x:name="listbox1" > <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=title}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel> </Window>

import sys if 'win' in sys.platform: import pythoncom pythoncom.coinitialize() IronPython + XAML import clr clr.addreference("system.xml") clr.addreference("presentationframework") clr.addreference("presentationcore") from System.IO import StringReader from System.Xml import XmlReader from System.Windows.Markup import XamlReader, XamlWriter from System.Windows import Window, Application xaml = """<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Title="XamlReader Example" Width="300" Height="200"> <StackPanel Margin="5"> <Button Margin="5">One</Button> <Button Margin="5">Two</Button> <Button Margin="5">Three</Button> </StackPanel> </Window>""" xr = XmlReader.Create(StringReader(xaml)) win = XamlReader.Load(xr) Application().Run(win)

IronPython with XAML Files import clr from Entry import Entry clr.addreferencetofileandpath("lib/wpfextension.dll") clr.addreferencebypartialname("presentationcore") clr.addreferencebypartialname("presentationframework") clr.addreferencebypartialname("windowsbase") clr.addreferencebypartialname("ironpython") clr.addreferencebypartialname("microsoft.scripting") from System.IO import File from System.Windows.Markup import XamlReader from System.Windows import Application def listbox1_onselectionchanged(self, event): for item in event.addeditems: print item.title titles = [Entry("Book", "Great For reading"), Entry("Shelf", "Ideal for storing stuff"), Entry("Cupboard", "Store and hide stuff")] file = File.OpenRead('Main.xaml') window = XamlReader.Load(file) window.listbox1.selectionchanged += listbox1_onselectionchanged window.listbox1.itemssource = titles Application().Run(window)

C# Code Entry Object using System; using System.Windows; using Microsoft.Scripting.Runtime; [assembly: ExtensionType( typeof(frameworkelement), typeof(sample.scripting.frameworkelementextension))] namespace Sample.Scripting { public static class FrameworkElementExtension { [System.Runtime.CompilerServices.SpecialName] public static object GetBoundMember(FrameworkElement e, string n) { object result = e.findname(n); if (result == null) { return OperationFailed.Value; } return result; } } }

import clr clr.addreference("system.speech ) from System.Speech.Recognition import * count = 0 def main(): sre = SpeechRecognitionEngine() sre.setinputtodefaultaudiodevice() sre.unloadallgrammars() gb = GrammarBuilder() gb.append(choices('cut', 'copy', 'paste', 'delete')) sre.loadgrammar(grammar(gb)) def OnSpeechRecognized(sender, e): global count count += 1 print '%d. %s' % (count, e.result.text) sre.speechrecognized += OnSpeechRecognized sre.recognizeasync(recognizemode.multiple) raw_input('press ENTER to quit\n\n') Using other parts of Windows if name == ' main ': import sys if sys.platform == 'cli': from System.Threading import Thread, ThreadStart thread = Thread(ThreadStart(main)) thread.start() else: main()

XAML Shapes xaml_str=""" <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="A Crazy Window" Height="300" Width="300" WindowStyle="None" AllowsTransparency="True" Background="{x:Null}" > <Grid Name="gid"> <Viewbox Stretch="Uniform"> <Path Fill="#80D0E0FF" Stroke="Red" StrokeThickness="3" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M79,3L65,82 17,91 50,138 96,157 104,192 175,154 190,167 218,78 156,76 157,9 111,39z"/> </Viewbox> <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=Title}" FontSize="18" Background="Transparent" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20" FontFamily="Impact" Foreground="#C030A060"/> <TextBlock Text="Right Click Anywhere to Close" Background="Black" Width="200" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="14" TextWrapping="Wrap" /> </Grid> </Window> """