Browse Source

Added support for AnchorStyles in python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3919 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
64965103ae
  1. 6
      src/AddIns/BackendBindings/Python/PyWalker/ResolveWalker.cs
  2. 19
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs
  3. 16
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalker.cs
  4. 33
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs
  5. 57
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadAnchorStylesFormTestFixture.cs
  6. 22
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonCodeDeserializerTests.cs
  7. 18
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonPropertyAssignmentToStringTests.cs
  8. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

6
src/AddIns/BackendBindings/Python/PyWalker/ResolveWalker.cs

@ -146,6 +146,12 @@ namespace PyWalker @@ -146,6 +146,12 @@ namespace PyWalker
return base.Walk(node);
}
public override bool Walk(MemberExpression node)
{
writer.WriteLine("Member: " + node.Name);
return base.Walk(node);
}
public override bool Walk(FromImportStatement node)
{
writer.WriteLine("FromImport: " + node.Root.MakeString());

19
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs

@ -58,11 +58,28 @@ namespace ICSharpCode.PythonBinding @@ -58,11 +58,28 @@ namespace ICSharpCode.PythonBinding
MemberExpression memberExpression = node as MemberExpression;
CallExpression callExpression = node as CallExpression;
BinaryExpression binaryExpression = node as BinaryExpression;
if (callExpression != null) {
return Deserialize(callExpression);
}
} else if (binaryExpression != null) {
return Deserialize(binaryExpression);
}
return Deserialize(memberExpression);
}
/// <summary>
/// Deserializes expressions of the form:
///
/// System.Windows.Form.AnchorStyles.Top | System.Windows.Form.AnchorStyles.Bottom
/// </summary>
public object Deserialize(BinaryExpression binaryExpression)
{
object lhs = Deserialize(binaryExpression.Left);
object rhs = Deserialize(binaryExpression.Right);
int value = Convert.ToInt32(lhs) | Convert.ToInt32(rhs);
return Enum.ToObject(lhs.GetType(), value);
}
/// <summary>
/// Deserializes expressions of the form:

16
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalker.cs

@ -88,7 +88,12 @@ namespace ICSharpCode.PythonBinding @@ -88,7 +88,12 @@ namespace ICSharpCode.PythonBinding
SetPropertyValue(fieldExpression.MemberName, propertyValue);
} else {
walkingAssignment = true;
node.Right.Walk(this);
BinaryExpression binaryExpression = node.Right as BinaryExpression;
if (binaryExpression != null) {
WalkAssignment(binaryExpression);
} else {
node.Right.Walk(this);
}
walkingAssignment = false;
}
}
@ -137,6 +142,15 @@ namespace ICSharpCode.PythonBinding @@ -137,6 +142,15 @@ namespace ICSharpCode.PythonBinding
return false;
}
/// <summary>
/// Walks the binary expression which is the right hand side of an assignment statement.
/// </summary>
void WalkAssignment(BinaryExpression binaryExpression)
{
object value = deserializer.Deserialize(binaryExpression);
SetPropertyValue(fieldExpression.MemberName, value);
}
static bool IsInitializeComponentMethod(FunctionDefinition node)
{
string name = node.Name.ToString().ToLowerInvariant();

33
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs

@ -10,6 +10,7 @@ using System.Drawing; @@ -10,6 +10,7 @@ using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
using System.Reflection;
using System.Text;
namespace ICSharpCode.PythonBinding
{
@ -42,8 +43,6 @@ namespace ICSharpCode.PythonBinding @@ -42,8 +43,6 @@ namespace ICSharpCode.PythonBinding
} else if (propertyType == typeof(SizeF)) {
SizeF size = (SizeF)propertyValue;
return size.GetType().FullName + "(" + size.Width + ", " + size.Height + ")";
} else if (propertyType.IsEnum) {
return propertyType.FullName + "." + propertyValue.ToString();
} else if (propertyType == typeof(Cursor)) {
return GetCursorAsString(propertyValue as Cursor);
} else if (propertyType == typeof(Point)) {
@ -58,6 +57,11 @@ namespace ICSharpCode.PythonBinding @@ -58,6 +57,11 @@ namespace ICSharpCode.PythonBinding
} else if (propertyType == typeof(Font)) {
Font font = (Font)propertyValue;
return GetFontAsString(font);
} else if (propertyType == typeof(AnchorStyles)) {
AnchorStyles anchor = (AnchorStyles)propertyValue;
return GetAnchorStyleAsString(anchor);
} else if (propertyType.IsEnum) {
return propertyType.FullName + "." + propertyValue.ToString();
}
return propertyValue.ToString();
}
@ -100,5 +104,30 @@ namespace ICSharpCode.PythonBinding @@ -100,5 +104,30 @@ namespace ICSharpCode.PythonBinding
{
return String.Concat(font.GetType().FullName, "(\"", font.Name, "\", ", font.Size.ToString(CultureInfo.InvariantCulture), ", ", typeof(FontStyle).FullName, ".", font.Style, ", ", typeof(GraphicsUnit).FullName, ".", font.Unit, ", ", font.GdiCharSet, ")");
}
static string GetAnchorStyleAsString(AnchorStyles anchorStyles)
{
if (anchorStyles == AnchorStyles.None) {
return typeof(AnchorStyles).FullName + "." + AnchorStyles.None;
}
StringBuilder text = new StringBuilder();
bool firstStyle = true;
foreach (AnchorStyles style in AnchorStyles.GetValues(typeof(AnchorStyles))) {
if (style != AnchorStyles.None) {
if ((anchorStyles & style) == style) {
if (firstStyle) {
firstStyle = false;
} else {
text.Append(" | ");
}
text.Append(typeof(AnchorStyles).FullName);
text.Append('.');
text.Append(style);
}
}
}
return text.ToString();
}
}
}

