BioImager  5.0.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
BioConsole.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10using BioLib;
11namespace BioImager
12{
13 public partial class BioConsole : Form
14 {
15 public BioConsole()
16 {
17 InitializeComponent();
18 }
19 public static bool onTab = false;
20 public static bool useBioformats = false;
21 public static bool headless = false;
22 public static bool newTab = false;
27 private void runBut_Click(object sender, EventArgs e)
28 {
29 object o = Scripting.Script.RunString(textBox.Text);
30 consoleBox.Text += textBox.Text + Environment.NewLine + o.ToString() + Environment.NewLine;
31 textBox.Text = "";
32 }
33
40 private void imagejBut_Click(object sender, EventArgs e)
41 {
42 if (ImageView.SelectedImage == null)
43 return;
44 ImageJ.RunOnImage(textBox.Text, headlessBox.Checked, tabRadioBut.Checked, biofBox.Checked, newTabBox.Checked);
45 consoleBox.Text += textBox.Text + Environment.NewLine;
46 textBox.Text = "";
47 string filename = "";
48
49 if (ImageView.SelectedImage.ID.EndsWith(".ome.tif"))
50 {
51 filename = System.IO.Path.GetFileNameWithoutExtension(ImageView.SelectedImage.ID);
52 filename = filename.Remove(filename.Length - 4, 4);
53 }
54 else
55 filename = System.IO.Path.GetFileNameWithoutExtension(ImageView.SelectedImage.ID);
56 string file = System.IO.Path.GetDirectoryName(ImageView.SelectedImage.ID) + "/" + filename + ".ome.tif";
57 if (ImageView.SelectedImage.ID.EndsWith(".ome.tif"))
58 ImageView.SelectedImage.Update();
59 else
60 App.tabsView.AddTab(BioImage.OpenOME(file, false));
61 }
62
67 private void topMostBox_CheckedChanged(object sender, EventArgs e)
68 {
69 this.TopMost = topMostBox.Checked;
70 }
71
76 private void BioConsole_FormClosing(object sender, FormClosingEventArgs e)
77 {
78 e.Cancel = true;
79 this.Hide();
80 }
81 int line = 0;
91 private void BioConsole_KeyDown(object sender, KeyEventArgs e)
92 {
93 if (e.KeyCode == Keys.Up)
94 {
95 line++;
96 textBox.Text = consoleBox.Lines[consoleBox.Lines.Length - 1 - line];
97 }
98 if (e.KeyCode == Keys.Down)
99 {
100 line--;
101 textBox.Text = consoleBox.Lines[consoleBox.Lines.Length - 1 - line];
102 }
103 }
104
109 private void tabRadioBut_CheckedChanged(object sender, EventArgs e)
110 {
111 onTab = tabRadioBut.Checked;
112 }
113
118 private void biofBox_CheckedChanged(object sender, EventArgs e)
119 {
120 useBioformats = biofBox.Checked;
121 }
122
123 private void headlessBox_CheckedChanged(object sender, EventArgs e)
124 {
125 headless = headlessBox.Checked;
126 }
127 bool skip = false;
128 string chs = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
129 private string pred = "";
130 private List<string> preds = new List<string>();
131 private void textBox_TextChanged(object sender, EventArgs e)
132 {
133 if (textBox.Text.Length == 0)
134 return;
135 if (skip)
136 {
137 skip = false;
138 return;
139 }
140 pred = pred.Replace("\t", "").Replace("\r", "").Replace("\n", "");
141 if (pred.Contains(' '))
142 pred = textBox.Text.Remove(0, textBox.Text.LastIndexOf(' '));
143 else
144 pred = textBox.Text.Replace("\t", "").Replace("\r", "").Replace("\n", "");
145 bool ends = false;
146 char ch = ' ';
147 int i = 0;
148 int ind = -1;
149 foreach (Char cs in pred)
150 {
151 ends = false;
152 foreach (Char c in chs)
153 {
154 if (cs == c)
155 {
156 ends = true;
157 ch = c;
158 }
159 }
160 if (!ends)
161 ind = i;
162 i++;
163 }
164 if (ind != -1)
165 pred = pred.Remove(0, ind + 1);
166
167 preds.Clear();
168 i = 0;
169 ind = -1;
170 foreach (var cs in ImageJ.Macro.Commands)
171 {
172 if (cs.Value.Name.StartsWith(pred))
173 preds.Add(cs.Value.Name);
174 }
175 foreach (var cs in ImageJ.Macro.Functions)
176 {
177 if (cs.Value[0].Name.StartsWith(pred))
178 preds.Add(cs.Value[0].Name);
179 }
180 predLabel.Text = "";
181 foreach (var item in preds)
182 {
183 if (this.Width > TextRenderer.MeasureText(predLabel.Text, this.Font).Width)
184 {
185 predLabel.Text += item + ", ";
186 }
187 else break;
188 }
189 if (textBox.Text.EndsWith('\t'))
190 {
191 string s = textBox.Text.TrimEnd('\t');
192 skip = true;
193 textBox.Text = s.Remove(s.Length - pred.Length, pred.Length) + preds[0];
194 }
195 textBox.SelectionStart = textBox.Text.Length;
196 }
197
198 private void newTabBox_CheckedChanged(object sender, EventArgs e)
199 {
200 newTab = newTabBox.Checked;
201 }
202 }
203}
System.Windows.Forms.Keys Keys
Definition ImageView.cs:17
BioLib.BioImage BioImage
Definition TabsView.cs:15
static bool useBioformats
Definition BioConsole.cs:20
static bool headless
Definition BioConsole.cs:21
static bool newTab
Definition BioConsole.cs:22
static bool onTab
Definition BioConsole.cs:19
static async void RunOnImage(string con, bool headless, bool onTab, bool bioformats, bool newTab)
Definition ImageJ.cs:189
ImageView control for image stacks, pyramidal and whole-slide-images.
static BioImage SelectedImage
Definition ImageView.cs:270
static object RunString(string st)
Definition Scripting.cs:99