BioGTK  6.0.0
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images. Including whole slide, pyramidal, and series.
All Classes Namespaces Functions
BioGTK.Scripting Class Reference
Inheritance diagram for BioGTK.Scripting:

Classes

class  Script
 
class  State
 

Public Types

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

Public Member Functions

void InitItems ()
 It loads all the scripts in the Scripts and Tools folders into the TreeView.
 
void RefreshItems ()
 It takes the list of scripts and puts them into a tree view.
 
void RunScriptFile (string file)
 
void Run ()
 
void Stop ()
 

Static Public Member Functions

static Scripting Create ()
 
static void LogLine (string s)
 
static State GetState ()
 
static bool Exit (string name)
 
static void UpdateState (State s)
 
static void RunByName (string name)
 
static void RunScript (string file)
 
static object RunString (string st)
 

Static Public Attributes

static Window window
 
static string log
 
static string output
 
static string error
 
static string ImageJPath = Fiji.ImageJPath
 
static Dictionary< string, Scriptscripts = new Dictionary<string,Script>()
 

Protected Member Functions

 Scripting (Builder builder, IntPtr handle)
 

Detailed Description

Definition at line 21 of file Scripting.cs.

Member Enumeration Documentation

◆ Event

enum BioGTK.Scripting.Event

Definition at line 415 of file Scripting.cs.

416 {
417 Down,
418 Up,
419 Move,
420 None
421 }

◆ ScriptType

enum BioGTK.Scripting.ScriptType

Definition at line 423 of file Scripting.cs.

424 {
425 tool,
426 script,
427 imagej
428 }

Constructor & Destructor Documentation

◆ Scripting()

BioGTK.Scripting.Scripting ( Builder builder,
IntPtr handle )
protected

Definition at line 67 of file Scripting.cs.

67 : base(handle)
68 {
69 _builder = builder;
70 builder.Autoconnect(this);
71 scriptView.RowActivated += ScriptView_RowActivated;
72 scriptView.ButtonPressEvent += ScriptView_ButtonPressEvent;
73 this.KeyPressEvent += Scripting_KeyPressEvent;
74 saveBut.ButtonPressEvent += SaveBut_ButtonPressEvent;
75 runBut.ButtonPressEvent += runButton_Click;
76 scriptLoadBut.ButtonPressEvent += scriptLoadBut_Click;
77 outputBox.ButtonPressEvent += OutputBox_ButtonPressEvent;
78 errorBox.ButtonPressEvent += OutputBox_ButtonPressEvent;
79 logBox.ButtonPressEvent += OutputBox_ButtonPressEvent;
80 stopBut.ButtonPressEvent += stopBut_Click;
81 tabsView.SwitchPage += TabsView_SwitchPage;
82 window = this;
83 if (!Directory.Exists(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "//" + "Scripts"))
84 Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "//" + "Scripts");
85 if (!Directory.Exists(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "//" + "Tools"))
86 Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "//" + "Tools");
87 InitItems();
88 scriptLabel.Text = "NewScript.cs";
89 App.ApplyStyles(this);
90 }
void InitItems()
It loads all the scripts in the Scripts and Tools folders into the TreeView.
Definition Scripting.cs:476

Member Function Documentation

◆ Create()

static Scripting BioGTK.Scripting.Create ( )
static

It creates a new instance of the Scripting class, which is a class that inherits from the Gtk.Window class

Returns
A new instance of the Scripting class.

Definition at line 60 of file Scripting.cs.