57
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadAnchorStylesFormTestFixture.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class LoadAnchorStylesTestFixture : LoadFormTestFixtureBase
{
public override string PythonCode {
get {
return "class TestForm(System.Windows.Forms.Form):\r\n" +
" def InitializeComponent(self):\r\n" +
" self._textBox1 = System.Windows.Forms.TextBox()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # textBox1\r\n" +
" # \r\n" +
" self._textBox1.Name = \"textBoxName\"\r\n" +
" self._textBox1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left\r\n" +
" # \r\n" +
" # TestForm\r\n" +
" # \r\n" +
" self.Name = \"TestForm\"\r\n" +
" self.Controls.Add(self._textBox1)\r\n" +
" self.ResumeLayout(False)\r\n";
}
}
[TestFixtureSetUp]
public new void SetUpFixture()
{
base.SetUpFixture();
}
[Test]
public void TextBoxAnchorStyle()
{
AnchorStyles style = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
TextBox textBox = Form.Controls[0] as TextBox;
Assert.AreEqual(style, textBox.Anchor);
}
}
}

22
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonCodeDeserializerTests.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using IronPython.Compiler.Ast;
@ -31,7 +32,8 @@ namespace PythonBinding.Tests.Designer @@ -31,7 +32,8 @@ namespace PythonBinding.Tests.Designer
[ExpectedException(typeof(ArgumentNullException))]
public void NullIronPythonAstNode()
{
deserializer.Deserialize(null);
Node node = null;
deserializer.Deserialize(node);
}
[Test]
@ -73,7 +75,25 @@ namespace PythonBinding.Tests.Designer @@ -73,7 +75,25 @@ namespace PythonBinding.Tests.Designer
Assert.AreEqual(expectedArgs, args);
}
[Test]
public void EnumBitwiseOr()
{
string pythonCode = "self.textBox1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom";
AnchorStyles expectedStyles = AnchorStyles.Top | AnchorStyles.Bottom;
Assert.AreEqual(expectedStyles, Deserialize(pythonCode));
}
[Test]
public void MultipleEnumBitwiseOr()
{
string pythonCode = "self.textBox1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left";
AnchorStyles expectedStyles = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
Assert.AreEqual(expectedStyles, Deserialize(pythonCode));
}
/// <summary>
/// Deserializes the right hand side of the assignment.
/// </summary>

18
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonPropertyAssignmentToStringTests.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
@ -47,5 +48,22 @@ namespace PythonBinding.Tests.Designer @@ -47,5 +48,22 @@ namespace PythonBinding.Tests.Designer
SizeF sizeF = new SizeF(4, 10);
Assert.AreEqual("System.Drawing.SizeF(4, 10)", PythonPropertyValueAssignment.ToString(sizeF));
}
[Test]
public void AnchorStyleToString()
{
AnchorStyles anchorStyle = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
string expectedText = "System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right";
Assert.AreEqual(expectedText, PythonPropertyValueAssignment.ToString(anchorStyle));
}
[Test]
public void AnchorStyleNoneToString()
{
AnchorStyles anchorStyle = AnchorStyles.None;
string expectedText = "System.Windows.Forms.AnchorStyles.None";
Assert.AreEqual(expectedText, PythonPropertyValueAssignment.ToString(anchorStyle));
}
}
}

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -168,6 +168,7 @@ @@ -168,6 +168,7 @@
<Compile Include="Designer\InsertNewEventHandlerTestFixture.cs" />
<Compile Include="Designer\IsFullyQualifiedBaseClassFormDesignableTestFixture.cs" />
<Compile Include="Designer\LoadAccessibleRoleTestFixture.cs" />
<Compile Include="Designer\LoadAnchorStylesFormTestFixture.cs" />
<Compile Include="Designer\LoadColorFromArgbTestFixture.cs" />
<Compile Include="Designer\LoadCursorTestFixture.cs" />
<Compile Include="Designer\LoadFontTestFixture.cs" />

Loading…
Cancel
Save