Browse Source

String, enum and boolean properties on a form now loading and being generated in the python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3837 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
2fdc3ee671
  1. 9
      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. 135
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlDefaultPropertyValues.cs
  6. 27
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlImeModeProperty.cs
  7. 29
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlProperty.cs
  8. 27
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlRightToLeftProperty.cs
  9. 29
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlTextProperty.cs
  10. 99
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs
  11. 91
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalker.cs
  12. 46
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonPropertyValueAssignment.cs
  13. 69
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs
  14. 53
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAccessibleRoleFormTestFixture.cs
  15. 65
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScaleModeFormTestFixture.cs
  16. 53
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScrollFormTestFixture.cs
  17. 68
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateDoubleBufferedFormTestFixture.cs
  18. 62
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateImeModeFormTestFixture.cs
  19. 62
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateRightToLeftFormTestFixture.cs
  20. 59
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IgnoreDesignTimePropertiesTestFixture.cs
  21. 114
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsDefaultPropertyValueTests.cs
  22. 53
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadAccessibleRoleTestFixture.cs
  23. 60
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormWithBooleanPropertiesSetTestFixture.cs
  24. 76
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/ShouldSerializeTests.cs
  25. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -86,7 +86,15 @@
<Compile Include="Src\PythonConsoleCompletionDataProvider.cs" /> <Compile Include="Src\PythonConsoleCompletionDataProvider.cs" />
<Compile Include="Src\PythonConsoleHost.cs" /> <Compile Include="Src\PythonConsoleHost.cs" />
<Compile Include="Src\PythonConsolePad.cs" /> <Compile Include="Src\PythonConsolePad.cs" />
<Compile Include="Src\PythonControlAutoScaleModeProperty.cs" />
<Compile Include="Src\PythonControlAutoValidateProperty.cs" />
<Compile Include="Src\PythonControlBooleanProperty.cs" />
<Compile Include="Src\PythonControlDefaultPropertyValues.cs" />
<Compile Include="Src\PythonControlFieldExpression.cs" /> <Compile Include="Src\PythonControlFieldExpression.cs" />
<Compile Include="Src\PythonControlImeModeProperty.cs" />
<Compile Include="Src\PythonControlProperty.cs" />
<Compile Include="Src\PythonControlRightToLeftProperty.cs" />
<Compile Include="Src\PythonControlTextProperty.cs" />
<Compile Include="Src\PythonDesignerGenerator.cs" /> <Compile Include="Src\PythonDesignerGenerator.cs" />
<Compile Include="Src\PythonDesignerLoader.cs" /> <Compile Include="Src\PythonDesignerLoader.cs" />
<Compile Include="Src\PythonDesignerLoaderProvider.cs" /> <Compile Include="Src\PythonDesignerLoaderProvider.cs" />
@ -102,6 +110,7 @@
<Compile Include="Src\PythonParser.cs" /> <Compile Include="Src\PythonParser.cs" />
<Compile Include="Src\PythonProcessRunner.cs" /> <Compile Include="Src\PythonProcessRunner.cs" />
<Compile Include="Src\PythonProject.cs" /> <Compile Include="Src\PythonProject.cs" />
<Compile Include="Src\PythonPropertyValueAssignment.cs" />
<Compile Include="Src\PythonResolver.cs" /> <Compile Include="Src\PythonResolver.cs" />
<Compile Include="Src\RunPythonCommand.cs" /> <Compile Include="Src\RunPythonCommand.cs" />
<Compile Include="Src\StandardPythonModules.cs" /> <Compile Include="Src\StandardPythonModules.cs" />

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

@ -0,0 +1,27 @@
// <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

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

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

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

