def __init__(self, title, default_value, extend_label_width=False, label_col="blue"): super().__init__(title, extend_label_width=extend_label_width, label_col=label_col) self.value_label = Checkbox(checked=default_value)
def accept_yes(): get_app().exit(result=True) def accept_no(): get_app().exit(result=False) 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',
def handle_blueprints(): """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 BLUEPRINTS ############################################################################ # Here we list out all possible blueprints we have that will be presented # as checkboxes. blueprint_order = ['auth', 'database'] blueprints = { 'auth': Checkbox(text='Authentication against LDAP'), 'database': Checkbox(text='Database'), } blueprint_checkboxes = [] for bp in blueprint_order: blueprints[bp].checked = False blueprint_checkboxes.append(blueprints[bp]) ############################################################################ # KEY BINDINGS ############################################################################ # Key bindings for this applications: # * radio buttons use inbuilt key-bindings of up and down arrows for focus and enter for selection. # * tab and shift tab bindings to shift focus from one frame to the next. bindings = KeyBindings() bindings.add(Keys.Down)(focus_next) bindings.add(Keys.Tab)(focus_next) bindings.add(Keys.Up)(focus_previous) 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(result=True) ############################################################################ # Actually application container. ############################################################################ # We use VSplit to not utilize the entire width of the window. root_container = VSplit([ HSplit([ Frame(title='Choose which blueprints do you want?', body=HSplit(children=blueprint_checkboxes), 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(blueprints_doc) result = app.run() if result: blueprint_options = {} for blueprint_name, blueprint_checkbox in blueprints.items(): if blueprint_checkbox.checked: blueprint_handler = blueprint_handlers[blueprint_name] blueprint_options[blueprint_name] = blueprint_handler( include=True) else: blueprint_options[blueprint_name] = {'include': False} return blueprint_options else: print("Aborted!") sys.exit(0) return blueprint_options
with open(configdir + '/config.yaml') as f: cfg = yaml.load(f, Loader=yaml.FullLoader) redis = redis.Redis(host='localhost', port=cfg['redis']['port'], db=0, charset="utf-8", decode_responses=True) globalvars = { "lastcall": None, } mode = set() special = set() auto_tune = Checkbox(text="auto tune") qrz = Checkbox(text="lookup qrz") current_band_only = Checkbox(text="follow band decoder") phone = Checkbox(text="phone") cw = Checkbox(text="cw") digi = Checkbox(text="digi") mobile = Checkbox(text="Mobile (/M)".rjust(10)) qrp = Checkbox(text="Qrp (/QRP)") portable = Checkbox(text="Portable (/P)".rjust(10)) beacon = Checkbox(text="Beacon (/B)".rjust(10)) iota = Checkbox(text="iota") sat = Checkbox(text="satelite") radios = SelectList( values=[('a', ' ')]
def accept_yes(): get_app().exit(result=True) def accept_no(): get_app().exit(result=False) 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",
#!/usr/bin/env python # vim: set fileencoding=utf-8 from prompt_toolkit import Application from prompt_toolkit.layout import Layout from prompt_toolkit.key_binding import KeyBindings from prompt_toolkit.application.current import get_app from prompt_toolkit.widgets import Checkbox def exit_clicked(): get_app().exit() checkbox = Checkbox("Checkbox") layout = Layout(checkbox) # napojení na klávesové zkratky key_bindings = KeyBindings() @key_bindings.add("escape") def on_escape_press(event): """Callback funkce volaná při stisku klávesy Esc.""" event.app.exit() def main(): # vytvoření aplikace s textovým uživatelským rozhraním application = Application(
#!/usr/bin/env python # vim: set fileencoding=utf-8 from prompt_toolkit import Application from prompt_toolkit.layout import Layout from prompt_toolkit.key_binding import KeyBindings from prompt_toolkit.application.current import get_app from prompt_toolkit.widgets import Checkbox def exit_clicked(): get_app().exit() checkbox = Checkbox('Checkbox') layout = Layout(checkbox) # napojení na klávesové zkratky key_bindings = KeyBindings() @key_bindings.add('escape') def on_escape_press(event): """Callback funkce volaná při stisku klávesy Esc.""" event.app.exit() def main(): # vytvoření aplikace s textovým uživatelským rozhraním application = Application(layout=layout,