home · contact · privacy
Browser: Simplify and improve prompt reduction in by_1st view.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 13 Nov 2024 02:30:42 +0000 (03:30 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 13 Nov 2024 02:30:42 +0000 (03:30 +0100)
browser.py

index 1e6fc424aa1e574dafe38045ee7f0628430df82f..81ec8870d69555a08bd48d18bda3eb9d8883338d 100755 (executable)
@@ -25,8 +25,7 @@ from stable.gen_params import (GenParams,  GEN_PARAMS_FLOAT,  # noqa: E402
                                GEN_PARAMS_INT, GEN_PARAMS_STR,  # noqa: E402
                                GEN_PARAMS)  # noqa: E402
 
-PromptDiff = tuple[str, str, str]
-PromptsDiff = dict[str, PromptDiff]
+PromptsDiff = dict[str, str]
 BasicItemsAttrs = dict[str, set[str]]
 AttrVals: TypeAlias = list[str]
 AttrValsByVisibility: TypeAlias = dict[str, AttrVals]
@@ -856,7 +855,9 @@ class Gallery:
                 for i, p in enumerate(cores):
                     cores[i] = p[:-len(suffix)]
             for i, p in enumerate(prompts):
-                prompts_diff[p] = (cores[i], '', '')
+                pre_ell = '…' if prefix else ''
+                post_ell = '…' if suffix else ''
+                prompts_diff[p] = f'{pre_ell}{cores[i]}{post_ell}'
             return prompts_diff
 
         basic_items_attrs = {}
@@ -1030,8 +1031,8 @@ class Gallery:
                     for i, attr in enumerate(ancestors):
                         parent_attr_name, parent_attr_value = attr
                         if 'prompt' == parent_attr_name:
-                            prompt_diff = self._prompts_diff[parent_attr_value]
-                            parent_attr_value = f'…{prompt_diff[0]}…'
+                            parent_attr_value = self\
+                                    ._prompts_diff[parent_attr_value]
                         txt = f'<b>{parent_attr_name}</b>: {parent_attr_value}'
                         vlabel = VerticalLabel(txt, self._slots_geometry)
                         self._grid.attach(vlabel, i, i_row_ref[0], 1, 1)
@@ -1077,7 +1078,7 @@ class Gallery:
                 top_attr_name: str = sort_attrs[-1][0]
                 for i, val in enumerate(sort_attrs[-1][1]):
                     if 'prompt' == top_attr_name:
-                        val = f'…{self._prompts_diff[val][0]}…'
+                        val = self._prompts_diff[val]
                     label = Gtk.Label(label=f'<b>{top_attr_name}</b>: {val}',
                                       xalign=0,
                                       ellipsize=Pango.EllipsizeMode.MIDDLE)