@ -0,0 +1,135 @@
// <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.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Contains the default values for all properties on a Control, Form or UserControl.
/// </summary>
public class PythonControlDefaultPropertyValues
{
Dictionary<string, PythonControlProperty> defaultPropertyValues = new Dictionary<string, PythonControlProperty>();
public PythonControlDefaultPropertyValues()
{
defaultPropertyValues.Add("Text", new PythonControlTextProperty());
defaultPropertyValues.Add("AutoValidate", new PythonControlAutoValidateProperty());
defaultPropertyValues.Add("Enabled", new PythonControlBooleanProperty(true));
defaultPropertyValues.Add("AutoScaleMode", new PythonControlAutoScaleModeProperty());
defaultPropertyValues.Add("DoubleBuffered", new PythonControlBooleanProperty(false));
defaultPropertyValues.Add("ImeMode", new PythonControlImeModeProperty());
defaultPropertyValues.Add("RightToLeft", new PythonControlRightToLeftProperty());
}
/// <summary>
/// Determines if the property value has its default value.
/// </summary>
/// <param name="propertyName">The name of the property.</param>
/// <param name="obj">The object that has the property.</param>
/// <returns>False if the property does not exist.</returns>
public bool IsDefaultValue(string propertyName, object obj)
{
PropertyInfo propertyInfo = obj.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
if (propertyInfo != null) {
object propertyValue = propertyInfo.GetValue(obj, null);
return IsDefaultValue(propertyInfo, propertyValue);
}
return false;
}
/// <summary>
/// Determines if the property value is the default value by checking the DefaultValueAttribute.
/// </summary>
/// <param name="propertyDescriptor">The property descriptor for the property.</param>
/// <param name="obj">The object that has the property.</param>
/// <remarks>
/// For some properties such as Form.AutoValidate there is no default value specified by the
/// DefaultValueAttribute.
/// </remarks>
public bool IsDefaultValue(PropertyDescriptor propertyDescriptor, object obj)
{
PropertyInfo propertyInfo = obj.GetType().GetProperty(propertyDescriptor.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
if (propertyInfo != null) {
return IsDefaultValue(propertyInfo, propertyDescriptor.GetValue(obj));
}
return false;
}
/// <summary>
/// Determines if the property value is the default value by checking the DefaultValueAttribute.
/// </summary>
/// <remarks>
/// For some properties such as Form.AutoValidate there is no default value specified by the
/// DefaultValueAttribute.
/// </remarks>
public bool IsDefaultValue(PropertyInfo propertyInfo, object propertyValue)
{
// Check default attribute.
DefaultValueAttribute defaultValueAttribute = (DefaultValueAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(DefaultValueAttribute), true);
if (defaultValueAttribute != null) {
if (defaultValueAttribute.Value != null) {
return defaultValueAttribute.Value.Equals(propertyValue);
}
return defaultValueAttribute.Value == propertyValue;
}
PythonControlProperty controlProperty = null;
if (defaultPropertyValues.TryGetValue(propertyInfo.Name, out controlProperty)) {
return controlProperty.IsDefaultValue(propertyValue);
}
if (propertyInfo.Name == "BackColor") {
// Default is Control.DefaultBackColor
return true;
} else if (propertyInfo.Name == "Visible") {
return true;
} else if (propertyInfo.Name == "Icon") {
return true;
} else if (propertyInfo.Name == "Location") {
// 0, 0
return true;
} else if (propertyInfo.Name == "Margin") {
// Padding.DefaultMargin.
return true;
} else if (propertyInfo.Name == "MinimumSize") {
// 0, 0
return true;
} else if (propertyInfo.Name == "TransparencyKey") {
return true;
} else if (propertyInfo.Name == "AutoScrollMargin") {
return true;
} else if (propertyInfo.Name == "AutoScrollMinSize") {
return true;
} else if (propertyInfo.Name == "HorizontalScroll") {
return true;
} else if (propertyInfo.Name == "VerticalScroll") {
return true;
} else if (propertyInfo.Name == "Cursor") {
// Cursors.Default
return true;
} else if (propertyInfo.Name == "Font") {
// Default is Control.DefaultFont
return true;
} 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

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

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

@ -0,0 +1,29 @@
// <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

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

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

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

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

@ -7,7 +7,9 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Reflection;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.PythonBinding; using ICSharpCode.PythonBinding;
@ -16,7 +18,7 @@ using ICSharpCode.TextEditor.Document;
namespace ICSharpCode.PythonBinding namespace ICSharpCode.PythonBinding
{ {
/// <summary> /// <summary>
/// Represents a form in the designer. Used to generate a form for the forms designer and generate /// Represents a form in the designer. Used to generate
/// Python code after the form has been changed in the designer. /// Python code after the form has been changed in the designer.
/// </summary> /// </summary>
public class PythonForm public class PythonForm
@ -24,6 +26,12 @@ namespace ICSharpCode.PythonBinding
StringBuilder codeBuilder; StringBuilder codeBuilder;
string indentString = String.Empty; string indentString = String.Empty;
int indent; int indent;
PythonControlDefaultPropertyValues defaultPropertyValues = new PythonControlDefaultPropertyValues();
public PythonForm()
: this("\t")
{
}
public PythonForm(string indentString) public PythonForm(string indentString)
{ {
@ -58,30 +66,94 @@ namespace ICSharpCode.PythonBinding
return codeBuilder.ToString(); return codeBuilder.ToString();
} }
/// <summary>
/// Should serialize a property if:
///
/// 1) It has a different value to its default.
/// 2) DesignerSerializationVisibility is set to Hidden.
/// </summary>
public bool ShouldSerialize(object obj, PropertyDescriptor propertyDescriptor)
{
if (propertyDescriptor.DesignTimeOnly) {
return false;
}
// Is default value?
bool serialize = !defaultPropertyValues.IsDefaultValue(propertyDescriptor, obj);
// Is visible to designer?
if (serialize) {
serialize = propertyDescriptor.SerializationVisibility == DesignerSerializationVisibility.Visible;
if (!serialize) {
serialize = (propertyDescriptor.Name == "AutoScaleMode");
}
}
// Is browsable?
if (serialize) {
// Always serialize the Name.
if (propertyDescriptor.Name != "Name" && propertyDescriptor.Name != "AutoScaleMode" && propertyDescriptor.Name != "ClientSize") {
serialize = propertyDescriptor.IsBrowsable;
}
}
return serialize;
}
void GenerateInitializeComponentMethodBodyInternal(Form form) void GenerateInitializeComponentMethodBodyInternal(Form form)
{ {
// Add method body. // Add method body.
AppendIndentedLine("self.SuspendLayout()"); AppendIndentedLine("self.SuspendLayout()");
AppendControl(form);
AppendForm(form);
AppendIndentedLine("self.ResumeLayout(False)"); AppendIndentedLine("self.ResumeLayout(False)");
AppendIndentedLine("self.PerformLayout()"); AppendIndentedLine("self.PerformLayout()");
} }
void AppendControl(Control control) /// <summary>
/// Generates python code for the form's InitializeComponent method.
/// </summary>
/// <remarks>
/// Note that when the form is loaded in the designer the Name property appears twice:
///
/// Property.ComponentType: System.Windows.Forms.Design.DesignerExtenders+NameExtenderProvider
/// Property.SerializationVisibility: Hidden
/// Property.IsBrowsable: True
///
/// Property.ComponentType: System.Windows.Forms.Design.ControlDesigner
/// Property.SerializationVisibility: Visible
/// Property.IsBrowsable: False
/// </remarks>
void AppendForm(Form form)
{ {
AppendComment(control.Name); AppendComment(form.Name);
AppendSize("ClientSize", control.ClientSize);
AppendIndentedLine("self.Name = \"" + control.Name + "\""); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(form);
foreach (PropertyDescriptor property in properties) {
if (property.SerializationVisibility == DesignerSerializationVisibility.Hidden && property.Name == "Name") {
// Skip the duplicate Name property.
} else {
AppendProperty(form, property);
}
}
} }
void AppendSize(string name, Size size) /// <summary>
/// Appends a property to the InitializeComponents method.
/// </summary>
void AppendProperty(object obj, PropertyDescriptor propertyDescriptor)
{ {
AppendIndented("self."); if (propertyDescriptor.Name == "RightToLeft") {
Append(name + " = "); Console.WriteLine("ImeMode");
Append(size.GetType().FullName); }
Append("(" + size.Width + ", " + size.Height + ")"); object propertyValue = propertyDescriptor.GetValue(obj);
AppendLine(); if (propertyValue == null) {
return;
}
if (ShouldSerialize(obj, propertyDescriptor)) {
AppendIndentedLine("self." + propertyDescriptor.Name + " = " + PythonPropertyValueAssignment.ToString(propertyValue));
}
} }
/// <summary> /// <summary>
@ -94,6 +166,9 @@ namespace ICSharpCode.PythonBinding
AppendIndentedLine("# "); AppendIndentedLine("# ");
} }
/// <summary>
/// Increases the indent of any append lines.
/// </summary>
void IncreaseIndent() void IncreaseIndent()
{ {
++indent; ++indent;

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

@ -27,6 +27,7 @@ namespace ICSharpCode.PythonBinding
IComponentCreator componentCreator; IComponentCreator componentCreator;
bool walkingAssignment; bool walkingAssignment;
Dictionary<string, object> createdObjects = new Dictionary<string, object>(); Dictionary<string, object> createdObjects = new Dictionary<string, object>();
string formName = String.Empty;
public PythonFormWalker(IComponentCreator componentCreator) public PythonFormWalker(IComponentCreator componentCreator)
{ {
@ -52,6 +53,7 @@ namespace ICSharpCode.PythonBinding
public override bool Walk(ClassDefinition node) public override bool Walk(ClassDefinition node)
{ {
formName = node.Name.ToString();
if (node.Body != null) { if (node.Body != null) {
node.Body.Walk(this); node.Body.Walk(this);
} }
@ -61,7 +63,7 @@ namespace ICSharpCode.PythonBinding
public override bool Walk(FunctionDefinition node) public override bool Walk(FunctionDefinition node)
{ {
if (IsInitializeComponentMethod(node)) { if (IsInitializeComponentMethod(node)) {
form = (Form)componentCreator.CreateComponent(typeof(Form), "MainForm"); form = (Form)componentCreator.CreateComponent(typeof(Form), formName);
node.Body.Walk(this); node.Body.Walk(this);
} }
return false; return false;
@ -70,34 +72,30 @@ namespace ICSharpCode.PythonBinding
public override bool Walk(AssignmentStatement node) public override bool Walk(AssignmentStatement node)
{ {
if (node.Left.Count > 0) { if (node.Left.Count > 0) {
MemberExpression memberExpression = node.Left[0] as MemberExpression; MemberExpression lhsMemberExpression = node.Left[0] as MemberExpression;
if (memberExpression != null) { if (lhsMemberExpression != null) {
fieldExpression = PythonControlFieldExpression.Create(memberExpression); fieldExpression = PythonControlFieldExpression.Create(lhsMemberExpression);
MemberExpression rhsMemberExpression = node.Right as MemberExpression;
if (rhsMemberExpression != null) {
string name = PythonControlFieldExpression.GetMemberName(rhsMemberExpression);
SetPropertyValue(fieldExpression.MemberName, name);
} else {
walkingAssignment = true; walkingAssignment = true;
node.Right.Walk(this); node.Right.Walk(this);
walkingAssignment = false; walkingAssignment = false;
} }
} }
}
return false; return false;
} }
public override bool Walk(ConstantExpression node) public override bool Walk(ConstantExpression node)
{ {
Control control = GetCurrentControl(); SetPropertyValue(fieldExpression.MemberName, node.Value);
SetPropertyValue(control, fieldExpression.MemberName, node.Value);
return false; return false;
} }
Control GetCurrentControl()
{
string variableName = PythonControlFieldExpression.GetVariableNameFromSelfReference(fieldExpression.FullMemberName);
if (variableName.Length > 0) {
return GetControl(variableName);
}
return form;
}
public override bool Walk(CallExpression node) public override bool Walk(CallExpression node)
{ {
MemberExpression memberExpression = node.Target as MemberExpression; MemberExpression memberExpression = node.Target as MemberExpression;
@ -118,6 +116,12 @@ namespace ICSharpCode.PythonBinding
return false; return false;
} }
public override bool Walk(NameExpression node)
{
SetPropertyValue(fieldExpression.MemberName, node.Name.ToString());
return false;
}
/// <summary> /// <summary>
/// Gets the arguments passed to the call expression. /// Gets the arguments passed to the call expression.
/// </summary> /// </summary>
@ -140,18 +144,42 @@ namespace ICSharpCode.PythonBinding
} }
/// <summary> /// <summary>
/// Sets the value of a form's property. /// Sets the value of a property on the current control.
/// </summary>
bool SetPropertyValue(string name, object propertyValue)
{
Control control = GetCurrentControl();
return SetPropertyValue(control, name, propertyValue);
}
/// <summary>
/// Sets the value of a property on the control.
/// </summary> /// </summary>
bool SetPropertyValue(Control control, string name, object @value) bool SetPropertyValue(Control control, string name, object propertyValue)
{ {
PropertyInfo propertyInfo = control.GetType().GetProperty(name); PropertyDescriptor property = TypeDescriptor.GetProperties(control).Find(name, true);
if (propertyInfo != null) { if (property != null) {
propertyInfo.SetValue(control, @value, null); propertyValue = ConvertPropertyValue(property, propertyValue);
property.SetValue(control, propertyValue);
return true; return true;
} }
return false; return false;
} }
/// <summary>
/// Converts the value to the property's type if required.
/// </summary>
static object ConvertPropertyValue(PropertyDescriptor propertyDescriptor, object propertyValue)
{
if (propertyDescriptor.PropertyType != propertyValue.GetType()) {
if (propertyDescriptor.PropertyType.IsEnum) {
return Enum.Parse(propertyDescriptor.PropertyType, GetUnqualifiedEnumValue(propertyValue as String));
}
return Convert.ChangeType(propertyValue, propertyDescriptor.PropertyType);
}
return propertyValue;
}
Type GetType(string typeName) Type GetType(string typeName)
{ {
Type type = componentCreator.GetType(typeName); Type type = componentCreator.GetType(typeName);
@ -192,5 +220,26 @@ namespace ICSharpCode.PythonBinding
} }
return null; return null;
} }
Control GetCurrentControl()
{
string variableName = PythonControlFieldExpression.GetVariableNameFromSelfReference(fieldExpression.FullMemberName);
if (variableName.Length > 0) {
return GetControl(variableName);
}
return form;
}
/// <summary>
/// Gets the unqualified enum value from a fully qualified value.
/// </summary>
static string GetUnqualifiedEnumValue(string fullyQualifiedEnumValue)
{
int index = fullyQualifiedEnumValue.LastIndexOf('.');
if (index > 0) {
return fullyQualifiedEnumValue.Substring(index + 1);
}
return fullyQualifiedEnumValue;
}
} }
} }

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

@ -0,0 +1,46 @@
// <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;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Represents a property value assignment in a form or control.
/// </summary>
public class PythonPropertyValueAssignment
{
PythonPropertyValueAssignment()
{
}
/// <summary>
/// Converts the property assignment to the equivalent python string.
/// </summary>
/// <remarks>
/// 1) Strings are returned surrounded by double quotes.
/// 2) Objects are returned with their full name (e.g. System.Windows.Forms.Size(100, 200)).
/// 3) Enums are returned with their full name (e.g. System.Windows.Forms.AccessibleRole.None).
/// 4) By default the ToString method is used on the property value.
/// </remarks>
public static string ToString(object propertyValue)
{
Type propertyType = propertyValue.GetType();
if (propertyType == typeof(String)) {
return "\"" + propertyValue + "\"";
} else if (propertyType == typeof(Size)) {
Size size = (Size)propertyValue;
return size.GetType().FullName + "(" + size.Width + ", " + size.Height + ")";
} else if (propertyType.IsEnum) {
return propertyType.FullName + "." + propertyValue.ToString();
}
return propertyValue.ToString();
}
}
}

69
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs

@ -0,0 +1,69 @@
// <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.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// The PythonForm class should be getting the value from the PropertyDescriptor and not
/// the PropertyInfo information returned from the form object. If this is not done then when the
/// user sets Enabled to false in the designer the value is not generated in the InitializeComponent method.
/// </summary>
[TestFixture]
public class EnabledSetUsingPropertyDescriptorTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
Form form = (Form)host.RootComponent;
form.ClientSize = new Size(284, 264);
form.AllowDrop = false;
form.Enabled = false;
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
PropertyDescriptor enabledPropertyDescriptor = descriptors.Find("Enabled", false);
enabledPropertyDescriptor.SetValue(form, false);
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.Name = \"MainForm\"\r\n" +
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.Enabled = False\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
}
}

