Browse Source

Python form designer now supports assigning a local variable to a property on a control.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4699 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
4a261f6202
  1. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs
  2. 54
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs
  3. 64
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadLocalVariablePropertyAssignmentTestFixture.cs
  4. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

2
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs

@ -148,7 +148,7 @@ namespace ICSharpCode.PythonBinding @@ -148,7 +148,7 @@ namespace ICSharpCode.PythonBinding
return false;
}
fieldExpression.SetPropertyValue(componentCreator, node.Name.ToString());
fieldExpression.SetPropertyValue(componentCreator, node);
return false;
}

54
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs

@ -261,6 +261,30 @@ namespace ICSharpCode.PythonBinding @@ -261,6 +261,30 @@ namespace ICSharpCode.PythonBinding
return currentComponent;
}
/// <summary>
/// Sets the property value that is referenced by this field expression.
/// </summary>
/// <remarks>
/// This method checks that the name expression matches a created instance before
/// converting the name expression as a string and setting the property value.
/// </remarks>
public bool SetPropertyValue(IComponentCreator componentCreator, NameExpression nameExpression)
{
object component = GetComponent(componentCreator);
PropertyDescriptor property = GetProperty(component, memberName);
if (property != null) {
string name = nameExpression.Name.ToString();
if (property.PropertyType != typeof(bool)) {
object instance = componentCreator.GetInstance(name);
if (instance != null) {
return SetPropertyValue(component, memberName, instance);
}
}
return SetPropertyValue(component, memberName, name);
}
return false;
}
/// <summary>
/// Sets the property value that is referenced by this field expression.
/// </summary>
@ -270,13 +294,7 @@ namespace ICSharpCode.PythonBinding @@ -270,13 +294,7 @@ namespace ICSharpCode.PythonBinding
/// </remarks>
public bool SetPropertyValue(IComponentCreator componentCreator, object propertyValue)
{
object component = null;
if (IsSelfReference) {
component = GetObject(componentCreator);
component = GetObjectForMemberName(component);
} else {
component = componentCreator.GetInstance(variableName);
}
object component = GetComponent(componentCreator);
return SetPropertyValue(component, memberName, propertyValue);
}
@ -437,7 +455,7 @@ namespace ICSharpCode.PythonBinding @@ -437,7 +455,7 @@ namespace ICSharpCode.PythonBinding
/// </summary>
static bool SetPropertyValue(object component, string name, object propertyValue)
{
PropertyDescriptor property = TypeDescriptor.GetProperties(component).Find(name, true);
PropertyDescriptor property = GetProperty(component, name);
if (property != null) {
propertyValue = ConvertPropertyValue(property, propertyValue);
property.SetValue(component, propertyValue);
@ -445,5 +463,25 @@ namespace ICSharpCode.PythonBinding @@ -445,5 +463,25 @@ namespace ICSharpCode.PythonBinding
}
return false;
}
/// <summary>
/// Gets the component that this field refers to.
/// </summary>
object GetComponent(IComponentCreator componentCreator)
{
object component = null;
if (IsSelfReference) {
component = GetObject(componentCreator);
component = GetObjectForMemberName(component);
} else {
component = componentCreator.GetInstance(variableName);
}
return component;
}
static PropertyDescriptor GetProperty(object component, string name)
{
return TypeDescriptor.GetProperties(component).Find(name, true);
}
}
}

64
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadLocalVariablePropertyAssignmentTestFixture.cs

@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
// <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 LoadLocalVariablePropertyAssignmentTestFixture : LoadFormTestFixtureBase
{
public override string PythonCode {
get {
return "class MainForm(System.Windows.Forms.Form):\r\n" +
" def InitializeComponent(self):\r\n" +
" button1 = System.Windows.Forms.Button()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.AcceptButton = button1\r\n" +
" self.ClientSize = System.Drawing.Size(300, 400)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n";
}
}
[Test]
public void OneComponentCreated()
{
Assert.AreEqual(1, ComponentCreator.CreatedComponents.Count);
}
[Test]
public void TwoObjectsCreated()
{
Assert.AreEqual(2, ComponentCreator.CreatedInstances.Count);
}
[Test]
public void ButtonInstance()
{
CreatedInstance expectedInstance = new CreatedInstance(typeof(Button), new object[0], "button1", false);
Assert.AreEqual(expectedInstance, ComponentCreator.CreatedInstances[0]);
}
[Test]
public void AcceptButtonPropertyIsNotNull()
{
Assert.IsNotNull(Form.AcceptButton);
}
}
}

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

@ -246,6 +246,7 @@ @@ -246,6 +246,7 @@
<Compile Include="Designer\LoadInheritedToolTipTestFixture.cs" />
<Compile Include="Designer\LoadListViewFormTestFixture.cs" />
<Compile Include="Designer\LoadLocalImageResourceTestFixture.cs" />
<Compile Include="Designer\LoadLocalVariablePropertyAssignmentTestFixture.cs" />
<Compile Include="Designer\LoadMenuStripFormTestFixture.cs" />
<Compile Include="Designer\LoadMonthCalendarTestFixture.cs" />
<Compile Include="Designer\LoadSimpleFormTestFixture.cs" />

Loading…
Cancel
Save