Browse Source

Added support for designing user controls in the python forms designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3990 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
f9557c8c74
  1. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  2. 87
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs
  3. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalkerException.cs
  4. 40
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs
  5. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerGenerator.cs
  6. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs
  7. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs
  8. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/FindAddRangeMethodTests.cs
  9. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs
  10. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAccessibleRoleFormTestFixture.cs
  11. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScaleModeFormTestFixture.cs
  12. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScrollFormTestFixture.cs
  13. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateComboBoxItemsTestFixture.cs
  14. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateCursorFormTestFixture.cs
  15. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateDoubleBufferedFormTestFixture.cs
  16. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateEventHandlerFormTestFixture.cs
  17. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormColorTestFixture.cs
  18. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormLocationTestFixture.cs
  19. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormPaddingTestFixture.cs
  20. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateImeModeFormTestFixture.cs
  21. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripFormTestFixture.cs
  22. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripItemsTestFixture.cs
  23. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMinSizeFormTestFixture.cs
  24. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateNestedPanelFormTestFixture.cs
  25. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratePanelFormTestFixture.cs
  26. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateRightToLeftFormTestFixture.cs
  27. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateSimpleFormTestFixture.cs
  28. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs
  29. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetSerializableContentPropertiesTestFixture.cs
  30. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IgnoreDesignTimePropertiesTestFixture.cs
  31. 8
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsSitedComponentTests.cs
  32. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs
  33. 72
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadSimpleUserControlTestFixture.cs
  34. 10
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs
  35. 26
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/NoNewLineAfterInitializeComponentTestFixture.cs
  36. 74
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonBaseClassTests.cs
  37. 6
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/UnknownTypeTestFixture.cs
  38. 2
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -91,10 +91,10 @@
<Compile Include="Src\PythonDesignerLoader.cs" /> <Compile Include="Src\PythonDesignerLoader.cs" />
<Compile Include="Src\PythonDesignerLoaderProvider.cs" /> <Compile Include="Src\PythonDesignerLoaderProvider.cs" />
<Compile Include="Src\PythonExpressionFinder.cs" /> <Compile Include="Src\PythonExpressionFinder.cs" />
<Compile Include="Src\PythonForm.cs" /> <Compile Include="Src\PythonControl.cs" />
<Compile Include="Src\PythonFormsDesignerDisplayBinding.cs" /> <Compile Include="Src\PythonFormsDesignerDisplayBinding.cs" />
<Compile Include="Src\PythonFormWalker.cs" /> <Compile Include="Src\PythonComponentWalker.cs" />
<Compile Include="Src\PythonFormWalkerException.cs" /> <Compile Include="Src\PythonComponentWalkerException.cs" />
<Compile Include="Src\PythonLanguageBinding.cs" /> <Compile Include="Src\PythonLanguageBinding.cs" />
<Compile Include="Src\PythonOptionsPanel.cs" /> <Compile Include="Src\PythonOptionsPanel.cs" />
<Compile Include="Src\PythonOutputStream.cs" /> <Compile Include="Src\PythonOutputStream.cs" />

87
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalker.cs → src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs

@ -21,41 +21,59 @@ namespace ICSharpCode.PythonBinding
/// <summary> /// <summary>
/// Visits the code's Python AST and creates a Windows Form. /// Visits the code's Python AST and creates a Windows Form.
/// </summary> /// </summary>
public class PythonFormWalker : PythonWalker public class PythonComponentWalker : PythonWalker
{ {
Form form; IComponent component;
PythonControlFieldExpression fieldExpression; PythonControlFieldExpression fieldExpression;
IComponentCreator componentCreator; IComponentCreator componentCreator;
bool walkingAssignment; bool walkingAssignment;
string formName = String.Empty; string componentName = String.Empty;
PythonCodeDeserializer deserializer; PythonCodeDeserializer deserializer;
ClassDefinition classDefinition;
public PythonFormWalker(IComponentCreator componentCreator) public PythonComponentWalker(IComponentCreator componentCreator)
{ {
this.componentCreator = componentCreator; this.componentCreator = componentCreator;
deserializer = new PythonCodeDeserializer(componentCreator); deserializer = new PythonCodeDeserializer(componentCreator);
} }
/// <summary> /// <summary>
/// Creates a form from python code. /// Creates a control either a UserControl or Form from the python code.
/// </summary> /// </summary>
public Form CreateForm(string pythonCode) public IComponent CreateComponent(string pythonCode)
{ {
PythonParser parser = new PythonParser(); PythonParser parser = new PythonParser();
PythonAst ast = parser.CreateAst(@"Form.py", pythonCode); PythonAst ast = parser.CreateAst(@"Control.py", pythonCode);
ast.Walk(this); ast.Walk(this);
// Did we find the InitializeComponent method? // Did we find the InitializeComponent method?
if (form == null) { if (component == null) {
throw new PythonFormWalkerException("Unable to find InitializeComponents method."); throw new PythonComponentWalkerException("Unable to find InitializeComponents method.");
} }
return component;
return form; }
}
/// <summary>
/// Gets the fully qualified name of the base class.
/// </summary>
public static string GetBaseClassName(ClassDefinition classDefinition)
{
if (classDefinition.Bases.Length > 0) {
Expression baseClassExpression = classDefinition.Bases[0];
NameExpression nameExpression = baseClassExpression as NameExpression;
MemberExpression memberExpression = baseClassExpression as MemberExpression;
if (nameExpression != null) {
return nameExpression.Name.ToString();
}
return PythonControlFieldExpression.GetMemberName(memberExpression);
}
return String.Empty;
}
public override bool Walk(ClassDefinition node) public override bool Walk(ClassDefinition node)
{ {
formName = node.Name.ToString(); classDefinition = node;
componentName = node.Name.ToString();
if (node.Body != null) { if (node.Body != null) {
node.Body.Walk(this); node.Body.Walk(this);
} }
@ -65,7 +83,8 @@ namespace ICSharpCode.PythonBinding
public override bool Walk(FunctionDefinition node) public override bool Walk(FunctionDefinition node)
{ {
if (IsInitializeComponentMethod(node)) { if (IsInitializeComponentMethod(node)) {
form = (Form)componentCreator.CreateComponent(typeof(Form), formName); Type type = GetComponentType();
component = componentCreator.CreateComponent(type, componentName);
node.Body.Walk(this); node.Body.Walk(this);
} }
return false; return false;
@ -132,14 +151,14 @@ namespace ICSharpCode.PythonBinding
MemberExpression eventHandlerExpression = node.Right as MemberExpression; MemberExpression eventHandlerExpression = node.Right as MemberExpression;
string eventHandlerName = eventHandlerExpression.Name.ToString(); string eventHandlerName = eventHandlerExpression.Name.ToString();
Control control = form; IComponent currentComponent = this.component;
if (field.VariableName.Length > 0) { if (field.VariableName.Length > 0) {
control = GetControl(field.VariableName); currentComponent = GetComponent(field.VariableName);
} }
EventDescriptor eventDescriptor = TypeDescriptor.GetEvents(control).Find(eventName, false); EventDescriptor eventDescriptor = TypeDescriptor.GetEvents(currentComponent).Find(eventName, false);
PropertyDescriptor propertyDescriptor = componentCreator.GetEventProperty(eventDescriptor); PropertyDescriptor propertyDescriptor = componentCreator.GetEventProperty(eventDescriptor);
propertyDescriptor.SetValue(control, eventHandlerName); propertyDescriptor.SetValue(currentComponent, eventHandlerName);
return false; return false;
} }
@ -192,12 +211,12 @@ namespace ICSharpCode.PythonBinding
} }
/// <summary> /// <summary>
/// Looks for the control with the specified name in the objects that have been /// Looks for the component with the specified name in the objects that have been
/// created whilst processing the InitializeComponent method. /// created whilst processing the InitializeComponent method.
/// </summary> /// </summary>
Control GetControl(string name) IComponent GetComponent(string name)
{ {
return componentCreator.GetComponent(name) as Control; return componentCreator.GetComponent(name);
} }
/// <summary> /// <summary>
@ -217,7 +236,19 @@ namespace ICSharpCode.PythonBinding
if (fieldExpression.VariableName.Length > 0) { if (fieldExpression.VariableName.Length > 0) {
return componentCreator.GetComponent(fieldExpression.VariableName); return componentCreator.GetComponent(fieldExpression.VariableName);
} }
return form; return component;
}
/// <summary>
/// Gets the type for the control being walked.
/// </summary>
Type GetComponentType()
{
string baseClass = GetBaseClassName(classDefinition);
if (baseClass.Contains("UserControl")) {
return typeof(UserControl);
}
return typeof(Form);
} }
/// <summary> /// <summary>
@ -230,7 +261,7 @@ namespace ICSharpCode.PythonBinding
if (propertyValue == null) { if (propertyValue == null) {
PythonControlFieldExpression field = PythonControlFieldExpression.Create(memberExpression); PythonControlFieldExpression field = PythonControlFieldExpression.Create(memberExpression);
if (field.MemberName.Length > 0) { if (field.MemberName.Length > 0) {
propertyValue = GetControl(PythonControlFieldExpression.GetVariableName(field.MemberName)); propertyValue = GetComponent(PythonControlFieldExpression.GetVariableName(field.MemberName));
} else { } else {
propertyValue = field.FullMemberName; propertyValue = field.FullMemberName;
} }
@ -259,9 +290,9 @@ namespace ICSharpCode.PythonBinding
} else { } else {
object obj = deserializer.Deserialize(node); object obj = deserializer.Deserialize(node);
if (obj != null) { if (obj != null) {
SetPropertyValue(form, fieldExpression.MemberName, obj); SetPropertyValue(component, fieldExpression.MemberName, obj);
} else { } else {
throw new PythonFormWalkerException(String.Format("Could not find type '{0}'.", name)); throw new PythonComponentWalkerException(String.Format("Could not find type '{0}'.", name));
} }
} }
} }
@ -283,7 +314,7 @@ namespace ICSharpCode.PythonBinding
// Try to get the object being called. Try the form first then // Try to get the object being called. Try the form first then
// look for other controls. // look for other controls.
object member = PythonControlFieldExpression.GetMember(form, node); object member = PythonControlFieldExpression.GetMember(component, node);
PythonControlFieldExpression field = PythonControlFieldExpression.Create(node); PythonControlFieldExpression field = PythonControlFieldExpression.Create(node);
if (member == null) { if (member == null) {
member = field.GetMember(componentCreator); member = field.GetMember(componentCreator);

6
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalkerException.cs → src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalkerException.cs

@ -10,11 +10,11 @@ using System;
namespace ICSharpCode.PythonBinding namespace ICSharpCode.PythonBinding
{ {
/// <summary> /// <summary>
/// Exception thrown by the PythonFormWalker class. /// Exception thrown by the PythonComponentWalker class.
/// </summary> /// </summary>
public class PythonFormWalkerException : Exception public class PythonComponentWalkerException : Exception
{ {
public PythonFormWalkerException(string message) : base(message) public PythonComponentWalkerException(string message) : base(message)
{ {
} }
} }

40
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs → src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs

@ -20,10 +20,10 @@ using ICSharpCode.TextEditor.Document;
namespace ICSharpCode.PythonBinding namespace ICSharpCode.PythonBinding
{ {
/// <summary> /// <summary>
/// Represents a form in the designer. Used to generate /// Represents a form or user control in the designer. Used to generate
/// Python code after the form has been changed in the designer. /// Python code after the form has been changed in the designer.
/// </summary> /// </summary>
public class PythonForm public class PythonControl
{ {
StringBuilder codeBuilder; StringBuilder codeBuilder;
string indentString = String.Empty; string indentString = String.Empty;
@ -70,17 +70,17 @@ namespace ICSharpCode.PythonBinding
} }
} }
public PythonForm() public PythonControl()
: this("\t") : this("\t")
{ {
} }
public PythonForm(string indentString) public PythonControl(string indentString)
: this(indentString, new PythonFormEventBindingService()) : this(indentString, new PythonFormEventBindingService())
{ {
} }
PythonForm(string indentString, IEventBindingService eventBindingService) PythonControl(string indentString, IEventBindingService eventBindingService)
{ {
this.indentString = indentString; this.indentString = indentString;
this.eventBindingService = eventBindingService; this.eventBindingService = eventBindingService;
@ -89,14 +89,14 @@ namespace ICSharpCode.PythonBinding
/// <summary> /// <summary>
/// Generates python code for the InitializeComponent method based on the controls added to the form. /// Generates python code for the InitializeComponent method based on the controls added to the form.
/// </summary> /// </summary>
public string GenerateInitializeComponentMethod(Form form) public string GenerateInitializeComponentMethod(Control control)
{ {
codeBuilder = new StringBuilder(); codeBuilder = new StringBuilder();
AppendIndentedLine("def InitializeComponent(self):"); AppendIndentedLine("def InitializeComponent(self):");
IncreaseIndent(); IncreaseIndent();
GenerateInitializeComponentMethodBodyInternal(form); GenerateInitializeComponentMethodBodyInternal(control);
return codeBuilder.ToString(); return codeBuilder.ToString();
} }
@ -104,12 +104,12 @@ namespace ICSharpCode.PythonBinding
/// <summary> /// <summary>
/// Generates the InitializeComponent method body. /// Generates the InitializeComponent method body.
/// </summary> /// </summary>
public string GenerateInitializeComponentMethodBody(Form form, int initialIndent) public string GenerateInitializeComponentMethodBody(Control control, int initialIndent)
{ {
codeBuilder = new StringBuilder(); codeBuilder = new StringBuilder();
indent = initialIndent; indent = initialIndent;
GenerateInitializeComponentMethodBodyInternal(form); GenerateInitializeComponentMethodBodyInternal(control);
return codeBuilder.ToString(); return codeBuilder.ToString();
} }
@ -243,29 +243,29 @@ namespace ICSharpCode.PythonBinding
return childComponents.ToArray(); return childComponents.ToArray();
} }
void GenerateInitializeComponentMethodBodyInternal(Form form) void GenerateInitializeComponentMethodBodyInternal(Control control)
{ {
AppendChildControlCreation(form); AppendChildControlCreation(control);
AppendChildControlSuspendLayout(form.Controls); AppendChildControlSuspendLayout(control.Controls);
AppendIndentedLine("self.SuspendLayout()"); AppendIndentedLine("self.SuspendLayout()");
AppendForm(form); AppendRootControl(control);
AppendChildControlResumeLayout(form.Controls); AppendChildControlResumeLayout(control.Controls);
AppendIndentedLine("self.ResumeLayout(False)"); AppendIndentedLine("self.ResumeLayout(False)");
AppendIndentedLine("self.PerformLayout()"); AppendIndentedLine("self.PerformLayout()");
} }
/// <summary> /// <summary>
/// Generates python code for the form's InitializeComponent method. /// Generates python code for the control's InitializeComponent method.
/// </summary> /// </summary>
void AppendForm(Form form) void AppendRootControl(Control rootControl)
{ {
// Add the controls on the form. // Add the controls on the form.
foreach (Control control in form.Controls) { foreach (Control control in rootControl.Controls) {
AppendComponent(control); AppendComponent(control);
} }
// Add form. // Add root control.
AppendComponent(form, false, false); AppendComponent(rootControl, false, false);
} }
void AppendComponent(IComponent component) void AppendComponent(IComponent component)
@ -506,7 +506,7 @@ namespace ICSharpCode.PythonBinding
/// </summary> /// </summary>
void AppendChildComponentProperties(object component) void AppendChildComponentProperties(object component)
{ {
foreach (PropertyDescriptor property in PythonForm.GetSerializableContentProperties(component)) { foreach (PropertyDescriptor property in PythonControl.GetSerializableContentProperties(component)) {
object propertyCollection = property.GetValue(component); object propertyCollection = property.GetValue(component);
ICollection collection = propertyCollection as ICollection; ICollection collection = propertyCollection as ICollection;
if (collection != null) { if (collection != null) {

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerGenerator.cs

@ -96,9 +96,9 @@ namespace ICSharpCode.PythonBinding
IMethod method = GetInitializeComponents(compilationUnit); IMethod method = GetInitializeComponents(compilationUnit);
// Generate the python source code. // Generate the python source code.
PythonForm pythonForm = new PythonForm(NRefactoryToPythonConverter.GetIndentString(textEditorProperties)); PythonControl pythonForm = new PythonControl(NRefactoryToPythonConverter.GetIndentString(textEditorProperties));
int indent = method.Region.BeginColumn; int indent = method.Region.BeginColumn;
string methodBody = pythonForm.GenerateInitializeComponentMethodBody(component as Form, indent); string methodBody = pythonForm.GenerateInitializeComponentMethodBody(component as Control, indent);
// Merge the code. // Merge the code.
DomRegion methodRegion = GetBodyRegionInDocument(method); DomRegion methodRegion = GetBodyRegionInDocument(method);

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs

@ -115,8 +115,8 @@ namespace ICSharpCode.PythonBinding
{ {
// Create designer root object. // Create designer root object.
this.serializationManager = serializationManager; this.serializationManager = serializationManager;
PythonFormWalker visitor = new PythonFormWalker(this); PythonComponentWalker visitor = new PythonComponentWalker(this);
visitor.CreateForm(generator.ViewContent.DesignerCodeFileContent); visitor.CreateComponent(generator.ViewContent.DesignerCodeFileContent);
} }
} }
} }

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

@ -44,7 +44,7 @@ namespace PythonBinding.Tests.Designer
enabledPropertyDescriptor.SetValue(form, false); enabledPropertyDescriptor.SetValue(form, false);
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

12
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/FindAddRangeMethodTests.cs

@ -27,7 +27,7 @@ namespace PythonBinding.Tests.Designer
MethodInfo expectedMethodInfo = FindMethod(menuStrip.Items, "AddRange", typeof(ToolStripItem[])); MethodInfo expectedMethodInfo = FindMethod(menuStrip.Items, "AddRange", typeof(ToolStripItem[]));
Assert.IsNotNull(expectedMethodInfo); Assert.IsNotNull(expectedMethodInfo);
Assert.AreSame(expectedMethodInfo, PythonForm.GetAddRangeSerializationMethod(menuStrip.Items)); Assert.AreSame(expectedMethodInfo, PythonControl.GetAddRangeSerializationMethod(menuStrip.Items));
} }
} }
@ -36,7 +36,7 @@ namespace PythonBinding.Tests.Designer
{ {
using (MenuStrip menuStrip = new MenuStrip()) { using (MenuStrip menuStrip = new MenuStrip()) {
MethodInfo methodInfo = FindMethod(menuStrip.Items, "AddRange", typeof(ToolStripItem[])); MethodInfo methodInfo = FindMethod(menuStrip.Items, "AddRange", typeof(ToolStripItem[]));
Assert.AreEqual(typeof(ToolStripItem), PythonForm.GetArrayParameterType(methodInfo)); Assert.AreEqual(typeof(ToolStripItem), PythonControl.GetArrayParameterType(methodInfo));
} }
} }
@ -44,13 +44,13 @@ namespace PythonBinding.Tests.Designer
public void GetArrayParameterTypeFromMethodWithNoParameters() public void GetArrayParameterTypeFromMethodWithNoParameters()
{ {
MethodInfo methodInfo = typeof(String).GetMethod("Clone"); MethodInfo methodInfo = typeof(String).GetMethod("Clone");
Assert.IsNull(PythonForm.GetArrayParameterType(methodInfo)); Assert.IsNull(PythonControl.GetArrayParameterType(methodInfo));
} }
[Test] [Test]
public void GetArrayParameterTypeWithNullMethodInfo() public void GetArrayParameterTypeWithNullMethodInfo()
{ {
Assert.IsNull(PythonForm.GetArrayParameterType(null)); Assert.IsNull(PythonControl.GetArrayParameterType(null));
} }
/// <summary> /// <summary>
@ -61,7 +61,7 @@ namespace PythonBinding.Tests.Designer
public void FormControlsAddRangeMethodNotFound() public void FormControlsAddRangeMethodNotFound()
{ {
using (Form form = new Form()) { using (Form form = new Form()) {
Assert.IsNull(PythonForm.GetAddRangeSerializationMethod(form.Controls)); Assert.IsNull(PythonControl.GetAddRangeSerializationMethod(form.Controls));
} }
} }
@ -72,7 +72,7 @@ namespace PythonBinding.Tests.Designer
MethodInfo expectedMethodInfo = FindMethod(form.Controls, "Add", typeof(Control)); MethodInfo expectedMethodInfo = FindMethod(form.Controls, "Add", typeof(Control));
Assert.IsNotNull(expectedMethodInfo); Assert.IsNotNull(expectedMethodInfo);
Assert.AreSame(expectedMethodInfo, PythonForm.GetAddSerializationMethod(form.Controls)); Assert.AreSame(expectedMethodInfo, PythonControl.GetAddSerializationMethod(form.Controls));
} }
} }

6
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs

@ -48,11 +48,11 @@ namespace PythonBinding.Tests.Designer
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
PythonForm pythonForm = new PythonForm(" "); PythonControl pythonForm = new PythonControl(" ");
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
formChildComponents = PythonForm.GetChildComponents(form); formChildComponents = PythonControl.GetChildComponents(form);
buttonChildComponents = PythonForm.GetChildComponents(button); buttonChildComponents = PythonControl.GetChildComponents(button);
} }
} }

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

@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -52,7 +52,7 @@ namespace PythonBinding.Tests.Designer
autoScaleDimensionsDescriptor.SetValue(form, new SizeF(6F, 13F)); autoScaleDimensionsDescriptor.SetValue(form, new SizeF(6F, 13F));
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -47,7 +47,7 @@ namespace PythonBinding.Tests.Designer
form.Controls.Add(comboBox); form.Controls.Add(comboBox);
PythonForm pythonForm = new PythonForm(" "); PythonControl pythonForm = new PythonControl(" ");
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -43,7 +43,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -52,7 +52,7 @@ namespace PythonBinding.Tests.Designer
PropertyDescriptor closedEventProperty = eventBindingService.GetEventProperty(closedEvent); PropertyDescriptor closedEventProperty = eventBindingService.GetEventProperty(closedEvent);
closedEventProperty.SetValue(form, "MainFormClosed"); closedEventProperty.SetValue(form, "MainFormClosed");
PythonForm pythonForm = new PythonForm(" "); PythonControl pythonForm = new PythonControl(" ");
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -40,7 +40,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -37,7 +37,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -48,7 +48,7 @@ namespace PythonBinding.Tests.Designer
menuStrip.Location = new Point(0, 0); menuStrip.Location = new Point(0, 0);
form.Controls.Add(menuStrip); form.Controls.Add(menuStrip);
PythonForm pythonForm = new PythonForm(" "); PythonControl pythonForm = new PythonControl(" ");
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

6
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripItemsTestFixture.cs

@ -77,11 +77,11 @@ namespace PythonBinding.Tests.Designer
exitMenuItemSize = exitMenuItem.Size; exitMenuItemSize = exitMenuItem.Size;
editMenuItemSize = editMenuItem.Size; editMenuItemSize = editMenuItem.Size;
PythonForm pythonForm = new PythonForm(" "); PythonControl pythonForm = new PythonControl(" ");
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
menuStripChildComponents = PythonForm.GetChildComponents(menuStrip); menuStripChildComponents = PythonControl.GetChildComponents(menuStrip);
fileMenuItemChildComponents = PythonForm.GetChildComponents(fileMenuItem); fileMenuItemChildComponents = PythonControl.GetChildComponents(fileMenuItem);
} }
} }

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

@ -47,7 +47,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -56,7 +56,7 @@ namespace PythonBinding.Tests.Designer
form.Controls.Add(panel1); form.Controls.Add(panel1);
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -54,7 +54,7 @@ namespace PythonBinding.Tests.Designer
form.Controls.Add(panel); form.Controls.Add(panel);
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -37,7 +37,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -34,7 +34,7 @@ namespace PythonBinding.Tests.Designer
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -41,7 +41,7 @@ namespace PythonBinding.Tests.Designer
form.Controls.Add(textBox); form.Controls.Add(textBox);
string indentString = " "; string indentString = " ";
PythonForm pythonForm = new PythonForm(indentString); PythonControl pythonForm = new PythonControl(indentString);
generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form);
} }
} }

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