53
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAccessibleRoleFormTestFixture.cs

@ -0,0 +1,53 @@
// <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 GenerateAccessibleRoleFormTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (Form form = new Form()) {
form.Name = "MainForm";
form.ClientSize = new Size(284, 264);
form.AccessibleRole = AccessibleRole.None;
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.AccessibleRole = System.Windows.Forms.AccessibleRole.None\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
}
}

65
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScaleModeFormTestFixture.cs

@ -0,0 +1,65 @@
// <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
{
/// <summary>
/// A Form has a base ContainerControl class which has an AutoScaleMode property. This has the following attributes:
///
/// Browsable = false
/// DesignerSerializationVisibility = Hidden
/// EditorBrowsable = EditorBrowsableState.Advanced
///
/// However the forms root designer overrides these and shows it in the designer.
///
/// This test fixture checks that the AutoScaleMode value will be generated in the form's code
/// by the python forms designer.
/// </summary>
[TestFixture]
public class GenerateAutoScaleModeFormTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (Form form = new Form()) {
form.Name = "MainForm";
form.ClientSize = new Size(284, 264);
form.AutoScaleMode = AutoScaleMode.Font;
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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
}
}

53
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScrollFormTestFixture.cs

@ -0,0 +1,53 @@
// <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 GenerateAutoScrollFormTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (Form form = new Form()) {
form.Name = "MainForm";
form.ClientSize = new Size(284, 264);
form.AutoScroll = true;
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.AutoScroll = True\r\n" +
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
}
}

