BioCore  5.0.0
A Windows .NET microscopy library and application for viewing, editing, and annotating images.
Loading...
Searching...
No Matches
BioCore.Scripting Class Reference
Inheritance diagram for BioCore.Scripting:

Classes

class  Script
 
class  State
 

Public Types

enum  Event { Down , Up , Move , None }
 
enum  ScriptType { tool , script , imagej }
 

Public Member Functions

void RefreshItems ()
 It reads all the files in the Scripts and Tools folders and adds them to a listview.
 
void RefreshStatus ()
 It updates the status of the script and the log.
 
 Scripting ()
 
void RunScriptFile (string file)
 
void Run ()
 
void Stop ()
 

Static Public Member Functions

static void LogLine (string s)
 
static State GetState ()
 
static void UpdateState (State s)
 
static void RunScript (string file)
 
static void RunString (string st)
 
static void RunByName (string name)
 

Public Attributes

CodeView view = null
 

Static Public Attributes

static string log
 
static string ImageJPath = Properties.Settings.Default.ImageJPath
 
static Dictionary< string, Script > Scripts = new Dictionary<string, Script>()
 

Protected Member Functions

override void Dispose (bool disposing)
 Clean up any resources being used.
 

Detailed Description

Definition at line 3 of file Scripting.Designer.cs.

Member Enumeration Documentation

◆ Event

Enumerator
Down 
Up 
Move 
None 

Definition at line 259 of file Scripting.cs.

◆ ScriptType

Enumerator
tool 
script 
imagej 

Definition at line 266 of file Scripting.cs.

Constructor & Destructor Documentation

◆ Scripting()

BioCore.Scripting.Scripting ( )

Definition at line 378 of file Scripting.cs.

379 {
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;
386 RefreshItems();
387 timer.Start();
388 codeview = new CodeView();
389 codeview.Dock = DockStyle.Fill;
390 scriptLabel.Text = "NewScript.cs";
391 //splitContainer.Dock = DockStyle.Fill;
392 textBox = codeview.TextBox;
393 splitContainer.Panel1.Controls.Add(codeview);
394 }
System.Windows.Forms.Application Application
Definition ImageView.cs:14
RichTextBox TextBox
Definition CodeView.cs:31
void RefreshItems()
It reads all the files in the Scripts and Tools folders and adds them to a listview.
Definition Scripting.cs:302

Member Function Documentation

◆ Dispose()

override void BioCore.Scripting.Dispose ( bool disposing)
protected

Clean up any resources being used.

Parameters
disposingtrue if managed resources should be disposed; otherwise, false.

Definition at line 14 of file Scripting.Designer.cs.

15 {
16 if (disposing && (components != null))
17 {
18 components.Dispose();
19 }
20 base.Dispose(disposing);
21 }

◆ GetState()

static State BioCore.Scripting.GetState ( )
static

It returns the state of the game.

Returns
The state of the game.

Definition at line 276 of file Scripting.cs.

277 {
278 return state;
279 }

◆ LogLine()

static void BioCore.Scripting.LogLine ( string s)
static

Definition at line 12 of file Scripting.cs.

13 {
14 log += s + Environment.NewLine;
15 }
static string log
Definition Scripting.cs:8

◆ RefreshItems()

void BioCore.Scripting.RefreshItems ( )

It reads all the files in the Scripts and Tools folders and adds them to a listview.

Definition at line 302 of file Scripting.cs.

303 {
304 Scripts.Clear();
305 string st = Application.StartupPath;
306 foreach (string file in Directory.GetFiles(st + "/Scripts"))
307 {
308 if (!Scripts.ContainsKey(Path.GetFileName(file)))
309 {
310 //This is a script file.
311 Script sc = new Script(file, File.ReadAllText(file));
312 ListViewItem lv = new ListViewItem();
313 lv.Tag = sc;
314 lv.Text = sc.ToString();
315 scriptView.Items.Add(lv);
316 Scripts.Add(lv.Text, sc);
317 }
318 }
319 foreach (string file in Directory.GetFiles(st + "/Tools"))
320 {
321 if (file.EndsWith(".cs"))
322 {
323 if (!Scripts.ContainsKey(Path.GetFileName(file)))
324 {
325 //This is a script file.
326 Script sc = new Script(file, File.ReadAllText(file));
327 sc.type = ScriptType.tool;
328 ListViewItem lv = new ListViewItem();
329 lv.Tag = sc;
330 lv.Text = sc.ToString();
331 scriptView.Items.Add(lv);
332 Scripts.Add(lv.Text, sc);
333 }
334 }
335 }
336 }
static Dictionary< string, Script > Scripts
Definition Scripting.cs:16

◆ RefreshStatus()

void BioCore.Scripting.RefreshStatus ( )

It updates the status of the script and the log.

Definition at line 338 of file Scripting.cs.

