BioGTK  5.1.1
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images.
Loading...
Searching...
No Matches
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 = ImageJ.ImageJPath
 
static Dictionary< string, Scriptscripts = new Dictionary<string,Script>()
 

Protected Member Functions

 Scripting (Builder builder, IntPtr handle)
 

Member Enumeration Documentation

◆ Event

Enumerator
Down 
Up 
Move 
None 

◆ ScriptType

Enumerator
tool 
script 
imagej 

Constructor & Destructor Documentation

◆ Scripting()

BioGTK.Scripting.Scripting ( Builder  builder,
IntPtr  handle 
)
inlineprotected
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 }
static Window window
Definition Scripting.cs:177
void InitItems()
It loads all the scripts in the Scripts and Tools folders into the TreeView.
Definition Scripting.cs:473

Member Function Documentation

◆ Create()

static Scripting BioGTK.Scripting.Create ( )
inlinestatic

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.
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 }
Definition Scripting.cs:22

◆ Exit()

static bool BioGTK.Scripting.Exit ( string  name)
inlinestatic
444 {
445 if(scripts.ContainsKey(name))
446 {
447 return scripts[name].exit;
448 }
449 return false;
450 }
static Dictionary< string, Script > scripts
Definition Scripting.cs:183

◆ GetState()

static State BioGTK.Scripting.GetState ( )
inlinestatic

It returns the state of the game.

Returns
The state of the game.
439 {
440 return state;
441 }

◆ InitItems()

void BioGTK.Scripting.InitItems ( )
inline

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

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

◆ LogLine()

static void BioGTK.Scripting.LogLine ( string  s)
inlinestatic
185 {
186 log += s + Environment.NewLine;
187 }
static string log
Definition Scripting.cs:179

◆ RefreshItems()

void BioGTK.Scripting.RefreshItems ( )
inline

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

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

◆ Run()

void BioGTK.Scripting.Run ( )
inline

It runs the script that is currently selected in the list

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

◆ RunByName()

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

Runs a script file by name

Parameters
fileThe filename of the script you want to run.
578 {
579 scripts[name].Run();
580 }

◆ RunScript()

static void BioGTK.Scripting.RunScript ( string  file)
inlinestatic

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

Parameters
fileThe file path to the script.
595 {
596 Script sc = new Script(file);
597 scripts.Add(sc.name, sc);
598 RunByName(sc.name);
599 }
static void RunByName(string name)
Definition Scripting.cs:577

◆ RunScriptFile()

void BioGTK.Scripting.RunScriptFile ( string  file)
inline

It runs a script file

Parameters
fileThe file path of the script you want to run.
585 {
586 Script sc = new Script(file);
587 scripts.Add(sc.name,sc);
588 RefreshItems();
589 RunByName(sc.name);
590 }

◆ RunString()

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

It runs a string as a Bio script

Parameters
stThe string to run.
604 {
605 return Script.RunString(st);
606 }

◆ Stop()

void BioGTK.Scripting.Stop ( )
inline

We stop the script.

Returns
The SelectedItem is being returned.
630 {
631 if (SelectedItem == null)
632 return;
633 //We stop this script
634 SelectedItem.Stop();
635 RefreshItems();
636 }
void Stop()
It stops the thread.
Definition Scripting.cs:320

◆ UpdateState()

static void BioGTK.Scripting.UpdateState ( State  s)
inlinestatic

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.
460 {
461 if (s == null)
462 return;
463 if (state == null)
464 state = s;
465 if (s.p.X == state.p.X && s.p.Y == state.p.Y && s.type == state.type)
466 {
467 state.processed = true;
468 }
469 else
470 state = s;
471 }
PointD p
Definition Scripting.cs:401
Event type
Definition Scripting.cs:342

Member Data Documentation

◆ error

string BioGTK.Scripting.error
static

◆ ImageJPath

string BioGTK.Scripting.ImageJPath = ImageJ.ImageJPath
static

◆ log

string BioGTK.Scripting.log
static

◆ output

string BioGTK.Scripting.output
static

◆ scripts

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

◆ window

Window BioGTK.Scripting.window
static

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