68
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateDoubleBufferedFormTestFixture.cs

@ -0,0 +1,68 @@
// <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.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// The DoubleBuffered property on the Control class is a protected method so using the GetType().GetProperty(...)
/// method will not return it. This test checks that this property is generated when creating the python code
/// for the form.
/// </summary>
[TestFixture]
public class GenerateDoubleBufferedFormTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
Form form = (Form)host.RootComponent;
form.ClientSize = new Size(284, 264);
form.AllowDrop = false;
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor doubleBufferedPropertyDescriptor = descriptors.Find("DoubleBuffered", false);
doubleBufferedPropertyDescriptor.SetValue(form, true);
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
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.DoubleBuffered = True\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
}
}

62
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateImeModeFormTestFixture.cs

@ -0,0 +1,62 @@
// <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.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class GenerateImeModeFormTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
Form form = (Form)host.RootComponent;
form.ClientSize = new Size(284, 264);
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor doubleBufferedPropertyDescriptor = descriptors.Find("ImeMode", false);
doubleBufferedPropertyDescriptor.SetValue(form, ImeMode.Alpha);
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
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.ImeMode = System.Windows.Forms.ImeMode.Alpha\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
}
}

62
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateRightToLeftFormTestFixture.cs

@ -0,0 +1,62 @@
// <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.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class GenerateRightToLeftFormTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
Form form = (Form)host.RootComponent;
form.ClientSize = new Size(284, 264);
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor doubleBufferedPropertyDescriptor = descriptors.Find("RightToLeft", false);
doubleBufferedPropertyDescriptor.SetValue(form, RightToLeft.Yes);
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
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.RightToLeft = System.Windows.Forms.RightToLeft.Yes\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
}
}

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

