Skip to content

Commit

Permalink
fix: None length issue for formatting
Browse files Browse the repository at this point in the history
TODO: FIX TABLE CALC
  • Loading branch information
kraanzu committed Aug 24, 2024
1 parent 073cd44 commit 2f11163
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dooit/ui/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def __init__(self) -> None:
def __get_max_column_width(self, items: List, property: str, formatter: Callable):
# TODO: OPTIMIZE THIS !!!

values = [getattr(item, property) for item in items]
values = [getattr(item, property) or "" for item in items]

return max(
[len(formatter(getattr(item, property), item)) for item in items]
[len(formatter(getattr(item, property) or "", item)) for item in items]
+ [len(value) for value in values]
)

Expand Down
9 changes: 6 additions & 3 deletions dooit/ui/widgets/inputs/simple_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ def __init__(self, model: ModelType) -> None:
super().__init__()

self.model = model
self.value = getattr(model, self._property)
self._cursor_pos = len(self.value)
self.formatters = set()
self.reset()

def add_formatter(self, formatter: Callable[[str], TextType]):
self.formatters.add(formatter)
Expand All @@ -30,8 +29,12 @@ def add_formatter(self, formatter: Callable[[str], TextType]):
def _property(self) -> str:
return self.__class__.__name__.lower()

@property
def model_value(self) -> str:
return getattr(self.model, self._property) or ""

def reset(self) -> str:
self.value = getattr(self.model, self._property)
self.value = self.model_value
self._cursor_pos = len(self.value)
return self.value

Expand Down

0 comments on commit 2f11163

Please sign in to comment.