diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs
index 5f966503a9..29aa7a690e 100644
--- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs
+++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs
@@ -83,13 +83,13 @@ namespace ICSharpCode.PythonBinding
}
void GenerateInitializeComponentMethodBodyInternal(Form form)
- {
- foreach (Control control in form.Controls) {
- AppendControlCreation(control);
- }
+ {
+ AppendChildControlCreation(form.Controls);
+ AppendChildControlSuspendLayout(form.Controls);
AppendIndentedLine("self.SuspendLayout()");
AppendForm(form);
+ AppendChildControlResumeLayout(form.Controls);
AppendIndentedLine("self.ResumeLayout(False)");
AppendIndentedLine("self.PerformLayout()");
}
@@ -99,30 +99,24 @@ namespace ICSharpCode.PythonBinding
///
void AppendForm(Form form)
{
-
// Add the controls on the form.
foreach (Control control in form.Controls) {
AppendControl(control);
}
// Add form.
- AppendControl(form, false);
-
- // Add controls to form.
- foreach (Control control in form.Controls) {
- AppendIndentedLine("self.Controls.Add(self." + control.Name + ")");
- }
+ AppendControl(form, false, false);
}
void AppendControl(Control control)
{
- AppendControl(control, true);
+ AppendControl(control, true, true);
}
///
/// Generates python code for the control.
///
- void AppendControl(Control control, bool addControlNameToProperty)
+ void AppendControl(Control control, bool addControlNameToProperty, bool addChildControlProperties)
{
AppendComment(control.Name);
@@ -134,6 +128,16 @@ namespace ICSharpCode.PythonBinding
foreach (PropertyDescriptor property in GetSerializableProperties(control)) {
AppendProperty(propertyOwnerName, control, property);
}
+
+ foreach (Control childControl in control.Controls) {
+ AppendIndentedLine(GetPropertyName(propertyOwnerName, "Controls") + ".Add(self._" + childControl.Name + ")");
+ }
+
+ if (addChildControlProperties) {
+ foreach (Control childControl in control.Controls) {
+ AppendControl(childControl, true, true);
+ }
+ }
}
///
@@ -199,9 +203,39 @@ namespace ICSharpCode.PythonBinding
codeBuilder.Append(text);
}
+ void AppendChildControlCreation(Control.ControlCollection controls)
+ {
+ foreach (Control control in controls) {
+ AppendControlCreation(control);
+ AppendChildControlCreation(control.Controls);
+ }
+ }
+
void AppendControlCreation(Control control)
{
- AppendIndentedLine("self._" + control.Name + " = " + control.GetType().FullName + "()");
+ AppendIndentedLine("self._" + control.Name + " = " + control.GetType().FullName + "()");
+ }
+
+ void AppendChildControlSuspendLayout(Control.ControlCollection controls)
+ {
+ AppendChildControlLayoutMethodCalls(controls, new string[] {"SuspendLayout()"});
+ }
+
+ void AppendChildControlResumeLayout(Control.ControlCollection controls)
+ {
+ AppendChildControlLayoutMethodCalls(controls, new string[] {"ResumeLayout(false)", "PerformLayout()"});
+ }
+
+
+ void AppendChildControlLayoutMethodCalls(Control.ControlCollection controls, string[] methods)
+ {
+ foreach (Control control in controls) {
+ if (control.Controls.Count > 0) {
+ foreach (string method in methods) {
+ AppendIndentedLine("self._" + control.Name + "." + method);
+ }
+ }
+ }
}
}
}
diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratePanelFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratePanelFormTestFixture.cs
new file mode 100644
index 0000000000..96d9ec6aff
--- /dev/null
+++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratePanelFormTestFixture.cs
@@ -0,0 +1,87 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+using ICSharpCode.PythonBinding;
+using NUnit.Framework;
+using PythonBinding.Tests.Utils;
+
+namespace PythonBinding.Tests.Designer
+{
+ [TestFixture]
+ public class GeneratePanelFormTestFixture
+ {
+ string generatedPythonCode;
+
+ [TestFixtureSetUp]
+ public void SetUpFixture()
+ {
+ using (Form form = new Form()) {
+ form.Name = "MainForm";
+ form.ClientSize = new Size(284, 264);
+
+ Panel panel = new Panel();
+ panel.Location = new Point(10, 15);
+ panel.Name = "panel1";
+ panel.TabIndex = 0;
+ panel.Size = new Size(100, 120);
+ TextBox textBox = new TextBox();
+ textBox.Location = new Point(5, 5);
+ textBox.Name = "textBox1";
+ textBox.TabIndex = 0;
+ textBox.Size = new Size(110, 20);
+ panel.Controls.Add(textBox);
+
+ form.Controls.Add(panel);
+
+ string indentString = " ";
+ PythonForm pythonForm = new PythonForm(indentString);
+ generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
+ }
+ }
+
+ [Test]
+ public void GeneratedCode()
+ {
+ string expectedCode = "def InitializeComponent(self):\r\n" +
+ " self._panel1 = System.Windows.Forms.Panel()\r\n" +
+ " self._textBox1 = System.Windows.Forms.TextBox()\r\n" +
+ " self._panel1.SuspendLayout()\r\n" +
+ " self.SuspendLayout()\r\n" +
+ " # \r\n" +
+ " # panel1\r\n" +
+ " # \r\n" +
+ " self._panel1.Location = System.Drawing.Point(10, 15)\r\n" +
+ " self._panel1.Name = \"panel1\"\r\n" +
+ " self._panel1.Size = System.Drawing.Size(100, 120)\r\n" +
+ " self._panel1.TabIndex = 0\r\n" +
+ " self._panel1.Controls.Add(self._textBox1)\r\n" +
+ " # \r\n" +
+ " # textBox1\r\n" +
+ " # \r\n" +
+ " self._textBox1.Location = System.Drawing.Point(5, 5)\r\n" +
+ " self._textBox1.Name = \"textBox1\"\r\n" +
+ " self._textBox1.Size = System.Drawing.Size(110, 20)\r\n" +
+ " self._textBox1.TabIndex = 0\r\n" +
+ " # \r\n" +
+ " # MainForm\r\n" +
+ " # \r\n" +
+ " self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
+ " self.Name = \"MainForm\"\r\n" +
+ " self.Visible = False\r\n" +
+ " self.Controls.Add(self._panel1)\r\n" +
+ " self._panel1.ResumeLayout(false)\r\n" +
+ " self._panel1.PerformLayout()\r\n" +
+ " self.ResumeLayout(False)\r\n" +
+ " self.PerformLayout()\r\n";
+
+ Assert.AreEqual(expectedCode, generatedPythonCode);
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs
index 8d89eefafe..51f2db047b 100644
--- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs
+++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs
@@ -59,7 +59,7 @@ namespace PythonBinding.Tests.Designer
" self.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.Visible = False\r\n" +
- " self.Controls.Add(self.textBox1)\r\n" +
+ " self.Controls.Add(self._textBox1)\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
index e779ba7194..5b7b6f8509 100644
--- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
+++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
@@ -160,6 +160,7 @@
+