Browse Source

Code is now generated for controls added to a panel in the python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3933 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
b7704c9524
  1. 58
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs
  2. 87
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratePanelFormTestFixture.cs
  3. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs
  4. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

58
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs

@ -84,12 +84,12 @@ namespace ICSharpCode.PythonBinding
void GenerateInitializeComponentMethodBodyInternal(Form form) void GenerateInitializeComponentMethodBodyInternal(Form form)
{ {
foreach (Control control in form.Controls) { AppendChildControlCreation(form.Controls);
AppendControlCreation(control); AppendChildControlSuspendLayout(form.Controls);
}
AppendIndentedLine("self.SuspendLayout()"); AppendIndentedLine("self.SuspendLayout()");
AppendForm(form); AppendForm(form);
AppendChildControlResumeLayout(form.Controls);
AppendIndentedLine("self.ResumeLayout(False)"); AppendIndentedLine("self.ResumeLayout(False)");
AppendIndentedLine("self.PerformLayout()"); AppendIndentedLine("self.PerformLayout()");
} }
@ -99,30 +99,24 @@ namespace ICSharpCode.PythonBinding
/// </summary> /// </summary>
void AppendForm(Form form) void AppendForm(Form form)
{ {
// Add the controls on the form. // Add the controls on the form.
foreach (Control control in form.Controls) { foreach (Control control in form.Controls) {
AppendControl(control); AppendControl(control);
} }
// Add form. // Add form.
AppendControl(form, false); AppendControl(form, false, false);
// Add controls to form.
foreach (Control control in form.Controls) {
AppendIndentedLine("self.Controls.Add(self." + control.Name + ")");
}
} }
void AppendControl(Control control) void AppendControl(Control control)
{ {
AppendControl(control, true); AppendControl(control, true, true);
} }
/// <summary> /// <summary>
/// Generates python code for the control. /// Generates python code for the control.
/// </summary> /// </summary>
void AppendControl(Control control, bool addControlNameToProperty) void AppendControl(Control control, bool addControlNameToProperty, bool addChildControlProperties)
{ {
AppendComment(control.Name); AppendComment(control.Name);
@ -134,6 +128,16 @@ namespace ICSharpCode.PythonBinding
foreach (PropertyDescriptor property in GetSerializableProperties(control)) { foreach (PropertyDescriptor property in GetSerializableProperties(control)) {
AppendProperty(propertyOwnerName, control, property); 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);
}
}
} }
/// <summary> /// <summary>
@ -199,9 +203,39 @@ namespace ICSharpCode.PythonBinding
codeBuilder.Append(text); codeBuilder.Append(text);
} }
void AppendChildControlCreation(Control.ControlCollection controls)
{
foreach (Control control in controls) {
AppendControlCreation(control);
AppendChildControlCreation(control.Controls);
}
}
void AppendControlCreation(Control control) 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);
}
}
}
}
} }
} }

87
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratePanelFormTestFixture.cs

@ -0,0 +1,87 @@
// <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.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);
}
}
}

2
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.ClientSize = System.Drawing.Size(284, 264)\r\n" +
" self.Name = \"MainForm\"\r\n" + " self.Name = \"MainForm\"\r\n" +
" self.Visible = False\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.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n"; " self.PerformLayout()\r\n";

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

@ -160,6 +160,7 @@
<Compile Include="Designer\GenerateFormPaddingTestFixture.cs" /> <Compile Include="Designer\GenerateFormPaddingTestFixture.cs" />
<Compile Include="Designer\GenerateImeModeFormTestFixture.cs" /> <Compile Include="Designer\GenerateImeModeFormTestFixture.cs" />
<Compile Include="Designer\GenerateMinSizeFormTestFixture.cs" /> <Compile Include="Designer\GenerateMinSizeFormTestFixture.cs" />
<Compile Include="Designer\GeneratePanelFormTestFixture.cs" />
<Compile Include="Designer\GenerateRightToLeftFormTestFixture.cs" /> <Compile Include="Designer\GenerateRightToLeftFormTestFixture.cs" />
<Compile Include="Designer\GenerateSimpleFormTestFixture.cs" /> <Compile Include="Designer\GenerateSimpleFormTestFixture.cs" />
<Compile Include="Designer\GenerateTextBoxFormTestFixture.cs" /> <Compile Include="Designer\GenerateTextBoxFormTestFixture.cs" />

Loading…
Cancel
Save