-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (47 loc) · 1.63 KB
/
Copy pathmain.py
File metadata and controls
58 lines (47 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
import os
import importlib.util
import tkinter as tk
from tkinter import messagebox
from tkinter.ttk import Style
from ttkbootstrap import Style
from main_gui import MainGui
def load_plugin(plugin_name):
script_dir=os.path.dirname(os.path.abspath(__file__))
plugin_path = os.path.join(script_dir,f"{plugin_name}.py")
if not os.path.exists(plugin_path):
raise FileNotFoundError(f"Plugin {plugin_name} not found under {script_dir}")
spec = importlib.util.spec_from_file_location(plugin_name,plugin_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
if hasattr(module,"PowerSupply"):
return module.PowerSupply
else:
raise AttributeError(f"Plugin '{plugin_name}' does not contain a 'PowerSupply' class")
def main():
if len(sys.argv) < 2:
tk.Tk().withdraw()
messagebox.showerror("Missing Plugin", "Please specify a plugin name as command line argument.")
sys.exit(1)
plugin_name = sys.argv[1]
try:
plugin_class = load_plugin(plugin_name)
except Exception as e:
tk.Tk().withdraw() #Just to start without window for message box
messagebox.showerror("Plugin Load Error", str(e))
sys.exit(1)
root = tk.Tk()
# GUI-Design mit ttkbootstrap
style = Style(theme='darkly')
root = style.master
root.title("Power Supply Control")
try:
root.iconbitmap('psu.ico')
except:
print("psu.ico not found")
pass
app = MainGui(root, plugin_class)
#root.protocol("WM_DELETE_WINDOW", app.on_close())
root.mainloop()
if __name__ == "__main__":
main()