From 8b0740778c5232303ff068890ff74eff655dd0eb Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 12 Jun 2019 16:12:04 +0000 Subject: [PATCH] Set an edit widget's text Also make the width calculation take into account the Edit's cursor. --- cheuph/euphoria/edit_widgets.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cheuph/euphoria/edit_widgets.py b/cheuph/euphoria/edit_widgets.py index 0d2bc93..ce2bf65 100644 --- a/cheuph/euphoria/edit_widgets.py +++ b/cheuph/euphoria/edit_widgets.py @@ -30,12 +30,16 @@ class EditWidget(urwid.WidgetWrap): def width(self) -> int: prompt_width, _ = self._prompt.pack(None) edit_width, _ = self._edit.pack(None) - return max(prompt_width, edit_width) + return max(prompt_width, edit_width + 1) @property def text(self) -> str: return self._edit.edit_text + @text.setter + def text(self, text: str) -> None: + self._edit.edit_text = text + class PasswordEditWidget(urwid.WidgetWrap): def __init__(self, @@ -65,12 +69,16 @@ class PasswordEditWidget(urwid.WidgetWrap): def width(self) -> int: prompt_width, _ = self._prompt.pack(None) edit_width, _ = self._edit.pack(None) - return max(prompt_width, edit_width) + return max(prompt_width, edit_width + 1) @property def text(self) -> str: return self._edit.edit_text + @text.setter + def text(self, text: str) -> None: + self._edit.edit_text = text + def update_fake_edit(self) -> None: fake_text = self._mask_char * len(self._edit.edit_text) self._fake_edit.edit_text = fake_text