Browse Source

MonthCalendar SelectionRange and DateTime[] properties now supported in Python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4603 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
bc83afbe0c
  1. 10
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeDeserializer.cs
  2. 14
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs
  3. 24
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs
  4. 37
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/DeserializeDateTimeArrayTestFixture.cs
  5. 80
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMonthCalendarTestFixture.cs
  6. 69
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadMonthCalendarTestFixture.cs
  7. 3
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -165,6 +165,7 @@ namespace ICSharpCode.PythonBinding @@ -165,6 +165,7 @@ namespace ICSharpCode.PythonBinding
ConstantExpression constantExpression = listItemExpression as ConstantExpression;
MemberExpression memberExpression = listItemExpression as MemberExpression;
NameExpression nameExpression = listItemExpression as NameExpression;
CallExpression listItemCallExpression = listItemExpression as CallExpression;
if (constantExpression != null) {
array.SetValue(constantExpression.Value, i);
} else if (memberExpression != null) {
@ -172,6 +173,9 @@ namespace ICSharpCode.PythonBinding @@ -172,6 +173,9 @@ namespace ICSharpCode.PythonBinding
array.SetValue(componentCreator.GetComponent(name), i);
} else if (nameExpression != null) {
array.SetValue(componentCreator.GetInstance(nameExpression.Name.ToString()), i);
} else if (listItemCallExpression != null) {
object instance = componentCreator.CreateInstance(arrayType, GetArguments(listItemCallExpression), null, false);
array.SetValue(instance, i);
}
}
return array;
@ -194,6 +198,12 @@ namespace ICSharpCode.PythonBinding @@ -194,6 +198,12 @@ namespace ICSharpCode.PythonBinding
}
}
}
} else {
// Maybe it is a call to a constructor?
type = componentCreator.GetType(field.FullMemberName);
if (type != null) {
return componentCreator.CreateInstance(type, GetArguments(callExpression), null, false);
}
}
return null;
}

14
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs

@ -33,7 +33,8 @@ namespace ICSharpCode.PythonBinding @@ -33,7 +33,8 @@ namespace ICSharpCode.PythonBinding
PythonCodeDeserializer deserializer;
ClassDefinition classDefinition;
public PythonComponentWalker(IComponentCreator componentCreator) {
public PythonComponentWalker(IComponentCreator componentCreator)
{
this.componentCreator = componentCreator;
deserializer = new PythonCodeDeserializer(componentCreator);
}
@ -277,6 +278,8 @@ namespace ICSharpCode.PythonBinding @@ -277,6 +278,8 @@ namespace ICSharpCode.PythonBinding
throw new PythonComponentWalkerException(String.Format("Could not find type '{0}'.", PythonControlFieldExpression.GetMemberName(memberExpression)));
}
}
} else if (node.Target is IndexExpression) {
WalkArrayAssignmentRhs(node);
}
}
@ -356,5 +359,14 @@ namespace ICSharpCode.PythonBinding @@ -356,5 +359,14 @@ namespace ICSharpCode.PythonBinding
}
return null;
}
/// <summary>
/// Walks the right hand side of an assignment when the assignment is an array creation.
/// </summary>
void WalkArrayAssignmentRhs(CallExpression callExpression)
{
object array = deserializer.Deserialize(callExpression);
fieldExpression.SetPropertyValue(componentCreator, array);
}
}
}

24
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerComponent.cs

@ -543,6 +543,10 @@ namespace ICSharpCode.PythonBinding @@ -543,6 +543,10 @@ namespace ICSharpCode.PythonBinding
}
} else if (IsResourcePropertyValue(propertyValue)) {
AppendResourceProperty(codeBuilder, propertyName, propertyValue);
} else if (propertyValue.GetType().IsArray) {
codeBuilder.AppendIndented(propertyName + " = ");
AppendSystemArray(codeBuilder, GetArrayType(propertyValue).FullName, propertyValue as ICollection, false);
codeBuilder.AppendLine();
} else {
codeBuilder.AppendIndentedLine(propertyName + " = " + PythonPropertyValueAssignment.ToString(propertyValue));
}
@ -723,6 +727,16 @@ namespace ICSharpCode.PythonBinding @@ -723,6 +727,16 @@ namespace ICSharpCode.PythonBinding
}
public static void AppendSystemArray(PythonCodeBuilder codeBuilder, string typeName, ICollection components)
{
AppendSystemArray(codeBuilder, typeName, components, true);
}
/// <summary>
/// Appends an array.
/// </summary>
/// <param name="localVariables">Indicates that the array is for an AddRange method that
/// requires the code to reference local variables.</param>
public static void AppendSystemArray(PythonCodeBuilder codeBuilder, string typeName, ICollection components, bool localVariables)
{
if (components.Count > 0) {
codeBuilder.Append("System.Array[" + typeName + "](");
@ -743,8 +757,10 @@ namespace ICSharpCode.PythonBinding @@ -743,8 +757,10 @@ namespace ICSharpCode.PythonBinding
codeBuilder.Append(PythonPropertyValueAssignment.ToString(component));
} else if (component is IArrayItem) {
codeBuilder.Append(((IArrayItem)component).Name);
} else {
} else if (localVariables) {
codeBuilder.Append(GetVariableName(component, i + 1));
} else {
codeBuilder.Append(PythonPropertyValueAssignment.ToString(component));
}
++i;
}
@ -869,5 +885,11 @@ namespace ICSharpCode.PythonBinding @@ -869,5 +885,11 @@ namespace ICSharpCode.PythonBinding
AppendProperties(codeBuilder, propertyOwnerName, propertyValue);
}
}
static Type GetArrayType(object obj)
{
Type type = obj.GetType();
return obj.GetType().GetElementType();
}
}
}

37
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/DeserializeDateTimeArrayTestFixture.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
// <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.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.PythonBinding;
using IronPython.Compiler.Ast;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class DeserializeDateTimeArrayTestFixture : DeserializeAssignmentTestFixtureBase
{
public override string GetPythonCode()
{
return "self.Items = System.Array[System.DateTime](\r\n" +
" [System.DateTime(2010, 2, 3, 0, 0, 0, 0),\r\n" +
" System.DateTime(0)])";
}
[Test]
public void DeserializedObjectIsExpectedArray()
{
DateTime[] expectedArray = new DateTime[] {new DateTime(2010, 2, 3), new DateTime(0)};
Assert.AreEqual(expectedArray, deserializedObject);
}
}
}

80
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMonthCalendarTestFixture.cs

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
// <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 GenerateMonthCalendarTestFixture
{
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 month calendar.
MonthCalendar calendar = (MonthCalendar)host.CreateComponent(typeof(MonthCalendar), "monthCalendar1");
calendar.TabIndex = 0;
calendar.Location = new Point(0, 0);
calendar.AddMonthlyBoldedDate(new DateTime(2009, 1, 2));
calendar.AddMonthlyBoldedDate(new DateTime(0));
form.Controls.Add(calendar);
PythonControl pythonForm = new PythonControl(" ");
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
}
}
[Test]
public void GeneratedCode()
{
string expectedCode = "def InitializeComponent(self):\r\n" +
" self._monthCalendar1 = System.Windows.Forms.MonthCalendar()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # monthCalendar1\r\n" +
" # \r\n" +
" self._monthCalendar1.Location = System.Drawing.Point(0, 0)\r\n" +
" self._monthCalendar1.MonthlyBoldedDates = System.Array[System.DateTime](\r\n" +
" [System.DateTime(2009, 1, 2, 0, 0, 0, 0),\r\n" +
" System.DateTime(0)])\r\n" +
" self._monthCalendar1.Name = \"monthCalendar1\"\r\n" +
" self._monthCalendar1.TabIndex = 0\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
" self.Controls.Add(self._monthCalendar1)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode);
}
}
}

