BioGTK  6.7.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
TextInput.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 TextInput : 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.Entry textinputBox;
23 [Builder.Object]
24 private Gtk.ColorButton colorBut;
25 [Builder.Object]
26 private Gtk.FontButton fontBut;
27#pragma warning restore 649
28
29 #endregion
30
31 #region Constructors / Destructors
32 private bool ROItype = true;
36 public static TextInput Create(bool ROItype = true)
37 {
38 Builder builder = new Builder(new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/" + "Glade/TextInput.glade", FileMode.Open));
39 var ti = new TextInput(builder, builder.GetObject("textInput").Handle);
40 ti.ROItype = ROItype;
41 return ti;
42 }
43
44 /* The constructor for the TextInput class. */
45 protected TextInput(Builder builder, IntPtr handle) : base(handle)
46 {
47 _builder = builder;
48 builder.Autoconnect(this);
49 okBut.ButtonPressEvent += OkBut_ButtonPressEvent;
50 cancelBut.ButtonPressEvent += CancelBut_ButtonPressEvent;
51 textinputBox.Activated += TextinputBox_Activated;
52 App.ApplyStyles(this);
53 }
54
55 private void TextinputBox_Activated(object sender, EventArgs e)
56 {
57 if(ROItype)
58 SetText();
59 Hide();
60 Respond(ResponseType.Ok);
61 }
62
67 private void CancelBut_ButtonPressEvent(object o, ButtonPressEventArgs args)
68 {
69 Respond(ResponseType.Cancel);
70 Hide();
71 }
72
80 private void OkBut_ButtonPressEvent(object o, ButtonPressEventArgs args)
81 {
82 if (ROItype)
83 SetText();
84 Hide();
85 Respond(ResponseType.Ok);
86 }
87
88 void SetText()
89 {
90 try
91 {
92 ROI ro = null;
93 foreach (var r in ImageView.SelectedImage.Annotations)
94 {
95 if (r.Selected)
96 {
97 ro = r;
98 break;
99 }
100 }
101 if (ro == null)
102 return;
103 ro.Text = textinputBox.Text;
104 string s = fontBut.Font;
105 s = s.Replace(",", "");
106 string[] sts = s.Split(' ');
107 s = s.Replace(sts[sts.Length-1],"");
108 ro.family = fontBut.FontFamily.Name;
109 ro.fontSize = float.Parse(sts[sts.Length - 1]);
110 }
111 catch (Exception e)
112 {
113
114 }
115 }
116
117 /* A property that returns the Text value of the text input textbox. */
118 public string Text
119 {
120 get { return textinputBox.Text; }
121 }
122
123 /* A property that returns the RGBA value of the color button. */
124 public Gdk.RGBA RGBA
125 {
126 get { return colorBut.Rgba; }
127 }
128
129 /* Returning the font family of the font button. */
130 public string FontFamily
131 {
132 get
133 {
134 return fontBut.FontOptions.HintStyle.ToString();
135 }
136 }
137 #endregion
138
139 }
140}
static TextInput Create(bool ROItype=true)
Definition TextInput.cs:36
Definition ML.cs:17