From f9557c8c747cb0b73fe18085b1493147ce7165b5 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 13 Apr 2009 17:00:32 +0000 Subject: [PATCH] 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 --- .../Project/PythonBinding.csproj | 6 +- ...FormWalker.cs => PythonComponentWalker.cs} | 87 +++++++++++++------ ...n.cs => PythonComponentWalkerException.cs} | 6 +- .../Src/{PythonForm.cs => PythonControl.cs} | 40 ++++----- .../Project/Src/PythonDesignerGenerator.cs | 4 +- .../Project/Src/PythonDesignerLoader.cs | 4 +- ...edSetUsingPropertyDescriptorTestFixture.cs | 2 +- .../Test/Designer/FindAddRangeMethodTests.cs | 12 +-- .../GenerateAcceptButtonFormTestFixture.cs | 6 +- .../GenerateAccessibleRoleFormTestFixture.cs | 2 +- .../GenerateAutoScaleModeFormTestFixture.cs | 2 +- .../GenerateAutoScrollFormTestFixture.cs | 2 +- .../GenerateComboBoxItemsTestFixture.cs | 2 +- .../Designer/GenerateCursorFormTestFixture.cs | 2 +- .../GenerateDoubleBufferedFormTestFixture.cs | 2 +- .../GenerateEventHandlerFormTestFixture.cs | 2 +- .../Designer/GenerateFormColorTestFixture.cs | 2 +- .../GenerateFormLocationTestFixture.cs | 2 +- .../GenerateFormPaddingTestFixture.cs | 2 +- .../GenerateImeModeFormTestFixture.cs | 2 +- .../GenerateMenuStripFormTestFixture.cs | 2 +- .../GenerateMenuStripItemsTestFixture.cs | 6 +- .../GenerateMinSizeFormTestFixture.cs | 2 +- .../GenerateNestedPanelFormTestFixture.cs | 2 +- .../Designer/GeneratePanelFormTestFixture.cs | 2 +- .../GenerateRightToLeftFormTestFixture.cs | 2 +- .../Designer/GenerateSimpleFormTestFixture.cs | 2 +- .../GenerateTextBoxFormTestFixture.cs | 2 +- ...erializableContentPropertiesTestFixture.cs | 2 +- .../IgnoreDesignTimePropertiesTestFixture.cs | 4 +- .../Test/Designer/IsSitedComponentTests.cs | 8 +- .../Test/Designer/LoadFormTestFixtureBase.cs | 4 +- .../LoadSimpleUserControlTestFixture.cs | 72 +++++++++++++++ ...ingInitializeComponentMethodTestFixture.cs | 10 +-- ...LineAfterInitializeComponentTestFixture.cs | 26 +++--- .../Test/Designer/PythonBaseClassTests.cs | 74 ++++++++++++++++ .../Test/Designer/UnknownTypeTestFixture.cs | 6 +- .../Test/PythonBinding.Tests.csproj | 2 + 38 files changed, 298 insertions(+), 119 deletions(-) rename src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/{PythonFormWalker.cs => PythonComponentWalker.cs} (76%) rename src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/{PythonFormWalkerException.cs => PythonComponentWalkerException.cs} (63%) rename src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/{PythonForm.cs => PythonControl.cs} (93%) create mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadSimpleUserControlTestFixture.cs create mode 100644 src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonBaseClassTests.cs diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj index fa83bc4fc2..60791adb91 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj @@ -91,10 +91,10 @@ - + - - + + diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalker.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs similarity index 76% rename from src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalker.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs index 221166963c..f261c38986 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalker.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalker.cs @@ -21,41 +21,59 @@ namespace ICSharpCode.PythonBinding /// /// Visits the code's Python AST and creates a Windows Form. /// - public class PythonFormWalker : PythonWalker + public class PythonComponentWalker : PythonWalker { - Form form; + IComponent component; PythonControlFieldExpression fieldExpression; IComponentCreator componentCreator; bool walkingAssignment; - string formName = String.Empty; + string componentName = String.Empty; PythonCodeDeserializer deserializer; + ClassDefinition classDefinition; - public PythonFormWalker(IComponentCreator componentCreator) + public PythonComponentWalker(IComponentCreator componentCreator) { this.componentCreator = componentCreator; deserializer = new PythonCodeDeserializer(componentCreator); - } + } /// - /// Creates a form from python code. + /// Creates a control either a UserControl or Form from the python code. /// - public Form CreateForm(string pythonCode) + public IComponent CreateComponent(string pythonCode) { PythonParser parser = new PythonParser(); - PythonAst ast = parser.CreateAst(@"Form.py", pythonCode); + PythonAst ast = parser.CreateAst(@"Control.py", pythonCode); ast.Walk(this); - + // Did we find the InitializeComponent method? - if (form == null) { - throw new PythonFormWalkerException("Unable to find InitializeComponents method."); + if (component == null) { + throw new PythonComponentWalkerException("Unable to find InitializeComponents method."); } - - return form; - } + return component; + } + + /// + /// Gets the fully qualified name of the base class. + /// + 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) { - formName = node.Name.ToString(); + classDefinition = node; + componentName = node.Name.ToString(); if (node.Body != null) { node.Body.Walk(this); } @@ -65,7 +83,8 @@ namespace ICSharpCode.PythonBinding public override bool Walk(FunctionDefinition node) { if (IsInitializeComponentMethod(node)) { - form = (Form)componentCreator.CreateComponent(typeof(Form), formName); + Type type = GetComponentType(); + component = componentCreator.CreateComponent(type, componentName); node.Body.Walk(this); } return false; @@ -132,14 +151,14 @@ namespace ICSharpCode.PythonBinding MemberExpression eventHandlerExpression = node.Right as MemberExpression; string eventHandlerName = eventHandlerExpression.Name.ToString(); - Control control = form; + IComponent currentComponent = this.component; 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.SetValue(control, eventHandlerName); + propertyDescriptor.SetValue(currentComponent, eventHandlerName); return false; } @@ -192,12 +211,12 @@ namespace ICSharpCode.PythonBinding } /// - /// 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. /// - Control GetControl(string name) + IComponent GetComponent(string name) { - return componentCreator.GetComponent(name) as Control; + return componentCreator.GetComponent(name); } /// @@ -217,7 +236,19 @@ namespace ICSharpCode.PythonBinding if (fieldExpression.VariableName.Length > 0) { return componentCreator.GetComponent(fieldExpression.VariableName); } - return form; + return component; + } + + /// + /// Gets the type for the control being walked. + /// + Type GetComponentType() + { + string baseClass = GetBaseClassName(classDefinition); + if (baseClass.Contains("UserControl")) { + return typeof(UserControl); + } + return typeof(Form); } /// @@ -230,7 +261,7 @@ namespace ICSharpCode.PythonBinding if (propertyValue == null) { PythonControlFieldExpression field = PythonControlFieldExpression.Create(memberExpression); if (field.MemberName.Length > 0) { - propertyValue = GetControl(PythonControlFieldExpression.GetVariableName(field.MemberName)); + propertyValue = GetComponent(PythonControlFieldExpression.GetVariableName(field.MemberName)); } else { propertyValue = field.FullMemberName; } @@ -259,9 +290,9 @@ namespace ICSharpCode.PythonBinding } else { object obj = deserializer.Deserialize(node); if (obj != null) { - SetPropertyValue(form, fieldExpression.MemberName, obj); + SetPropertyValue(component, fieldExpression.MemberName, obj); } 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 // look for other controls. - object member = PythonControlFieldExpression.GetMember(form, node); + object member = PythonControlFieldExpression.GetMember(component, node); PythonControlFieldExpression field = PythonControlFieldExpression.Create(node); if (member == null) { member = field.GetMember(componentCreator); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalkerException.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalkerException.cs similarity index 63% rename from src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalkerException.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalkerException.cs index cbeee4fa47..b9b85ad509 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormWalkerException.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonComponentWalkerException.cs @@ -10,11 +10,11 @@ using System; namespace ICSharpCode.PythonBinding { /// - /// Exception thrown by the PythonFormWalker class. + /// Exception thrown by the PythonComponentWalker class. /// - public class PythonFormWalkerException : Exception + public class PythonComponentWalkerException : Exception { - public PythonFormWalkerException(string message) : base(message) + public PythonComponentWalkerException(string message) : base(message) { } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs similarity index 93% rename from src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs index ecfc0a4198..126e2565f3 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonForm.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonControl.cs @@ -20,10 +20,10 @@ using ICSharpCode.TextEditor.Document; namespace ICSharpCode.PythonBinding { /// - /// 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. /// - public class PythonForm + public class PythonControl { StringBuilder codeBuilder; string indentString = String.Empty; @@ -70,17 +70,17 @@ namespace ICSharpCode.PythonBinding } } - public PythonForm() + public PythonControl() : this("\t") { } - public PythonForm(string indentString) + public PythonControl(string indentString) : this(indentString, new PythonFormEventBindingService()) { } - PythonForm(string indentString, IEventBindingService eventBindingService) + PythonControl(string indentString, IEventBindingService eventBindingService) { this.indentString = indentString; this.eventBindingService = eventBindingService; @@ -89,14 +89,14 @@ namespace ICSharpCode.PythonBinding /// /// Generates python code for the InitializeComponent method based on the controls added to the form. /// - public string GenerateInitializeComponentMethod(Form form) + public string GenerateInitializeComponentMethod(Control control) { codeBuilder = new StringBuilder(); AppendIndentedLine("def InitializeComponent(self):"); IncreaseIndent(); - GenerateInitializeComponentMethodBodyInternal(form); + GenerateInitializeComponentMethodBodyInternal(control); return codeBuilder.ToString(); } @@ -104,12 +104,12 @@ namespace ICSharpCode.PythonBinding /// /// Generates the InitializeComponent method body. /// - public string GenerateInitializeComponentMethodBody(Form form, int initialIndent) + public string GenerateInitializeComponentMethodBody(Control control, int initialIndent) { codeBuilder = new StringBuilder(); indent = initialIndent; - GenerateInitializeComponentMethodBodyInternal(form); + GenerateInitializeComponentMethodBodyInternal(control); return codeBuilder.ToString(); } @@ -243,29 +243,29 @@ namespace ICSharpCode.PythonBinding return childComponents.ToArray(); } - void GenerateInitializeComponentMethodBodyInternal(Form form) + void GenerateInitializeComponentMethodBodyInternal(Control control) { - AppendChildControlCreation(form); - AppendChildControlSuspendLayout(form.Controls); + AppendChildControlCreation(control); + AppendChildControlSuspendLayout(control.Controls); AppendIndentedLine("self.SuspendLayout()"); - AppendForm(form); - AppendChildControlResumeLayout(form.Controls); + AppendRootControl(control); + AppendChildControlResumeLayout(control.Controls); AppendIndentedLine("self.ResumeLayout(False)"); AppendIndentedLine("self.PerformLayout()"); } /// - /// Generates python code for the form's InitializeComponent method. + /// Generates python code for the control's InitializeComponent method. /// - void AppendForm(Form form) + void AppendRootControl(Control rootControl) { // Add the controls on the form. - foreach (Control control in form.Controls) { + foreach (Control control in rootControl.Controls) { AppendComponent(control); } - // Add form. - AppendComponent(form, false, false); + // Add root control. + AppendComponent(rootControl, false, false); } void AppendComponent(IComponent component) @@ -506,7 +506,7 @@ namespace ICSharpCode.PythonBinding /// void AppendChildComponentProperties(object component) { - foreach (PropertyDescriptor property in PythonForm.GetSerializableContentProperties(component)) { + foreach (PropertyDescriptor property in PythonControl.GetSerializableContentProperties(component)) { object propertyCollection = property.GetValue(component); ICollection collection = propertyCollection as ICollection; if (collection != null) { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerGenerator.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerGenerator.cs index efdf756d8b..d015591285 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerGenerator.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerGenerator.cs @@ -96,9 +96,9 @@ namespace ICSharpCode.PythonBinding IMethod method = GetInitializeComponents(compilationUnit); // Generate the python source code. - PythonForm pythonForm = new PythonForm(NRefactoryToPythonConverter.GetIndentString(textEditorProperties)); + PythonControl pythonForm = new PythonControl(NRefactoryToPythonConverter.GetIndentString(textEditorProperties)); int indent = method.Region.BeginColumn; - string methodBody = pythonForm.GenerateInitializeComponentMethodBody(component as Form, indent); + string methodBody = pythonForm.GenerateInitializeComponentMethodBody(component as Control, indent); // Merge the code. DomRegion methodRegion = GetBodyRegionInDocument(method); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs index 2d961183fe..f534912107 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonDesignerLoader.cs @@ -115,8 +115,8 @@ namespace ICSharpCode.PythonBinding { // Create designer root object. this.serializationManager = serializationManager; - PythonFormWalker visitor = new PythonFormWalker(this); - visitor.CreateForm(generator.ViewContent.DesignerCodeFileContent); + PythonComponentWalker visitor = new PythonComponentWalker(this); + visitor.CreateComponent(generator.ViewContent.DesignerCodeFileContent); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs index a116ef3abd..83a3f85aa7 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/EnabledSetUsingPropertyDescriptorTestFixture.cs @@ -44,7 +44,7 @@ namespace PythonBinding.Tests.Designer enabledPropertyDescriptor.SetValue(form, false); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/FindAddRangeMethodTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/FindAddRangeMethodTests.cs index 72f100de4b..4f48d4febe 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/FindAddRangeMethodTests.cs +++ b/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[])); 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()) { 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() { MethodInfo methodInfo = typeof(String).GetMethod("Clone"); - Assert.IsNull(PythonForm.GetArrayParameterType(methodInfo)); + Assert.IsNull(PythonControl.GetArrayParameterType(methodInfo)); } [Test] public void GetArrayParameterTypeWithNullMethodInfo() { - Assert.IsNull(PythonForm.GetArrayParameterType(null)); + Assert.IsNull(PythonControl.GetArrayParameterType(null)); } /// @@ -61,7 +61,7 @@ namespace PythonBinding.Tests.Designer public void FormControlsAddRangeMethodNotFound() { 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)); Assert.IsNotNull(expectedMethodInfo); - Assert.AreSame(expectedMethodInfo, PythonForm.GetAddSerializationMethod(form.Controls)); + Assert.AreSame(expectedMethodInfo, PythonControl.GetAddSerializationMethod(form.Controls)); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs index 994a0f2e0e..94e6823e2e 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAcceptButtonFormTestFixture.cs @@ -48,11 +48,11 @@ namespace PythonBinding.Tests.Designer PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); namePropertyDescriptor.SetValue(form, "MainForm"); - PythonForm pythonForm = new PythonForm(" "); + PythonControl pythonForm = new PythonControl(" "); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); - formChildComponents = PythonForm.GetChildComponents(form); - buttonChildComponents = PythonForm.GetChildComponents(button); + formChildComponents = PythonControl.GetChildComponents(form); + buttonChildComponents = PythonControl.GetChildComponents(button); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAccessibleRoleFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAccessibleRoleFormTestFixture.cs index aa94c25114..3f75fc85da 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAccessibleRoleFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAccessibleRoleFormTestFixture.cs @@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScaleModeFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScaleModeFormTestFixture.cs index e611058c86..dc6340e67a 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScaleModeFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScaleModeFormTestFixture.cs @@ -52,7 +52,7 @@ namespace PythonBinding.Tests.Designer autoScaleDimensionsDescriptor.SetValue(form, new SizeF(6F, 13F)); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScrollFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScrollFormTestFixture.cs index 45126651a9..225a37dcc8 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScrollFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateAutoScrollFormTestFixture.cs @@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateComboBoxItemsTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateComboBoxItemsTestFixture.cs index b6aa21e15a..f1258b4451 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateComboBoxItemsTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateComboBoxItemsTestFixture.cs @@ -47,7 +47,7 @@ namespace PythonBinding.Tests.Designer form.Controls.Add(comboBox); - PythonForm pythonForm = new PythonForm(" "); + PythonControl pythonForm = new PythonControl(" "); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateCursorFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateCursorFormTestFixture.cs index 814e23b373..62664d8125 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateCursorFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateCursorFormTestFixture.cs @@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateDoubleBufferedFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateDoubleBufferedFormTestFixture.cs index 17fde8e5a1..976b2825db 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateDoubleBufferedFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateDoubleBufferedFormTestFixture.cs @@ -43,7 +43,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateEventHandlerFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateEventHandlerFormTestFixture.cs index f5324a42be..0e60b6b8ba 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateEventHandlerFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateEventHandlerFormTestFixture.cs @@ -52,7 +52,7 @@ namespace PythonBinding.Tests.Designer PropertyDescriptor closedEventProperty = eventBindingService.GetEventProperty(closedEvent); closedEventProperty.SetValue(form, "MainFormClosed"); - PythonForm pythonForm = new PythonForm(" "); + PythonControl pythonForm = new PythonControl(" "); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormColorTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormColorTestFixture.cs index 24aa80d697..0295d812f5 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormColorTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormColorTestFixture.cs @@ -40,7 +40,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormLocationTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormLocationTestFixture.cs index d093d4f3bb..f5bf5eeb55 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormLocationTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormLocationTestFixture.cs @@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormPaddingTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormPaddingTestFixture.cs index a55eb12f5c..b09a65522f 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormPaddingTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateFormPaddingTestFixture.cs @@ -38,7 +38,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateImeModeFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateImeModeFormTestFixture.cs index f41ac4fea5..0c246e72e2 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateImeModeFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateImeModeFormTestFixture.cs @@ -37,7 +37,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripFormTestFixture.cs index 77ede12f7f..343a35531e 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripFormTestFixture.cs @@ -48,7 +48,7 @@ namespace PythonBinding.Tests.Designer menuStrip.Location = new Point(0, 0); form.Controls.Add(menuStrip); - PythonForm pythonForm = new PythonForm(" "); + PythonControl pythonForm = new PythonControl(" "); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripItemsTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripItemsTestFixture.cs index 79c84defa1..2b4bf6bef1 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripItemsTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMenuStripItemsTestFixture.cs @@ -77,11 +77,11 @@ namespace PythonBinding.Tests.Designer exitMenuItemSize = exitMenuItem.Size; editMenuItemSize = editMenuItem.Size; - PythonForm pythonForm = new PythonForm(" "); + PythonControl pythonForm = new PythonControl(" "); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); - menuStripChildComponents = PythonForm.GetChildComponents(menuStrip); - fileMenuItemChildComponents = PythonForm.GetChildComponents(fileMenuItem); + menuStripChildComponents = PythonControl.GetChildComponents(menuStrip); + fileMenuItemChildComponents = PythonControl.GetChildComponents(fileMenuItem); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMinSizeFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMinSizeFormTestFixture.cs index 9835d62376..776a37d789 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMinSizeFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateMinSizeFormTestFixture.cs @@ -47,7 +47,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateNestedPanelFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateNestedPanelFormTestFixture.cs index 2de6de764d..1bc18b359d 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateNestedPanelFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateNestedPanelFormTestFixture.cs @@ -56,7 +56,7 @@ namespace PythonBinding.Tests.Designer form.Controls.Add(panel1); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratePanelFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratePanelFormTestFixture.cs index 37c695d885..e5f753ea13 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratePanelFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratePanelFormTestFixture.cs @@ -54,7 +54,7 @@ namespace PythonBinding.Tests.Designer form.Controls.Add(panel); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateRightToLeftFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateRightToLeftFormTestFixture.cs index e162fe5026..a29d439073 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateRightToLeftFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateRightToLeftFormTestFixture.cs @@ -37,7 +37,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateSimpleFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateSimpleFormTestFixture.cs index 0b95626571..a754b3a57e 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateSimpleFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateSimpleFormTestFixture.cs @@ -34,7 +34,7 @@ namespace PythonBinding.Tests.Designer namePropertyDescriptor.SetValue(form, "MainForm"); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs index e560077cab..47e0521d8b 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GenerateTextBoxFormTestFixture.cs @@ -41,7 +41,7 @@ namespace PythonBinding.Tests.Designer form.Controls.Add(textBox); string indentString = " "; - PythonForm pythonForm = new PythonForm(indentString); + PythonControl pythonForm = new PythonControl(indentString); generatedPythonCode = pythonForm.GenerateInitializeComponentMethod(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetSerializableContentPropertiesTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetSerializableContentPropertiesTestFixture.cs index 55342377af..0426759388 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetSerializableContentPropertiesTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GetSerializableContentPropertiesTestFixture.cs @@ -27,7 +27,7 @@ namespace PythonBinding.Tests.Designer using (Form form = new Form()) { // Modify Form.Text so it is identified as needing serialization. form.Text = "abc"; - properties = PythonForm.GetSerializableContentProperties(form); + properties = PythonControl.GetSerializableContentProperties(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IgnoreDesignTimePropertiesTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IgnoreDesignTimePropertiesTestFixture.cs index b928d8a429..1cd7d34bbd 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IgnoreDesignTimePropertiesTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IgnoreDesignTimePropertiesTestFixture.cs @@ -53,10 +53,10 @@ namespace PythonBinding.Tests.Designer PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); namePropertyDescriptor.SetValue(form, "MainForm"); - PythonForm pythonForm = new PythonForm(" "); + PythonControl pythonForm = new PythonControl(" "); generatedCode = pythonForm.GenerateInitializeComponentMethod(form); - propertyDescriptors = PythonForm.GetSerializableProperties(form); + propertyDescriptors = PythonControl.GetSerializableProperties(form); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsSitedComponentTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsSitedComponentTests.cs index 928ce5768c..8ba20b3df8 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsSitedComponentTests.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/IsSitedComponentTests.cs @@ -19,13 +19,13 @@ namespace PythonBinding.Tests.Designer [Test] public void NullComponent() { - Assert.IsFalse(PythonForm.IsSitedComponent(null)); + Assert.IsFalse(PythonControl.IsSitedComponent(null)); } [Test] public void ComponentNotSited() { - Assert.IsFalse(PythonForm.IsSitedComponent(new Component())); + Assert.IsFalse(PythonControl.IsSitedComponent(new Component())); } [Test] @@ -33,13 +33,13 @@ namespace PythonBinding.Tests.Designer { Component component = new Component(); component.Site = this; - Assert.IsTrue(PythonForm.IsSitedComponent(component)); + Assert.IsTrue(PythonControl.IsSitedComponent(component)); } [Test] public void NonComponent() { - Assert.IsFalse(PythonForm.IsSitedComponent(String.Empty)); + Assert.IsFalse(PythonControl.IsSitedComponent(String.Empty)); } public IComponent Component { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs index 46e3a90202..3f1db57be3 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadFormTestFixtureBase.cs @@ -31,8 +31,8 @@ namespace PythonBinding.Tests.Designer [TestFixtureSetUp] public void SetUpFixture() { - PythonFormWalker walker = new PythonFormWalker(componentCreator); - form = walker.CreateForm(PythonCode); + PythonComponentWalker walker = new PythonComponentWalker(componentCreator); + form = walker.CreateComponent(PythonCode) as Form; } [TestFixtureTearDown] diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadSimpleUserControlTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadSimpleUserControlTestFixture.cs new file mode 100644 index 0000000000..1780a2821a --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/LoadSimpleUserControlTestFixture.cs @@ -0,0 +1,72 @@ +// +// +// +// +// $Revision$ +// + +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); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs index e63c5a32bb..b703545a2f 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/MissingInitializeComponentMethodTestFixture.cs @@ -37,11 +37,11 @@ namespace PythonBinding.Tests.Designer " def MissingMethod(self):\r\n" + " pass\r\n"; [Test] - [ExpectedException(typeof(PythonFormWalkerException))] + [ExpectedException(typeof(PythonComponentWalkerException))] public void PythonFormWalkerExceptionThrown() { - PythonFormWalker walker = new PythonFormWalker(this); - walker.CreateForm(pythonCode); + PythonComponentWalker walker = new PythonComponentWalker(this); + walker.CreateComponent(pythonCode); Assert.Fail("Exception should have been thrown before this."); } @@ -52,7 +52,7 @@ namespace PythonBinding.Tests.Designer public void ClassWithNoBody() { ClassDefinition classDef = new ClassDefinition(new SymbolId(10), null, null); - PythonFormWalker walker = new PythonFormWalker(this); + PythonComponentWalker walker = new PythonComponentWalker(this); walker.Walk(classDef); } @@ -65,7 +65,7 @@ namespace PythonBinding.Tests.Designer { List lhs = new List(); AssignmentStatement assign = new AssignmentStatement(lhs.ToArray(), null); - PythonFormWalker walker = new PythonFormWalker(this); + PythonComponentWalker walker = new PythonComponentWalker(this); walker.Walk(assign); } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/NoNewLineAfterInitializeComponentTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/NoNewLineAfterInitializeComponentTestFixture.cs index 33296b74b2..5eee25cce1 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/NoNewLineAfterInitializeComponentTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/NoNewLineAfterInitializeComponentTestFixture.cs @@ -40,16 +40,16 @@ namespace PythonBinding.Tests.Designer PythonParser parser = new PythonParser(); 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)); - Form form = (Form)host.RootComponent; - form.ClientSize = new Size(499, 309); + UserControl userControl = (UserControl)host.RootComponent; + userControl.ClientSize = new Size(489, 389); - PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); + PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(userControl); 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] 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" + - "class MainForm(Form):\r\n" + + "class MyUserControl(UserControl):\r\n" + "\tdef __init__(self):\r\n" + "\t\tself.InitializeComponent()\r\n" + "\t\r\n" + "\tdef InitializeComponent(self):\r\n" + "\t\tself.SuspendLayout()\r\n" + "\t\t# \r\n" + - "\t\t# MainForm\r\n" + + "\t\t# userControl1\r\n" + "\t\t# \r\n" + - "\t\tself.ClientSize = System.Drawing.Size(499, 309)\r\n" + - "\t\tself.Name = \"MainForm\"\r\n" + + "\t\tself.Name = \"userControl1\"\r\n" + + "\t\tself.Size = System.Drawing.Size(489, 389)\r\n" + "\t\tself.ResumeLayout(False)\r\n" + "\t\tself.PerformLayout()\r\n"; @@ -81,9 +81,9 @@ namespace PythonBinding.Tests.Designer /// string GetTextEditorCode() { - return "from System.Windows.Forms import Form\r\n" + + return "from System.Windows.Forms import UserControl\r\n" + "\r\n" + - "class MainForm(Form):\r\n" + + "class MyUserControl(UserControl):\r\n" + "\tdef __init__(self):\r\n" + "\t\tself.InitializeComponent()\r\n" + "\t\r\n" + diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonBaseClassTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonBaseClassTests.cs new file mode 100644 index 0000000000..5d8b872080 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonBaseClassTests.cs @@ -0,0 +1,74 @@ +// +// +// +// +// $Revision$ +// + +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; + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/UnknownTypeTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/UnknownTypeTestFixture.cs index 89fd7f5ce4..3b50ce0a2f 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/UnknownTypeTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/UnknownTypeTestFixture.cs @@ -36,11 +36,11 @@ namespace PythonBinding.Tests.Designer " self.ClientSize = Unknown.Type(10)\r\n"; [Test] - [ExpectedException(typeof(PythonFormWalkerException))] + [ExpectedException(typeof(PythonComponentWalkerException))] public void PythonFormWalkerExceptionThrown() { - PythonFormWalker walker = new PythonFormWalker(new MockComponentCreator()); - walker.CreateForm(pythonCode); + PythonComponentWalker walker = new PythonComponentWalker(new MockComponentCreator()); + walker.CreateComponent(pythonCode); Assert.Fail("Exception should have been thrown before this."); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index 5e19865888..14968eaddd 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -194,12 +194,14 @@ + +