339 {
340 errorView.Clear();
341 foreach (ListViewItem item in scriptView.SelectedItems)
342 {
343 Script s = (Script)item.Tag;
344 //We update item text to show Script status.
345 item.Text = s.ToString();
346 outputBox.Text = s.output;
347 if (s.ex != null)
348 {
349 string[] sps = s.ex.Message.Split('>');
350 //ListViewItem it = new ListViewItem(s.ex.ToString());
351 for (int i = 1; i < sps.Length; i++)
352 {
353 ListViewItem er = new ListViewItem(sps[i]);
354 er.Tag = s.ex;
355 errorView.Items.Add(er);
356 }
357
358 }
359 }
360 foreach (ListViewItem item in scriptView.SelectedItems)
361 {
362 Script s = (Script)item.Tag;
363 //We update item text to show Script status.
364 item.Text = s.ToString();
365 }
366 logBox.Text = log;
367 //We scroll to end of text so we see latest log output.
368 if (logBox.SelectionStart != logBox.Text.Length)
369 {
370 logBox.SelectionStart = logBox.Text.Length;
371 logBox.ScrollToCaret();
372 }
373 }

◆ Run()

void BioCore.Scripting.Run ( )

It runs the script that is selected in the listview

Returns
The output of the script.

Definition at line 424 of file Scripting.cs.

425 {
426 log = "";
427 outputBox.Text = "";
428 logBox.Text = "";
429 if (scriptView.SelectedItems.Count == 0)
430 return;
431 foreach (ListViewItem item in scriptView.SelectedItems)
432 {
433 //We run this script
434 Script sc = (Script)item.Tag;
435 sc.scriptString = textBox.Text;
436 sc.output = "";
437 sc.Run();
438 outputBox.Text = sc.output;
439 logBox.Text = log;
440 }
441 }

◆ RunByName()

static void BioCore.Scripting.RunByName ( string name)
static

RunByName(string name)

Parameters
nameThe name of the script.

Definition at line 459 of file Scripting.cs.

460 {
461 Scripts[name].Run();
462 }

◆ RunScript()

static void BioCore.Scripting.RunScript ( string file)
static

It creates a new script object, adds it to the dictionary, and then runs it

Parameters
fileThe file path to the script.

Definition at line 408 of file Scripting.cs.

409 {
410 Script sc = new Script(file);
411 Scripts.Add(sc.name, sc);
412 RunByName(sc.name);
413 }
static void RunByName(string name)
Definition Scripting.cs:459

◆ RunScriptFile()

void BioCore.Scripting.RunScriptFile ( string file)

It runs a script file

Parameters
fileThe file path of the script to run.

Definition at line 398 of file Scripting.cs.

399 {
400 Script sc = new Script(file);
401 Scripts.Add(sc.name, sc);
402 RefreshItems();
403 RunByName(sc.name);
404 }

◆ RunString()

static void BioCore.Scripting.RunString ( string st)
static

It runs a string as a Lua script

Parameters
stThe string to run.

Definition at line 417 of file Scripting.cs.

418 {
419 Script.RunString(st);
420 }

◆ Stop()

void BioCore.Scripting.Stop ( )

We stop the script

Returns
The script is being returned.

Definition at line 445 of file Scripting.cs.

446 {
447 if (scriptView.SelectedItems.Count == 0)
448 return;
449 foreach (ListViewItem item in scriptView.SelectedItems)
450 {
451 //We run this script
452 Script sc = (Script)item.Tag;
453 sc.Stop();
454 }
455 }

◆ UpdateState()

static void BioCore.Scripting.UpdateState ( State s)
static

If the state is null, return. If the state is not null, set the state to the new state. If the state is not null and the new state is the same as the old state, set the processed flag to true

Parameters
StateThis is the state of the game. It contains the position of the player, the type of the player, and whether the state has been processed or not.
Returns
The state of the current object.

Definition at line 288 of file Scripting.cs.

289 {
290 if (s == null)
291 return;
292 if (state == null)
293 state = s;
294 if (s.p.X == state.p.X && s.p.Y == state.p.Y && s.type == state.type)
295 {
296 state.processed = true;
297 }
298 else
299 state = s;
300 }

Member Data Documentation

◆ ImageJPath

string BioCore.Scripting.ImageJPath = Properties.Settings.Default.ImageJPath
static

Definition at line 10 of file Scripting.cs.

◆ log

string BioCore.Scripting.log
static

Definition at line 8 of file Scripting.cs.

◆ Scripts

Dictionary<string, Script> BioCore.Scripting.Scripts = new Dictionary<string, Script>()
static

Definition at line 16 of file Scripting.cs.

◆ view

CodeView BioCore.Scripting.view = null

Definition at line 9 of file Scripting.cs.


The documentation for this class was generated from the following files: