Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T1.2 accept/reject code changes #5

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/Libraries/PythonNodeModels/PythonNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ public enum PythonEngineVersion
CPython3
}

/// <summary>
/// Event arguments used to send the original and migrated code to the ScriptEditor
/// </summary>
public class PythonCodeMigrationEventArgs : EventArgs
{
public string OldCode { get; private set; }
public string NewCode { get; private set; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might also be useful to add properties that tell us the old version and the new one so we know more about the context of the migration (2->3, 3->3.1 for example). Could be used downstream (in assistant) to launch different documentation etc based on the versions

public PythonCodeMigrationEventArgs(string oldCode, string newCode)
{
OldCode = oldCode;
NewCode = newCode;
}
}

public abstract class PythonNodeBase : VariableInputNode
{
private PythonEngineVersion engine = PythonEngineVersion.IronPython2;
Expand Down Expand Up @@ -228,6 +242,31 @@ protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
return base.UpdateValueCore(updateValueParams);
}

/// <summary>
/// Updates the Script property of the node.
/// NOTE: This is a temporary method used during the Python 2 to Python 3 transistion period,
/// it will be removed when the transistion period is over.
/// </summary>
/// <param name="newCode">The new migrated code</param>
[Obsolete("Method will be deprecated after the Python 3 transition period")]
public void MigrateCode(string newCode)
{
var e = new PythonCodeMigrationEventArgs(Script, newCode);
Script = newCode;
OnCodeMigrated(e);
}

/// <summary>
/// Fires when the Script content is migrated to Python 3.
/// NOTE: This is a temporary event used during the Python 2 to Python 3 transistion period,
SHKnudsen marked this conversation as resolved.
Show resolved Hide resolved
/// it will be removed when the transistion period is over.
/// </summary>
public event EventHandler CodeMigrated;
SHKnudsen marked this conversation as resolved.
Show resolved Hide resolved
private void OnCodeMigrated(PythonCodeMigrationEventArgs e)
{
CodeMigrated?.Invoke(this, e);
}

#region SerializeCore/DeserializeCore

[Obsolete]
Expand Down
12 changes: 12 additions & 0 deletions src/Libraries/PythonNodeModelsWpf/ScriptEditorWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ref ModelessChildWindow.WindowRect windowRect

completionProvider = new SharedCompletionProvider(nodeModel.Engine,dynamoViewModel.Model.PathManager.DynamoCoreDirectory);
completionProvider.MessageLogged += dynamoViewModel.Model.Logger.Log;
nodeModel.CodeMigrated += OnNodeModelCodeMigrated;

InitializeComponent();

Expand Down Expand Up @@ -131,6 +132,17 @@ private void OnTextAreaTextEntered(object sender, TextCompositionEventArgs e)

#region Private Event Handlers

private void OnNodeModelCodeMigrated(object sender, EventArgs e)
{
var args = e as PythonCodeMigrationEventArgs;
if (args is null)
throw new NullReferenceException(nameof(args));
SHKnudsen marked this conversation as resolved.
Show resolved Hide resolved

originalScript = args.OldCode;
editText.Text = args.NewCode;
UpdateScript(args.NewCode);
}

private void OnSaveClicked(object sender, RoutedEventArgs e)
{
UpdateScript(editText.Text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
HorizontalAlignment="Right"
Grid.Column="1">
<Button x:Name="AcceptButton"
Click="OnAcceptButtonClicked"
HorizontalAlignment="Right"
ToolTip="{x:Static p:Resources.AcceptButtonTooltip}"
Height="44">
Expand All @@ -90,6 +91,7 @@
</Button.Resources>
</Button>
<Button x:Name="RejectButton"
Click="OnRejectButtonClicked"
HorizontalAlignment="Right"
ToolTip="{x:Static p:Resources.RejectButtonTooltip}"
Height="44">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ namespace Dynamo.PythonMigration.Controls
public partial class VisualDifferenceViewer : Window
{
private PythonMigrationAssistantViewModel ViewModel { get; set; }
internal VisualDifferenceViewer(PythonMigrationAssistantViewModel viewModel, Window ownerWindow)

internal VisualDifferenceViewer(PythonMigrationAssistantViewModel viewModel)
{
ViewModel = viewModel;
Owner = ownerWindow;
Owner = ViewModel.OwnerWindow;
InitializeComponent();
LoadData();
DiffView.ViewModeChanged += OnViewModeChanged;
Expand Down Expand Up @@ -55,6 +56,17 @@ private void SizeWindowToContent()
SizeToContent = SizeToContent.Manual;
}

private void OnAcceptButtonClicked(object sender, RoutedEventArgs e)
{
ViewModel.ChangeCode();
this.Close();
}

private void OnRejectButtonClicked(object sender, RoutedEventArgs e)
{
this.Close();
}

private void OnVisualDifferenceViewerClosed(object sender, System.EventArgs e)
{
DiffView.ViewModeChanged -= OnViewModeChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Python.Included;

namespace Dynamo.PythonMigration.MigrationAssistant
{
Expand All @@ -18,7 +19,7 @@ internal static class ScriptMigrator
/// <returns></returns>
internal static string MigrateCode(string code)
{
Python.Included.Installer.SetupPython().Wait();
Installer.SetupPython().Wait();

if (!PythonEngine.IsInitialized)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dynamo.PythonMigration.MigrationAssistant;
using PythonNodeModels;
using PythonNodeModelsWpf;
using System.Collections.Generic;

namespace Dynamo.PythonMigration
Expand All @@ -8,16 +9,33 @@ internal class PythonMigrationAssistantViewModel
{
public string OldCode { get; set; }
public string NewCode { get; set; }
internal ScriptEditorWindow OwnerWindow { get; private set; }
SHKnudsen marked this conversation as resolved.
Show resolved Hide resolved
private PythonNode PythonNode { get; set; }

public PythonMigrationAssistantViewModel(PythonNode pythonNode)
public PythonMigrationAssistantViewModel(PythonNode pythonNode, ScriptEditorWindow parentWindow = null)
{
PythonNode = pythonNode;
OldCode = pythonNode.Script;
MigrateCode();

if (parentWindow is null)
return;
SetOwnerWindow(parentWindow);
}

private void MigrateCode()
{
NewCode = ScriptMigrator.MigrateCode(OldCode);
}

public void ChangeCode()
{
PythonNode.MigrateCode(NewCode);
}

private void SetOwnerWindow(ScriptEditorWindow parentWindow)
SHKnudsen marked this conversation as resolved.
Show resolved Hide resolved
{
OwnerWindow = parentWindow;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Dynamo.ViewModels;
using Dynamo.Wpf.Extensions;
using PythonNodeModels;
using PythonNodeModelsWpf;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -107,11 +108,11 @@ private void OnMigrationAssistantRequested(object sender, EventArgs e)
throw new NullReferenceException(nameof(e));

var btn = routedEventArgs.OriginalSource as System.Windows.Controls.Button;
var parentWindow = Window.GetWindow(btn);
var parentWindow = Window.GetWindow(btn) as ScriptEditorWindow;

var node = sender as PythonNode;
var viewModel = new PythonMigrationAssistantViewModel(node);
var assistantWindow = new VisualDifferenceViewer(viewModel, parentWindow);
var viewModel = new PythonMigrationAssistantViewModel(node, parentWindow);
var assistantWindow = new VisualDifferenceViewer(viewModel);
SHKnudsen marked this conversation as resolved.
Show resolved Hide resolved
// show modal window so user cant interact with dynamo while migration assistant is open
assistantWindow.ShowDialog();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@
<Reference Include="PresentationFramework">
<Private>False</Private>
</Reference>
<Reference Include="Python.Included, Version=3.7.3.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Python.Included.3.7.3.4\lib\netstandard2.0\Python.Included.dll</HintPath>
<Reference Include="Python.Included, Version=2.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\extern\Python\Python.Included.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Python.Runtime.NETStandard, Version=3.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Python.Runtime.NETStandard.3.7.0\lib\netstandard2.0\Python.Runtime.NETStandard.dll</HintPath>
<Reference Include="Python.Runtime, Version=2.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\extern\Python\Python.Runtime.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System">
Expand Down Expand Up @@ -129,6 +131,11 @@
<Name>DynamoCore</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\Libraries\PythonNodeModelsWpf\PythonNodeModelsWpf.csproj">
<Project>{01DE9B06-0BCB-4D8A-862E-E8170F5D6B4F}</Project>
<Name>PythonNodeModelsWpf</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\Libraries\PythonNodeModels\PythonNodeModels.csproj">
<Project>{8872ca17-c10d-43b9-8393-5c5a57065eb0}</Project>
<Name>PythonNodeModels</Name>
Expand Down