Browse Source

Python forms designer now supports Control's Padding property.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3853 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
dc48a81a05
  1. 10
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  2. 27
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlAutoScaleModeProperty.cs
  3. 30
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlAutoValidateProperty.cs
  4. 26
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlBooleanProperty.cs
  5. 28
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlCursorProperty.cs
  6. 41
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlDefaultPropertyValues.cs
  7. 27
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlImeModeProperty.cs
  8. 30
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlPointProperty.cs
  9. 29
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlProperty.cs
  10. 27
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlRightToLeftProperty.cs
  11. 30
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlSizeProperty.cs
  12. 29
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlTextProperty.cs
  13. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs
  14. 3
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs
  15. 54
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormPaddingTestFixture.cs
  16. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IgnoreDesignTimePropertiesTestFixture.cs
  17. 16
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsDefaultPropertyValueTests.cs
  18. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

10
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj

@ -87,18 +87,8 @@ @@ -87,18 +87,8 @@
<Compile Include="Src\PythonConsoleCompletionDataProvider.cs" />
<Compile Include="Src\PythonConsoleHost.cs" />
<Compile Include="Src\PythonConsolePad.cs" />
<Compile Include="Src\PythonControlAutoScaleModeProperty.cs" />
<Compile Include="Src\PythonControlAutoValidateProperty.cs" />
<Compile Include="Src\PythonControlBooleanProperty.cs" />
<Compile Include="Src\PythonControlCursorProperty.cs" />
<Compile Include="Src\PythonControlDefaultPropertyValues.cs" />
<Compile Include="Src\PythonControlFieldExpression.cs" />
<Compile Include="Src\PythonControlImeModeProperty.cs" />
<Compile Include="Src\PythonControlPointProperty.cs" />
<Compile Include="Src\PythonControlProperty.cs" />
<Compile Include="Src\PythonControlRightToLeftProperty.cs" />
<Compile Include="Src\PythonControlSizeProperty.cs" />
<Compile Include="Src\PythonControlTextProperty.cs" />
<Compile Include="Src\PythonDesignerGenerator.cs" />
<Compile Include="Src\PythonDesignerLoader.cs" />
<Compile Include="Src\PythonDesignerLoaderProvider.cs" />

27
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlAutoScaleModeProperty.cs

@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
// <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.Windows.Forms;
namespace ICSharpCode.PythonBinding
{
public class PythonControlAutoScaleModeProperty : PythonControlProperty
{
public PythonControlAutoScaleModeProperty()
{
}
public override bool IsDefaultValue(object propertyValue)
{
if (propertyValue is AutoScaleMode) {
return (AutoScaleMode)propertyValue == AutoScaleMode.Inherit;
}
return false;
}
}
}

30
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlAutoValidateProperty.cs

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
// <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.Windows.Forms;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Represents the AutoValidate property for a Form or ContainerControl.
/// </summary>
public class PythonControlAutoValidateProperty : PythonControlProperty
{
public PythonControlAutoValidateProperty()
{
}
public override bool IsDefaultValue(object propertyValue)
{
if (propertyValue is AutoValidate) {
return (AutoValidate)propertyValue == AutoValidate.EnablePreventFocusChange;
}
return false;
}
}
}

26
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlBooleanProperty.cs

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
// <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;
namespace ICSharpCode.PythonBinding
{
public class PythonControlBooleanProperty : PythonControlProperty
{
bool defaultValue;
public PythonControlBooleanProperty(bool defaultValue)
{
this.defaultValue = defaultValue;
}
public override bool IsDefaultValue(object propertyValue)
{
return (bool)propertyValue == defaultValue;
}
}
}

28
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlCursorProperty.cs

@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
// <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.Windows.Forms;
namespace ICSharpCode.PythonBinding
{
public class PythonControlCursorProperty : PythonControlProperty
{
public PythonControlCursorProperty()
{
}
public override bool IsDefaultValue(object propertyValue)
{
Cursor cursor = propertyValue as Cursor;
if (cursor != null) {
return cursor == Cursors.Default;
}
return false;
}
}
}

41
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlDefaultPropertyValues.cs