@ -0,0 +1,59 @@
// <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.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// The python form code generator should ignore any design time properties (e.g. Locked) of the form.
/// These are put in the .resx file not the source code.
/// </summary>
[TestFixture]
public class IgnoreDesignTimePropertiesTestFixture
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
/// <summary>
/// Loads a form into a DesignSurface and checks that the PythonForm does not try to
/// add design time properties and does not throw a null reference exception.
/// </summary>
[Test]
public void DesignTimePropertyIsIgnore()
{
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
Form form = (Form)host.RootComponent;
form.AllowDrop = false;
form.ClientSize = new Size(200, 300);
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
PythonForm pythonForm = new PythonForm(" ");
string code = pythonForm.GenerateInitializeComponentMethod(form);
Assert.AreEqual(expectedCode, code);
}
}
}
}

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

@ -0,0 +1,114 @@
// <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.ComponentModel;
using System.ComponentModel.Design;
using System.Reflection;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// Tests the PythonControlDefaultPropertyValues.IsDefaultValue method.
/// This checks the property and returns true if the value of the property is the same as its default.
/// </summary>
[TestFixture]
public class IsDefaultPropertyValueTests
{
Form form;
PythonControlDefaultPropertyValues defaultPropertyValues;
[TestFixtureSetUp]
public void InitFixture()
{
form = new Form();
defaultPropertyValues = new PythonControlDefaultPropertyValues();
}
[TestFixtureTearDown]
public void TearDownFixture()
{
form.Dispose();
}
[Test]
public void TextPropertyDefaultIsEmptyString()
{
form.Text = String.Empty;
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("Text", form));
}
[Test]
public void TextPropertyIsNotEmptyString()
{
form.Text = "abc";
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("Text", form));
}
[Test]
public void AutoValidatePropertyDefaultIsEnablePreventFocusChange()
{
form.AutoValidate = AutoValidate.EnablePreventFocusChange;
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("AutoValidate", form));
}
[Test]
public void AutoValidatePropertyIsDisable()
{
form.AutoValidate = AutoValidate.Disable;
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("AutoValidate", form));
}
[Test]
public void EnabledPropertyDefaultIsTrue()
{
form.Enabled = true;
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("Enabled", form));
}
[Test]
public void EnabledPropertyIsFalse()
{
form.Enabled = false;
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("Enabled", form));
}
[Test]
public void AccessibleDescriptionDefaultValueIsNull()
{
form.AccessibleDescription = null;
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("AccessibleDescription", form));
}
[Test]
public void AutoScaleModeDefaultIsInherit()
{
form.AutoScaleMode = AutoScaleMode.Inherit;
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("AutoScaleMode", form));
}
[Test]
public void PropertyDoesNotExist()
{
Assert.IsFalse(defaultPropertyValues.IsDefaultValue("PropertyDoesNotExist", form));
}
[Test]
public void DoubleBufferedDefaultIsFalse()
{
PropertyInfo property = form.GetType().GetProperty("DoubleBuffered", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
property.SetValue(form, false, null);
Assert.IsTrue(defaultPropertyValues.IsDefaultValue("DoubleBuffered", form));
}
}
}

