Skip to content

Commit

Permalink
Improve error display if a selector item is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Sep 28, 2024
1 parent c33cc7a commit fe9ab07
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/app/selector_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class NavKeys(Enum):
# Callbacks used to get the info for items in the window.
type GetterFunc[T] = Callable[[packages.PackagesSet, utils.SpecialID], T]

# The three kinds of font for the display textbox.
type DispFont = Literal['suggested', 'mouseover', 'normal']
# The kinds of font for the display textbox.
type DispFont = Literal['suggested', 'mouseover', 'normal', 'error']

TRANS_ATTR_DESC = TransToken.untranslated('{desc}: ')
TRANS_ATTR_COLOR = TransToken.ui('Color: R={r}, G={g}, B={b}') # i18n: Tooltip for colour swatch.
Expand Down Expand Up @@ -556,11 +556,13 @@ def set_disp(self) -> None:
if text is None:
# No override for the text is set, use the
# suggested-rollover one, or the selected item.
if self._suggested_rollover is not None:
data = self._get_data(self._suggested_rollover)
else:
data = self._get_data(self.chosen.value)
item_id = self._suggested_rollover or self.chosen.value
data = self._get_data(item_id)
text = data.context_lbl
if data is packages.SEL_DATA_MISSING:
# Override tooltip to highlight the issue.
tooltip = packages.TRANS_MISSING_ITEM_DESC.format(id=item_id)
font = 'error'

self._ui_display_set(enabled=enabled, text=text, tooltip=tooltip, font=font)

Expand Down
5 changes: 3 additions & 2 deletions src/packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
'The ID "{obj_id}" was used twice for a {obj_type} in the packages "{pak1}" and "{pak2}"!'
)
TRANS_CORR_OPTS = TransToken.ui_plural('{n} option', '{n} options') # i18n: Corridor options count
TRANS_MISSING_ITEM_DESC = TransToken.ui('The object {id} is missing from loaded packages. Exporting it will fail.')


@utils.freeze_enum_props
Expand Down Expand Up @@ -366,10 +367,10 @@ def iter_trans_tokens(self, source: str) -> Iterator[TransTokenSource]:
desc=TransToken.ui('Do not add anything.'),
)
SEL_DATA_MISSING = SelitemData.build(
long_name=TransToken.ui('Unknown Item'),
long_name=TransToken.ui('Unknown Object'),
short_name=TransToken.ui('???'),
small_icon=img.Handle.error(consts.SEL_ICON_SIZE, consts.SEL_ICON_SIZE),
desc=TransToken.ui('This item is missing from loaded packages. Exporting it will fail.'),
desc=TransToken.ui('This object is missing from loaded packages. Exporting it will fail.'),
)


Expand Down
3 changes: 2 additions & 1 deletion src/ui_tk/selector_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ def _ui_display_set(
return # Nothing to do.

match font:
case 'normal':
case 'normal' | 'error':
font_obj = self.norm_font
case 'suggested':
font_obj = self.sugg_font
Expand All @@ -832,6 +832,7 @@ def _ui_display_set(
# Changing the font causes a flicker, so only set it
# when the font is actually different.
self.display['font'] = font_obj
self.display['foreground'] = 'red' if font == 'error' else ''
set_tooltip(self.display, tooltip)
set_stringvar(self.disp_label, text)

Expand Down
4 changes: 3 additions & 1 deletion src/ui_wx/selector_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
wx.Font(wx.FontInfo(i))
for i in range(10, 5, -1)
]
ERROR_COLOUR = wx.Colour(255, 0, 0)


class ItemSlot(wx.Panel):
Expand Down Expand Up @@ -736,7 +737,7 @@ def _ui_display_set(
return # Nothing to do.

match font:
case 'normal':
case 'normal' | 'error':
font_obj = self.norm_font
case 'suggested':
font_obj = self.sugg_font
Expand All @@ -746,6 +747,7 @@ def _ui_display_set(
assert_never(font)

self.display.SetFont(font_obj)
self.display.SetForegroundColour(ERROR_COLOUR if font == 'error' else wx.NullColour)
wid_transtoken.set_entry_value(self.display, text)
wid_transtoken.set_tooltip(self.display, tooltip)
self.display.Enabled = self.disp_btn.Enabled = enabled

0 comments on commit fe9ab07

Please sign in to comment.