Browse Source

Python forms designer now creates an instance of the form's base class instead of just a Form or UserControl when loading a form in the designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4561 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
ccddc2cd65
  1. 8
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs
  2. 47
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/FormBaseClassCreatedOnLoadTestFixture.cs
  3. 11
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadSimpleFormTestFixture.cs
  4. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  5. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs

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

@ -33,8 +33,7 @@ namespace ICSharpCode.PythonBinding
PythonCodeDeserializer deserializer; PythonCodeDeserializer deserializer;
ClassDefinition classDefinition; ClassDefinition classDefinition;
public PythonComponentWalker(IComponentCreator componentCreator) public PythonComponentWalker(IComponentCreator componentCreator) {
{
this.componentCreator = componentCreator; this.componentCreator = componentCreator;
deserializer = new PythonCodeDeserializer(componentCreator); deserializer = new PythonCodeDeserializer(componentCreator);
} }
@ -232,6 +231,11 @@ namespace ICSharpCode.PythonBinding
Type GetComponentType() Type GetComponentType()
{ {
string baseClass = GetBaseClassName(classDefinition); string baseClass = GetBaseClassName(classDefinition);
Type type = componentCreator.GetType(baseClass);
if (type != null) {
return type;
}
if (baseClass.Contains("UserControl")) { if (baseClass.Contains("UserControl")) {
return typeof(UserControl); return typeof(UserControl);
} }

47
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/FormBaseClassCreatedOnLoadTestFixture.cs

@ -0,0 +1,47 @@
// <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.ComponentModel.Design;
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 FormBaseClassCreatedOnLoadTestFixture : LoadFormTestFixtureBase
{
public override string PythonCode {
get {
ComponentCreator.AddType("FormBase.FormBase", typeof(Component));
return "class TestForm(FormBase.FormBase):\r\n" +
" def InitializeComponent(self):\r\n" +
" pass";
}
}
[Test]
public void BaseClassNamePassedAsGetTypeParam()
{
Assert.AreEqual("FormBase.FormBase", ComponentCreator.TypeNames[0]);
}
[Test]
public void BaseClassTypePassedToCreateComponent()
{
Assert.AreEqual(typeof(Component).FullName, ComponentCreator.CreatedComponents[0].TypeName);
}
}
}

11
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadSimpleFormTestFixture.cs

@ -74,15 +74,22 @@ namespace PythonBinding.Tests.Designer
Size size = new Size(300, 400); Size size = new Size(300, 400);
Assert.AreEqual(size, Form.ClientSize); Assert.AreEqual(size, Form.ClientSize);
} }
[Test]
public void BaseClassTypeNameLookedUp()
{
Assert.AreEqual("System.Windows.Forms.Form", ComponentCreator.TypeNames[0]);
}
/// <summary> /// <summary>
/// The System.Drawing.Size type name should have been looked up by the PythonFormWalker when /// The System.Drawing.Size type name should have been looked up by the PythonFormWalker when
/// parsing the InitializeComponent method. /// parsing the InitializeComponent method. Note that this is the second type that is looked up.
/// The first lookup is the base class type.
/// </summary> /// </summary>
[Test] [Test]
public void TypeNameLookedUp() public void TypeNameLookedUp()
{ {
Assert.AreEqual("System.Drawing.Size", ComponentCreator.TypeNames[0]); Assert.AreEqual("System.Drawing.Size", ComponentCreator.TypeNames[1]);
} }
[Test] [Test]

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

@ -175,6 +175,7 @@
<Compile Include="Designer\EventHandlerExistsWithIncorrectParameterCountTestFixture.cs" /> <Compile Include="Designer\EventHandlerExistsWithIncorrectParameterCountTestFixture.cs" />
<Compile Include="Designer\FindAddRangeMethodTests.cs" /> <Compile Include="Designer\FindAddRangeMethodTests.cs" />
<Compile Include="Designer\FindInitializeComponentMethodTestFixture.cs" /> <Compile Include="Designer\FindInitializeComponentMethodTestFixture.cs" />
<Compile Include="Designer\FormBaseClassCreatedOnLoadTestFixture.cs" />
<Compile Include="Designer\GenerateAcceptButtonFormTestFixture.cs" /> <Compile Include="Designer\GenerateAcceptButtonFormTestFixture.cs" />
<Compile Include="Designer\GenerateAccessibleRoleFormTestFixture.cs" /> <Compile Include="Designer\GenerateAccessibleRoleFormTestFixture.cs" />
<Compile Include="Designer\GenerateAutoScaleModeFormTestFixture.cs" /> <Compile Include="Designer\GenerateAutoScaleModeFormTestFixture.cs" />

12
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs

@ -34,6 +34,7 @@ namespace PythonBinding.Tests.Utils
bool getResourceWriterCalled; bool getResourceWriterCalled;
CultureInfo cultureInfoPassedToGetResourceWriter; CultureInfo cultureInfoPassedToGetResourceWriter;
IResourceReader resourceReader; IResourceReader resourceReader;
Dictionary<string, Type> types = new Dictionary<string, Type>();
public MockComponentCreator() public MockComponentCreator()
{ {
@ -109,6 +110,14 @@ namespace PythonBinding.Tests.Utils
return o; return o;
} }
/// <summary>
/// Adds a type that can be returned from the GetType method.
/// </summary>
public void AddType(string name, Type type)
{
types.Add(name, type);
}
public Type GetType(string typeName) public Type GetType(string typeName)
{ {
typeNames.Add(typeName); typeNames.Add(typeName);
@ -125,6 +134,9 @@ namespace PythonBinding.Tests.Utils
if (type == null) { if (type == null) {
type = typeof(Component).Assembly.GetType(typeName); type = typeof(Component).Assembly.GetType(typeName);
} }
if (type == null) {
types.TryGetValue(typeName, out type);
}
return type; return type;
} }

Loading…
Cancel
Save