53
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadAccessibleRoleTestFixture.cs

@ -0,0 +1,53 @@
// <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
{
/// <summary>
/// Tests that the Form's AccessibleRole property can be loaded into the designer.
/// </summary>
[TestFixture]
public class LoadAccessibleRoleTestFixture : LoadFormTestFixtureBase
{
string pythonCode = "class TestForm(System.Windows.Forms.Form):\r\n" +
" def InitializeComponent(self):\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # TestForm\r\n" +
" # \r\n" +
" self.AccessibleRole = System.Windows.Forms.AccessibleRole.None\r\n" +
" self.Name = \"TestForm\"\r\n" +
" self.ResumeLayout(False)\r\n";
Form form;
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonFormWalker walker = new PythonFormWalker(this);
form = walker.CreateForm(pythonCode);
}
[TestFixtureTearDown]
public void TearDownFixture()
{
form.Dispose();
}
[Test]
public void AccessibleRoleIsNone()
{
Assert.AreEqual(AccessibleRole.None, form.AccessibleRole);
}
}
}

60
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormWithBooleanPropertiesSetTestFixture.cs

@ -0,0 +1,60 @@
// <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 LoadFormWithBooleanPropertiesSetTestFixture : LoadFormTestFixtureBase
{
string pythonCode = "class TestForm(System.Windows.Forms.Form):\r\n" +
" def InitializeComponent(self):\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # TestForm\r\n" +
" # \r\n" +
" self.AllowDrop = False\r\n" +
" self.Enabled = False\r\n" +
" self.Name = \"TestForm\"\r\n" +
" self.ResumeLayout(False)\r\n";
Form form;
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonFormWalker walker = new PythonFormWalker(this);
form = walker.CreateForm(pythonCode);
}
[TestFixtureTearDown]
public void TearDownFixture()
{
form.Dispose();
}
[Test]
public void FormEnabledIsFalse()
{
Assert.IsFalse(form.Enabled);
}
[Test]
public void FormAllowDropIsFalse()
{
Assert.IsFalse(form.AllowDrop);
}
}
}

