Coding style
- Rename appearance to appearance_for.
This commit is contained in:
parent
62ebbd562b
commit
6681101b1c
4 changed files with 65 additions and 64 deletions
|
|
@ -81,11 +81,11 @@ class Row:
|
|||
self.widgets = widgets
|
||||
self.widths_func = widths_func
|
||||
|
||||
def appearance(self, dimensions):
|
||||
def appearance_for(self, dimensions):
|
||||
width, height = dimensions
|
||||
widths = self.widths_func(self.widgets, width)
|
||||
assert sum(widths) == width, (sum(widths), width)
|
||||
return join_horizontal([column_widget.appearance((item_width, height))
|
||||
return join_horizontal([column_widget.appearance_for((item_width, height))
|
||||
for column_widget, item_width in zip(self.widgets, widths)])
|
||||
|
||||
def appearance_min(self):
|
||||
|
|
@ -120,13 +120,13 @@ class Column:
|
|||
self.partition_func = partition_func
|
||||
self.background_char = background_char
|
||||
|
||||
def appearance(self, dimensions):
|
||||
def appearance_for(self, dimensions):
|
||||
width, height = dimensions
|
||||
if len(self.widgets) == 0: # FIX: Really allow zero widgets?
|
||||
return [self.background_char * width] * height
|
||||
heights = self.partition_func(self.widgets, height)
|
||||
assert sum(heights) == height, (sum(heights), height)
|
||||
return join_vertical([row_widget.appearance((width, item_height))
|
||||
return join_vertical([row_widget.appearance_for((width, item_height))
|
||||
for row_widget, item_height in zip(self.widgets, heights)])
|
||||
|
||||
def _appearance_list(self, widgets):
|
||||
|
|
@ -155,7 +155,7 @@ class Filler:
|
|||
def __init__(self, widget):
|
||||
self.widget = widget
|
||||
|
||||
def appearance(self, dimensions):
|
||||
def appearance_for(self, dimensions):
|
||||
return appearance_resize(self.widget.appearance_min(), dimensions)
|
||||
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ class ScrollBar:
|
|||
termstr.TermStr(char).fg_color(background_color).bg_color(bar_color))
|
||||
for char in self._PARTIAL_CHARS[self._is_horizontal]]
|
||||
|
||||
def appearance(self, dimensions):
|
||||
def appearance_for(self, dimensions):
|
||||
width, height = dimensions
|
||||
assert width == 1 or height == 1, (width, height)
|
||||
length = width if self._is_horizontal else height
|
||||
|
|
@ -225,7 +225,7 @@ class Portal:
|
|||
def scroll_right(self):
|
||||
self._scroll_half_pages(1, 0)
|
||||
|
||||
def appearance(self, dimensions):
|
||||
def appearance_for(self, dimensions):
|
||||
width, height = dimensions
|
||||
x, y = self.position
|
||||
try:
|
||||
|
|
@ -265,7 +265,7 @@ class View:
|
|||
def widget(self, widget):
|
||||
self.portal.widget = widget
|
||||
|
||||
def appearance(self, dimensions):
|
||||
def appearance_for(self, dimensions):
|
||||
width, height = dimensions
|
||||
try:
|
||||
full_width, full_height = self.portal.widget.appearance_dimensions()
|
||||
|
|
@ -273,7 +273,7 @@ class View:
|
|||
full_appearance = self.portal.widget.appearance_min()
|
||||
full_width, full_height = appearance_dimensions(full_appearance)
|
||||
if full_width == 0 or full_height == 0:
|
||||
return self.portal.appearance(dimensions)
|
||||
return self.portal.appearance_for(dimensions)
|
||||
x, y = self.portal.position
|
||||
hide_scrollbar_vertical = self.hide_scrollbars and full_height <= height and y == 0
|
||||
hide_scrollbar_horizontal = self.hide_scrollbars and full_width <= width and x == 0
|
||||
|
|
@ -285,14 +285,14 @@ class View:
|
|||
full_height = max(full_height, y + height)
|
||||
self.vertical_scrollbar.interval = (y / full_height, (y + height) / full_height)
|
||||
width -= 1
|
||||
portal_appearance = self.portal.appearance((width, height))
|
||||
portal_appearance = self.portal.appearance_for((width, height))
|
||||
if hide_scrollbar_vertical:
|
||||
result = portal_appearance
|
||||
else:
|
||||
scrollbar_v_appearance = self.vertical_scrollbar.appearance((1, height))
|
||||
scrollbar_v_appearance = self.vertical_scrollbar.appearance_for((1, height))
|
||||
result = join_horizontal([portal_appearance, scrollbar_v_appearance])
|
||||
if not hide_scrollbar_horizontal:
|
||||
scrollbar_h_appearance = self.horizontal_scrollbar.appearance((width, 1))
|
||||
scrollbar_h_appearance = self.horizontal_scrollbar.appearance_for((width, 1))
|
||||
result.append(scrollbar_h_appearance[0] + ("" if hide_scrollbar_vertical else " "))
|
||||
return result
|
||||
|
||||
|
|
@ -314,7 +314,7 @@ class Text:
|
|||
def appearance_min(self):
|
||||
return self.text
|
||||
|
||||
def appearance(self, dimensions):
|
||||
def appearance_for(self, dimensions):
|
||||
return appearance_resize(self.appearance_min(), dimensions)
|
||||
|
||||
|
||||
|
|
@ -379,9 +379,9 @@ class Border:
|
|||
def appearance_min(self):
|
||||
return self._add_border(self.widget.appearance_min())
|
||||
|
||||
def appearance(self, dimensions):
|
||||
def appearance_for(self, dimensions):
|
||||
width, height = dimensions
|
||||
return self._add_border(self.widget.appearance((width-2, height-2)))
|
||||
return self._add_border(self.widget.appearance_for((width-2, height-2)))
|
||||
|
||||
|
||||
class Placeholder:
|
||||
|
|
@ -392,8 +392,8 @@ class Placeholder:
|
|||
def appearance_min(self):
|
||||
return self.widget.appearance_min()
|
||||
|
||||
def appearance(self, dimensions):
|
||||
return self.widget.appearance(dimensions)
|
||||
def appearance_for(self, dimensions):
|
||||
return self.widget.appearance_for(dimensions)
|
||||
|
||||
|
||||
class Fixed:
|
||||
|
|
@ -430,7 +430,7 @@ def handle_exception(func):
|
|||
@handle_exception
|
||||
def draw_screen(widget):
|
||||
global _LAST_APPEARANCE
|
||||
appearance = widget.appearance(os.get_terminal_size())
|
||||
appearance = widget.appearance_for(os.get_terminal_size())
|
||||
print(terminal.move(0, 0), *appearance, sep="", end="", flush=True)
|
||||
_LAST_APPEARANCE = appearance
|
||||
|
||||
|
|
@ -438,7 +438,7 @@ def draw_screen(widget):
|
|||
@handle_exception
|
||||
def patch_screen(widget):
|
||||
global _LAST_APPEARANCE
|
||||
appearance = widget.appearance(os.get_terminal_size())
|
||||
appearance = widget.appearance_for(os.get_terminal_size())
|
||||
zip_func = (itertools.zip_longest if len(appearance) > len(_LAST_APPEARANCE) else zip)
|
||||
changed_lines = (str(terminal.move(0, row_index)) + line for row_index, (line, old_line)
|
||||
in enumerate(zip_func(appearance, _LAST_APPEARANCE)) if line != old_line)
|
||||
|
|
@ -504,8 +504,8 @@ class _Screen:
|
|||
def __init__(self):
|
||||
self.content = Filler(Text("Hello World"))
|
||||
|
||||
def appearance(self, dimensions):
|
||||
return self.content.appearance(dimensions)
|
||||
def appearance_for(self, dimensions):
|
||||
return self.content.appearance_for(dimensions)
|
||||
|
||||
def on_keyboard_input(self, term_code):
|
||||
if term_code in ["q", terminal.ESC, terminal.CTRL_C]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue