Changeset 0792ddd in flexograder for gui/gui.py
- Timestamp:
- 11/20/25 13:15:40 (5 months ago)
- Branches:
- fake-data, main, master
- Children:
- e75910d
- Parents:
- aaaa4b8
- File:
-
- 1 edited
-
gui/gui.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gui/gui.py
raaaa4b8 r0792ddd 5 5 from pathlib import Path 6 6 from datetime import datetime 7 from flexoentity import FlexOID, logger7 from flexoentity import FlexOID, DomainManager, logger, Domain 8 8 from builder.exam import Exam 9 9 from builder.question_catalog import QuestionCatalog 10 from builder.question_catalog import question_factory 10 11 from builder.media_items import NullMediaItem 11 12 from builder.catalog_manager import CatalogManager … … 13 14 from builder.exam_elements import SingleChoiceQuestion, MultipleChoiceQuestion, InstructionBlock 14 15 from .menu import AppMenu 16 from gui.domain_management_dialog import DomainManagementDialog 15 17 from .actions_panel import ActionsPanel 16 18 from .select_panel import SelectPanel … … 26 28 def __init__(self): 27 29 super().__init__() 30 self.domain_manager = DomainManager() 28 31 self.catalog_manager = CatalogManager() 29 32 self.exam_manager = ExamManager() … … 47 50 48 51 self._recent_actions = [] 49 self.domain_set = set()50 52 self.clipboard = [] # holds copied Question objects 51 53 self.clipboard_action = None # "copy" … … 147 149 simpledialog.askstring("Author", "Enter author:", parent=self) or "unknown" 148 150 ) 149 catalog = QuestionCatalog.with_domain (did)151 catalog = QuestionCatalog.with_domain_id(did) 150 152 catalog.title = title 151 153 catalog.author =author … … 242 244 return [] 243 245 # Always provide deterministic order (e.g. by question ID) 244 return sorted(self.active_catalog.questions, key=lambda q: q. id)246 return sorted(self.active_catalog.questions, key=lambda q: q.flexo_id) 245 247 246 248 def create_exam_dialog(self): … … 265 267 self.target_exam_var.set(active_exam.title) 266 268 267 def get_question_editor_for( parent, question, available_domains):269 def get_question_editor_for(self, parent, question, available_domains): 268 270 """ 269 271 Return the appropriate editor dialog instance for a given question. … … 271 273 """ 272 274 if question.qtype in ("single_choice", "multiple_choice"): 273 return OptionQuestionEditorDialog(parent, question , available_domains)275 return OptionQuestionEditorDialog(parent, question.to_dict(), available_domains) 274 276 if question.qtype in ("instruction", "text"): 275 277 # even though InstructionBlock may subclass Question, 276 278 # it doesn’t need options 277 return DefaultQuestionEditorDialog(parent, question , available_domains)278 else:279 # Fallback for any unknown or simple Question subclass280 return DefaultQuestionEditorDialog(parent, question, available_domains)279 return DefaultQuestionEditorDialog(parent, question.to_dict(), available_domains) 280 281 # Fallback for any unknown or simple Question subclass 282 return DefaultQuestionEditorDialog(parent, question.to_dict(), available_domains) 281 283 282 284 def add_question(self): … … 290 292 media = [] 291 293 292 if qtype == "single_choice": 293 q = SingleChoiceQuestion(text="Neue Frage", 294 options=[], media=media) 295 elif qtype == "multiple_choice": 296 q = MultipleChoiceQuestion(text="Neue Mehrfachfrage", 297 options=[], media=media) 294 if qtype in ["single_choice", "multiple_choice"]: 295 question_dict = {"qtype": qtype, 296 "text": "Neue Frage", 297 "options": [], 298 "media": media} 298 299 elif qtype == "instruction": 299 q = InstructionBlock(text="Neue Instruktion", media=media)300 question_dict = InstructionBlock(text="Neue Instruktion", media=media) 300 301 else: 301 302 messagebox.showerror("Error", f"Unknown question type: {qtype}") 302 303 return 303 304 304 dlg = OptionQuestionEditorDialog(self, q, self.domain_set) 305 print(self.domain_manager.all_domain_ids()) 306 dlg = OptionQuestionEditorDialog(self, question_dict, self.domain_manager.all_domain_ids()) 305 307 self.wait_window(dlg) 306 current_question = dlg.result 307 308 if current_question: 309 current_question.flexo_id = FlexOID.generate( 310 current_question.domain, 311 current_question.entity_type, 312 current_question.state, 313 current_question.text_seed 314 ) 308 question_dict = dlg.result 309 310 if question_dict: 311 question_dict["qtype"] = "single_choice" 312 current_question = question_factory(question_dict) 315 313 active_catalog.add_questions([current_question]) 316 314 self.refresh_all() 317 self.log_action(f"Updated - Question { q.id} updated.")318 self.log_action(f"New Question ID - Assigned ID: {current_question. id}")315 self.log_action(f"Updated - Question {current_question.flexo_id} updated.") 316 self.log_action(f"New Question ID - Assigned ID: {current_question.flexo_id}") 319 317 320 318 def add_selected_question_to_exam(self): … … 332 330 return 333 331 334 if not messagebox.askyesno("Delete", f"Delete question {q. id}?"):332 if not messagebox.askyesno("Delete", f"Delete question {q.flexo_id}?"): 335 333 return 336 334 337 335 try: 338 if self.active_catalog.remove(q. id):336 if self.active_catalog.remove(q.flexo_id): 339 337 self.refresh_all() 340 self.log_action(f"Deleted - Question {q. id} removed.")338 self.log_action(f"Deleted - Question {q.flexo_id} removed.") 341 339 except ValueError as e: 342 340 messagebox.showerror("Forbidden", str(e)) … … 358 356 def edit_selected_question(self): 359 357 q = self.require_selected_question() 360 dlg = self.get_question_editor_for( q, self.domain_set)358 dlg = self.get_question_editor_for(self, q, self.domain_manager.all_domain_ids()) 361 359 self.wait_window(dlg) 362 360 current_question = dlg.result … … 364 362 self.active_catalog.add_questions([current_question]) 365 363 self.refresh_all() 366 self.log_action(f"Updated - Question {q. id} updated.")364 self.log_action(f"Updated - Question {q.flexo_id} updated.") 367 365 368 366 def import_exam_as_temp_catalog(self, exam_path: str): … … 484 482 return 485 483 486 catalogs = self.catalog_manager.catalogs ()484 catalogs = self.catalog_manager.catalogs 487 485 if len(catalogs) < 2: 488 486 messagebox.showinfo(action.title(), "You need at least two catalogs.") … … 606 604 return 607 605 608 entry = simpledialog.askstring("Add Domain", 609 "Enter domain (e.g. ELEK_Elektrotechnik):", 610 parent=self) 611 if not entry: 606 dlg = DomainManagementDialog(self, self.domain_manager) 607 self.wait_window() 608 if not dlg: 612 609 return 613 610 614 611 try: 615 active.add_domain(entry) 616 self.domain_set.update([entry]) 617 self.log_action(f"Added - Domain '{entry}' added to catalog '{active.catalog_id}'.") 612 self.domain_manager.register(Domain.with_domain_id(dlg.result)) 613 self.log_action(f"Added - Domain '{dlg.result}' added to catalog '{active.catalog_id}'.") 618 614 except ValueError as e: 619 615 messagebox.showerror("Invalid Input", str(e))
Note:
See TracChangeset
for help on using the changeset viewer.
