Browse Source

Fixed bug in python forms designer failing to convert an integer into a double when loading a form with a property of type double.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4747 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
70942e3ac3
  1. 22
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDomSerializer.cs
  2. 9
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs
  3. 69
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadUserControlWithDoublePropertyTestFixture.cs
  4. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  5. 26
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DoublePropertyUserControl.cs

22
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDomSerializer.cs

@ -32,27 +32,7 @@ namespace ICSharpCode.PythonBinding @@ -32,27 +32,7 @@ namespace ICSharpCode.PythonBinding
{
this.indentString = indentString;
}
// public string GenerateInitializeComponentMethod(IDesignerHost host, IDesignerSerializationManager serializationManager)
// {
// return GenerateInitializeComponentMethod(host, serializationManager, String.Empty);
// }
//
// public string GenerateInitializeComponentMethod(IDesignerHost host, IDesignerSerializationManager serializationManager, string rootNamespace)
// {
// CodeMemberMethod method = FindInitializeComponentMethod(host, serializationManager);
//
// codeBuilder = new PythonCodeBuilder();
// codeBuilder.IndentString = indentString;
// codeBuilder.AppendIndentedLine("def " + method.Name + "(self):");
// codeBuilder.IncreaseIndent();
//
// GetResourceRootName(rootNamespace, host.RootComponent);
// AppendStatements(method.Statements);
//
// return codeBuilder.ToString();
// }
public string GenerateInitializeComponentMethodBody(IDesignerHost host, IDesignerSerializationManager serializationManager)
{
return GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty);

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

@ -304,8 +304,13 @@ namespace ICSharpCode.PythonBinding @@ -304,8 +304,13 @@ namespace ICSharpCode.PythonBinding
public static object ConvertPropertyValue(PropertyDescriptor propertyDescriptor, object propertyValue)
{
if (propertyValue != null) {
if (!propertyDescriptor.PropertyType.IsAssignableFrom(propertyValue.GetType())) {
return propertyDescriptor.Converter.ConvertFrom(propertyValue);
Type propertyValueType = propertyValue.GetType();
if (!propertyDescriptor.PropertyType.IsAssignableFrom(propertyValueType)) {
if (propertyDescriptor.Converter.CanConvertFrom(propertyValueType)) {
return propertyDescriptor.Converter.ConvertFrom(propertyValue);
}
TypeConverter converter = TypeDescriptor.GetConverter(propertyValue);
return converter.ConvertTo(propertyValue, propertyDescriptor.PropertyType);
}
}
return propertyValue;

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

@ -0,0 +1,69 @@ @@ -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.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 LoadUserControlWithDoublePropertyTestFixture
{
MockComponentCreator componentCreator = new MockComponentCreator();
DoublePropertyUserControl userControl;
Form form;
public string PythonCode {
get {
Type type = typeof(DoublePropertyUserControl);
componentCreator.AddType(type.FullName, type);
return "class MainForm(System.Windows.Forms.Form):\r\n" +
" def InitializeComponent(self):\r\n" +
" self._userControl = PythonBinding.Tests.Utils.DoublePropertyUserControl()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # userControl1\r\n" +
" # \r\n" +
" self._userControl.DoubleValue = 0\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(300, 400)\r\n" +
" self.Controls.Add(self._userControl)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n";
}
}
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonComponentWalker walker = new PythonComponentWalker(componentCreator);
form = walker.CreateComponent(PythonCode) as Form;
userControl = form.Controls[0] as DoublePropertyUserControl;
}
[TestFixtureTearDown]
public void TearDownFixture()
{
form.Dispose();
}
[Test]
public void UserControlDoubleProperty()
{
Assert.AreEqual(0, userControl.DoubleValue);
}
}
}

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

@ -260,6 +260,7 @@ @@ -260,6 +260,7 @@
<Compile Include="Designer\LoadTimerTestFixture.cs" />
<Compile Include="Designer\LoadToolTipTestFixture.cs" />
<Compile Include="Designer\LoadTreeViewTestFixture.cs" />
<Compile Include="Designer\LoadUserControlWithDoublePropertyTestFixture.cs" />
<Compile Include="Designer\MergeFormTestFixture.cs" />
<Compile Include="Designer\MissingInitializeComponentMethodTestFixture.cs" />
<Compile Include="Designer\NoNewLineAfterInitializeComponentTestFixture.cs" />
@ -338,6 +339,7 @@ @@ -338,6 +339,7 @@
<Compile Include="Utils\DerivedPythonDesignerLoader.cs" />
<Compile Include="Utils\DerivedPythonFormsDesignerDisplayBinding.cs" />
<Compile Include="Utils\DerivedToolStripMenuItem.cs" />
<Compile Include="Utils\DoublePropertyUserControl.cs" />
<Compile Include="Utils\FooItemCollection.cs" />
<Compile Include="Utils\MockClass.cs" />
<Compile Include="Utils\MockComponentCreator.cs" />

26
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DoublePropertyUserControl.cs

@ -0,0 +1,26 @@ @@ -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;
using System.Windows.Forms;
namespace PythonBinding.Tests.Utils
{
public class DoublePropertyUserControl : UserControl
{
double doubleValue = -1.1;
public DoublePropertyUserControl()
{
}
public double DoubleValue {
get { return doubleValue; }
set { doubleValue = value; }
}
}
}
Loading…
Cancel
Save