From 59e00cb81209cfa1f917bd437ed06cc3e80fbb48 Mon Sep 17 00:00:00 2001
From: DerGrumpf
Date: Thu, 2 Jan 2025 18:13:55 +0100
Subject: [PATCH] Added: Lecture Editor
---
main.py | 89 +++++++++++++++++++++++++++++++++++++++++-------
requirements.txt | 6 ++++
2 files changed, 83 insertions(+), 12 deletions(-)
create mode 100644 requirements.txt
diff --git a/main.py b/main.py
index ee6e45b..45817de 100644
--- a/main.py
+++ b/main.py
@@ -76,16 +76,22 @@ class GUI(object):
self.impl = GlfwRenderer(self.window)
# App states
- self.select = 0
-
+ self.select_student: int = 0
+ self.select_lecture: int = 0
+ self.lectures: list = list()
+ self.add_lecture_text = str()
+ self.add_lecture_points = 0
+ self.edit_lecture_title = str()
+ self.edit_lecture_points = 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 * font_scaling_factor)
- io.font_global_scale /= font_scaling_factor'''
+ io.font_global_scale /= font_scaling_factor
self.loop()
@@ -136,9 +142,9 @@ class GUI(object):
return
for n, student in enumerate(students):
- opened, _ = imgui.selectable(student.name, self.select == n)
+ opened, _ = imgui.selectable(student.name, self.select_student == n)
if opened:
- self.select = n
+ self.select_student = n
def student_graph(self, student: Student):
@@ -165,27 +171,86 @@ class GUI(object):
# 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)
+ imgui.set_next_window_size(io.display_size.x, io.display_size.y*0.03)
+ imgui.set_next_window_position(0, io.display_size.y*0.02)
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)
+ imgui.set_window_font_scale(1.3)
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 editor(self):
+ # 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_position(io.display_size.x*0.7, io.display_size.y*0.45)
+ lecture = None
+
+ with imgui.begin("Lecture Editor", False, imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_COLLAPSE):
+ with imgui.begin_group():
+ if not self.lectures:
+ imgui.text("No Lecture Added")
+ else:
+ for n, lecture in enumerate(self.lectures):
+ opened, _ = imgui.selectable(lecture.name, self.select_lecture == n, width=imgui.get_window_size().x*0.3)
+ if opened:
+ self.select_lecture = n
+ lecture = self.lectures[self.select_lecture]
+ self.edit_lecture_title = lecture.name
+ self.edit_lecture_points = lecture.max_points
+
+ imgui.same_line(spacing=int(imgui.get_window_size().x * 0.05))
+
+ with imgui.begin_group():
+ imgui.push_item_width(imgui.get_window_size().x * 0.2)
+ imgui.text("Add Lecture")
+ _, self.add_lecture_text = imgui.input_text(" ", self.add_lecture_text)
+ _, self.add_lecture_points = imgui.input_int("", self.add_lecture_points)
+
+ if self.add_lecture_points < 0:
+ self.add_lecture_points = 0
+
+ clicked = imgui.button("Confirm")
+ if clicked:
+ self.lectures.append(Lecture(self.add_lecture_text, 0, self.add_lecture_points))
+ self.add_lecture_points = 0
+ self.add_lecture_text = str()
+ imgui.pop_item_width()
+
+ if lecture:
+ imgui.same_line(spacing=int(imgui.get_window_size().x * 0.05))
+ with imgui.begin_group():
+ _, self.edit_lecture_title = imgui.input_text(" ", self.edit_lecture_title)
+ _, self.edit_lecture_points = imgui.input_int("", self.edit_lecture_points)
+ if self.edit_lecture_points < 0:
+ self.edit_lecture_points = 0
+
+ def main_menu(self):
+ with imgui.begin_main_menu_bar() as main_menu_bar:
+ if main_menu_bar:
+ with imgui.begin_menu("File", True) as file_menu:
+ if file_menu.opened:
+ imgui.menu_item("New", " ", False, True)
+ imgui.menu_item("Open", " ", False, True)
+ imgui.menu_item("Save", " ", False, True)
+ imgui.menu_item("Save as", " ", False, True)
+
def loop(self):
while not glfw.window_should_close(self.window):
glfw.poll_events()
self.impl.process_inputs()
imgui.new_frame()
-
+
+ self.main_menu()
self.header()
self.table(students)
- self.student_info(students[self.select])
- self.student_graph(students[self.select])
+ self.student_info(students[self.select_student])
+ self.student_graph(students[self.select_student])
+ self.editor()
#imgui.show_test_window()
imgui.render()
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..81bd2e1
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,6 @@
+glfw==2.8.0
+imgui==2.0.0
+numpy==2.2.1
+pillow==11.0.0
+PyOpenGL==3.1.7
+PySDL2==0.9.17