61 {
62 Builder builder = new Builder(new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/" + "Glade/Scripting.glade", FileMode.Open));
63 return new Scripting(builder, builder.GetObject("scripting").Handle);
64 }

◆ Exit()

static bool BioGTK.Scripting.Exit ( string name)
static

Definition at line 446 of file Scripting.cs.

447 {
448 if(scripts.ContainsKey(name))
449 {
450 return scripts[name].exit;
451 }
452 return false;
453 }

◆ GetState()

static State BioGTK.Scripting.GetState ( )
static

It returns the state of the game.

Returns
The state of the game.

Definition at line 441 of file Scripting.cs.

442 {
443 return state;
444 }

◆ InitItems()

void BioGTK.Scripting.InitItems ( )

It loads all the scripts in the Scripts and Tools folders into the TreeView.

Definition at line 476 of file Scripting.cs.

477 {
478 Gtk.TreeViewColumn typeCol = new Gtk.TreeViewColumn();
479 typeCol.Title = "Script";
480 Gtk.CellRendererText typeCell = new Gtk.CellRendererText();
481 typeCol.PackStart(typeCell, true);
482 scriptView.AppendColumn(typeCol);
483 typeCol.AddAttribute(typeCell, "text", 0);
484
485 Gtk.TreeViewColumn statCol = new Gtk.TreeViewColumn();
486 statCol.Title = "Status";
487 Gtk.CellRendererText statCell = new Gtk.CellRendererText();
488 statCol.PackStart(statCell, true);
489 scriptView.AppendColumn(statCol);
490 statCol.AddAttribute(statCell, "text", 1);
491
492 Gtk.TreeStore store = new Gtk.TreeStore(typeof(string), typeof(string));
493 scriptView.Model = store;
494 scripts.Clear();
495 string st = System.IO.Path.GetDirectoryName(Environment.ProcessPath);
496 foreach (string file in Directory.GetFiles(st + "/Scripts"))
497 {
498 if (!scripts.ContainsKey(System.IO.Path.GetFileName(file)))
499 {
500 Script sc = new Script(file, File.ReadAllText(file));
501 if(sc.thread == null)
502 store.AppendValues(sc.name, ThreadState.Unstarted.ToString());
503 else
504 store.AppendValues(sc.name, sc.thread.ThreadState.ToString());
505 scripts.Add(sc.name, sc);
506 }
507 }
508 foreach (string file in Directory.GetFiles(st + "/Tools"))
509 {
510 if (file.EndsWith(".cs"))
511 {
512 if (!scripts.ContainsKey(System.IO.Path.GetFileName(file)))
513 {
514 Script sc = new Script(file, File.ReadAllText(file));
515 if (sc.thread == null)
516 store.AppendValues(sc.name, ThreadState.Unstarted.ToString());
517 else
518 store.AppendValues(sc.name, sc.thread.ThreadState.ToString());
519 scripts.Add(sc.name, sc);
520 }
521 }
522 }
523 }

◆ LogLine()

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

Definition at line 184 of file Scripting.cs.

185 {
186 log += s + Environment.NewLine;
187 }

◆ RefreshItems()

void BioGTK.Scripting.RefreshItems ( )

It takes the list of scripts and puts them into a tree view.

Definition at line 526 of file Scripting.cs.

527 {
528 Gtk.TreeStore store = new Gtk.TreeStore(typeof(string), typeof(string));
529 foreach (Script sc in scripts.Values)
530 {
531 if (sc.thread == null)
532 store.AppendValues(sc.name, ThreadState.Unstarted.ToString());
533 else
534 store.AppendValues(sc.name, sc.thread.ThreadState.ToString());
535 }
536 scriptView.Model = store;
537 }

◆ Run()

void BioGTK.Scripting.Run ( )

It runs the script that is currently selected in the list

Returns
The output of the script is being returned.

Definition at line 613 of file Scripting.cs.

614 {
615 log = "";
616 outputBox.Buffer.Text = "";
617 logBox.Buffer.Text = "";
618 if (SelectedItem == null)
619 return;
620 //We run this script
621 Script sc = SelectedItem;
622 sc.scriptString = view.Buffer.Text;
623 sc.output = "";
624 sc.Run();
625 outputBox.Buffer.Text = sc.output;
626 logBox.Buffer.Text = log;
627 RefreshItems();
628 }
void RefreshItems()
It takes the list of scripts and puts them into a tree view.
Definition Scripting.cs:526

◆ RunByName()

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

Runs a script file by name

Parameters
fileThe filename of the script you want to run.

Definition at line 580 of file Scripting.cs.

581 {
582 scripts[name].Run();
583 }

◆ RunScript()

static void BioGTK.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 597 of file Scripting.cs.

598 {
599 Script sc = new Script(file);
600 scripts.Add(sc.name, sc);
601 RunByName(sc.name);
602 }
static void RunByName(string name)
Definition Scripting.cs:580

◆ RunScriptFile()

void BioGTK.Scripting.RunScriptFile ( string file)

It runs a script file

Parameters
fileThe file path of the script you want to run.

Definition at line 587 of file Scripting.cs.

588 {
589 Script sc = new Script(file);
590 scripts.Add(sc.name,sc);
591 RefreshItems();
592 RunByName(sc.name);
593 }

◆ RunString()

static object BioGTK.Scripting.RunString ( string st)
static

It runs a string as a Bio script

Parameters
stThe string to run.

Definition at line 606 of file Scripting.cs.

607 {
608 return Script.RunString(st);
609 }

◆ Stop()

void BioGTK.Scripting.Stop ( )

We stop the script.

Returns
The SelectedItem is being returned.

Definition at line 632 of file Scripting.cs.

633 {
634 if (SelectedItem == null)
635 return;
636 //We stop this script
637 SelectedItem.Stop();
638 RefreshItems();
639 }
void Stop()
It stops the thread.
Definition Scripting.cs:323

◆ UpdateState()

static void BioGTK.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
StateThe state of the game.
Returns
The state of the current object.

Definition at line 462 of file Scripting.cs.

463 {
464 if (s == null)
465 return;
466 if (state == null)
467 state = s;
468 if (s.p.X == state.p.X && s.p.Y == state.p.Y && s.type == state.type)
469 {
470 state.processed = true;
471 }
472 else
473 state = s;
474 }

Member Data Documentation

◆ error

string BioGTK.Scripting.error
static

Definition at line 181 of file Scripting.cs.

◆ ImageJPath

string BioGTK.Scripting.ImageJPath = Fiji.ImageJPath
static

Definition at line 182 of file Scripting.cs.

◆ log

string BioGTK.Scripting.log
static

Definition at line 179 of file Scripting.cs.

◆ output

string BioGTK.Scripting.output
static

Definition at line 180 of file Scripting.cs.

◆ scripts

Dictionary<string,Script> BioGTK.Scripting.scripts = new Dictionary<string,Script>()
static

Definition at line 183 of file Scripting.cs.

◆ window

Window BioGTK.Scripting.window
static

Definition at line 177 of file Scripting.cs.


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