BioGTK  6.7.0
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images. Including whole slide, pyramidal, and series.
Loading...
Searching...
No Matches
Plugin.cs
1using AForge;
2using Gtk;
3using System;
4using System.Collections.Generic;
5using System.IO;
6using System.Linq;
7using System.Reflection;
8using System.Text;
9using System.Threading.Tasks;
10using static BioGTK.Plugin;
11
12namespace BioGTK
13{
14 public class Plugin
15 {
16 public static Dictionary<string, IPlugin> Plugins = new Dictionary<string, IPlugin>();
17 public interface IPlugin
18 {
19 string Name { get; }
20 string MenuPath { get; }
21 bool ContextMenu { get; }
22 void Execute(string[] args);
23 void KeyUpEvent(object o, KeyReleaseEventArgs e);
24 void KeyDownEvent(object o, KeyPressEventArgs e);
25 void ScrollEvent(object o, ScrollEventArgs args);
26 void Render(object sender, SkiaSharp.Views.Desktop.SKPaintSurfaceEventArgs e);
27 void MouseMove(object o, PointD e, MotionNotifyEventArgs buts);
28 void MouseUp(object o, PointD e, ButtonReleaseEventArgs buts);
29 void MouseDown(object o, PointD e, ButtonPressEventArgs buts);
30 }
31 }
32
33 public static class Plugins
34 {
35 public static void Initialize()
36 {
37 foreach (string s in Directory.GetFiles(System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/Plugins"))
38 {
39 try
40 {
41 if (!s.EndsWith(".dll") || Plugin.Plugins.ContainsKey(Path.GetFileName(s)))
42 continue;
43 string dir = System.IO.Path.GetDirectoryName(Environment.ProcessPath) + "/Plugins/" + Path.GetFileName(s);
44 dir.Replace("\\", "/");
45 // Load the plugin assembly
46 Assembly pluginAssembly = Assembly.LoadFile(dir);
47 // Find the type which implements the IPlugin interface
48 var pluginType = pluginAssembly.GetTypes().FirstOrDefault(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsInterface);
49 if (pluginType != null)
50 {
51 // Create an instance of this type
52 IPlugin pluginInstance = Activator.CreateInstance(pluginType) as IPlugin;
53 Plugin.Plugins.Add(Path.GetFileName(s), pluginInstance);
54 if (pluginInstance.ContextMenu)
55 App.AddContextMenu(pluginInstance.MenuPath);
56 else
57 App.AddMenu(pluginInstance.MenuPath);
58 }
59 }
60 catch (Exception e)
61 {
62 Console.WriteLine(e.Message.ToString());
63 }
64
65 }
66 }
67 public static void KeyUpEvent(object o, KeyReleaseEventArgs e)
68 {
69 foreach (IPlugin p in Plugin.Plugins.Values)
70 {
71 p.KeyUpEvent(o, e);
72 }
73 }
74 public static void KeyDownEvent(object o, KeyPressEventArgs e)
75 {
76 foreach (IPlugin p in Plugin.Plugins.Values)
77 {
78 p.KeyDownEvent(o, e);
79 }
80 }
81 public static void ScrollEvent(object o, ScrollEventArgs args)
82 {
83 foreach (IPlugin p in Plugin.Plugins.Values)
84 {
85 p.ScrollEvent(o, args);
86 }
87 }
88 public static void Render(object o, SkiaSharp.Views.Desktop.SKPaintSurfaceEventArgs e)
89 {
90 foreach (IPlugin p in Plugin.Plugins.Values)
91 {
92 ((IPlugin)p).Render(o, e);
93 }
94 }
95 public static void MouseMove(object o, PointD e, MotionNotifyEventArgs buts)
96 {
97 foreach (IPlugin p in Plugin.Plugins.Values)
98 {
99 p.MouseMove(o, e, buts);
100 }
101 }
102 public static void MouseUp(object o, PointD e, ButtonReleaseEventArgs buts)
103 {
104 foreach (IPlugin p in Plugin.Plugins.Values)
105 {
106 p.MouseUp(o, e, buts);
107 }
108 }
109 public static void MouseDown(object o, PointD e, ButtonPressEventArgs buts)
110 {
111 foreach (IPlugin p in Plugin.Plugins.Values)
112 {
113 p.MouseDown(o, e, buts);
114 }
115 }
116 }
117
118}
Definition ML.cs:17