76
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/ShouldSerializeTests.cs

@ -0,0 +1,76 @@
// <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.ComponentModel;
using System.ComponentModel.Design;
using System.Reflection;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
namespace PythonBinding.Tests.Designer
{
/// <summary>
/// Tests the PythonForm.ShouldSerialize method which determines whether a form's property
/// should be serialized.
/// </summary>
[TestFixture]
public class ShouldSerializeTests
{
PythonForm pythonForm;
Form form;
[TestFixtureSetUp]
public void SetUpFixture()
{
form = new Form();
}
[TestFixtureTearDown]
public void TearDownFixture()
{
form.Dispose();
}
[SetUp]
public void Init()
{
pythonForm = new PythonForm();
}
[Test]
public void ShouldNotSerializePropertyWithFalseBrowseAttribute()
{
AssertShouldNotSerialize("LayoutEngine", form);
}
[Test]
public void ShouldNotSerializeEmptyStringTextProperty()
{
form.Text = String.Empty;
AssertShouldNotSerialize("Text", form);
}
void AssertShouldSerialize(string propertyName, Form form)
{
AssertShouldSerialize(propertyName, form, true);
}
void AssertShouldNotSerialize(string propertyName, Form form)
{
AssertShouldSerialize(propertyName, form, false);
}
void AssertShouldSerialize(string propertyName, Form form, bool isTrue)
{
PropertyDescriptor property = TypeDescriptor.GetProperties(form).Find(propertyName, true);
Assert.AreEqual(isTrue, pythonForm.ShouldSerialize(form, property));
}
}
}

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

