From 82d00d495b816c237cbefac3ff2387907a7f8843 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 19 Aug 2016 01:00:06 +0200 Subject: Add a "confirm" tab type This tab will be used when an external events prompts a boolean choice to a user, like a new ssl cert, or a XEP (e.g. 0070) that needs an answer, and for which a command-line interface with an info message would be a pain. --- poezio/windows/__init__.py | 3 ++- poezio/windows/confirm.py | 38 ++++++++++++++++++++++++++++++++++++++ poezio/windows/info_wins.py | 18 ++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 poezio/windows/confirm.py (limited to 'poezio/windows') diff --git a/poezio/windows/__init__.py b/poezio/windows/__init__.py index 463c27e1..06200a41 100644 --- a/poezio/windows/__init__.py +++ b/poezio/windows/__init__.py @@ -6,10 +6,11 @@ used to display information on the screen from poezio.windows.base_wins import Win from poezio.windows.data_forms import FormWin from poezio.windows.bookmark_forms import BookmarksWin +from poezio.windows.confirm import Dialog from poezio.windows.info_bar import GlobalInfoBar, VerticalGlobalInfoBar from poezio.windows.info_wins import InfoWin, XMLInfoWin, PrivateInfoWin, MucListInfoWin, \ ConversationInfoWin, DynamicConversationInfoWin, MucInfoWin, \ - ConversationStatusMessageWin, BookmarksInfoWin + ConversationStatusMessageWin, BookmarksInfoWin, ConfirmStatusWin from poezio.windows.input_placeholders import HelpText, YesNoInput from poezio.windows.inputs import Input, HistoryInput, MessageInput, CommandInput from poezio.windows.list import ListWin, ColumnHeaderWin diff --git a/poezio/windows/confirm.py b/poezio/windows/confirm.py new file mode 100644 index 00000000..591ff89a --- /dev/null +++ b/poezio/windows/confirm.py @@ -0,0 +1,38 @@ +from poezio.windows.base_wins import Win + +from poezio.theming import get_theme, to_curses_attr + +class Dialog(Win): + str_accept = " Accept " + str_refuse = " Reject " + def __init__(self, helper_text, critical=False): + self.text = helper_text + self.accept = False + self.critical = critical + + def refresh(self): + self._win.erase() + self.addstr(self.text + "\n ") + + if self.critical: + col = to_curses_attr(get_theme().COLOR_WARNING_PROMPT) + else: + col = to_curses_attr(get_theme().COLOR_TAB_NORMAL) + + if self.accept: + self.addstr(self.str_accept, col) + else: + self.addstr(self.str_accept) + + self.addstr(" ") + + if self.accept: + self.addstr(self.str_refuse) + else: + self.addstr(self.str_refuse, col) + + self._refresh() + + def toggle_choice(self): + self.accept = not self.accept + diff --git a/poezio/windows/info_wins.py b/poezio/windows/info_wins.py index 4ca72449..da470cb5 100644 --- a/poezio/windows/info_wins.py +++ b/poezio/windows/info_wins.py @@ -304,3 +304,21 @@ class BookmarksInfoWin(InfoWin): def write_remote_status(self, preferred): self.addstr('Remote storage: %s' % preferred, to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) +class ConfirmStatusWin(Win): + def __init__(self, text, critical=False): + Win.__init__(self) + self.text = text + self.critical = critical + + def refresh(self): + log.debug('Refresh: %s', self.__class__.__name__) + self._win.erase() + if self.critical: + color = get_theme().COLOR_WARNING_PROMPT + else: + color = get_theme().COLOR_INFORMATION_BAR + c_color = to_curses_attr(color) + self.addstr(self.text, c_color) + self.finish_line(color) + self._refresh() + -- cgit v1.2.3