chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.ComponentModel;
 
namespace OpenTap.Plugins.PluginDevelopment.GUI
{
    [Display("OpenTAP Picture Example", Groups: new[] { "Examples", "Plugin Development", "GUI" },
        Description: "This example shows how to use OpenTap Pictures.")]
    public class OpenTapPictureExample : TestStep
    {
        enum ResponseEnum
        {
            [Display("I pressed the button, proceed!")]
            Yes,
            [Display("Something is wrong, abort!")]
            No
        }
 
        [Display("Confirm instrument configuration")]
        class PictureDialogRequest
        {
            public PictureDialogRequest(string question)
            {
                Question = question;
            }
 
            /// <summary>
            /// The layout of a picture can be controlled using the Layout attribute, just like other UserInput members
            /// </summary>
            [Layout(LayoutMode.FullRow)]
            [Display("Picture", Order: 1)]
            public Picture Picture { get; set; }
 
            [Layout(LayoutMode.FullRow, rowHeight: 2)]
            [Browsable(true)]
            [Display("Message", Order: 2)]
            public string Question { get; }
 
            [Layout(LayoutMode.FloatBottom | LayoutMode.FullRow)]
            [Submit]
            public ResponseEnum response { get; set; }
 
        }
        public override void Run()
        {
            // Open a dialog with the picture settings defined in the test step
            var request = new PictureDialogRequest(Question)
            {
                Picture = Picture,
            };
 
            UserInput.Request(request);
 
            if (request.response == ResponseEnum.No)
            {
                UpgradeVerdict(Verdict.Error);
            }
        }
 
        public string Question { get; set; } = "Press the button labeled 'A' in the figure.";
 
        /// <summary>
        /// Instantiate an OpenTAP picture with some default picture
        /// These can be controlled by other test step properties if they should be configurable, or they can be hardcoded values
        /// </summary>
        public Picture Picture { get; } = new Picture()
        {
            Source = "GUI\\SomeInstrument.png",
            Description = "The instrument we are controlling."
        };
 
        /// <summary>
        /// Control the source of the picture with a regular test step property
        /// </summary>
        [Display("Source", "The source of the picture. This can be a URL or a file path.", "Picture", Order: 2,
            Collapsed: true)]
        [FilePath(FilePathAttribute.BehaviorChoice.Open)]
        public string PictureSource
        {
            get => Picture.Source;
            set => Picture.Source = value;
        }
 
        /// <summary>
        /// Control the description of the picture with a regular test step property
        /// </summary>
        [Display("Description", "A description of the picture. " +
                                "This can be helpful to set if the picture cannot be loaded for some reason, " +
                                "or if the test plan is not running in a GUI environment.",
            "Picture", Order: 3, Collapsed: true)]
 
        public string PictureDescription
        {
            get => Picture.Description;
            set => Picture.Description = value;
        }
    }
}