Changed: Window Layout

This commit is contained in:
DerGrumpf 2025-01-02 02:36:42 +01:00
parent 47393a3466
commit f16f3e4558
3 changed files with 77 additions and 47 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
# ---> ImGUI
imgui.ini
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/

View File

@ -1,20 +0,0 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Custom window]
Pos=355,219
Size=321,302
Collapsed=0
[Window][Dear ImGui Demo]
Pos=323,104
Size=550,680
Collapsed=0
[Window][Student Table]
Pos=5,9
Size=251,142
Collapsed=0

101
main.py
View File

@ -4,6 +4,7 @@ import OpenGL.GL as gl
from imgui.integrations.glfw import GlfwRenderer
from PIL import ImageColor
from dataclasses import dataclass
import numpy
@dataclass
class Lecture:
@ -18,6 +19,20 @@ class Student:
project: str
lectures: list
phil = Student(
"Phil Keier", "772fb04b24caa68fd38a05ec2a22e62b", "Geomapping",
[Lecture("1. Tutorial 1", 28.5, 31), Lecture("2. Tutorial 2", 4.5, 15), Lecture("3. Extended Application", 18, 18)]
)
nova = Student(
"Nova Eib", "772fb04b24caa68fd38a05ec2a22e62b", "Mapping Maps",
[Lecture("1. Tutorial 1", 28.5, 31), Lecture("2. Tutorial 2", 4.5, 15), Lecture("3. Extended Application", 18, 18)]
)
kathi = Student(
"Katharina Walz", "772fb04b24caa68fd38a05ec2a22e62b", "Geomapping",
[Lecture("1. Tutorial 1", 28.5, 31), Lecture("2. Tutorial 2", 4.5, 15), Lecture("3. Extended Application", 18, 18), Lecture("4. Numpy & MatPlotLib", 3, 30)]
)
students = [phil, nova, kathi]
# Global Color Pallet
COLOR_BACKGROUND = tuple([e/255 for e in ImageColor.getcolor("#29132E","RGBA")])
COLOR_1 = tuple([e/255 for e in ImageColor.getcolor("#321450","RGBA")])
@ -27,7 +42,7 @@ COLOR_TEXT = tuple([e/255 for e in ImageColor.getcolor("#F887FF","RGBA")])
COLOR_TEXT_PASSED = tuple([e/255 for e in ImageColor.getcolor("#1AFE49","RGBA")])
COLOR_TEXT_FAILED = tuple([e/255 for e in ImageColor.getcolor("#FF124F","RGBA")])
def impl_glfw_init(window_name="minimal ImGui/GLFW3 example", width=1280, height=720):
def impl_glfw_init(window_name="Grapher Tool", width=1280, height=720):
if not glfw.init():
print("Could not initialize OpenGL context")
exit(1)
@ -59,18 +74,18 @@ class GUI(object):
gl.glClearColor(*self.backgroundColor)
imgui.create_context()
self.impl = GlfwRenderer(self.window)
# App states
self.select = 0
# Global GUI Setting
win_w, win_h = glfw.get_window_size(self.window)
'''win_w, win_h = glfw.get_window_size(self.window)
fb_w, fb_h = glfw.get_framebuffer_size(self.window)
font_scaling_factor = max(float(fb_w) / win_w, float(fb_h) / win_h)
font_size_in_pixels = 30
io = imgui.get_io()
io.fonts.add_font_from_file_ttf(
"assets/MPLUSRounded1c-Regular.ttf", font_size_in_pixels
)
io.font_global_scale /= font_scaling_factor
io.fonts.add_font_from_file_ttf("assets/MPLUSRounded1c-Regular.ttf", font_size_in_pixels * font_scaling_factor)
io.font_global_scale /= font_scaling_factor'''
self.loop()
@ -78,7 +93,7 @@ class GUI(object):
# Window Position and Sizing
io = imgui.get_io()
imgui.set_next_window_size(io.display_size.x*0.3, io.display_size.y*0.3)
imgui.set_next_window_size(io.display_size.x*0.3, io.display_size.y*0.4)
imgui.set_next_window_position(io.display_size.x*0.7, io.display_size.y*0.05)
# Student accumulated Info
@ -92,8 +107,10 @@ class GUI(object):
imgui.text("No Student selected")
return
s = f"{student.name} {overall_points}/{overall_max}"
imgui.text_colored(s, *COLOR_TEXT)
s = f"{overall_points}/{overall_max} | {round(overall_points/overall_max*100, 1)}%"
imgui.text_colored(student.name, *COLOR_TEXT)
w, h = imgui.get_window_size()
imgui.progress_bar(overall_points/overall_max, (w*0.5, h*0.1), s)
imgui.text("Jupyter ID:")
imgui.text_colored(student.jupyter_id.rjust(4+len(student.jupyter_id), " "), *COLOR_TEXT)
@ -110,35 +127,65 @@ class GUI(object):
# Window Position and Sizing
io = imgui.get_io()
imgui.set_next_window_size(max(min(io.display_size.x*0.2, 200), 120), io.display_size.y*0.9)
imgui.set_next_window_position(io.display_size.y*0.01, io.display_size.y*0.05)
# Boiler
selected = [False for _ in range(len(students))]
visible = True
imgui.set_next_window_size(io.display_size.x*0.15, io.display_size.y*0.95)
imgui.set_next_window_position(0, io.display_size.y*0.05)
with imgui.begin("Student Table", False, imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_COLLAPSE):
if not students:
imgui.text("No Dataset selected")
return
for i, student in enumerate(students):
_, selected[i] = imgui.selectable(student, selected[i])
for n, student in enumerate(students):
opened, _ = imgui.selectable(student.name, self.select == n)
if opened:
self.select = n
def student_graph(self, student: Student):
# Window Position and Sizing
io = imgui.get_io()
imgui.set_next_window_size(io.display_size.x*0.55, io.display_size.y*0.4)
imgui.set_next_window_position(io.display_size.x*0.15, io.display_size.y*0.05)
# Setup Data
data = numpy.array([float(lecture.points) / float(lecture.max_points) * 100 for lecture in student.lectures], dtype=numpy.float32)
with imgui.begin("Student Graph", False, imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_COLLAPSE):
if not students:
imgui.text("No Dataset selected")
return
imgui.plot_histogram(
"##Data", data, overlay_text="Performance per Lecture (in %)",
scale_min=0.0, scale_max=100,
graph_size=imgui.get_content_region_available()
)
def header(self):
# Window Position and Sizing
io = imgui.get_io()
imgui.set_next_window_size(io.display_size.x, io.display_size.y*0.05)
imgui.set_next_window_position(0, 0)
with imgui.begin("HEADER", False, imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_TITLE_BAR):
imgui.set_window_font_scale(1.5)
text = "Student Analyzer"
ww = imgui.get_window_size().x
tw = imgui.calc_text_size(text).x
imgui.set_cursor_pos_x((ww - tw) * 0.5)
imgui.text("Student Analyzer")
def loop(self):
phil = Student(
"Phil Keier", "772fb04b24caa68fd38a05ec2a22e62b", "Geomapping",
[Lecture("1. Tutorial 1", 28.5, 31), Lecture("2. Tutorial 2", 4.5, 15), Lecture("3. Extended Application", 18, 18)]
)
while not glfw.window_should_close(self.window):
glfw.poll_events()
self.impl.process_inputs()
imgui.new_frame()
self.table(["Phil Keier", "Nova Eib", "Katharina Walz"])
self.student_info(phil)
self.header()
self.table(students)
self.student_info(students[self.select])
self.student_graph(students[self.select])
#imgui.show_test_window()
imgui.render()