@ -27,7 +27,7 @@ namespace PythonBinding.Tests.Designer
using (Form form = new Form()) { using (Form form = new Form()) {
// Modify Form.Text so it is identified as needing serialization. // Modify Form.Text so it is identified as needing serialization.
form.Text = "abc"; form.Text = "abc";
properties = PythonForm.GetSerializableContentProperties(form); properties = PythonControl.GetSerializableContentProperties(form);
} }
} }

4
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IgnoreDesignTimePropertiesTestFixture.cs

@ -53,10 +53,10 @@ namespace PythonBinding.Tests.Designer
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(form, "MainForm");
PythonForm pythonForm = new PythonForm(" "); PythonControl pythonForm = new PythonControl(" ");
generatedCode = pythonForm.GenerateInitializeComponentMethod(form); generatedCode = pythonForm.GenerateInitializeComponentMethod(form);
propertyDescriptors = PythonForm.GetSerializableProperties(form); propertyDescriptors = PythonControl.GetSerializableProperties(form);
} }
} }

8
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsSitedComponentTests.cs

@ -19,13 +19,13 @@ namespace PythonBinding.Tests.Designer
[Test] [Test]
public void NullComponent() public void NullComponent()
{ {
Assert.IsFalse(PythonForm.IsSitedComponent(null)); Assert.IsFalse(PythonControl.IsSitedComponent(null));
} }
[Test] [Test]
public void ComponentNotSited() public void ComponentNotSited()
{ {
Assert.IsFalse(PythonForm.IsSitedComponent(new Component())); Assert.IsFalse(PythonControl.IsSitedComponent(new Component()));
} }
[Test] [Test]
@ -33,13 +33,13 @@ namespace PythonBinding.Tests.Designer
{ {
Component component = new Component(); Component component = new Component();
component.Site = this; component.Site = this;
Assert.IsTrue(PythonForm.IsSitedComponent(component)); Assert.IsTrue(PythonControl.IsSitedComponent(component));
} }
[Test] [Test]
public void NonComponent() public void NonComponent()
{ {
Assert.IsFalse(PythonForm.IsSitedComponent(String.Empty)); Assert.IsFalse(PythonControl.IsSitedComponent(String.Empty));
} }
public IComponent Component { public IComponent Component {

4
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs

@ -31,8 +31,8 @@ namespace PythonBinding.Tests.Designer
[TestFixtureSetUp] [TestFixtureSetUp]
public void SetUpFixture() public void SetUpFixture()
{ {
PythonFormWalker walker = new PythonFormWalker(componentCreator); PythonComponentWalker walker = new PythonComponentWalker(componentCreator);
form = walker.CreateForm(PythonCode); form = walker.CreateComponent(PythonCode) as Form;
} }
[TestFixtureTearDown] [TestFixtureTearDown]

72
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadSimpleUserControlTestFixture.cs

@ -0,0 +1,72 @@
// <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.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 LoadSimpleUserControlTestFixture
{
MockComponentCreator componentCreator = new MockComponentCreator();
UserControl userControl;
public string PythonCode {
get {
return "class MainForm(System.Windows.Forms.UserControl):\r\n" +
" def InitializeComponent(self):\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # userControl1\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(300, 400)\r\n" +
" self.Name = \"userControl1\"\r\n" +
" self.ResumeLayout(False)\r\n";
}
}
[TestFixtureSetUp]
public void SetUpFixture()
{
PythonComponentWalker walker = new PythonComponentWalker(componentCreator);
userControl = walker.CreateComponent(PythonCode) as UserControl;
}
[TestFixtureTearDown]
public void TearDownFixture()
{
userControl.Dispose();
}
[Test]
public void UserControlCreated()
{
Assert.IsNotNull(userControl);
}
[Test]
public void UserControlName()
{
Assert.AreEqual("userControl1", userControl.Name);
}
[Test]
public void UserControlClientSize()
{
Size size = new Size(300, 400);
Assert.AreEqual(size, userControl.ClientSize);
}
}
}

10
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs

@ -37,11 +37,11 @@ namespace PythonBinding.Tests.Designer
" def MissingMethod(self):\r\n" + " def MissingMethod(self):\r\n" +
" pass\r\n"; " pass\r\n";
[Test] [Test]
[ExpectedException(typeof(PythonFormWalkerException))] [ExpectedException(typeof(PythonComponentWalkerException))]
public void PythonFormWalkerExceptionThrown() public void PythonFormWalkerExceptionThrown()
{ {
PythonFormWalker walker = new PythonFormWalker(this); PythonComponentWalker walker = new PythonComponentWalker(this);
walker.CreateForm(pythonCode); walker.CreateComponent(pythonCode);
Assert.Fail("Exception should have been thrown before this."); Assert.Fail("Exception should have been thrown before this.");
} }
@ -52,7 +52,7 @@ namespace PythonBinding.Tests.Designer
public void ClassWithNoBody() public void ClassWithNoBody()
{ {
ClassDefinition classDef = new ClassDefinition(new SymbolId(10), null, null); ClassDefinition classDef = new ClassDefinition(new SymbolId(10), null, null);
PythonFormWalker walker = new PythonFormWalker(this); PythonComponentWalker walker = new PythonComponentWalker(this);
walker.Walk(classDef); walker.Walk(classDef);
} }
@ -65,7 +65,7 @@ namespace PythonBinding.Tests.Designer
{ {
List<Expression> lhs = new List<Expression>(); List<Expression> lhs = new List<Expression>();
AssignmentStatement assign = new AssignmentStatement(lhs.ToArray(), null); AssignmentStatement assign = new AssignmentStatement(lhs.ToArray(), null);
PythonFormWalker walker = new PythonFormWalker(this); PythonComponentWalker walker = new PythonComponentWalker(this);
walker.Walk(assign); walker.Walk(assign);
} }

26
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/NoNewLineAfterInitializeComponentTestFixture.cs

@ -40,16 +40,16 @@ namespace PythonBinding.Tests.Designer
PythonParser parser = new PythonParser(); PythonParser parser = new PythonParser();
ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.TextContent); ICompilationUnit compilationUnit = parser.Parse(new DefaultProjectContent(), @"test.py", document.TextContent);
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { using (DesignSurface designSurface = new DesignSurface(typeof(UserControl))) {
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
Form form = (Form)host.RootComponent; UserControl userControl = (UserControl)host.RootComponent;
form.ClientSize = new Size(499, 309); userControl.ClientSize = new Size(489, 389);
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl);
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false);
namePropertyDescriptor.SetValue(form, "MainForm"); namePropertyDescriptor.SetValue(userControl, "userControl1");
PythonDesignerGenerator.Merge(form, document, compilationUnit, new MockTextEditorProperties()); PythonDesignerGenerator.Merge(userControl, document, compilationUnit, new MockTextEditorProperties());
} }
} }
} }
@ -57,19 +57,19 @@ namespace PythonBinding.Tests.Designer
[Test] [Test]
public void GeneratedCode() public void GeneratedCode()
{ {
string expectedCode = "from System.Windows.Forms import Form\r\n" + string expectedCode = "from System.Windows.Forms import UserControl\r\n" +
"\r\n" + "\r\n" +
"class MainForm(Form):\r\n" + "class MyUserControl(UserControl):\r\n" +
"\tdef __init__(self):\r\n" + "\tdef __init__(self):\r\n" +
"\t\tself.InitializeComponent()\r\n" + "\t\tself.InitializeComponent()\r\n" +
"\t\r\n" + "\t\r\n" +
"\tdef InitializeComponent(self):\r\n" + "\tdef InitializeComponent(self):\r\n" +
"\t\tself.SuspendLayout()\r\n" + "\t\tself.SuspendLayout()\r\n" +
"\t\t# \r\n" + "\t\t# \r\n" +
"\t\t# MainForm\r\n" + "\t\t# userControl1\r\n" +
"\t\t# \r\n" + "\t\t# \r\n" +
"\t\tself.ClientSize = System.Drawing.Size(499, 309)\r\n" + "\t\tself.Name = \"userControl1\"\r\n" +
"\t\tself.Name = \"MainForm\"\r\n" + "\t\tself.Size = System.Drawing.Size(489, 389)\r\n" +
"\t\tself.ResumeLayout(False)\r\n" + "\t\tself.ResumeLayout(False)\r\n" +
"\t\tself.PerformLayout()\r\n"; "\t\tself.PerformLayout()\r\n";
@ -81,9 +81,9 @@ namespace PythonBinding.Tests.Designer
/// </summary> /// </summary>
string GetTextEditorCode() string GetTextEditorCode()
{ {
return "from System.Windows.Forms import Form\r\n" + return "from System.Windows.Forms import UserControl\r\n" +
"\r\n" + "\r\n" +
"class MainForm(Form):\r\n" + "class MyUserControl(UserControl):\r\n" +
"\tdef __init__(self):\r\n" + "\tdef __init__(self):\r\n" +
"\t\tself.InitializeComponent()\r\n" + "\t\tself.InitializeComponent()\r\n" +
"\t\r\n" + "\t\r\n" +

74
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonBaseClassTests.cs

@ -0,0 +1,74 @@
// <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 ICSharpCode.PythonBinding;
using IronPython.Compiler.Ast;
using NUnit.Framework;
namespace PythonBinding.Tests.Designer
{
[TestFixture]
public class PythonBaseClassTests
{
[Test]
public void FormBaseClass()
{
string code = "class MainForm(System.Windows.Forms.Form):\r\n" +
" def InitializeComponent(self):\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(300, 400)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n";
ClassDefinition classDef = GetClassDefinition(code);
Assert.AreEqual("System.Windows.Forms.Form", PythonComponentWalker.GetBaseClassName(classDef));
}
[Test]
public void NoBaseClass()
{
string code = "class MainForm:\r\n" +
" def InitializeComponent(self):\r\n" +
" pass\r\n";
ClassDefinition classDef = GetClassDefinition(code);
Assert.AreEqual(String.Empty, PythonComponentWalker.GetBaseClassName(classDef));
}
[Test]
public void UnqualifiedBaseClass()
{
string code = "class MainForm(Form):\r\n" +
" def InitializeComponent(self):\r\n" +
" self.SuspendLayout()\r\n" +
" # \r\n" +
" # MainForm\r\n" +
" # \r\n" +
" self.ClientSize = System.Drawing.Size(300, 400)\r\n" +
" self.Name = \"MainForm\"\r\n" +
" self.ResumeLayout(False)\r\n";
ClassDefinition classDef = GetClassDefinition(code);
Assert.AreEqual("Form", PythonComponentWalker.GetBaseClassName(classDef));
}
ClassDefinition GetClassDefinition(string code)
{
PythonParser parser = new PythonParser();
PythonAst ast = parser.CreateAst(@"test.py", code);
SuiteStatement suite = ast.Body as SuiteStatement;
return suite.Statements[0] as ClassDefinition;
}
}
}

6
src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/UnknownTypeTestFixture.cs

@ -36,11 +36,11 @@ namespace PythonBinding.Tests.Designer
" self.ClientSize = Unknown.Type(10)\r\n"; " self.ClientSize = Unknown.Type(10)\r\n";
[Test] [Test]
[ExpectedException(typeof(PythonFormWalkerException))] [ExpectedException(typeof(PythonComponentWalkerException))]
public void PythonFormWalkerExceptionThrown() public void PythonFormWalkerExceptionThrown()
{ {
PythonFormWalker walker = new PythonFormWalker(new MockComponentCreator()); PythonComponentWalker walker = new PythonComponentWalker(new MockComponentCreator());
walker.CreateForm(pythonCode); walker.CreateComponent(pythonCode);
Assert.Fail("Exception should have been thrown before this."); Assert.Fail("Exception should have been thrown before this.");
} }
} }

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

@ -194,12 +194,14 @@
<Compile Include="Designer\LoadFormWithBooleanPropertiesSetTestFixture.cs" /> <Compile Include="Designer\LoadFormWithBooleanPropertiesSetTestFixture.cs" />
<Compile Include="Designer\LoadMenuStripFormTestFixture.cs" /> <Compile Include="Designer\LoadMenuStripFormTestFixture.cs" />
<Compile Include="Designer\LoadSimpleFormTestFixture.cs" /> <Compile Include="Designer\LoadSimpleFormTestFixture.cs" />
<Compile Include="Designer\LoadSimpleUserControlTestFixture.cs" />
<Compile Include="Designer\LoadTextBoxOnPanelTestFixture.cs" /> <Compile Include="Designer\LoadTextBoxOnPanelTestFixture.cs" />
<Compile Include="Designer\LoadTextBoxTestFixture.cs" /> <Compile Include="Designer\LoadTextBoxTestFixture.cs" />
<Compile Include="Designer\MergeFormTestFixture.cs" /> <Compile Include="Designer\MergeFormTestFixture.cs" />
<Compile Include="Designer\MissingInitializeComponentMethodTestFixture.cs" /> <Compile Include="Designer\MissingInitializeComponentMethodTestFixture.cs" />
<Compile Include="Designer\NoNewLineAfterInitializeComponentTestFixture.cs" /> <Compile Include="Designer\NoNewLineAfterInitializeComponentTestFixture.cs" />
<Compile Include="Designer\OneCompatibleMethodTestFixture.cs" /> <Compile Include="Designer\OneCompatibleMethodTestFixture.cs" />
<Compile Include="Designer\PythonBaseClassTests.cs" />
<Compile Include="Designer\PythonCodeDeserializerTests.cs" /> <Compile Include="Designer\PythonCodeDeserializerTests.cs" />
<Compile Include="Designer\PythonControlFieldExpressionTests.cs" /> <Compile Include="Designer\PythonControlFieldExpressionTests.cs" />
<Compile Include="Designer\PythonGeneratorTestFixture.cs" /> <Compile Include="Designer\PythonGeneratorTestFixture.cs" />

Loading…
Cancel
Save