@ -19,23 +19,24 @@ namespace ICSharpCode.PythonBinding @@ -19,23 +19,24 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public class PythonControlDefaultPropertyValues
{
Dictionary<string, PythonControlProperty> defaultPropertyValues = new Dictionary<string, PythonControlProperty>();
Dictionary<string, object> defaultPropertyValues = new Dictionary<string, object>();
public PythonControlDefaultPropertyValues()
{
defaultPropertyValues.Add("Text", new PythonControlTextProperty());
defaultPropertyValues.Add("AutoValidate", new PythonControlAutoValidateProperty());
defaultPropertyValues.Add("Enabled", new PythonControlBooleanProperty(true));
defaultPropertyValues.Add("Visible", new PythonControlBooleanProperty(true));
defaultPropertyValues.Add("AutoScaleMode", new PythonControlAutoScaleModeProperty());
defaultPropertyValues.Add("DoubleBuffered", new PythonControlBooleanProperty(false));
defaultPropertyValues.Add("ImeMode", new PythonControlImeModeProperty());
defaultPropertyValues.Add("RightToLeft", new PythonControlRightToLeftProperty());
defaultPropertyValues.Add("Cursor", new PythonControlCursorProperty());
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));
defaultPropertyValues.Add("Text", String.Empty);
defaultPropertyValues.Add("AutoValidate", AutoValidate.EnablePreventFocusChange);
defaultPropertyValues.Add("Enabled", true);
defaultPropertyValues.Add("Visible", true);
defaultPropertyValues.Add("AutoScaleMode", AutoScaleMode.Inherit);
defaultPropertyValues.Add("DoubleBuffered", false);
defaultPropertyValues.Add("ImeMode", ImeMode.NoControl);
defaultPropertyValues.Add("RightToLeft", RightToLeft.No);
defaultPropertyValues.Add("Cursor", Cursors.Default);
defaultPropertyValues.Add("MinimumSize", new Size(0, 0));
defaultPropertyValues.Add("AutoScrollMinSize", new Size(0, 0));
defaultPropertyValues.Add("AutoScrollMargin", new Size(0, 0));
defaultPropertyValues.Add("Location", new Point(0, 0));
defaultPropertyValues.Add("Padding", Padding.Empty);
}
/// <summary>
@ -90,9 +91,9 @@ namespace ICSharpCode.PythonBinding @@ -90,9 +91,9 @@ namespace ICSharpCode.PythonBinding
return defaultValueAttribute.Value == propertyValue;
}
PythonControlProperty controlProperty = null;
if (defaultPropertyValues.TryGetValue(propertyInfo.Name, out controlProperty)) {
return controlProperty.IsDefaultValue(propertyValue);
object defaultPropertyValue = null;
if (defaultPropertyValues.TryGetValue(propertyInfo.Name, out defaultPropertyValue)) {
return defaultPropertyValue.Equals(propertyValue);
}
if (propertyInfo.Name == "BackColor") {
@ -108,11 +109,7 @@ namespace ICSharpCode.PythonBinding @@ -108,11 +109,7 @@ namespace ICSharpCode.PythonBinding
} else if (propertyInfo.Name == "ForeColor") {
// Default is Control.DefaultForeColor
return true;
} else if (propertyInfo.Name == "Padding") {
// Padding.Empty.
return true;
}
return false;
}
}

27
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlImeModeProperty.cs

@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
// <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.Windows.Forms;
namespace ICSharpCode.PythonBinding
{
public class PythonControlImeModeProperty : PythonControlProperty
{
public PythonControlImeModeProperty()
{
}
public override bool IsDefaultValue(object propertyValue)
{
if (propertyValue is ImeMode) {
return (ImeMode)propertyValue == ImeMode.NoControl;
}
return false;
}
}
}

30
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlPointProperty.cs

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
// <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.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;
}
}
}

29
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlProperty.cs

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
// <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;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Represents a property on a control or form.
/// </summary>
public abstract class PythonControlProperty
{
public PythonControlProperty()
{
}
/// <summary>
/// Returns true if the property value matches the default for this control's property.
/// </summary>
public virtual bool IsDefaultValue(object propertyValue)
{
return false;
}
}
}

27
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlRightToLeftProperty.cs

@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
// <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.Windows.Forms;
namespace ICSharpCode.PythonBinding
{
public class PythonControlRightToLeftProperty : PythonControlProperty
{
public PythonControlRightToLeftProperty()
{
}
public override bool IsDefaultValue(object propertyValue)
{
if (propertyValue is RightToLeft) {
return (RightToLeft)propertyValue == RightToLeft.No;
}
return false;
}
}
}

