grapher/class_editor.py

37 lines
1013 B
Python
Raw Normal View History

2025-01-05 01:01:39 +01:00
import imgui
from model import *
class ClassEditor:
def __init__(self):
super().__init__()
self.add_name = str()
self.select = 0
def __call__(self):
classes = Class.select()
with imgui.begin("Class Editor", False, imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_COLLAPSE):
imgui.text("Add Class")
_, self.add_name = imgui.input_text(" ", self.add_name)
if imgui.button("Add"):
if self.add_name:
Class.create(name=self.add_name)
self.add_name = str()
imgui.separator()
if not classes:
imgui.text("No Dataset could be queried")
return
for n, c in enumerate(classes, start=1):
display = f"{n}. {c.name}"
opened, _ = imgui.selectable(display, self.select == n-1)
if opened:
self.select = n-1
return classes[self.select]