69
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadMonthCalendarTestFixture.cs

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
// <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.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 LoadMonthCalendarTestFixture : LoadFormTestFixtureBase
{
public override string PythonCode {
get {
return "class MainForm(System.Windows.Forms.Form):\r\n" +
" def InitializeComponent(self):\r\n" +
" self._monthCalendar1 = System.Windows.Forms.MonthCalendar()\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # monthCalendar1\r\n" +
" # \r\n" +
" self._monthCalendar1.Location = System.Drawing.Point(0, 0)\r\n" +
" self._monthCalendar1.MonthlyBoldedDates = System.Array[System.DateTime](\r\n" +
" [System.DateTime(2009, 1, 2, 0, 0, 0, 0),\r\n" +
" System.DateTime(0)])\r\n" +
" self._monthCalendar1.Name = \"monthCalendar1\"\r\n" +
" self._monthCalendar1.SelectionRange = System.Windows.Forms.SelectionRange(System.DateTime(2009, 8, 4, 0, 0, 0, 0), System.DateTime(2009, 8, 5, 0, 0, 0, 0))\r\n" +
" self._monthCalendar1.TabIndex = 0\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" +
" self.Controls.Add(self._monthCalendar1)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n" +
" self.PerformLayout()\r\n";
}
}
public MonthCalendar Calendar {
get { return Form.Controls[0] as MonthCalendar; }
}
[Test]
public void MonthlyBoldedDates()
{
DateTime[] expectedDates = new DateTime[] { new DateTime(2009, 1, 2), new DateTime(0) };
Assert.AreEqual(expectedDates, Calendar.MonthlyBoldedDates);
}
[Test]
public void SelectionRange()
{
SelectionRange expectedRange = new SelectionRange(new DateTime(2009, 8, 4, 0, 0, 0, 0), new DateTime(2009, 8, 5, 0, 0, 0, 0));
Assert.AreEqual(expectedRange.ToString(), Calendar.SelectionRange.ToString());
}
}
}

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

@ -167,6 +167,7 @@ @@ -167,6 +167,7 @@
<Compile Include="Designer\DeserializeAssignmentTestFixtureBase.cs" />
<Compile Include="Designer\DeserializeColorFromArgbTestFixture.cs" />
<Compile Include="Designer\DeserializeComponentAssignmentTestFixture.cs" />
<Compile Include="Designer\DeserializeDateTimeArrayTestFixture.cs" />
<Compile Include="Designer\DeserializeLocalVariableTestFixture.cs" />
<Compile Include="Designer\DeserializerConstructorStringArrayTestFixture.cs" />
<Compile Include="Designer\DeserializeStringArrayTestFixture.cs" />
@ -209,6 +210,7 @@ @@ -209,6 +210,7 @@
<Compile Include="Designer\GenerateMenuStripFormTestFixture.cs" />
<Compile Include="Designer\GenerateMenuStripItemsTestFixture.cs" />
<Compile Include="Designer\GenerateMinSizeFormTestFixture.cs" />
<Compile Include="Designer\GenerateMonthCalendarTestFixture.cs" />
<Compile Include="Designer\GenerateNestedPanelFormTestFixture.cs" />
<Compile Include="Designer\GeneratePanelFormTestFixture.cs" />
<Compile Include="Designer\GenerateRightToLeftFormTestFixture.cs" />
@ -246,6 +248,7 @@ @@ -246,6 +248,7 @@
<Compile Include="Designer\LoadListViewFormTestFixture.cs" />
<Compile Include="Designer\LoadLocalImageResourceTestFixture.cs" />
<Compile Include="Designer\LoadMenuStripFormTestFixture.cs" />
<Compile Include="Designer\LoadMonthCalendarTestFixture.cs" />
<Compile Include="Designer\LoadSimpleFormTestFixture.cs" />
<Compile Include="Designer\LoadSimpleUserControlTestFixture.cs" />
<Compile Include="Designer\LoadTextBoxOnPanelTestFixture.cs" />

Loading…
Cancel
Save