30
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlSizeProperty.cs

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
// <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.Drawing;
namespace ICSharpCode.PythonBinding
{
public class PythonControlSizeProperty : PythonControlProperty
{
Size defaultSize;
public PythonControlSizeProperty(int width, int height)
{
defaultSize = new Size(width, height);
}
public override bool IsDefaultValue(object propertyValue)
{
if (propertyValue is Size) {
return (Size)propertyValue == defaultSize;
}
return false;
}
}
}

29
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlTextProperty.cs

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
// <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;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Represents a Control's Text Property.
/// </summary>
public class PythonControlTextProperty : PythonControlProperty
{
public PythonControlTextProperty()
{
}
/// <summary>
/// Returns true if the Text property's value is an empty string.
/// </summary>
public override bool IsDefaultValue(object propertyValue)
{
return (string)propertyValue == String.Empty;
}
}
}

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs

@ -143,6 +143,10 @@ namespace ICSharpCode.PythonBinding @@ -143,6 +143,10 @@ namespace ICSharpCode.PythonBinding
/// </summary>
void AppendProperty(object obj, PropertyDescriptor propertyDescriptor)
{
if (propertyDescriptor.Name == "Text") {
Console.WriteLine("asfads");
}
object propertyValue = propertyDescriptor.GetValue(obj);
if (propertyValue == null) {
return;

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

@ -45,6 +45,9 @@ namespace ICSharpCode.PythonBinding @@ -45,6 +45,9 @@ namespace ICSharpCode.PythonBinding
} else if (propertyType == typeof(Point)) {
Point point = (Point)propertyValue;
return point.GetType().FullName + "(" + point.X + ", " + point.Y + ")";
} else if (propertyType == typeof(Padding)) {
Padding padding = (Padding)propertyValue;
return padding.GetType().FullName + "(" + padding.Left + ", " + padding.Top + ", " + padding.Right + ", " + padding.Bottom + ")";
}
return propertyValue.ToString();
}

54
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormPaddingTestFixture.cs

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
// <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.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class GenerateFormPaddingTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (Form form = new Form()) {
form.Name = "MainForm";
form.ClientSize = new Size(284, 264);
form.Padding = new Padding(10, 20, 15, 18);
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.Name = \"MainForm\"\r\n" +
" self.Visible = False\r\n" +
" self.Padding = System.Windows.Forms.Padding(10, 20, 15, 18)\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
}
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IgnoreDesignTimePropertiesTestFixture.cs

@ -37,7 +37,7 @@ namespace PythonBinding.Tests.Designer @@ -37,7 +37,7 @@ namespace PythonBinding.Tests.Designer
/// add design time properties and does not throw a null reference exception.
/// </summary>
[Test]
public void DesignTimePropertyIsIgnore()
public void DesignTimePropertyIsIgnored()
{
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));

16
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsDefaultPropertyValueTests.cs

@ -196,6 +196,20 @@ namespace PythonBinding.Tests.Designer @@ -196,6 +196,20 @@ namespace PythonBinding.Tests.Designer
{
form.Location = new Point(10, 20);
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("Location", form));
}
}
[Test]
public void PaddingPropertyDefaultIsPaddingEmpty()
{
form.Padding = Padding.Empty;
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("Padding", form));
}
[Test]
public void NonDefaultPaddingProperty()
{
form.Padding = new Padding(10, 10, 10, 10);
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("Padding", form));
}
}
}

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

@ -154,6 +154,7 @@ @@ -154,6 +154,7 @@
<Compile Include="Designer\GenerateCursorFormTestFixture.cs" />
<Compile Include="Designer\GenerateDoubleBufferedFormTestFixture.cs" />
<Compile Include="Designer\GenerateFormLocationTestFixture.cs" />
<Compile Include="Designer\GenerateFormPaddingTestFixture.cs" />
<Compile Include="Designer\GenerateImeModeFormTestFixture.cs" />
<Compile Include="Designer\GenerateMinSizeFormTestFixture.cs" />
<Compile Include="Designer\GenerateRightToLeftFormTestFixture.cs" />

Loading…
Cancel
Save