Commit cce1a409 authored by Link Mauve's avatar Link Mauve

Add __slots__ in most of the poezio.windows classes, to be more explicit about their data.

parent d967c246
...@@ -37,6 +37,8 @@ class DummyWin: ...@@ -37,6 +37,8 @@ class DummyWin:
class Win: class Win:
__slots__ = ('_win', 'height', 'width', 'y', 'x')
def __init__(self) -> None: def __init__(self) -> None:
self._win = None self._win = None
self.height, self.width = 0, 0 self.height, self.width = 0, 0
......
...@@ -152,6 +152,9 @@ class BookmarkAutojoinWin(FieldInputMixin): ...@@ -152,6 +152,9 @@ class BookmarkAutojoinWin(FieldInputMixin):
class BookmarksWin(Win): class BookmarksWin(Win):
__slots__ = ('scroll_pos', '_current_input', 'current_horizontal_input',
'_bookmarks', 'lines')
def __init__(self, bookmarks: BookmarkList, height: int, width: int, y: int, x: int) -> None: def __init__(self, bookmarks: BookmarkList, height: int, width: int, y: int, x: int) -> None:
self._win = base_wins.TAB_WIN.derwin(height, width, y, x) self._win = base_wins.TAB_WIN.derwin(height, width, y, x)
self.scroll_pos = 0 self.scroll_pos = 0
......
...@@ -4,6 +4,8 @@ from poezio.theming import get_theme, to_curses_attr ...@@ -4,6 +4,8 @@ from poezio.theming import get_theme, to_curses_attr
class Dialog(Win): class Dialog(Win):
__slots__ = ('text', 'accept', 'critical')
str_accept = " Accept " str_accept = " Accept "
str_refuse = " Reject " str_refuse = " Reject "
......
...@@ -20,6 +20,9 @@ class FieldInput: ...@@ -20,6 +20,9 @@ class FieldInput:
'windows' library. 'windows' library.
""" """
# XXX: This conflicts with Win in the FieldInputMixin.
#__slots__ = ('_field', 'color')
def __init__(self, field): def __init__(self, field):
self._field = field self._field = field
self.color = get_theme().COLOR_NORMAL_TEXT self.color = get_theme().COLOR_NORMAL_TEXT
...@@ -47,6 +50,8 @@ class FieldInput: ...@@ -47,6 +50,8 @@ class FieldInput:
class FieldInputMixin(FieldInput, Win): class FieldInputMixin(FieldInput, Win):
"Mix both FieldInput and Win" "Mix both FieldInput and Win"
__slots__ = ()
def __init__(self, field): def __init__(self, field):
FieldInput.__init__(self, field) FieldInput.__init__(self, field)
Win.__init__(self) Win.__init__(self)
...@@ -60,6 +65,8 @@ class FieldInputMixin(FieldInput, Win): ...@@ -60,6 +65,8 @@ class FieldInputMixin(FieldInput, Win):
class ColoredLabel(Win): class ColoredLabel(Win):
__slots__ = ('text', 'color')
def __init__(self, text): def __init__(self, text):
self.text = text self.text = text
self.color = get_theme().COLOR_NORMAL_TEXT self.color = get_theme().COLOR_NORMAL_TEXT
...@@ -85,6 +92,8 @@ class DummyInput(FieldInputMixin): ...@@ -85,6 +92,8 @@ class DummyInput(FieldInputMixin):
Used for fields that do not require any input ('fixed') Used for fields that do not require any input ('fixed')
""" """
__slots__ = ()
def __init__(self, field): def __init__(self, field):
FieldInputMixin.__init__(self, field) FieldInputMixin.__init__(self, field)
...@@ -99,6 +108,8 @@ class DummyInput(FieldInputMixin): ...@@ -99,6 +108,8 @@ class DummyInput(FieldInputMixin):
class BooleanWin(FieldInputMixin): class BooleanWin(FieldInputMixin):
__slots__ = ('last_key', 'value')
def __init__(self, field): def __init__(self, field):
FieldInputMixin.__init__(self, field) FieldInputMixin.__init__(self, field)
self.last_key = 'KEY_RIGHT' self.last_key = 'KEY_RIGHT'
...@@ -133,6 +144,8 @@ class BooleanWin(FieldInputMixin): ...@@ -133,6 +144,8 @@ class BooleanWin(FieldInputMixin):
class TextMultiWin(FieldInputMixin): class TextMultiWin(FieldInputMixin):
__slots__ = ('options', 'val_pos', 'edition_input')
def __init__(self, field): def __init__(self, field):
FieldInputMixin.__init__(self, field) FieldInputMixin.__init__(self, field)
options = field.get_value() options = field.get_value()
...@@ -212,6 +225,8 @@ class TextMultiWin(FieldInputMixin): ...@@ -212,6 +225,8 @@ class TextMultiWin(FieldInputMixin):
class ListMultiWin(FieldInputMixin): class ListMultiWin(FieldInputMixin):
__slots__ = ('options', 'val_pos')
def __init__(self, field): def __init__(self, field):
FieldInputMixin.__init__(self, field) FieldInputMixin.__init__(self, field)
values = field.get_value() or [] values = field.get_value() or []
...@@ -261,6 +276,8 @@ class ListMultiWin(FieldInputMixin): ...@@ -261,6 +276,8 @@ class ListMultiWin(FieldInputMixin):
class ListSingleWin(FieldInputMixin): class ListSingleWin(FieldInputMixin):
__slots__ = ('options', 'val_pos')
def __init__(self, field): def __init__(self, field):
FieldInputMixin.__init__(self, field) FieldInputMixin.__init__(self, field)
# the option list never changes # the option list never changes
...@@ -306,6 +323,8 @@ class ListSingleWin(FieldInputMixin): ...@@ -306,6 +323,8 @@ class ListSingleWin(FieldInputMixin):
class TextSingleWin(FieldInputMixin, Input): class TextSingleWin(FieldInputMixin, Input):
__slots__ = ('text', 'pos')
def __init__(self, field): def __init__(self, field):
FieldInputMixin.__init__(self, field) FieldInputMixin.__init__(self, field)
Input.__init__(self) Input.__init__(self)
...@@ -323,6 +342,8 @@ class TextSingleWin(FieldInputMixin, Input): ...@@ -323,6 +342,8 @@ class TextSingleWin(FieldInputMixin, Input):
class TextPrivateWin(TextSingleWin): class TextPrivateWin(TextSingleWin):
__slots__ = ()
def __init__(self, field): def __init__(self, field):
TextSingleWin.__init__(self, field) TextSingleWin.__init__(self, field)
...@@ -352,6 +373,8 @@ class FormWin: ...@@ -352,6 +373,8 @@ class FormWin:
On resize, move and resize all the subwin and define how the text will be written On resize, move and resize all the subwin and define how the text will be written
On refresh, write all the text, and refresh all the subwins On refresh, write all the text, and refresh all the subwins
""" """
__slots__ = ('_form', '_win', 'scroll_pos', 'current_input', 'inputs')
input_classes = { input_classes = {
'boolean': BooleanWin, 'boolean': BooleanWin,
'fixed': DummyInput, 'fixed': DummyInput,
......
...@@ -24,6 +24,8 @@ class ImageWin(Win): ...@@ -24,6 +24,8 @@ class ImageWin(Win):
A window which contains either an image or a border. A window which contains either an image or a border.
""" """
__slots__ = ('_image', '_display_avatar')
def __init__(self) -> None: def __init__(self) -> None:
self._image = None # type: Optional[Image] self._image = None # type: Optional[Image]
Win.__init__(self) Win.__init__(self)
......
...@@ -16,6 +16,8 @@ from poezio.theming import get_theme, to_curses_attr ...@@ -16,6 +16,8 @@ from poezio.theming import get_theme, to_curses_attr
class GlobalInfoBar(Win): class GlobalInfoBar(Win):
__slots__ = ('core')
def __init__(self, core) -> None: def __init__(self, core) -> None:
Win.__init__(self) Win.__init__(self)
self.core = core self.core = core
...@@ -63,6 +65,8 @@ class GlobalInfoBar(Win): ...@@ -63,6 +65,8 @@ class GlobalInfoBar(Win):
class VerticalGlobalInfoBar(Win): class VerticalGlobalInfoBar(Win):
__slots__ = ('core')
def __init__(self, core, scr) -> None: def __init__(self, core, scr) -> None:
Win.__init__(self) Win.__init__(self)
self.core = core self.core = core
......
...@@ -20,6 +20,8 @@ class InfoWin(Win): ...@@ -20,6 +20,8 @@ class InfoWin(Win):
MucInfoWin, etc. Provides some useful methods. MucInfoWin, etc. Provides some useful methods.
""" """
__slots__ = ()
def __init__(self): def __init__(self):
Win.__init__(self) Win.__init__(self)
...@@ -40,6 +42,8 @@ class XMLInfoWin(InfoWin): ...@@ -40,6 +42,8 @@ class XMLInfoWin(InfoWin):
Info about the latest xml filter used and the state of the buffer. Info about the latest xml filter used and the state of the buffer.
""" """
__slots__ = ()
def __init__(self): def __init__(self):
InfoWin.__init__(self) InfoWin.__init__(self)
...@@ -63,6 +67,8 @@ class PrivateInfoWin(InfoWin): ...@@ -63,6 +67,8 @@ class PrivateInfoWin(InfoWin):
about the MUC user we are talking to about the MUC user we are talking to
""" """
__slots__ = ()
def __init__(self): def __init__(self):
InfoWin.__init__(self) InfoWin.__init__(self)
...@@ -104,6 +110,8 @@ class MucListInfoWin(InfoWin): ...@@ -104,6 +110,8 @@ class MucListInfoWin(InfoWin):
about the muc server being listed about the muc server being listed
""" """
__slots__ = ('message')
def __init__(self, message=''): def __init__(self, message=''):
InfoWin.__init__(self) InfoWin.__init__(self)
self.message = message self.message = message
...@@ -129,6 +137,8 @@ class ConversationInfoWin(InfoWin): ...@@ -129,6 +137,8 @@ class ConversationInfoWin(InfoWin):
about the user we are talking to about the user we are talking to
""" """
__slots__ = ()
def __init__(self): def __init__(self):
InfoWin.__init__(self) InfoWin.__init__(self)
...@@ -218,6 +228,8 @@ class ConversationInfoWin(InfoWin): ...@@ -218,6 +228,8 @@ class ConversationInfoWin(InfoWin):
class DynamicConversationInfoWin(ConversationInfoWin): class DynamicConversationInfoWin(ConversationInfoWin):
__slots__ = ()
def write_contact_jid(self, jid): def write_contact_jid(self, jid):
""" """
Just displays the resource in an other color Just displays the resource in an other color
...@@ -240,6 +252,8 @@ class MucInfoWin(InfoWin): ...@@ -240,6 +252,8 @@ class MucInfoWin(InfoWin):
about the MUC we are viewing about the MUC we are viewing
""" """
__slots__ = ()
def __init__(self): def __init__(self):
InfoWin.__init__(self) InfoWin.__init__(self)
...@@ -306,6 +320,8 @@ class ConversationStatusMessageWin(InfoWin): ...@@ -306,6 +320,8 @@ class ConversationStatusMessageWin(InfoWin):
The upper bar displaying the status message of the contact The upper bar displaying the status message of the contact
""" """
__slots__ = ()
def __init__(self): def __init__(self):
InfoWin.__init__(self) InfoWin.__init__(self)
...@@ -331,6 +347,8 @@ class ConversationStatusMessageWin(InfoWin): ...@@ -331,6 +347,8 @@ class ConversationStatusMessageWin(InfoWin):
class BookmarksInfoWin(InfoWin): class BookmarksInfoWin(InfoWin):
__slots__ = ()
def __init__(self): def __init__(self):
InfoWin.__init__(self) InfoWin.__init__(self)
...@@ -347,6 +365,8 @@ class BookmarksInfoWin(InfoWin): ...@@ -347,6 +365,8 @@ class BookmarksInfoWin(InfoWin):
class ConfirmStatusWin(Win): class ConfirmStatusWin(Win):
__slots__ = ('text', 'critical')
def __init__(self, text, critical=False): def __init__(self, text, critical=False):
Win.__init__(self) Win.__init__(self)
self.text = text self.text = text
......
...@@ -19,6 +19,8 @@ class HelpText(Win): ...@@ -19,6 +19,8 @@ class HelpText(Win):
command mode. command mode.
""" """
__slots__ = ('txt')
def __init__(self, text: str = '') -> None: def __init__(self, text: str = '') -> None:
Win.__init__(self) Win.__init__(self)
self.txt = text # type: str self.txt = text # type: str
......
...@@ -32,6 +32,9 @@ class Input(Win): ...@@ -32,6 +32,9 @@ class Input(Win):
passing the list of items that can be used to complete. The completion can be used passing the list of items that can be used to complete. The completion can be used
in a very flexible way. in a very flexible way.
""" """
__slots__ = ('key_func', 'text', 'pos', 'view_pos', 'on_input', 'color',
'last_completion', 'hit_list')
text_attributes = 'bou1234567ti' text_attributes = 'bou1234567ti'
clipboard = '' # A common clipboard for all the inputs, this makes clipboard = '' # A common clipboard for all the inputs, this makes
...@@ -586,6 +589,8 @@ class HistoryInput(Input): ...@@ -586,6 +589,8 @@ class HistoryInput(Input):
An input with colors and stuff, plus an history An input with colors and stuff, plus an history
^R allows to search inside the history (as in a shell) ^R allows to search inside the history (as in a shell)
""" """
__slots__ = ('help_message', 'histo_pos', 'current_completed', 'search')
history = [] # type: List[str] history = [] # type: List[str]
def __init__(self) -> None: def __init__(self) -> None:
......
...@@ -19,6 +19,9 @@ class ListWin(Win): ...@@ -19,6 +19,9 @@ class ListWin(Win):
scrolled up and down, with one selected line at a time scrolled up and down, with one selected line at a time
""" """
__slots__ = ('_columns', '_columns_sizes', 'sorted_by', 'lines',
'_selected_row', '_starting_pos')
def __init__(self, columns: Dict[str, int], with_headers: bool = True) -> None: def __init__(self, columns: Dict[str, int], with_headers: bool = True) -> None:
Win.__init__(self) Win.__init__(self)
self._columns = columns # type: Dict[str, int] self._columns = columns # type: Dict[str, int]
...@@ -165,6 +168,9 @@ class ColumnHeaderWin(Win): ...@@ -165,6 +168,9 @@ class ColumnHeaderWin(Win):
A class displaying the column's names A class displaying the column's names
""" """
__slots__ = ('_columns', '_columns_sizes', '_column_sel', '_column_order',
'_column_order_asc')
def __init__(self, columns: List[str]) -> None: def __init__(self, columns: List[str]) -> None:
Win.__init__(self) Win.__init__(self)
self._columns = columns self._columns = columns
......
...@@ -19,6 +19,8 @@ class VerticalSeparator(Win): ...@@ -19,6 +19,8 @@ class VerticalSeparator(Win):
refreshed only on resize, but never on refresh, for efficiency refreshed only on resize, but never on refresh, for efficiency
""" """
__slots__ = ()
def rewrite_line(self) -> None: def rewrite_line(self) -> None:
self._win.vline(0, 0, curses.ACS_VLINE, self.height, self._win.vline(0, 0, curses.ACS_VLINE, self.height,
to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR)) to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR))
...@@ -30,6 +32,8 @@ class VerticalSeparator(Win): ...@@ -30,6 +32,8 @@ class VerticalSeparator(Win):
class SimpleTextWin(Win): class SimpleTextWin(Win):
__slots__ = ('_text', 'built_lines')
def __init__(self, text) -> None: def __init__(self, text) -> None:
Win.__init__(self) Win.__init__(self)
self._text = text self._text = text
......
...@@ -28,6 +28,8 @@ def userlist_to_cache(userlist: List[User]) -> List[CachedUser]: ...@@ -28,6 +28,8 @@ def userlist_to_cache(userlist: List[User]) -> List[CachedUser]:
class UserList(Win): class UserList(Win):
__slots__ = ('pos', 'cache')
def __init__(self) -> None: def __init__(self) -> None:
Win.__init__(self) Win.__init__(self)
self.pos = 0 self.pos = 0
...@@ -128,6 +130,8 @@ class UserList(Win): ...@@ -128,6 +130,8 @@ class UserList(Win):
class Topic(Win): class Topic(Win):
__slots__ = ('_message')
def __init__(self) -> None: def __init__(self) -> None:
Win.__init__(self) Win.__init__(self)
self._message = '' self._message = ''
......
...@@ -20,6 +20,8 @@ Row = Union[RosterGroup, Contact] ...@@ -20,6 +20,8 @@ Row = Union[RosterGroup, Contact]
class RosterWin(Win): class RosterWin(Win):
__slots__ = ('pos', 'start_pos', 'selected_row', 'roster_cache')
def __init__(self) -> None: def __init__(self) -> None:
Win.__init__(self) Win.__init__(self)
self.pos = 0 # cursor position in the contact list self.pos = 0 # cursor position in the contact list
...@@ -342,6 +344,8 @@ class RosterWin(Win): ...@@ -342,6 +344,8 @@ class RosterWin(Win):
class ContactInfoWin(Win): class ContactInfoWin(Win):
__slots__ = ()
def draw_contact_info(self, contact: Contact) -> None: def draw_contact_info(self, contact: Contact) -> None:
""" """
draw the contact information draw the contact information
......
...@@ -32,6 +32,9 @@ class Line: ...@@ -32,6 +32,9 @@ class Line:
class BaseTextWin(Win): class BaseTextWin(Win):
__slots__ = ('lines_nb_limit', 'pos', 'built_lines', 'lock', 'lock_buffer',
'separator_after')
def __init__(self, lines_nb_limit: Optional[int] = None) -> None: def __init__(self, lines_nb_limit: Optional[int] = None) -> None:
if lines_nb_limit is None: if lines_nb_limit is None:
lines_nb_limit = config.get('max_lines_in_memory') lines_nb_limit = config.get('max_lines_in_memory')
...@@ -175,6 +178,8 @@ class BaseTextWin(Win): ...@@ -175,6 +178,8 @@ class BaseTextWin(Win):
class TextWin(BaseTextWin): class TextWin(BaseTextWin):
__slots__ = ('highlights', 'hl_pos', 'nb_of_highlights_after_separator')
def __init__(self, lines_nb_limit: Optional[int] = None) -> None: def __init__(self, lines_nb_limit: Optional[int] = None) -> None:
BaseTextWin.__init__(self, lines_nb_limit) BaseTextWin.__init__(self, lines_nb_limit)
...@@ -190,8 +195,6 @@ class TextWin(BaseTextWin): ...@@ -190,8 +195,6 @@ class TextWin(BaseTextWin):
# This is useful to make “go to next highlight“ work after a “move to separator”. # This is useful to make “go to next highlight“ work after a “move to separator”.
self.nb_of_highlights_after_separator = 0 self.nb_of_highlights_after_separator = 0
self.separator_after = None
def next_highlight(self) -> None: def next_highlight(self) -> None:
""" """
Go to the next highlight in the buffer. Go to the next highlight in the buffer.
...@@ -563,6 +566,8 @@ class TextWin(BaseTextWin): ...@@ -563,6 +566,8 @@ class TextWin(BaseTextWin):
class XMLTextWin(BaseTextWin): class XMLTextWin(BaseTextWin):
__slots__ = ()
def __init__(self) -> None: def __init__(self) -> None:
BaseTextWin.__init__(self) BaseTextWin.__init__(self)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment