diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs index db92195927..b46177af90 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControlFieldExpression.cs @@ -309,6 +309,9 @@ namespace ICSharpCode.PythonBinding object obj = componentCreator.GetComponent(variableName); if (obj == null) { obj = componentCreator.GetInstance(variableName); + if (obj == null) { + obj = GetInheritedObject(memberName, componentCreator.RootComponent); + } } if (obj != null) { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs index 9e85fe4bfc..34d1d5a5e0 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs @@ -557,8 +557,8 @@ namespace ICSharpCode.PythonBinding /// public void AppendExtenderProperty(PythonCodeBuilder codeBuilder, string propertyOwnerName, ExtenderProvidedPropertyAttribute extender, PropertyDescriptor propertyDescriptor, object propertyValue) { - IComponent component = extender.Provider as IComponent; - codeBuilder.AppendIndented("self._" + component.Site.Name); + PythonDesignerComponent designerComponent = PythonDesignerComponentFactory.CreateDesignerComponent(extender.Provider as IComponent); + codeBuilder.AppendIndented(designerComponent.GetPropertyOwnerName()); codeBuilder.Append(".Set" + propertyDescriptor.Name); codeBuilder.Append("("); codeBuilder.Append(propertyOwnerName); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateInheritedToolTipTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateInheritedToolTipTestFixture.cs new file mode 100644 index 0000000000..d3b40521d2 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateInheritedToolTipTestFixture.cs @@ -0,0 +1,77 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Drawing; +using System.Windows.Forms; +using ICSharpCode.PythonBinding; +using NUnit.Framework; +using PythonBinding.Tests.Utils; + +namespace PythonBinding.Tests.Designer +{ + class PublicToolTipBaseForm : Form + { + public ToolTip toolTip; + Container components = new Container(); + + public PublicToolTipBaseForm() + { + toolTip = new ToolTip(components); + } + } + + class PublicToolTipDerivedForm : PublicToolTipBaseForm + { + } + + [TestFixture] + public class GenerateInheritedToolTipTestFixture + { + string generatedPythonCode; + + [TestFixtureSetUp] + public void SetUpFixture() + { + using (DesignSurface designSurface = new DesignSurface(typeof(PublicToolTipDerivedForm))) { + IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); + IEventBindingService eventBindingService = new MockEventBindingService(host); + PublicToolTipDerivedForm form = (PublicToolTipDerivedForm)host.RootComponent; + form.ClientSize = new Size(284, 264); + + PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); + PropertyDescriptor descriptor = descriptors.Find("Name", false); + descriptor.SetValue(form, "MainForm"); + + form.toolTip.SetToolTip(form, "test"); + + string indentString = " "; + PythonControl pythonForm = new PythonControl(indentString); + generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); + } + } + + [Test] + public void GeneratedCode() + { + string expectedCode = "def InitializeComponent(self):\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.toolTip.SetToolTip(self, \"test\")\r\n" + + " self.ResumeLayout(False)\r\n" + + " self.PerformLayout()\r\n"; + + Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadInheritedToolTipTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadInheritedToolTipTestFixture.cs new file mode 100644 index 0000000000..15fb47f0e1 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadInheritedToolTipTestFixture.cs @@ -0,0 +1,68 @@ +// +// +// +// +// $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 LoadInheritedToolTipTestFixture : LoadFormTestFixtureBase + { + public override string PythonCode { + get { + ComponentCreator.AddType("PythonBinding.Tests.Designer.PublicToolTipDerivedForm", typeof(PythonBinding.Tests.Designer.PublicToolTipDerivedForm)); + + return "class TestForm(PythonBinding.Tests.Designer.PublicToolTipDerivedForm):\r\n" + + " def InitializeComponent(self):\r\n" + + " self._button1 = System.Windows.Forms.Button()\r\n" + + " self.SuspendLayout()\r\n" + + " # \r\n" + + " # button1\r\n" + + " # \r\n" + + " self._button1.Location = System.Drawing.Point(0, 0)\r\n" + + " self._button1.Name = \"button1\"\r\n" + + " self._button1.Size = System.Drawing.Size(10, 10)\r\n" + + " self._button1.TabIndex = 0\r\n" + + " self._button1.Text = \"button1\"\r\n" + + " self.toolTip.SetToolTip(self._button1, \"buttonTest\")\r\n" + + " # \r\n" + + " # MainForm\r\n" + + " # \r\n" + + " self.ClientSize = System.Drawing.Size(284, 264)\r\n" + + " self.Controls.Add(self._button1)\r\n" + + " self.Name = \"MainForm\"\r\n" + + " self.toolTip.SetToolTip(self, \"test\")\r\n" + + " self.ResumeLayout(False)\r\n" + + " self.PerformLayout()\r\n"; + } + } + + [Test] + public void FormHasToolTip() + { + PublicToolTipDerivedForm form = Form as PublicToolTipDerivedForm; + Assert.AreEqual("test", form.toolTip.GetToolTip(form)); + } + + [Test] + public void ButtonHasToolTip() + { + PublicToolTipDerivedForm form = Form as PublicToolTipDerivedForm; + Assert.AreEqual("buttonTest", form.toolTip.GetToolTip(form.Controls[0])); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index 1c43075c45..f179b9c203 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -198,6 +198,7 @@ + @@ -238,6 +239,7 @@ +