summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--poezio/windows/list.py66
1 files changed, 34 insertions, 32 deletions
diff --git a/poezio/windows/list.py b/poezio/windows/list.py
index 26cb1e5f..b24b8aea 100644
--- a/poezio/windows/list.py
+++ b/poezio/windows/list.py
@@ -3,13 +3,15 @@ Windows relevant for the listing tabs, not much else
"""
import logging
-log = logging.getLogger(__name__)
-
import curses
+from typing import Dict, List, Optional
+
from poezio.windows.base_wins import Win
from poezio.theming import to_curses_attr, get_theme
+log = logging.getLogger(__name__)
+
class ListWin(Win):
"""
@@ -17,23 +19,23 @@ class ListWin(Win):
scrolled up and down, with one selected line at a time
"""
- def __init__(self, columns, with_headers=True):
+ def __init__(self, columns: Dict[str, int], with_headers: bool = True) -> None:
Win.__init__(self)
- self._columns = columns # a dict {'column_name': tuple_index}
- self._columns_sizes = {} # a dict {'column_name': size}
+ self._columns = columns # type: Dict[str, int]
+ self._columns_sizes = {} # type: Dict[str, int]
self.sorted_by = (None, None) # for example: ('name', '↑')
- self.lines = [] # a list of dicts
+ self.lines = [] # type: List[str]
self._selected_row = 0
self._starting_pos = 0 # The column number from which we start the refresh
@property
- def pos(self):
+ def pos(self) -> int:
if len(self.lines) > self.height:
return len(self.lines)
else:
return 0
- def empty(self):
+ def empty(self) -> None:
"""
emtpy the list and reset some important values as well
"""
@@ -41,13 +43,13 @@ class ListWin(Win):
self._selected_row = 0
self._starting_pos = 0
- def resize_columns(self, dic):
+ def resize_columns(self, dic: Dict[str, int]) -> None:
"""
Resize the width of the columns
"""
self._columns_sizes = dic
- def sort_by_column(self, col_name, asc=True):
+ def sort_by_column(self, col_name: str, asc: bool = True) -> None:
"""
Sort the list by the given column, ascendant or descendant
"""
@@ -61,7 +63,7 @@ class ListWin(Win):
self.refresh()
curses.doupdate()
- def add_lines(self, lines):
+ def add_lines(self, lines: List[str]) -> None:
"""
Append some lines at the end of the list
"""
@@ -69,7 +71,7 @@ class ListWin(Win):
return
self.lines.extend(lines)
- def set_lines(self, lines):
+ def set_lines(self, lines: List[str]) -> None:
"""
Set the lines to another list
"""
@@ -77,7 +79,7 @@ class ListWin(Win):
return
self.lines = lines
- def get_selected_row(self):
+ def get_selected_row(self) -> Optional[str]:
"""
Return the tuple representing the selected row
"""
@@ -85,7 +87,7 @@ class ListWin(Win):
return self.lines[self._selected_row]
return None
- def refresh(self):
+ def refresh(self) -> None:
log.debug('Refresh: %s', self.__class__.__name__)
self._win.erase()
lines = self.lines[self._starting_pos:self._starting_pos + self.height]
@@ -109,12 +111,12 @@ class ListWin(Win):
x += size
self._refresh()
- def move_cursor_down(self):
+ def move_cursor_down(self) -> bool:
"""
Move the cursor Down
"""
if not self.lines:
- return
+ return False
if self._selected_row < len(self.lines) - 1:
self._selected_row += 1
while self._selected_row >= self._starting_pos + self.height:
@@ -123,21 +125,21 @@ class ListWin(Win):
self._starting_pos = 0
return True
- def move_cursor_up(self):
+ def move_cursor_up(self) -> bool:
"""
Move the cursor Up
"""
if not self.lines:
- return
+ return False
if self._selected_row > 0:
self._selected_row -= 1
while self._selected_row < self._starting_pos:
self._starting_pos -= self.height // 2
return True
- def scroll_down(self):
+ def scroll_down(self) -> bool:
if not self.lines:
- return
+ return False
self._selected_row += self.height
if self._selected_row > len(self.lines) - 1:
self._selected_row = len(self.lines) - 1
@@ -147,9 +149,9 @@ class ListWin(Win):
self._starting_pos = 0
return True
- def scroll_up(self):
+ def scroll_up(self) -> bool:
if not self.lines:
- return
+ return False
self._selected_row -= self.height + 1
if self._selected_row < 0:
self._selected_row = 0
@@ -163,21 +165,21 @@ class ColumnHeaderWin(Win):
A class displaying the column's names
"""
- def __init__(self, columns):
+ def __init__(self, columns: List[str]) -> None:
Win.__init__(self)
self._columns = columns
- self._columns_sizes = {}
+ self._columns_sizes = {} # type: Dict[str, int]
self._column_sel = ''
self._column_order = ''
self._column_order_asc = False
- def resize_columns(self, dic):
+ def resize_columns(self, dic) -> None:
self._columns_sizes = dic
- def get_columns(self):
+ def get_columns(self) -> List[str]:
return self._columns
- def refresh(self):
+ def refresh(self) -> None:
log.debug('Refresh: %s', self.__class__.__name__)
self._win.erase()
x = 0
@@ -201,23 +203,23 @@ class ColumnHeaderWin(Win):
x += size
self._refresh()
- def sel_column(self, dic):
+ def sel_column(self, dic) -> None:
self._column_sel = dic
def get_sel_column(self):
return self._column_sel
- def set_order(self, order):
+ def set_order(self, order) -> None:
self._column_order = self._column_sel
self._column_order_asc = order
- def get_order(self):
+ def get_order(self) -> bool:
if self._column_sel == self._column_order:
return self._column_order_asc
else:
return False
- def sel_column_left(self):
+ def sel_column_left(self) -> None:
if self._column_sel in self._columns:
index = self._columns.index(self._column_sel)
if index > 1:
@@ -229,7 +231,7 @@ class ColumnHeaderWin(Win):
self._column_sel = self._columns[index]
self.refresh()
- def sel_column_right(self):
+ def sel_column_right(self) -> None:
if self._column_sel in self._columns:
index = self._columns.index(self._column_sel)
if index < len(self._columns) - 2: