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