From 0b9ce6e1aba32a1d081c21aac1bd99cad74dae98 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sat, 14 Mar 2009 18:32:19 +0000 Subject: [PATCH] Python forms designer now supports the Form's Location property. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3852 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/PythonBinding.csproj | 1 + .../Src/PythonControlDefaultPropertyValues.cs | 4 +- .../Project/Src/PythonControlPointProperty.cs | 30 +++++++++++ .../PythonBinding/Project/Src/PythonForm.cs | 5 +- .../Src/PythonPropertyValueAssignment.cs | 3 ++ .../GenerateFormLocationTestFixture.cs | 54 +++++++++++++++++++ .../Designer/IsDefaultPropertyValueTests.cs | 14 +++++ .../Test/PythonBinding.Tests.csproj | 1 + 8 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlPointProperty.cs create mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormLocationTestFixture.cs diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj index 44f8b6c772..8beb05e895 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj @@ -94,6 +94,7 @@ + diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlDefaultPropertyValues.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlDefaultPropertyValues.cs index 77e5ffa3f7..8e953edfa0 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlDefaultPropertyValues.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlDefaultPropertyValues.cs @@ -35,6 +35,7 @@ namespace ICSharpCode.PythonBinding defaultPropertyValues.Add("MinimumSize", new PythonControlSizeProperty(0, 0)); defaultPropertyValues.Add("AutoScrollMinSize", new PythonControlSizeProperty(0, 0)); defaultPropertyValues.Add("AutoScrollMargin", new PythonControlSizeProperty(0, 0)); + defaultPropertyValues.Add("Location", new PythonControlPointProperty(0, 0)); } /// @@ -99,9 +100,6 @@ namespace ICSharpCode.PythonBinding return true; } else if (propertyInfo.Name == "Icon") { return true; - } else if (propertyInfo.Name == "Location") { - // 0, 0 - return true; } else if (propertyInfo.Name == "TransparencyKey") { return true; } else if (propertyInfo.Name == "Font") { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlPointProperty.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlPointProperty.cs new file mode 100644 index 0000000000..9b655b7476 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlPointProperty.cs @@ -0,0 +1,30 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Drawing; + +namespace ICSharpCode.PythonBinding +{ + public class PythonControlPointProperty : PythonControlProperty + { + Point defaultPoint; + + public PythonControlPointProperty(int x, int y) + { + defaultPoint = new Point(x, y); + } + + public override bool IsDefaultValue(object propertyValue) + { + if (propertyValue is Point) { + return (Point)propertyValue == defaultPoint; + } + return false; + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs index 314eaec585..d86f997e3c 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs @@ -142,10 +142,7 @@ namespace ICSharpCode.PythonBinding /// Appends a property to the InitializeComponents method. /// void AppendProperty(object obj, PropertyDescriptor propertyDescriptor) - { - if (propertyDescriptor.Name == "Cursor") { - Console.WriteLine("ImeMode"); - } + { object propertyValue = propertyDescriptor.GetValue(obj); if (propertyValue == null) { return; diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs index 23a378d694..4b7589538c 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs @@ -42,6 +42,9 @@ namespace ICSharpCode.PythonBinding return propertyType.FullName + "." + propertyValue.ToString(); } else if (propertyType == typeof(Cursor)) { return GetCursorToString(propertyValue as Cursor); + } else if (propertyType == typeof(Point)) { + Point point = (Point)propertyValue; + return point.GetType().FullName + "(" + point.X + ", " + point.Y + ")"; } return propertyValue.ToString(); } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormLocationTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormLocationTestFixture.cs new file mode 100644 index 0000000000..8fdc5b3c60 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormLocationTestFixture.cs @@ -0,0 +1,54 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Drawing; +using System.Windows.Forms; +using ICSharpCode.PythonBinding; +using NUnit.Framework; +using PythonBinding.Tests.Utils; + +namespace PythonBinding.Tests.Designer +{ + [TestFixture] + public class GenerateFormLocationTestFixture + { + string generatedPythonCode; + + [TestFixtureSetUp] + public void SetUpFixture() + { + using (Form form = new Form()) { + form.Name = "MainForm"; + form.ClientSize = new Size(284, 264); + form.Location = new Point(10, 20); + + string indentString = " "; + PythonForm pythonForm = new PythonForm(indentString); + generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); + } + } + + [Test] + public void GeneratedCode() + { + string expectedCode = "def InitializeComponent(self):\r\n" + + " self.SuspendLayout()\r\n" + + " # \r\n" + + " # MainForm\r\n" + + " # \r\n" + + " self.ClientSize = System.Drawing.Size(284, 264)\r\n" + + " self.Location = System.Drawing.Point(10, 20)\r\n" + + " self.Name = \"MainForm\"\r\n" + + " self.Visible = False\r\n" + + " self.ResumeLayout(False)\r\n" + + " self.PerformLayout()\r\n"; + + Assert.AreEqual(expectedCode, generatedPythonCode); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsDefaultPropertyValueTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsDefaultPropertyValueTests.cs index 4b329aa61b..e483cad94b 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsDefaultPropertyValueTests.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsDefaultPropertyValueTests.cs @@ -183,5 +183,19 @@ namespace PythonBinding.Tests.Designer form.AutoScrollMargin = new Size(100, 100); Assert.IsFalse(defaultPropertyValues.IsDefaultValue("AutoScrollMargin", form)); } + + [Test] + public void LocationDefaultIsEmpty() + { + form.Location = new Point(0, 0); + Assert.IsTrue(defaultPropertyValues.IsDefaultValue("Location", form)); + } + + [Test] + public void NonDefaultLocation() + { + form.Location = new Point(10, 20); + Assert.IsFalse(defaultPropertyValues.IsDefaultValue("Location", form)); + } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index a0bbc27cca..7220496a33 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -153,6 +153,7 @@ +