@ -145,12 +145,23 @@
<Compile Include="Converter\VBClassConversionTestFixture.cs" /> <Compile Include="Converter\VBClassConversionTestFixture.cs" />
<Compile Include="Converter\VBStringConcatTestFixture.cs" /> <Compile Include="Converter\VBStringConcatTestFixture.cs" />
<Compile Include="Converter\WhileLoopConversionTestFixture.cs" /> <Compile Include="Converter\WhileLoopConversionTestFixture.cs" />
<Compile Include="Designer\EnabledSetUsingPropertyDescriptorTestFixture.cs" />
<Compile Include="Designer\FindInitializeComponentMethodTestFixture.cs" /> <Compile Include="Designer\FindInitializeComponentMethodTestFixture.cs" />
<Compile Include="Designer\GenerateAccessibleRoleFormTestFixture.cs" />
<Compile Include="Designer\GenerateAutoScaleModeFormTestFixture.cs" />
<Compile Include="Designer\GenerateAutoScrollFormTestFixture.cs" />
<Compile Include="Designer\GenerateDoubleBufferedFormTestFixture.cs" />
<Compile Include="Designer\GenerateImeModeFormTestFixture.cs" />
<Compile Include="Designer\GenerateRightToLeftFormTestFixture.cs" />
<Compile Include="Designer\GenerateSimpleFormTestFixture.cs" /> <Compile Include="Designer\GenerateSimpleFormTestFixture.cs" />
<Compile Include="Designer\GeneratorMergeFindsInitializeComponentsTestFixture.cs" /> <Compile Include="Designer\GeneratorMergeFindsInitializeComponentsTestFixture.cs" />
<Compile Include="Designer\IgnoreDesignTimePropertiesTestFixture.cs" />
<Compile Include="Designer\InsertNewEventHandlerTestFixture.cs" /> <Compile Include="Designer\InsertNewEventHandlerTestFixture.cs" />
<Compile Include="Designer\IsDefaultPropertyValueTests.cs" />
<Compile Include="Designer\IsFullyQualifiedBaseClassFormDesignableTestFixture.cs" /> <Compile Include="Designer\IsFullyQualifiedBaseClassFormDesignableTestFixture.cs" />
<Compile Include="Designer\LoadAccessibleRoleTestFixture.cs" />
<Compile Include="Designer\LoadFormTestFixtureBase.cs" /> <Compile Include="Designer\LoadFormTestFixtureBase.cs" />
<Compile Include="Designer\LoadFormWithBooleanPropertiesSetTestFixture.cs" />
<Compile Include="Designer\LoadSimpleFormTestFixture.cs" /> <Compile Include="Designer\LoadSimpleFormTestFixture.cs" />
<Compile Include="Designer\LoadTextBoxTestFixture.cs" /> <Compile Include="Designer\LoadTextBoxTestFixture.cs" />
<Compile Include="Designer\MergeFormTestFixture.cs" /> <Compile Include="Designer\MergeFormTestFixture.cs" />
@ -162,6 +173,7 @@
<Compile Include="Designer\NullGeneratorPassedToLoader.cs" /> <Compile Include="Designer\NullGeneratorPassedToLoader.cs" />
<Compile Include="Designer\PythonDesignerLoaderProviderTestFixture.cs" /> <Compile Include="Designer\PythonDesignerLoaderProviderTestFixture.cs" />
<Compile Include="Designer\PythonDesignerLoaderTestFixture.cs" /> <Compile Include="Designer\PythonDesignerLoaderTestFixture.cs" />
<Compile Include="Designer\ShouldSerializeTests.cs" />
<Compile Include="Designer\TextBoxNotAddedToFormTestFixture.cs" /> <Compile Include="Designer\TextBoxNotAddedToFormTestFixture.cs" />
<Compile Include="Designer\TextEditorIndentPassedToGeneratorTestFixture.cs" /> <Compile Include="Designer\TextEditorIndentPassedToGeneratorTestFixture.cs" />
<Compile Include="Designer\UnknownTypeTestFixture.cs" /> <Compile Include="Designer\UnknownTypeTestFixture.cs" />

Loading…
Cancel
Save