BioGTK  6.5.0
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images. Including whole slide, pyramidal, and series.
Loading...
Searching...
No Matches
ComboPicker.cs
1using Gtk;
2using System;
3using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8
9namespace BioGTK
10{
11 public class ComboPicker : Dialog
12 {
13 #region Properties
14 private Builder _builder;
15
16#pragma warning disable 649
17 [Builder.Object]
18 private Gtk.Button okBut;
19 [Builder.Object]
20 private Gtk.Button cancelBut;
21 [Builder.Object]
22 private Gtk.ComboBox comboBox;
23#pragma warning restore 649
24
25 #endregion
26
27 #region Constructors / Destructors
28 string selection;
29 Type ens;
33 public static ComboPicker Create(string[] sts)
34 {
35 Builder builder = new Builder(new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/" + "Glade/ComboPicker.glade", FileMode.Open));
36 return new ComboPicker(builder, builder.GetObject("comboPicker").Handle, sts);
37 }
41 public static ComboPicker Create(Type ems)
42 {
43 Builder builder = new Builder(new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/" + "Glade/ComboPicker.glade", FileMode.Open));
44 return new ComboPicker(builder, builder.GetObject("comboPicker").Handle, ems);
45 }
46 /* The constructor for the ComboPicker class. */
47 protected ComboPicker(Builder builder, IntPtr handle, Type ems) : base(handle)
48 {
49 _builder = builder;
50 builder.Autoconnect(this);
51 okBut.ButtonPressEvent += OkBut_ButtonPressEvent;
52 cancelBut.ButtonPressEvent += CancelBut_ButtonPressEvent;
53 ens = ems;
54 List<string> sts = new List<string>();
55 Array ar = Enum.GetValues(ems);
56 foreach (Enum s in ar)
57 {
58 sts.Add(s.ToString());
59 }
60 var states = new ListStore(typeof(string));
61 //We add button states to buttonState box.
62 foreach (string val in sts)
63 {
64 states.AppendValues(val);
65 }
66 // Set the model for the ComboBox
67 comboBox.Model = states;
68 // Set the text column to display
69 var renderer2 = new CellRendererText();
70 comboBox.PackStart(renderer2, false);
71 comboBox.AddAttribute(renderer2, "text", 0);
72 comboBox.Active = 0;
73 App.ApplyStyles(this);
74 }
75 /* The constructor for the ComboPicker class. */
76 protected ComboPicker(Builder builder, IntPtr handle, string[] sts) : base(handle)
77 {
78 _builder = builder;
79 builder.Autoconnect(this);
80 okBut.ButtonPressEvent += OkBut_ButtonPressEvent;
81 cancelBut.ButtonPressEvent += CancelBut_ButtonPressEvent;
82 var states = new ListStore(typeof(string));
83 //We add button states to buttonState box.
84 foreach (string val in sts)
85 {
86 states.AppendValues(val);
87 }
88 // Set the model for the ComboBox
89 comboBox.Model = states;
90 // Set the text column to display
91 var renderer2 = new CellRendererText();
92 comboBox.PackStart(renderer2, false);
93 comboBox.AddAttribute(renderer2, "text", 0);
94 comboBox.Active = 0;
95 App.ApplyStyles(this);
96 }
97
102 private void CancelBut_ButtonPressEvent(object o, ButtonPressEventArgs args)
103 {
104 Respond(ResponseType.Cancel);
105 Hide();
106 }
107
108 private void OkBut_ButtonPressEvent(object o, ButtonPressEventArgs args)
109 {
110 Respond(ResponseType.Ok);
111 Hide();
112 }
113
114 /* A property that returns the selected index of the combobox. */
115 public int SelectedIndex
116 {
117 get { return comboBox.Active; }
118 }
119 #endregion
120
121 }
122}
static ComboPicker Create(string[] sts)
static ComboPicker Create(Type ems)
Definition ML.cs:17