/// <summary> /// Updates Engine property for a list of python nodes. /// </summary> private void UpdateEnginePropertyForAllPythonNodes(List <PythonNode> list, PythonEngineVersion pythonEngineVersion) { foreach (var pyNode in list) { pyNode.Engine = pythonEngineVersion; } }
internal void Initialize(Guid workspaceGuid, Guid nodeGuid, string propName, string propValue) { boundWorkspaceId = workspaceGuid; boundNodeId = nodeGuid; propertyName = propName; // Register auto-completion callbacks editText.TextArea.TextEntering += OnTextAreaTextEntering; editText.TextArea.TextEntered += OnTextAreaTextEntered; // Initialize editor with global settings for show/hide tabs and spaces editText.Options = dynamoViewModel.PythonScriptEditorTextOptions.GetTextOptions(); // Set options to reflect global settings when python script editor in initialized for the first time. editText.Options.ShowSpaces = dynamoViewModel.ShowTabsAndSpacesInScriptEditor; editText.Options.ShowTabs = dynamoViewModel.ShowTabsAndSpacesInScriptEditor; const string highlighting = "ICSharpCode.PythonBinding.Resources.Python.xshd"; var elem = GetType().Assembly.GetManifestResourceStream( "PythonNodeModelsWpf.Resources." + highlighting); editText.SyntaxHighlighting = HighlightingLoader.Load( new XmlTextReader(elem), HighlightingManager.Instance); editText.Text = propValue; originalScript = propValue; CachedEngine = nodeModel.Engine; EngineSelectorComboBox.SelectedItem = CachedEngine; }
/// <summary> /// Updates Engine property for a list of python nodes. /// </summary> private void UpdateEngineAndRunForAllPythonNodes(List <PythonNode> list, PythonEngineVersion pythonEngineVersion) { foreach (var pyNode in list) { pyNode.Engine = pythonEngineVersion; pyNode.OnNodeModified(); } }
private void OnRevertClicked(object sender, RoutedEventArgs e) { if (nodeWasModified) { editText.Text = originalScript; CachedEngine = nodeModel.Engine; EngineSelectorComboBox.SelectedItem = CachedEngine; UpdateScript(originalScript); } }
private void OnNodeModelCodeMigrated(object sender, PythonCodeMigrationEventArgs e) { originalScript = e.OldCode; editText.Text = e.NewCode; if (CachedEngine != PythonEngineVersion.CPython3) { CachedEngine = PythonEngineVersion.CPython3; EngineSelectorComboBox.SelectedItem = CachedEngine; } }
private void UpdateAvailableEngines(object sender = null, NotifyCollectionChangedEventArgs e = null) { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (var item in e.NewItems) { PythonEngineVersion engine = (PythonEngineVersion)item; if (!AvailableEngines.Contains(engine)) { AvailableEngines.Add(engine); } } } }
internal SharedCompletionProvider(PythonEngineVersion version, string dynamoCoreDir) { var versionName = Enum.GetName(typeof(PythonEngineVersion), version); var matchingCore = FindMatchingCodeCompletionCore(versionName, this.AsLogger()); if (matchingCore != null) { this.providerImplementation = matchingCore; this.providerImplementation.Initialize(dynamoCoreDir); if (providerImplementation is ILogSource) { (providerImplementation as ILogSource).MessageLogged += this.Log; } } }
private static void SetEngineViaContextMenu(NodeView nodeView, PythonEngineVersion engine) { var engineSelection = nodeView.MainContextMenu.Items .Cast <MenuItem>() .Where(item => (item.Header as string) == PythonNodeModels.Properties.Resources.PythonNodeContextMenuEngineSwitcher).FirstOrDefault(); switch (engine) { case PythonEngineVersion.IronPython2: (engineSelection.Items[0] as MenuItem).RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent)); break; case PythonEngineVersion.CPython3: (engineSelection.Items[1] as MenuItem).RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent)); break; } DispatcherUtil.DoEvents(); }
/// <summary> /// Set the engine to be used by default for this node, based on user and system settings. /// </summary> private void SetEngineByDefault() { PythonEngineVersion version; var setting = PreferenceSettings.GetDefaultPythonEngine(); var systemDefault = DynamoModel.DefaultPythonEngine; if (!string.IsNullOrEmpty(setting) && Enum.TryParse(setting, out version)) { engine = version; } else if (!string.IsNullOrEmpty(systemDefault) && Enum.TryParse(systemDefault, out version)) { engine = version; } else { // In the absence of both a setting and system default, default to deserialization default. engine = PythonEngineVersion.IronPython2; } }
/// <summary> /// Set the engine to be used by default for this node, based on user and system settings. /// </summary> private void SetEngineByDefault() { PythonEngineVersion version; var setting = PreferenceSettings.GetDefaultPythonEngine(); var systemDefault = DynamoModel.DefaultPythonEngine; if (!string.IsNullOrEmpty(setting) && Enum.TryParse(setting, out version)) { engine = version; } else if (!string.IsNullOrEmpty(systemDefault) && Enum.TryParse(systemDefault, out version)) { engine = version; } else { // Use CPython as default engine = PythonEngineVersion.CPython3; } }
/// <summary> /// The shared logic for Python node evaluation /// </summary> /// <param name="engine"></param> /// <param name="evaluatorClass"></param> /// <param name="evaluationMethod"></param> internal void GetEvaluatorInfo(PythonEngineVersion engine, out string evaluatorClass, out string evaluationMethod) { // Provide evaluator info when the selected engine is loaded if (engine == PythonEngineVersion.IronPython2 && GetEngine(PythonEngineVersion.IronPython2) != null) { evaluatorClass = IronPythonEvaluatorClass; evaluationMethod = IronPythonEvaluationMethod; return; } if (engine == PythonEngineVersion.CPython3 && GetEngine(PythonEngineVersion.CPython3) != null) { evaluatorClass = CPythonEvaluatorClass; evaluationMethod = CPythonEvaluationMethod; return; } // Throwing at the compilation stage is handled as a non-retryable error by the Dynamo engine. // Instead, we want to produce an error at the evaluation stage, so we can eventually recover. // We handle this by providing a dummy Python evaluator that will evaluate to an error message. evaluatorClass = DummyEvaluatorClass; evaluationMethod = DummyEvaluatorMethod; }
/// <summary> /// Updates Engine property for a single python node. /// </summary> private void UpdatePythonEngineAndRun(PythonNode pythonNode, PythonEngineVersion pythonEngineVersion) { pythonNode.Engine = pythonEngineVersion; //to kick off a run node modified must be called pythonNode.OnNodeModified(); }
private PythonEngine GetEngine(PythonEngineVersion version) { return(GetEngine(version.ToString())); }
/// <summary> /// Updates Engine property for a single python node. /// </summary> private void UpdateEnginePropertyForPythonNode(PythonNode pythonNode, PythonEngineVersion pythonEngineVersion) { pythonNode.Engine = pythonEngineVersion; }