def get_root_container(self) -> Dialog: sort_radiolist = RadioList([(sort_method, sort_method.column_name) for sort_method in ScoreSort]) def ok_handler() -> None: self._selected_sort_setter(sort_radiolist.current_value) self.multi_screen.clear_floating() def cancel_handler() -> None: self.multi_screen.clear_floating() return Dialog( title="Sort By", body=HSplit( [ Label(text="Select the column to sort by", dont_extend_height=True), sort_radiolist, ], padding=1, ), buttons=[ Button(text="Okay", handler=ok_handler), Button(text="Cancel", handler=cancel_handler), ], with_background=True, )
def radiolist_dialog(title='', text='', ok_text='Ok', cancel_text='Cancel', values=None, style=None, async_=False): """ Display a simple list of element the user can choose amongst. Only one element can be selected at a time using Arrow keys and Enter. The focus can be moved between the list and the Ok/Cancel button with tab. """ def ok_handler(): get_app().exit(result=radio_list.current_value) radio_list = RadioList(values) dialog = Dialog( title=title, body=HSplit([ Label(text=text, dont_extend_height=True), radio_list, ], padding=1), buttons=[ Button(text=ok_text, handler=ok_handler), Button(text=cancel_text, handler=_return_none), ], with_background=True) return _run_dialog(dialog, style, async_=async_)
def get_root_container(self) -> Dialog: difficulty_store = DifficultyPresets() with difficulty_store: difficulty_names = difficulty_store.get_difficulty_names( self._selected_game_getter().game_name) difficulty_radiolist = RadioList([(difficulty, difficulty) for difficulty in difficulty_names]) def ok_handler() -> None: self._selected_difficulty_setter( difficulty_radiolist.current_value) self.multi_screen.clear_floating() def cancel_handler() -> None: self.multi_screen.clear_floating() return Dialog( title="Difficulty", body=HSplit( [ Label(text="Select a difficulty", dont_extend_height=True), difficulty_radiolist, ], padding=1, ), buttons=[ Button(text="Okay", handler=ok_handler), Button(text="Cancel", handler=cancel_handler), ], with_background=True, )
def radiolist_dialog(title='', text='', ok_text='Ok', cancel_text='Cancel', values=None, style=None, async_=False): """ Display a simple message box and wait until the user presses enter. """ def ok_handler(): get_app().exit(result=radio_list.current_value) radio_list = RadioList(values) dialog = Dialog(title=title, body=HSplit([ Label(text=text, dont_extend_height=True), radio_list, ], padding=1), buttons=[ Button(text=ok_text, handler=ok_handler), Button(text=cancel_text, handler=_return_none), ], with_background=True) return _run_dialog(dialog, style, async_=async_)
def radiolist_dialog(title: AnyFormattedText = '', text: AnyFormattedText = '', ok_text: str = 'Ok', cancel_text: str = 'Cancel', values: Optional[List[Tuple[_T, AnyFormattedText]]] = None, style: Optional[BaseStyle] = None) -> Application[_T]: """ Display a simple list of element the user can choose amongst. Only one element can be selected at a time using Arrow keys and Enter. The focus can be moved between the list and the Ok/Cancel button with tab. """ if values is None: values = [] def ok_handler() -> None: get_app().exit(result=radio_list.current_value) radio_list = RadioList(values) dialog = Dialog(title=title, body=HSplit([ Label(text=text, dont_extend_height=True), radio_list, ], padding=1), buttons=[ Button(text=ok_text, handler=ok_handler), Button(text=cancel_text, handler=_return_none), ], with_background=True) return _create_app(dialog, style)
async def prompt_radio_list(self, values, title, header, allow_other=True): result = ImbTuiResult() input_done = asyncio.Event() def ok_handler() -> None: result.value = radio_list.current_value input_done.set() def back_handler() -> None: result.back_selected = True input_done.set() def other_handler() -> None: result.other_selected = True input_done.set() buttons = [ Button(text='Ok', handler=ok_handler), Button(text='Back', handler=back_handler), ] if allow_other: buttons.append(Button(text='Other', handler=other_handler)) radio_list = RadioList(list(enumerate(values))) dialog = Dialog( title=title, body=HSplit([ Label(text=HTML(" <b>{}</b>".format(header)), dont_extend_height=True), radio_list, ], padding=1), buttons=buttons, modal=False, ) # disable a_reverse style applied to dialogs dialog.container.container.content.style = "" self.app_frame.body = HSplit([ # Window(FormattedTextControl(HTML('<b>Kubernetes Config</b>')), align=WindowAlign.CENTER, height=1), # TODO: screen header Window(), dialog, Window() ]) self.app.invalidate() self.app.layout.focus(self.app_frame) await input_done.wait() return result
def __init__(self, event): kb = KeyBindings() def ok_handler(): sort_by = self.radio_list.current_value['sort_by'] order = self.radio_list.current_value['order'] SortOrder.sort_by = sort_by SortOrder.order = order root_container.floats.pop() event.app.layout = Layout(root_container.create(), focused_element=servers.content) ButtonManager.prev_button = event.app.layout.current_window def cancel_handler(): root_container.floats.pop() root_container.float_container.key_bindings = None event.app.layout.focus(ButtonManager.prev_button) ok_button = Button(text='OK', handler=ok_handler) cancel_button = Button(text='Cancel', handler=cancel_handler) self.radio_list = RadioList(values=[({ 'sort_by': 'name', 'order': 'asc' }, 'Name'), ({ 'sort_by': 'name', 'order': 'desc' }, 'Name - Desc' ), ({ 'sort_by': 'timestamp', 'order': 'asc' }, 'Time Added'), ({ 'sort_by': 'timestamp', 'order': 'desc' }, 'Time Added - Desc')]) kb = self.radio_list.control.key_bindings @kb.add('j') def down(event): self.radio_list._selected_index = min( len(self.radio_list.values) - 1, self.radio_list._selected_index + 1) @kb.add('k') def up(event): self.radio_list._selected_index = max( 0, self.radio_list._selected_index - 1) @kb.add('g', 'g') def top(event): self.radio_list._selected_index = 0 @kb.add('G') def bottom(event): self.radio_list._selected_index = len(self.radio_list.values) - 1 self.dialog = Dialog(title='Sort', body=self.radio_list, buttons=[ok_button, cancel_button], width=D(preferred=80), with_background=True, modal=True) root_container.float_container.key_bindings = kb root_container.floats.append(Float(self.dialog)) event.app.layout.focus(self.dialog)
def main(): """Entrypoint for first interaction with user. Ask user to choose type of pypackage. NOTE: We're using python-prompt-toolkit which is both powerful and complicated, so we try to document its use asmuch as possible. """ ############################################################################ # LIST OF APPLICATIONS ############################################################################ # Here we list out all possible applications we have that will be presented # as radio buttons. package_radios = RadioList(values=[ # Tuple format: ("Why is this used? This is presented to the user.") ("package_simple", "Simple Python App"), # ("package_flask", "Simple Flask App"), ("package_blueprints", "Flask App with Blueprints"), ]) ############################################################################ # KEY BINDINGS ############################################################################ # Key bindings for this applications: # * radio buttons use key-bindings of up and down arrows for focus. (comes inbuilt) # * radio buttons use key-bindings of Enter to select. (comes inbuilt) # * tab and shift tab bindings to shift focus from one frame to the next. bindings = KeyBindings() bindings.add(Keys.Tab)(focus_next) bindings.add(Keys.BackTab)(focus_previous) # CTRL-C to quit the prompt-app. @bindings.add("c-c") def exit_c(event): """Ctrl-C to quit.""" event.app.exit(result=False) # End App. def exit_app(): get_app().exit(True) ############################################################################ # Actually application container. ############################################################################ # We use VSplit to not utilize the entire width of the window. root_container = VSplit([ HSplit( [ Frame( title="Choose which package-type do you want?", body=package_radios, width=80, ), Button("Done", handler=exit_app), ], padding=1, ) ]) layout = Layout(root_container) app = Application(layout=layout, key_bindings=bindings, full_screen=False) ############################################################################ # Actually application container. ############################################################################ print(main_doc) result = app.run() if result: cli_package.main(package_radios.current_value) else: print("Aborted!") sys.exit(0)
def do_exit(): get_app().exit(result=False) yes_button = Button(text='Yes', handler=accept_yes) no_button = Button(text='No', handler=accept_no) textfield = TextArea(lexer=PygmentsLexer(HtmlLexer)) checkbox1 = Checkbox(text='Checkbox') checkbox2 = Checkbox(text='Checkbox') radios = RadioList(values=[ ('Red', 'red'), ('Green', 'green'), ('Blue', 'blue'), ('Orange', 'orange'), ('Yellow', 'yellow'), ('Purple', 'Purple'), ('Brown', 'Brown'), ]) animal_completer = WordCompleter([ 'alligator', 'ant', 'ape', 'bat', 'bear', 'beaver', 'bee', 'bison', 'butterfly', 'cat', 'chicken', 'crocodile', 'dinosaur', 'dog', 'dolphin', 'dove', 'duck', 'eagle', 'elephant', 'fish', 'goat', 'gorilla', 'kangaroo', 'leopard', 'lion', 'mouse', 'rabbit', 'rat', 'snake', 'spider', 'turkey', 'turtle', ], ignore_case=True) root_container = HSplit([ VSplit([ Frame(body=Label(text='Left frame\ncontent')),
registration_dialog = Dialog( title="Registration", body=HSplit([ Label("Team Name:"), registration_input_field, ]), buttons=[ Button(text="Submit", handler=lambda :registration_submit_handler(None)) ]) ############################# ## Rusults Selection Dialog ############################# results_select = RadioList([(None, None)]) def show_results_select_dialog(): output_field.text = "Getting submission information..." loop = asyncio.get_event_loop() loop.create_task(async_show_results_select_dialog()) async def async_show_results_select_dialog(): loop = asyncio.get_event_loop() auth = HTTPBasicAuth(registered_team_name, registered_auth_token) response = await loop.run_in_executor( None, lambda: requests.get("http://" + host + "/submissions/list", auth=auth))
def __init__(self, event): def dialog_opener(authtype, auth={}): if authtype == 'basic': BasicAuthDialog(event, auth) elif authtype == 'digest': DigestAuthDialog(event, auth) def ok_handler(): root_container.floats.pop() authtype = self.radio_list.current_value['authtype'] dialog_opener(authtype) def cancel_handler(): root_container.floats.pop() root_container.float_container.key_bindings = None event.app.layout.focus(ButtonManager.prev_button) kb = KeyBindings() server = db.fetch_one(name=ButtonManager.current_button) if server.auth: auth = json.loads(server.auth) auth_type = auth.get('type') dialog_opener(auth_type, auth=auth) else: ok_button = Button(text='OK', handler=ok_handler) cancel_button = Button(text='Cancel', handler=cancel_handler) self.radio_list = RadioList(values=[({ 'authtype': 'basic' }, 'Basic'), ({ 'authtype': 'digest' }, 'Digest')]) kb = self.radio_list.control.key_bindings @kb.add('j') def down(event): self.radio_list._selected_index = min( len(self.radio_list.values) - 1, self.radio_list._selected_index + 1) @kb.add('k') def up(event): self.radio_list._selected_index = max( 0, self.radio_list._selected_index - 1) @kb.add('g', 'g') def top(event): self.radio_list._selected_index = 0 @kb.add('G') def bottom(event): self.radio_list._selected_index = len( self.radio_list.values) - 1 self.dialog = Dialog(title='Select auth type', body=self.radio_list, buttons=[ok_button, cancel_button], width=D(preferred=80), with_background=True, modal=True) root_container.float_container.key_bindings = kb root_container.floats.append(Float(self.dialog)) event.app.layout.focus(self.dialog)
return "User ID: {}\nAccount: {}\nCaller ARN: {}".format( caller_identity["UserId"], caller_identity["Account"], caller_identity["Arn"], ) def do_exit(): get_app().exit(result=False) console_area = Frame(body=TextArea()) service_radio = RadioList(values=[ ("ec2", "ec2"), ("s3", "s3"), ("vpc", "vpc"), ("route53", "route53"), ("ecr", "ecr"), ("blah", "blah"), ], ) service_selection_frame = service_radio root_container = HSplit([ Window(FormattedTextControl("AWS > "), height=1, style="reverse"), service_selection_frame, console_area, Frame( title="Caller Identity", body=Window( FormattedTextControl( text=get_caller_identity(), focusable=False, ),
def _get_answer_widget(self): return RadioList(self.answers)
#ignore search command_container.text = command_container.text + "/" command_container.buffer.cursor_right(len(command_container.text)) return layout.focus(command_container) command_container.text = "/" command_container.buffer.cursor_right() #content windows namespaceList = namespaces.list() nodesList = nodes.list() namespaceWindow = RadioList(namespaceList) windowHeight = len(namespaceList) + 2 if windowHeight > 8: windowHeight = 8 namespaceWindowFrame = Frame(namespaceWindow, title="Namespaces", height=windowHeight, width=namespaceWindowSize) nodeListArea = RadioList(nodesList) nodeWindowFrame = Frame(nodeListArea, title="Nodes", height=windowHeight, width=nodeWindowSize) #check permissions for nodes #normal OpenShift user does not see nodes nor namespaces other than his/her own.
spinner.start("rendering interface ...") class FormatText(Processor): def apply_transformation(self, input_): fragments = to_formatted_text( ANSI(fragment_list_to_text(input_.fragments))) return Transformation(fragments) # layout. search_field = SearchToolbar() # for reverse search. output_field = Buffer() channels_window = RadioList(utils.get_channels()) general_ch = utils.config['channels']['general'] channels_window.current_value = general_ch channels_frame = Frame(channels_window, title="channels", width=23) output_window = Frame(Window(BufferControl(buffer=output_field, focusable=False, input_processors=[FormatText()]), wrap_lines=True), title="#general") input_field = TextArea( height=1, prompt='> ', multiline=False, wrap_lines=False, search_field=search_field,
#search both pods and output window at the same time if (len(command_container.text)>0): #if length of text is command container is > 0 # assume that command is currently written #ignore search command_container.text=command_container.text+"/" command_container.buffer.cursor_right(len(command_container.text)) return layout.focus(command_container) command_container.text="/" command_container.buffer.cursor_right() #content windows namespaceWindow = RadioList(namespaces.list()) namespaceWindowFrame= Frame(namespaceWindow,title="Namespaces",height=8,width=namespaceWindowSize) nodeListArea = RadioList(nodes.list()) nodeWindowFrame= Frame(nodeListArea,title="Nodes",height=8,width=nodeWindowSize) upper_left_container = VSplit([namespaceWindowFrame, #HorizontalLine(), #Window(height=1, char='-'), nodeWindowFrame]) def setCommandWindowTitle(): selected_namespace=namespaceWindow.current_value selected_node=nodeListArea.current_value selected_pod=str(podListArea.buffer.document.current_line).strip()
def do_exit(): get_app().exit(result=False) yes_button = Button(text="Yes", handler=accept_yes) no_button = Button(text="No", handler=accept_no) textfield = TextArea(lexer=PygmentsLexer(HtmlLexer)) checkbox1 = Checkbox(text="Checkbox") checkbox2 = Checkbox(text="Checkbox") radios = RadioList(values=[ ("Red", "red"), ("Green", "green"), ("Blue", "blue"), ("Orange", "orange"), ("Yellow", "yellow"), ("Purple", "Purple"), ("Brown", "Brown"), ]) animal_completer = WordCompleter( [ "alligator", "ant", "ape", "bat", "bear", "beaver", "bee", "bison",