Browse Source

ComboBox items code now generated in Python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3981 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
43d1863925
  1. 10
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs
  2. 84
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateComboBoxItemsTestFixture.cs
  3. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadMenuStripFormTestFixture.cs
  4. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -177,8 +177,11 @@ namespace ICSharpCode.PythonBinding @@ -177,8 +177,11 @@ namespace ICSharpCode.PythonBinding
AppendEventHandlers(propertyOwnerName, control);
MenuStrip menuStrip = control as MenuStrip;
ComboBox comboBox = control as ComboBox;
if (menuStrip != null) {
AppendMenuStripItems(menuStrip);
} else if (comboBox != null) {
AppendSystemArray(comboBox.Name, "Items.AddRange", typeof(Object).FullName, comboBox.Items);
}
if (addChildControlProperties) {
@ -413,7 +416,12 @@ namespace ICSharpCode.PythonBinding @@ -413,7 +416,12 @@ namespace ICSharpCode.PythonBinding
AppendLine();
AppendIndented(String.Empty);
}
Append("self._" + ((IComponent)components[i]).Site.Name);
object component = components[i];
if (component is IComponent) {
Append("self._" + ((IComponent)component).Site.Name);
} else {
Append(PythonPropertyValueAssignment.ToString(component));
}
}
Append("]))");
AppendLine();

84
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateComboBoxItemsTestFixture.cs

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
// <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 GenerateComboBoxItemsFormTestFixture
{
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 combo box.
ComboBox comboBox = (ComboBox)host.CreateComponent(typeof(ComboBox), "comboBox1");
comboBox.TabIndex = 0;
comboBox.Location = new Point(0, 0);
comboBox.Size = new System.Drawing.Size(121, 21);
comboBox.Items.Add("aaa");
comboBox.Items.Add("bbb");
comboBox.Items.Add("ccc");
form.Controls.Add(comboBox);
PythonForm pythonForm = new PythonForm(" ");
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
}
}
[Test]
public void GeneratedCode()
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" self._comboBox1 = System.Windows.Forms.ComboBox()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # comboBox1\r\n" +
" # \r\n" +
" self._comboBox1.Location = System.Drawing.Point(0, 0)\r\n" +
" self._comboBox1.Name = \"comboBox1\"\r\n" +
" self._comboBox1.Size = System.Drawing.Size(121, 21)\r\n" +
" self._comboBox1.TabIndex = 0\r\n" +
" self._comboBox1.Items.AddRange(System.Array[System.Object](\r\n" +
" [\"aaa\",\r\n" +
" \"bbb\",\r\n" +
" \"ccc\"]))\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.Controls.Add(self._comboBox1)\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode);
}
}
}

2
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadMenuStripFormTestFixture.cs

@ -19,7 +19,7 @@ using PythonBinding.Tests.Utils; @@ -19,7 +19,7 @@ using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class LoadMenuStripTestFixture : LoadFormTestFixtureBase
public class LoadMenuStripFormTestFixture : LoadFormTestFixtureBase
{
public override string PythonCode {
get {

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

@ -156,6 +156,7 @@ @@ -156,6 +156,7 @@
<Compile Include="Designer\GenerateAccessibleRoleFormTestFixture.cs" />
<Compile Include="Designer\GenerateAutoScaleModeFormTestFixture.cs" />
<Compile Include="Designer\GenerateAutoScrollFormTestFixture.cs" />
<Compile Include="Designer\GenerateComboBoxItemsTestFixture.cs" />
<Compile Include="Designer\GenerateCursorFormTestFixture.cs" />
<Compile Include="Designer\GenerateDoubleBufferedFormTestFixture.cs" />
<Compile Include="Designer\GenerateEventHandlerFormTestFixture.cs" />

Loading…
Cancel
Save