From 56bab711924cd7a660c874abf40fd545693f8d98 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 15 Apr 2021 18:26:37 +0200 Subject: fix: display issue when changing show_timestamps value --- poezio/core/core.py | 17 +++++++++++++---- poezio/tabs/basetabs.py | 7 +++++-- poezio/tabs/conversationtab.py | 6 ++++-- poezio/tabs/muctab.py | 6 +++--- poezio/tabs/privatetab.py | 4 ++-- poezio/tabs/rostertab.py | 4 +++- poezio/windows/text_win.py | 5 +++-- 7 files changed, 33 insertions(+), 16 deletions(-) diff --git a/poezio/core/core.py b/poezio/core/core.py index 537f1bf2..a940e142 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -347,6 +347,7 @@ class Core: ('plugins_dir', self.plugin_manager.on_plugins_dir_change), ('request_message_receipts', self.on_request_receipts_config_change), + ('show_timestamps', self.on_show_timestamps_changed), ('theme', self.on_theme_config_change), ('themes_dir', theming.update_themes_dir), ('use_bookmarks_method', self.on_bookmarks_method_config_change), @@ -404,6 +405,12 @@ class Core: """ self.call_for_resize() + def on_show_timestamps_changed(self, option, value): + """ + Called when the show_timestamps option changes + """ + self.call_for_resize(ui_config_changed=True) + def on_bookmarks_method_config_change(self, option, value): """ Called when the use_bookmarks_method option changes @@ -1577,7 +1584,7 @@ class Core: self.information('Unable to write in the config file', 'Error') self.call_for_resize() - def resize_global_information_win(self): + def resize_global_information_win(self, ui_config_changed: bool = False): """ Resize the global_information_win only once at each resize. """ @@ -1588,7 +1595,8 @@ class Core: height = (tabs.Tab.height - 1 - self.information_win_size - tabs.Tab.tab_win_height()) self.information_win.resize(self.information_win_size, tabs.Tab.width, - height, 0) + height, 0, self.information_buffer, + force=ui_config_changed) def resize_global_info_bar(self): """ @@ -1619,7 +1627,7 @@ class Core: self.stdscr.clear() self.refresh_window() - def call_for_resize(self): + def call_for_resize(self, ui_config_changed: bool = False): """ Called when we want to resize the screen """ @@ -1642,8 +1650,9 @@ class Core: scr = self.stdscr tabs.Tab.initial_resize(scr) self.resize_global_info_bar() - self.resize_global_information_win() + self.resize_global_information_win(ui_config_changed) for tab in self.tabs: + tab.ui_config_changed = True if config.getbool('lazy_resize'): tab.need_resize = True else: diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 2046b866..51c34e62 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -124,12 +124,14 @@ class Tab: plugin_commands: Dict[str, Command] = {} plugin_keys: Dict[str, Callable] = {} # Placeholder values, set on resize - height = 1 - width = 1 + height: int = 1 + width: int = 1 core: Core input: Optional[windows.Input] key_func: Dict[str, Callable[[], Any]] commands: Dict[str, Command] + need_resize: bool + ui_config_changed: bool def __init__(self, core: Core): self.core = core @@ -142,6 +144,7 @@ class Tab: self._prev_state = None self.need_resize = False + self.ui_config_changed = False self.key_func = {} # each tab should add their keys in there # and use them in on_input self.commands = {} # and their own commands diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py index 873bf0d3..b8acfd8b 100644 --- a/poezio/tabs/conversationtab.py +++ b/poezio/tabs/conversationtab.py @@ -252,8 +252,10 @@ class ConversationTab(OneToOneTab): self.text_win.resize( self.height - 2 - bar_height - info_win_height - tab_win_height, - self.width, bar_height, 0) - self.text_win.rebuild_everything(self._text_buffer) + self.width, bar_height, 0, self._text_buffer, + force=self.ui_config_changed + ) + self.ui_config_changed = False if display_bar: self.upper_bar.resize(1, self.width, 0, 0) self.get_info_header().resize( diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 566c1d2b..becabfc5 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -1268,8 +1268,8 @@ class MucTab(ChatTab): self.text_win.resize( self.height - 3 - info_win_height - tab_win_height, text_width, 1, - 0) - self.text_win.rebuild_everything(self._text_buffer) + 0, self._text_buffer, force=self.ui_config_changed) + self.ui_config_changed = False self.info_header.resize( 1, self.width, self.height - 2 - info_win_height - tab_win_height, 0) @@ -1314,7 +1314,7 @@ class MucTab(ChatTab): Tab.tab_win_height(), 1, 1, 9 * (self.width // 10)) self.text_win.resize( self.height - 3 - self.core.information_win_size - - Tab.tab_win_height(), text_width, 1, 0) + Tab.tab_win_height(), text_width, 1, 0, self._text_buffer) self.info_header.resize( 1, self.width, self.height - 2 - self.core.information_win_size - Tab.tab_win_height(), 0) diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py index e24b5521..b07c7b65 100644 --- a/poezio/tabs/privatetab.py +++ b/poezio/tabs/privatetab.py @@ -214,8 +214,8 @@ class PrivateTab(OneToOneTab): self.text_win.resize( self.height - 2 - info_win_height - tab_win_height, self.width, 0, - 0) - self.text_win.rebuild_everything(self._text_buffer) + 0, self._text_buffer, force=self.ui_config_changed) + self.ui_config_changed = False self.info_header.resize( 1, self.width, self.height - 2 - info_win_height - tab_win_height, 0) diff --git a/poezio/tabs/rostertab.py b/poezio/tabs/rostertab.py index 6dd48726..66aff2b1 100644 --- a/poezio/tabs/rostertab.py +++ b/poezio/tabs/rostertab.py @@ -434,7 +434,9 @@ class RosterInfoTab(Tab): roster_width) self.information_win.resize( self.height - 1 - tab_win_height - contact_win_h, info_width, - 0, roster_width + 1, self.core.information_buffer) + 0, roster_width + 1, self.core.information_buffer, + force=self.ui_config_changed) + self.ui_config_changed = False if display_contact_win: y = self.height - tab_win_height - contact_win_h - 1 avatar_width = contact_win_h * 2 diff --git a/poezio/windows/text_win.py b/poezio/windows/text_win.py index 31dfb637..12d90e7d 100644 --- a/poezio/windows/text_win.py +++ b/poezio/windows/text_win.py @@ -146,14 +146,15 @@ class TextWin(Win): """ self.addstr_colored(txt, y, x) - def resize(self, height: int, width: int, y: int, x: int, room: TextBuffer=None) -> None: + def resize(self, height: int, width: int, y: int, x: int, + room: Optional[TextBuffer] = None, force: bool = False) -> None: old_width: Optional[int] if hasattr(self, 'width'): old_width = self.width else: old_width = None self._resize(height, width, y, x) - if room and self.width != old_width: + if room and (self.width != old_width or force): self.rebuild_everything(room) # reposition the scrolling after resize -- cgit v1.2.3