8 public static string log;
10 public static string ImageJPath = Properties.Settings.Default.ImageJPath;
14 log += s + Environment.NewLine;
16 public static Dictionary<string, Script>
Scripts =
new Dictionary<string, Script>();
26 public static List<string>
usings =
new List<string>();
27 public Exception
ex =
null;
35 if (
file.EndsWith(
".txt") ||
file.EndsWith(
".ijm"))
45 if (
file.EndsWith(
".txt") ||
file.EndsWith(
".ijm"))
78 Thread t =
new Thread(
new ThreadStart(RunScript));
81 private static string scriptName =
"";
82 private static string str =
"";
84 private static void RunScript()
109 rn.script = CSScript.Evaluator.LoadCode(rn.
scriptString);
110 rn.obj = rn.
script.Load();
111 rn.output = rn.
obj.ToString();
131 @"//css_reference " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name +
@".dll
133 using System.Windows.Forms;
134 using System.Drawing;
135 using System.Threading;
137 foreach (
string s
in usings)
139 loader +=
usings + Environment.NewLine;
150 dynamic
script = CSScript.Evaluator.LoadCode(loader);
155 MessageBox.Show(e.Message, e.Source);
164 scriptName = this.
name;
165 thread =
new Thread(
new ThreadStart(RunScript));
182 return name.ToString() +
", " +
thread.ThreadState.ToString();
185 return name.ToString();
216 st.type =
Event.Down;
231 st.type =
Event.Move;
244 st.type =
Event.None;
246 st.buts = MouseButtons.None;
255 return type.ToString() +
" ,(" +
p.X.ToString() +
", " +
p.Y.ToString() +
"), " +
buts.ToString();
272 private static State state;
294 if (s.
p.X == state.p.X && s.
p.Y == state.p.Y && s.
type == state.type)
296 state.processed =
true;
306 foreach (
string file
in Directory.GetFiles(st +
"/Scripts"))
308 if (!
Scripts.ContainsKey(Path.GetFileName(file)))
312 ListViewItem lv =
new ListViewItem();
315 scriptView.Items.Add(lv);
319 foreach (
string file
in Directory.GetFiles(st +
"/Tools"))
321 if (file.EndsWith(
".cs"))
323 if (!
Scripts.ContainsKey(Path.GetFileName(file)))
328 ListViewItem lv =
new ListViewItem();
331 scriptView.Items.Add(lv);
341 foreach (ListViewItem item
in scriptView.SelectedItems)
346 outputBox.Text = s.
output;
349 string[] sps = s.
ex.Message.Split(
'>');
351 for (
int i = 1; i < sps.Length; i++)
353 ListViewItem er =
new ListViewItem(sps[i]);
355 errorView.Items.Add(er);
360 foreach (ListViewItem item
in scriptView.SelectedItems)
368 if (logBox.SelectionStart != logBox.Text.Length)
370 logBox.SelectionStart = logBox.Text.Length;
371 logBox.ScrollToCaret();
375 private RichTextBox textBox;
380 if (!Directory.Exists(
Application.StartupPath +
"//" +
"Scripts"))
381 Directory.CreateDirectory(
Application.StartupPath +
"//" +
"Scripts");
382 if (!Directory.Exists(
Application.StartupPath +
"//" +
"Tools"))
383 Directory.CreateDirectory(
Application.StartupPath +
"//" +
"Tools");
384 InitializeComponent();
385 scriptView.MultiSelect =
false;
389 codeview.Dock = DockStyle.Fill;
390 scriptLabel.Text =
"NewScript.cs";
393 splitContainer.Panel1.Controls.Add(codeview);
429 if (scriptView.SelectedItems.Count == 0)
431 foreach (ListViewItem item
in scriptView.SelectedItems)
435 sc.scriptString = textBox.Text;
438 outputBox.Text = sc.
output;
447 if (scriptView.SelectedItems.Count == 0)
449 foreach (ListViewItem item
in scriptView.SelectedItems)
468 private void scriptView_MouseDoubleClick(
object sender, MouseEventArgs e)
477 private void runToolStripMenuItem_Click(
object sender, EventArgs e)
486 private void openScriptFolderToolStripMenuItem_Click(
object sender, EventArgs e)
488 string path = Application.StartupPath +
"\\Scripts";
489 System.Diagnostics.Process.Start(
"explorer.exe", path);
496 private void refreshToolStripMenuItem_Click(
object sender, EventArgs e)
506 private void timer_Tick(
object sender, EventArgs e)
508 if (this.WindowState != FormWindowState.Minimized)
518 private void ScriptRunner_FormClosing(
object sender, FormClosingEventArgs e)
521 this.WindowState = FormWindowState.Minimized;
531 private void scriptView_SelectedIndexChanged(
object sender, EventArgs e)
533 if (scriptView.SelectedItems.Count == 0)
535 ListViewItem item = scriptView.SelectedItems[0];
536 Script s = (Script)item.Tag;
537 textBox.Text = s.scriptString;
538 scriptLabel.Text = s.name;
545 private void runButton_Click(
object sender, EventArgs e)
547 if (scriptLabel.Text.EndsWith(
".ijm"))
564 private void scriptLoadBut_Click(
object sender, EventArgs e)
566 openFileDialog.InitialDirectory = Application.StartupPath +
"\\Scripts";
567 if (openFileDialog.ShowDialog() != DialogResult.OK)
569 Script
script =
new Script(openFileDialog.FileName, File.ReadAllText(openFileDialog.FileName));
570 script.name = Path.GetFileName(openFileDialog.FileName);
571 textBox.Text =
script.scriptString;
572 scriptLabel.Text = Path.GetFileName(openFileDialog.FileName);
573 ListViewItem item =
new ListViewItem();
576 scriptView.Items.Add(item);
588 private void saveButton_Click(
object sender, EventArgs e)
590 saveFileDialog.InitialDirectory = Application.StartupPath +
"\\Scripts";
591 saveFileDialog.FileName = scriptLabel.Text;
592 if (saveFileDialog.ShowDialog() != DialogResult.OK)
594 scriptLabel.Text = Path.GetFileName(saveFileDialog.FileName);
595 File.WriteAllText(saveFileDialog.FileName, textBox.Text);
602 private void stopBut_Click(
object sender, EventArgs e)
611 private void topMostBox_CheckedChanged(
object sender, EventArgs e)
613 TopMost = topMostBox.Checked;
621 private void Scripting_KeyDown(
object sender, KeyEventArgs e)
623 if (e.KeyCode ==
Keys.S && e.Modifiers ==
Keys.Control)
625 saveButton.PerformClick();
634 private void errorBox_SelectionChanged(
object sender, EventArgs e)
636 Script sc = (Script)scriptView.SelectedItems[0].Tag;
637 Exception ex = sc.ex;
645 private void errorView_SelectedIndexChanged(
object sender, EventArgs e)
647 Exception ex = (Exception)errorView.SelectedItems[0].Tag;
648 string exs = ex.Message.Substring(ex.Message.IndexOf(
'('), ex.Message.IndexOf(
')'));
649 string ls = exs.Substring(1, exs.IndexOf(
',') - 1);
650 int line =
int.Parse(ls);
651 string c = exs.Substring(exs.IndexOf(
',') + 1, exs.IndexOf(
")") - exs.IndexOf(
',') - 1);
652 int cr =
int.Parse(c);
654 textBox.SelectionStart = line;
System.Windows.Forms.Keys Keys
System.Windows.Forms.Application Application
static bool useBioformats
ImageView control for image stacks, pyramidal and whole-slide-images.
static BioImage SelectedImage
static List< string > usings
void Stop()
The function stops the thread.
override string ToString()
static void Run(Script rn)
static object RunString(string st)
void Run()
It creates a new thread and starts it.
Script(string file, string scriptStr)
static State GetDown(PointD pf, MouseButtons mb)
override string ToString()
static State GetMove(PointD pf, MouseButtons mb)
static State GetUp(PointD pf, MouseButtons mb)
static void RunScript(string file)
static void LogLine(string s)
void RefreshStatus()
It updates the status of the script and the log.
static Dictionary< string, Script > Scripts
void RunScriptFile(string file)
static void UpdateState(State s)
static void RunString(string st)
static void RunByName(string name)
void RefreshItems()
It reads all the files in the Scripts and Tools folders and adds them to a listview.