Changeset 9b1abd2 in flexograder for gui/detail_panel.py


Ignore:
Timestamp:
12/16/25 16:28:34 (4 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
fake-data, main, master
Children:
1a60982
Parents:
a14c6b0
Message:

fix some subtype issues, support png rendering via tk.PhotoImage and remove pillow - rename type to mtype attribute for media items

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/detail_panel.py

    ra14c6b0 r9b1abd2  
    22from tkinter import ttk
    33import tkinter.font as tkfont
    4 from PIL import Image, ImageTk
     4# from PIL import Image, ImageTk
    55
    66class DetailPanel(ttk.Frame):
     
    2727        self.font_question = tkfont.Font(family="TkDefaultFont", size=13)
    2828        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
    2946        # ─────────────────────────── Metadata ────────────────────────────────
    3047        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))
    3249        meta.columnconfigure(1, weight=1)
    3350
    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")
    3552        self.lbl_type = ttk.Label(meta, text="—")
    3653        self.lbl_type.grid(row=0, column=1, sticky="w")
     
    5269        self.img_frame.grid(row=3, column=0, sticky="nsew", pady=(0, 4))
    5370        self.img_frame.columnconfigure(0, weight=1)
    54         self.rowconfigure(3, weight=3)  # allow preview area to expand
    5571
    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        )
    5780        self.img_label.grid(row=0, column=0, sticky="nsew")
    5881
     
    86109        """Load an image from disk and resize to fit preview area."""
    87110        try:
    88             img = Image.open(img_path)
     111            img = tk.PhotoImage(file=img_path)
    89112        except Exception:
    90113            return None
    91114
    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
    94127
    95128    # ───────────────────────────────────────────────────────────────────────
     
    101134
    102135        # Clear image preview
    103         self.img_label.configure(image="")
     136
    104137        self._image_ref = None
     138        self.img_label.configure(image=None)
    105139
    106140        # Clear answers
     
    111145            # Question text
    112146            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="—")
    113157
    114158            # Metadata
     
    134178
    135179        else:
     180            self.lbl_topic.config(text="—")
    136181            self.lbl_type.config(text="—")
    137182            self.lbl_state.config(text="—")
Note: See TracChangeset for help on using the changeset viewer.