forked from IronLanguages/ironpython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_wpf.cs
More file actions
115 lines (99 loc) · 5.47 KB
/
_wpf.cs
File metadata and controls
115 lines (99 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
#if FEATURE_WPF || NETCOREAPP3_0
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Markup;
using System.Xml;
using Microsoft.Scripting.Runtime;
using IronPython.Runtime;
using IronPython.Runtime.Operations;
#if NETCOREAPP3_0
using Microsoft.Internal.Scripting.Runtime; // TODO: get rid of this once DynamicXamlReader is in the DLR
#endif
[assembly: PythonModule("_wpf", typeof(IronPython.Modules.Wpf), PlatformsAttribute.PlatformFamily.Windows)]
namespace IronPython.Modules {
/// <summary>
/// Provides helpers for interacting with Windows Presentation Foundation applications.
/// </summary>
public static class Wpf {
[SpecialName]
public static void PerformModuleReload(PythonContext/*!*/ context, PythonDictionary/*!*/ dict) {
try {
// loading of assemblies will fail when running with the "Microsoft.NETCore.App" framework
LoadAssemblies(context);
} catch { }
static void LoadAssemblies(PythonContext/*!*/ context) {
context.DomainManager.LoadAssembly(typeof(XamlReader).Assembly); // PresentationFramework
context.DomainManager.LoadAssembly(typeof(Clipboard).Assembly); // PresentationCore
context.DomainManager.LoadAssembly(typeof(DependencyProperty).Assembly); // WindowsBase
context.DomainManager.LoadAssembly(typeof(System.Xaml.XamlReader).Assembly);// System.Xaml
}
}
/// <summary>
/// Loads XAML from the specified XmlReader and returns the deserialized object. Any event handlers
/// are bound to methods defined in the provided module. Any named objects are assigned to the object.
///
/// The provided object is expected to be the same type as the root of the XAML element.
/// </summary>
public static object LoadComponent(CodeContext context, object self, string filename) {
if (filename == null) {
throw PythonOps.TypeError("expected str, got None");
} else if (self == null) {
throw PythonOps.TypeError("expected module, got None");
}
return DynamicXamlReader.LoadComponent(self, context.LanguageContext.Operations, filename, XamlReader.GetWpfSchemaContext());
}
/// <summary>
/// Loads XAML from the specified XmlReader and returns the deserialized object. Any event handlers
/// are bound to methods defined in the provided module. Any named objects are assigned to the object.
///
/// The provided object is expected to be the same type as the root of the XAML element.
/// </summary>
public static object LoadComponent(CodeContext context, object self, [NotNull]Stream stream) {
if (self == null) {
throw PythonOps.TypeError("expected module, got None");
}
return DynamicXamlReader.LoadComponent(self, context.LanguageContext.Operations, stream, XamlReader.GetWpfSchemaContext());
}
/// <summary>
/// Loads XAML from the specified XmlReader and returns the deserialized object. Any event handlers
/// are bound to methods defined in the provided module. Any named objects are assigned to the object.
///
/// The provided object is expected to be the same type as the root of the XAML element.
/// </summary>
public static object LoadComponent(CodeContext context, object self, [NotNull]XmlReader xmlReader) {
if (self == null) {
throw PythonOps.TypeError("expected module, got None");
}
return DynamicXamlReader.LoadComponent(self, context.LanguageContext.Operations, xmlReader, XamlReader.GetWpfSchemaContext());
}
/// <summary>
/// Loads XAML from the specified XmlReader and returns the deserialized object. Any event handlers
/// are bound to methods defined in the provided module. Any named objects are assigned to the object.
///
/// The provided object is expected to be the same type as the root of the XAML element.
/// </summary>
public static object LoadComponent(CodeContext context, object self, [NotNull]TextReader filename) {
if (self == null) {
throw PythonOps.TypeError("expected module, got None");
}
return DynamicXamlReader.LoadComponent(self, context.LanguageContext.Operations, filename, XamlReader.GetWpfSchemaContext());
}
/// <summary>
/// Loads XAML from the specified XmlReader and returns the deserialized object. Any event handlers
/// are bound to methods defined in the provided module. Any named objects are assigned to the object.
///
/// The provided object is expected to be the same type as the root of the XAML element.
/// </summary>
public static object LoadComponent(CodeContext context, object self, [NotNull]System.Xaml.XamlXmlReader reader) {
if (self == null) {
throw PythonOps.TypeError("expected module, got None");
}
return DynamicXamlReader.LoadComponent(self, context.LanguageContext.Operations, reader);
}
}
}
#endif