diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IComponentCreator.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IComponentCreator.cs index b3a9cf2bbe..fff016442c 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IComponentCreator.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IComponentCreator.cs @@ -41,6 +41,11 @@ namespace ICSharpCode.PythonBinding /// Null if the component cannot be found. IComponent GetComponent(string name); + /// + /// Gets the RootComponent. + /// + IComponent RootComponent { get; } + /// /// Creates a new instance of the object given its type. /// diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs index 7709ad2401..c46ed3effa 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs @@ -36,12 +36,15 @@ namespace ICSharpCode.PythonBinding ConstantExpression constantExpression = a.Expression as ConstantExpression; MemberExpression memberExpression = a.Expression as MemberExpression; CallExpression callExpression = a.Expression as CallExpression; + NameExpression nameExpression = a.Expression as NameExpression; if (constantExpression != null) { args.Add(constantExpression.Value); } else if (memberExpression != null) { args.Add(Deserialize(memberExpression)); - } else if(callExpression != null) { + } else if (callExpression != null) { args.Add(Deserialize(callExpression)); + } else if (nameExpression != null) { + args.Add(Deserialize(nameExpression)); } } return args; @@ -71,7 +74,7 @@ namespace ICSharpCode.PythonBinding } return null; } - + /// /// Deserializes expressions of the form: /// @@ -85,7 +88,7 @@ namespace ICSharpCode.PythonBinding int value = Convert.ToInt32(lhs) | Convert.ToInt32(rhs); return Enum.ToObject(lhs.GetType(), value); } - + /// /// Deserializes expressions of the form: /// @@ -127,6 +130,19 @@ namespace ICSharpCode.PythonBinding return componentCreator.GetInstance(PythonControlFieldExpression.GetVariableName(field.MemberName)); } + /// + /// Deserializes expressions of the form: + /// + /// 1) self + /// + object Deserialize(NameExpression nameExpression) + { + if ("self" == nameExpression.Name.ToString().ToLowerInvariant()) { + return componentCreator.RootComponent; + } + return null; + } + Type GetType(PythonControlFieldExpression field) { return componentCreator.GetType(PythonControlFieldExpression.GetPrefix(field.FullMemberName)); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs index df76014942..2d95a8f134 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs @@ -358,8 +358,8 @@ namespace ICSharpCode.PythonBinding // Execute the method on the object. if (member != null) { - object parameter = deserializer.Deserialize(node.Args[0].Expression); - member.GetType().InvokeMember(field.MethodName, BindingFlags.InvokeMethod, Type.DefaultBinder, member, new object[] {parameter}); + object[] args = deserializer.GetArguments(node).ToArray(); + member.GetType().InvokeMember(field.MethodName, BindingFlags.InvokeMethod, Type.DefaultBinder, member, args); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs index 0a29979aef..1b7ef2cc82 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs @@ -261,6 +261,8 @@ namespace ICSharpCode.PythonBinding int endIndex = name.IndexOf('.'); if (endIndex > 0) { return GetVariableName(name.Substring(0, endIndex)); + } else if (name.StartsWith("_")) { + return GetVariableName(name); } return String.Empty; } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs index 87344533d1..039da1b42f 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs @@ -77,6 +77,13 @@ namespace ICSharpCode.PythonBinding return component; } + /// + /// Gets the root component. + /// + public IComponent RootComponent { + get { return base.LoaderHost.RootComponent; } + } + /// /// Creates a new instance of the specified type. /// diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadToolTipTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadToolTipTestFixture.cs new file mode 100644 index 0000000000..d9550178ca --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadToolTipTestFixture.cs @@ -0,0 +1,50 @@ +// +// +// +// +// $Revision$ +// + +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 LoadToolTipTestFixture : LoadFormTestFixtureBase + { + public override string PythonCode { + get { + return "class TestForm(System.Windows.Forms.Form):\r\n" + + " def InitializeComponent(self):\r\n" + + " self._components = System.ComponentModel.Container()\r\n" + + " self._toolTip1 = System.Windows.Forms.ToolTip(self._components)\r\n" + + " self.SuspendLayout()\r\n" + + " # \r\n" + + " # MainForm\r\n" + + " # \r\n" + + " self.ClientSize = System.Drawing.Size(284, 264)\r\n" + + " self.Name = \"MainForm\"\r\n" + + " self._toolTip1.SetToolTip(self, \"test\")\r\n" + + " self.ResumeLayout(False)\r\n" + + " self.PerformLayout()\r\n"; + } + } + + [Test] + public void FormHasToolTip() + { + ToolTip toolTip = (ToolTip)base.ComponentCreator.GetComponent("toolTip1"); + Assert.AreEqual("test",toolTip.GetToolTip(Form)); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs index 6b59d54122..7082459711 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs @@ -84,6 +84,10 @@ namespace PythonBinding.Tests.Designer return null; } + public IComponent RootComponent { + get { return null; } + } + public object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer) { throw new NotImplementedException(); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonControlFieldExpressionTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonControlFieldExpressionTests.cs index 8d83374e07..5558575861 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonControlFieldExpressionTests.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonControlFieldExpressionTests.cs @@ -95,7 +95,16 @@ namespace PythonBinding.Tests.Designer CallExpression expression = PythonParserHelper.GetCallExpression(code); PythonControlFieldExpression field = PythonControlFieldExpression.Create(expression); AssertAreEqual(field, String.Empty, "Items", "Add", "self.Items"); - } + } + + [Test] + public void SetToolTipMethodCall() + { + string code = "self._toolTip1.SetToolTip(self, \"Test\")"; + CallExpression expression = PythonParserHelper.GetCallExpression(code); + PythonControlFieldExpression field = PythonControlFieldExpression.Create(expression); + AssertAreEqual(field, "toolTip1", "_toolTip1", "SetToolTip", "self._toolTip1"); + } [Test] public void GetMemberNames() @@ -182,7 +191,7 @@ namespace PythonBinding.Tests.Designer { string expected = "Variable: " + variableName + " Member: " + memberName + " Method: " + methodName + " FullMemberName: " + fullMemberName; string actual = "Variable: " + field.VariableName + " Member: " + field.MemberName + " Method: " + field.MethodName + " FullMemberName: " + field.FullMemberName; - Assert.AreEqual(expected, actual); + Assert.AreEqual(expected, actual, actual); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs index ff7e126862..98a7b875bf 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs @@ -67,7 +67,7 @@ namespace PythonBinding.Tests.Designer designedForm = new Form(); designedForm.Name = "NewMainForm"; - mockDesignerLoaderHost.RootComponent = designedForm; + mockDesignerLoaderHost.RootComponent = designedForm; loader.CallPerformFlush(); } @@ -137,6 +137,12 @@ namespace PythonBinding.Tests.Designer Assert.AreEqual(expectedProperty, loader.GetEventProperty(e)); } + [Test] + public void GetRootComponentFromLoader() + { + Assert.AreEqual(designedForm, loader.RootComponent); + } + /// /// The code that the designer loader will parse. /// diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index 1d7aafd84d..f0ae1e2f61 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -218,6 +218,7 @@ + diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs index 2bfe6f4dfd..0f9d645db8 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockComponentCreator.cs @@ -25,14 +25,23 @@ namespace PythonBinding.Tests.Utils List typeNames = new List(); PropertyDescriptor propertyDescriptor; EventDescriptor eventDescriptor; - + IComponent rootComponent; + public MockComponentCreator() { } + public IComponent RootComponent { + get { return rootComponent; } + } + public IComponent CreateComponent(Type componentClass, string name) { object instance = componentClass.Assembly.CreateInstance(componentClass.FullName); + + if (rootComponent == null) { + rootComponent = instance as IComponent; + } CreatedComponent c = new CreatedComponent(componentClass.FullName, name, (IComponent)instance); createdComponents.Add(c);