Changeset 9b1abd2 in flexograder for gui/detail_panel.py
- Timestamp:
- 12/16/25 16:28:34 (4 months ago)
- Branches:
- fake-data, main, master
- Children:
- 1a60982
- Parents:
- a14c6b0
- File:
-
- 1 edited
-
gui/detail_panel.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gui/detail_panel.py
ra14c6b0 r9b1abd2 2 2 from tkinter import ttk 3 3 import tkinter.font as tkfont 4 from PIL import Image, ImageTk4 # from PIL import Image, ImageTk 5 5 6 6 class DetailPanel(ttk.Frame): … … 27 27 self.font_question = tkfont.Font(family="TkDefaultFont", size=13) 28 28 self.txt_question.configure(font=self.font_question) 29 30 # ─────────────────────────── Topic / Subtopic ───────────────────────── 31 topic_frame = ttk.Frame(self) 32 topic_frame.grid(row=2, column=0, sticky="ew", pady=(0, 4)) 33 topic_frame.columnconfigure(1, weight=1) 34 35 ttk.Label(topic_frame, text="Topic:", foreground="#555").grid( 36 row=0, column=0, sticky="w" 37 ) 38 39 self.lbl_topic = ttk.Label( 40 topic_frame, 41 text="—", 42 foreground="#555" 43 ) 44 self.lbl_topic.grid(row=0, column=1, sticky="w") 45 29 46 # ─────────────────────────── Metadata ──────────────────────────────── 30 47 meta = ttk.LabelFrame(self, text="Metadata", padding=(6, 4)) 31 meta.grid(row= 2, column=0, sticky="ew", pady=(0, 4))48 meta.grid(row=3, column=0, sticky="ew", pady=(0, 4)) 32 49 meta.columnconfigure(1, weight=1) 33 50 34 ttk.Label(meta, text="Type:").grid(row= 0, column=0, sticky="w")51 ttk.Label(meta, text="Type:").grid(row=4, column=0, sticky="w") 35 52 self.lbl_type = ttk.Label(meta, text="—") 36 53 self.lbl_type.grid(row=0, column=1, sticky="w") … … 52 69 self.img_frame.grid(row=3, column=0, sticky="nsew", pady=(0, 4)) 53 70 self.img_frame.columnconfigure(0, weight=1) 54 self.rowconfigure(3, weight=3) # allow preview area to expand55 71 56 self.img_label = ttk.Label(self.img_frame, anchor="center") 72 self.img_frame.rowconfigure(0, weight=1) 73 self.img_frame.columnconfigure(0, weight=1) 74 75 self.img_label = ttk.Label( 76 self.img_frame, 77 anchor="center", 78 relief="sunken" 79 ) 57 80 self.img_label.grid(row=0, column=0, sticky="nsew") 58 81 … … 86 109 """Load an image from disk and resize to fit preview area.""" 87 110 try: 88 img = Image.open(img_path)111 img = tk.PhotoImage(file=img_path) 89 112 except Exception: 90 113 return None 91 114 92 img.thumbnail((self.MAX_IMG_WIDTH, self.MAX_IMG_HEIGHT), Image.Resampling.LANCZOS) 93 return ImageTk.PhotoImage(img) 115 w = img.width() 116 h = img.height() 117 118 # Compute integer subsample factor 119 scale_w = max(1, w // self.MAX_IMG_WIDTH) 120 scale_h = max(1, h // self.MAX_IMG_HEIGHT) 121 scale = max(scale_w, scale_h) 122 123 if scale > 1: 124 img = img.subsample(scale, scale) 125 126 return img 94 127 95 128 # ─────────────────────────────────────────────────────────────────────── … … 101 134 102 135 # Clear image preview 103 self.img_label.configure(image="") 136 104 137 self._image_ref = None 138 self.img_label.configure(image=None) 105 139 106 140 # Clear answers … … 111 145 # Question text 112 146 self.txt_question.insert("1.0", question.text) 147 148 topic = getattr(question, "topic", None) 149 subtopic = getattr(question, "subtopic", None) 150 151 if topic and subtopic: 152 self.lbl_topic.config(text=f"{topic} › {subtopic}") 153 elif topic: 154 self.lbl_topic.config(text=topic) 155 else: 156 self.lbl_topic.config(text="—") 113 157 114 158 # Metadata … … 134 178 135 179 else: 180 self.lbl_topic.config(text="—") 136 181 self.lbl_type.config(text="—") 137 182 self.lbl_state.config(text="—")
Note:
See TracChangeset
for help on using the changeset viewer.
