Browse Source

Python forms designer shows a more useful error message if it is unable to find a type to create a local variable.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4738 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
ccc5df09db
  1. BIN
      data/resources/StringResources.de.resources
  2. BIN
      data/resources/StringResources.es-mx.resources
  3. BIN
      data/resources/StringResources.es.resources
  4. BIN
      data/resources/StringResources.nl.resources
  5. 14
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs
  6. 39
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/UnknownTypeTestFixture.cs
  7. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  8. 123
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Strings.resx
  9. BIN
      src/Main/StartUp/Project/Resources/StringResources.resources

BIN
data/resources/StringResources.de.resources

Binary file not shown.

BIN
data/resources/StringResources.es-mx.resources

Binary file not shown.

BIN
data/resources/StringResources.es.resources

Binary file not shown.

BIN
data/resources/StringResources.nl.resources

Binary file not shown.

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

@ -16,6 +16,7 @@ using System.Resources; @@ -16,6 +16,7 @@ using System.Resources;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.Core;
using IronPython.Compiler.Ast;
namespace ICSharpCode.PythonBinding
@ -111,7 +112,10 @@ namespace ICSharpCode.PythonBinding @@ -111,7 +112,10 @@ namespace ICSharpCode.PythonBinding
} else if (lhsNameExpression != null) {
CallExpression callExpression = node.Right as CallExpression;
if (callExpression != null) {
CreateInstance(lhsNameExpression.Name.ToString(), callExpression);
object instance = CreateInstance(lhsNameExpression.Name.ToString(), callExpression);
if (instance == null) {
ThrowCouldNotFindTypeException(callExpression.Target as MemberExpression);
}
}
}
}
@ -275,7 +279,7 @@ namespace ICSharpCode.PythonBinding @@ -275,7 +279,7 @@ namespace ICSharpCode.PythonBinding
} else if (IsResource(memberExpression)) {
fieldExpression.SetPropertyValue(componentCreator, GetResource(node));
} else {
throw new PythonComponentWalkerException(String.Format("Could not find type '{0}'.", PythonControlFieldExpression.GetMemberName(memberExpression)));
ThrowCouldNotFindTypeException(memberExpression);
}
}
} else if (node.Target is IndexExpression) {
@ -393,5 +397,11 @@ namespace ICSharpCode.PythonBinding @@ -393,5 +397,11 @@ namespace ICSharpCode.PythonBinding
object array = deserializer.Deserialize(callExpression);
fieldExpression.SetPropertyValue(componentCreator, array);
}
void ThrowCouldNotFindTypeException(MemberExpression memberExpression)
{
string typeName = PythonControlFieldExpression.GetMemberName(memberExpression);
throw new PythonComponentWalkerException(String.Format(StringParser.Parse("${res:ICSharpCode.PythonBinding.UnknownTypeName}"), typeName));
}
}
}

39
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/UnknownTypeTestFixture.cs

@ -9,8 +9,10 @@ using System; @@ -9,8 +9,10 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Resources;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.PythonBinding;
using IronPython.Compiler.Ast;
using Microsoft.Scripting;
@ -25,6 +27,16 @@ namespace PythonBinding.Tests.Designer @@ -25,6 +27,16 @@ namespace PythonBinding.Tests.Designer
/// </summary>
[TestFixture]
public class UnknownTypeTestFixture
{
[TestFixtureSetUp]
public void SetUpFixture()
{
ResourceManager rm = new ResourceManager("PythonBinding.Tests.Strings", GetType().Assembly);
ResourceService.RegisterNeutralStrings(rm);
}
[Test]
public void SelfAssignmentWithUnknownTypeRhs()
{
string pythonCode = "from System.Windows.Forms import Form\r\n" +
"\r\n" +
@ -35,13 +47,36 @@ namespace PythonBinding.Tests.Designer @@ -35,13 +47,36 @@ namespace PythonBinding.Tests.Designer
" def InitializeComponent(self):\r\n" +
" self.ClientSize = Unknown.Type(10)\r\n";
try {
PythonComponentWalker walker = new PythonComponentWalker(new MockComponentCreator());
walker.CreateComponent(pythonCode);
Assert.Fail("Exception should have been thrown before this.");
} catch (PythonComponentWalkerException ex) {
string expectedMessage = String.Format(StringParser.Parse("${res:ICSharpCode.PythonBinding.UnknownTypeName}"), "Unknown.Type");
Assert.AreEqual(expectedMessage, ex.Message);
}
}
[Test]
[ExpectedException(typeof(PythonComponentWalkerException))]
public void PythonFormWalkerExceptionThrown()
public void LocalVariableAssignmentWithUnknownTypeRhs()
{
string pythonCode = "from System.Windows.Forms import Form\r\n" +
"\r\n" +
"class MainForm(System.Windows.Forms.Form):\r\n" +
" def __init__(self):\r\n" +
" self.InitializeComponent()\r\n" +
"\r\n" +
" def InitializeComponent(self):\r\n" +
" abc = Unknown.Type(10)\r\n";
try {
PythonComponentWalker walker = new PythonComponentWalker(new MockComponentCreator());
walker.CreateComponent(pythonCode);
Assert.Fail("Exception should have been thrown before this.");
} catch (PythonComponentWalkerException ex) {
string expectedMessage = String.Format(StringParser.Parse("${res:ICSharpCode.PythonBinding.UnknownTypeName}"), "Unknown.Type");
Assert.AreEqual(expectedMessage, ex.Message);
}
}
}
}

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

@ -377,6 +377,7 @@ @@ -377,6 +377,7 @@
<Compile Include="Utils\PythonParserHelper.cs" />
<Compile Include="Utils\SupportInitCustomControl.cs" />
<EmbeddedResource Include="Designer\App.ico" />
<EmbeddedResource Include="Strings.resx" />
<None Include="TODO.txt" />
</ItemGroup>
<ItemGroup>

123
src/AddIns/BackendBindings/Python/PythonBinding/Test/Strings.resx

@ -0,0 +1,123 @@ @@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ICSharpCode.PythonBinding.UnknownTypeName" xml:space="preserve">
<value>Could not find type '{0}'. Are you missing an assembly reference?</value>
</data>
</root>

BIN
src/Main/StartUp/Project/Resources/StringResources.resources

Binary file not shown.
Loading…
Cancel
Save