Browse Source

Added support for TableLayoutPanel RowStyles and ColumnStyles in Python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4633 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
bc3c82105f
  1. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  2. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponentFactory.cs
  3. 71
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTableLayoutPanelComponent.cs
  4. 89
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTableLayoutPanelTestFixture.cs
  5. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

1
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj

@ -113,6 +113,7 @@ @@ -113,6 +113,7 @@
<Compile Include="Src\PythonProject.cs" />
<Compile Include="Src\PythonPropertyValueAssignment.cs" />
<Compile Include="Src\PythonResolver.cs" />
<Compile Include="Src\PythonTableLayoutPanelComponent.cs" />
<Compile Include="Src\PythonTreeViewComponent.cs" />
<Compile Include="Src\RunDebugPythonCommand.cs" />
<Compile Include="Src\RunPythonCommand.cs" />

2
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponentFactory.cs

@ -38,6 +38,8 @@ namespace ICSharpCode.PythonBinding @@ -38,6 +38,8 @@ namespace ICSharpCode.PythonBinding
return new PythonImageListComponent(parent, component);
} else if (component is TreeView) {
return new PythonTreeViewComponent(parent, component);
} else if (component is TableLayoutPanel) {
return new PythonTableLayoutPanelComponent(parent, component);
}
return new PythonDesignerComponent(parent, component);
}

71
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTableLayoutPanelComponent.cs

@ -0,0 +1,71 @@ @@ -0,0 +1,71 @@
// <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.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace ICSharpCode.PythonBinding
{
public class PythonTableLayoutPanelComponent : PythonDesignerComponent
{
public PythonTableLayoutPanelComponent(PythonDesignerComponent parent, IComponent component)
: base(parent, component)
{
}
public override void AppendMethodCallWithArrayParameter(PythonCodeBuilder codeBuilder, string propertyOwnerName, object propertyOwner, PropertyDescriptor propertyDescriptor)
{
if (IsStylesProperty(propertyDescriptor.Name)) {
ICollection collection = propertyDescriptor.GetValue(propertyOwner) as ICollection;
if (collection != null) {
AppendStylesCollection(codeBuilder, collection, propertyOwnerName);
}
} else {
base.AppendMethodCallWithArrayParameter(codeBuilder, propertyOwnerName, propertyOwner, propertyDescriptor);
}
}
bool IsStylesProperty(string name)
{
return "ColumnStyles".Equals(name, StringComparison.InvariantCultureIgnoreCase) || "RowStyles".Equals(name, StringComparison.InvariantCultureIgnoreCase);
}
void AppendStylesCollection(PythonCodeBuilder codeBuilder, ICollection collection, string propertyOwnerName)
{
string newPropertyOwnerName = propertyOwnerName;
SizeType sizeType = SizeType.Absolute;
float width = 0;
foreach (object item in collection) {
ColumnStyle columnStyle = item as ColumnStyle;
RowStyle rowStyle = item as RowStyle;
if (columnStyle != null) {
sizeType = columnStyle.SizeType;
width = columnStyle.Width;
newPropertyOwnerName = propertyOwnerName + ".ColumnStyles";
}
if (rowStyle != null) {
sizeType = rowStyle.SizeType;
width = rowStyle.Height;
newPropertyOwnerName = propertyOwnerName + ".RowStyles";
}
AppendStyle(codeBuilder, newPropertyOwnerName, item.GetType(), sizeType, width);
}
}
void AppendStyle(PythonCodeBuilder codeBuilder, string propertyOwnerName, Type type, SizeType sizeType, float value)
{
codeBuilder.AppendIndented(propertyOwnerName + ".Add(");
codeBuilder.Append(type.FullName + "(");
codeBuilder.Append(typeof(SizeType).FullName + "." + sizeType + ", ");
codeBuilder.Append(value + ")");
codeBuilder.Append(")");
codeBuilder.AppendLine();
}
}
}

89
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTableLayoutPanelTestFixture.cs

@ -0,0 +1,89 @@ @@ -0,0 +1,89 @@
// <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.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class GenerateTableLayoutPanelTestFixture
{
string generatedPythonCode;
[TestFixtureSetUp]
public void SetUpFixture()
{
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
IEventBindingService eventBindingService = new MockEventBindingService(host);
Form form = (Form)host.RootComponent;
form.ClientSize = new Size(200, 300);
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form);
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm");
// Add table layout panel.
TableLayoutPanel tableLayoutPanel1 = (TableLayoutPanel)host.CreateComponent(typeof(TableLayoutPanel), "tableLayoutPanel1");
tableLayoutPanel1.ColumnCount = 2;
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F));
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 60F));
tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
tableLayoutPanel1.RowCount = 2;
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F));
tableLayoutPanel1.Size = new System.Drawing.Size(200, 100);
tableLayoutPanel1.TabIndex = 0;
form.Controls.Add(tableLayoutPanel1);
PythonControl pythonControl = new PythonControl(" ");
generatedPythonCode = pythonControl.GenerateInitializeComponentMethod(form);
}
}
[Test]
public void GeneratedCode()
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" self._tableLayoutPanel1 = System.Windows.Forms.TableLayoutPanel()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # tableLayoutPanel1\r\n" +
" # \r\n" +
" self._tableLayoutPanel1.ColumnCount = 2\r\n" +
" self._tableLayoutPanel1.ColumnStyles.Add(System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 40))\r\n" +
" self._tableLayoutPanel1.ColumnStyles.Add(System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 60))\r\n" +
" self._tableLayoutPanel1.Location = System.Drawing.Point(0, 0)\r\n" +
" self._tableLayoutPanel1.Name = \"tableLayoutPanel1\"\r\n" +
" self._tableLayoutPanel1.RowCount = 2\r\n" +
" self._tableLayoutPanel1.RowStyles.Add(System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20))\r\n" +
" self._tableLayoutPanel1.RowStyles.Add(System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25))\r\n" +
" self._tableLayoutPanel1.Size = System.Drawing.Size(200, 100)\r\n" +
" self._tableLayoutPanel1.TabIndex = 0\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
" self.Controls.Add(self._tableLayoutPanel1)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode);
}
}
}

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

@ -217,6 +217,7 @@ @@ -217,6 +217,7 @@
<Compile Include="Designer\GenerateRichTextBoxTestFixture.cs" />
<Compile Include="Designer\GenerateRightToLeftFormTestFixture.cs" />
<Compile Include="Designer\GenerateSimpleFormTestFixture.cs" />
<Compile Include="Designer\GenerateTableLayoutPanelTestFixture.cs" />
<Compile Include="Designer\GenerateTextBoxFormTestFixture.cs" />
<Compile Include="Designer\GenerateTimerTestFixture.cs" />
<Compile Include="Designer\GenerateToolTipFormTestFixture.cs" />

Loading…
Cancel
Save