// $Header: $
// Copyright (c) CODE Consulting and Development, s.r.o., Plzen. All rights reserved.
// ReSharper disable StringLiteralTypo
#region Example
// This example shows how the current node and selected nodes can be persisted between dialog invocations.
using System.Windows.Forms;
using OpcLabs.EasyOpc.UA.Forms.Browsing;
namespace UAFormsDocExamples._UABrowseDialog
{
static partial class ShowDialog
{
public static void SelectionDescriptors(IWin32Window owner)
{
// The variables that persist the current and selected nodes.
var currentNodeDescriptor = new UABrowseNodeDescriptor();
var selectionDescriptors = new UABrowseNodeDescriptorCollection();
// The initial current node (optional).
currentNodeDescriptor.EndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
// Repeatedly show the dialog until the user cancels it.
do
{
var browseDialog = new UABrowseDialog();
browseDialog.Mode.MultiSelect = true;
// Set the dialog inputs from the persistence variables.
browseDialog.InputsOutputs.CurrentNodeDescriptor = currentNodeDescriptor;
browseDialog.InputsOutputs.SelectionDescriptors.Clear();
foreach (UABrowseNodeDescriptor browseNodeDescriptor in selectionDescriptors)
browseDialog.InputsOutputs.SelectionDescriptors.Add(browseNodeDescriptor);
DialogResult dialogResult = browseDialog.ShowDialog(owner);
if (dialogResult != DialogResult.OK)
break;
// Update the persistence variables with the dialog output.
currentNodeDescriptor = browseDialog.InputsOutputs.CurrentNodeDescriptor;
selectionDescriptors.Clear();
foreach (UABrowseNodeDescriptor browseNodeDescriptor in browseDialog.InputsOutputs.SelectionDescriptors)
selectionDescriptors.Add(browseNodeDescriptor);
} while (true);
}
}
}
#endregion
# This example shows how the current node and selected nodes can be persisted between dialog invocations.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
# Import .NET namespaces.
from System.Windows.Forms import *
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.Forms.Browsing import *
# The variables that persist the current and selected nodes.
currentNodeDescriptor = UABrowseNodeDescriptor()
selectionDescriptors = UABrowseNodeDescriptorCollection()
# The initial current node (optional).
currentNodeDescriptor.EndpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# Repeatedly show the dialog until the user cancels it.
while True:
browseDialog = UABrowseDialog()
browseDialog.Mode.MultiSelect = True
# Set the dialog inputs from the persistence variables.
browseDialog.InputsOutputs.CurrentNodeDescriptor = currentNodeDescriptor
browseDialog.InputsOutputs.SelectionDescriptors.Clear()
for browseNodeDescriptor in selectionDescriptors:
browseDialog.InputsOutputs.SelectionDescriptors.Add(browseNodeDescriptor)
dialogResult = browseDialog.ShowDialog()
print(dialogResult)
if dialogResult != DialogResult.OK:
break
# Update the persistence variables with the dialog output.
currentNodeDescriptor = browseDialog.InputsOutputs.CurrentNodeDescriptor
selectionDescriptors.Clear()
for browseNodeDescriptor in browseDialog.InputsOutputs.SelectionDescriptors:
selectionDescriptors.Add(browseNodeDescriptor)
print('Finished.')