def prompt(self, args=None): return Prompt(_("Please respond '%(yes)s' or '%(no)s'") % { # TRANSLATORS: 'yes' as positive reply "yes": C_('TUI|Spoke Navigation', 'yes'), # TRANSLATORS: 'no' as negative reply "no": C_('TUI|Spoke Navigation', 'no') })
def render(self, width): """Render the widget to internal buffer. It should be max width characters wide. """ super().render(width) if self.completed: checkchar = self._key else: checkchar = " " # prepare the checkbox checkbox = TextWidget("[%s]" % checkchar) data = [] # append lines if self.title: data.append(TextWidget(_(self.title))) if self.text: data.append(TextWidget("(%s)" % self.text)) # the checkbox has two columns # [x] is one and is 3 chars wide # text is second and can occupy width - 3 - 1 (for space) chars cols = ColumnWidget([(3, [checkbox]), (width - 4, data)], 1) cols.render(width) # transfer the column widget rendered stuff to internal buffer self.draw(cols)
def __init__(self, message=None): """ :param message: password prompt question :type message: string """ super().__init__() self.title = N_("Password") self._message = message or _("Enter your passphrase") self._password = None
def refresh(self, args=None): """ Show the help. """ super().refresh(args) help_message = _("The help is not available.") if self.help_path: with open(self.help_path, 'r') as f: help_message = f.read() self.window.add_with_separator(widgets.TextWidget(help_message))
def __str__(self): """Return the string representation of the prompt.""" if not self.message and not self.options: return "" parts = [] if self.message: parts.append(_(self.message)) if self.options: opt_list = [ "'%s' %s" % (key, _(self.options[key])) for key in sorted(self.options.keys()) ] opt_str = "[%s]" % ", ".join(opt_list) parts.append(opt_str) return " ".join(parts) + ": "
def prompt(self, args=None): handler = PasswordInputHandler(source=self) if self.password_func: handler.set_pass_func(self.password_func) handler.get_input(_("Passphrase: ")) handler.wait_on_input() if not handler.input_successful(): return None self._password = handler.value # this may seem innocuous, but it's really a giant hack; we should # not be calling close() from prompt(), but the input handling code # in the TUI is such that without this very simple workaround, we # would be forever pelting users with a prompt to enter their pw self.close() return None
def _print_widget(self, widget): """Prints a widget with user interaction (when needed). Could be longer than the screen height. :param widget: widget to print :type widget: Widget instance """ # TODO: Work even for lower screen_height than 4 pos = 0 lines = widget.get_lines() num_lines = len(lines) if num_lines == 0: return prompt_height = 2 real_screen_height = self._screen_height - prompt_height if num_lines < real_screen_height: # widget plus prompt are shorter than screen height, just print the widget print("\n".join(lines)) return # long widget, print it in steps and prompt user to continue last_line = num_lines - 1 while pos <= last_line: if pos + real_screen_height > last_line: # enough space to print the rest of the widget plus regular # prompt (2 lines) for line in lines[pos:]: print(line) pos += self._screen_height - 1 else: # print part with a prompt to continue for line in lines[pos:(pos + real_screen_height)]: print(line) custom_prompt = Prompt( _("\nPress %s to continue") % Prompt.ENTER) self._ask_user_input_blocking(custom_prompt) pos += real_screen_height
def prompt(self, args=None): return Prompt(_("Press %s to exit") % Prompt.ENTER)