def _create_application(self, input: Optional[Input], output: Optional[Output]) -> Application: """ Create an `Application` instance. """ return Application( layout=self.ptpython_layout.layout, key_bindings=merge_key_bindings([ load_python_bindings(self), load_auto_suggest_bindings(), load_sidebar_bindings(self), load_confirm_exit_bindings(self), ConditionalKeyBindings( load_open_in_editor_bindings(), Condition(lambda: self.enable_open_in_editor), ), # Extra key bindings should not be active when the sidebar is visible. ConditionalKeyBindings( self.extra_key_bindings, Condition(lambda: not self.show_sidebar), ), ]), color_depth=lambda: self.color_depth, paste_mode=Condition(lambda: self.paste_mode), mouse_support=Condition(lambda: self.enable_mouse_support), style=DynamicStyle(lambda: self._current_style), style_transformation=self.style_transformation, include_default_pygments_style=False, reverse_vi_search_direction=True, input=input, output=output, )
def _create_application(self, color_depth): """ Create an `Application` instance. """ return Application( input=self.input, output=self.output, layout=create_layout( self, lexer=DynamicLexer( lambda: self._lexer if self.enable_syntax_highlighting else SimpleLexer()), input_buffer_height=self._input_buffer_height, extra_buffer_processors=self._extra_buffer_processors, extra_body=self._extra_layout_body, extra_toolbars=self._extra_toolbars), key_bindings=merge_key_bindings([ load_python_bindings(self), load_sidebar_bindings(self), load_confirm_exit_bindings(self), # Extra key bindings should not be active when the sidebar is visible. ConditionalKeyBindings( self.extra_key_bindings, Condition(lambda: not self.show_sidebar)) ]), color_depth=color_depth, paste_mode=Condition(lambda: self.paste_mode), mouse_support=Condition(lambda: self.enable_mouse_support), style=DynamicStyle(lambda: self._current_style), include_default_pygments_style=False, reverse_vi_search_direction=True)
def _get_filemanager_kb(self, fm: Filemanager): kb_active = Condition(lambda: fm.view.fileman_visible) kb = KeyBindings() @kb.add('up') def _(event: E) -> None: self._selected_index = max(0, self._selected_index - 1) @kb.add('down') def _(event: E) -> None: self._selected_index = min( len(self.values) - 1, self._selected_index + 1) @kb.add('pageup') def _(event: E) -> None: w = event.app.layout.current_window self._selected_index = max( 0, self._selected_index - len(w.render_info.displayed_lines)) @kb.add('pagedown') def _(event: E) -> None: w = event.app.layout.current_window self._selected_index = min( len(self.values) - 1, self._selected_index + len(w.render_info.displayed_lines)) @kb.add('enter') def _(event: E) -> None: logging.debug("[FM] Selected: {}".format(self.selected)) if self.selected.endswith('/'): logging.debug("[FM] Changing dir: {}".format(self.selected)) self.fm.change_dir(Path(self.selected)) elif self.selected.endswith('|'): logging.debug("[FM] TODO handle: {}".format(self.selected)) pass # can't open PIPEs and other weird types else: logging.debug("[FM] Opening: {}".format(self.selected)) self._file_handler(self.selected) @kb.add('escape') def _(event: E) -> None: fm.view.app.layout.focus(fm.cancel_button) @kb.add('<any>') def _(event: E) -> None: # We first check values after the selected value, then all values. for value in self.values[self._selected_index + 1:] + self.values: if value.startswith(event.data): self._selected_index = self.values.index(value) return return ConditionalKeyBindings(kb, filter=kb_active)
def get_view_kb(view): kb_map = view.shared_state['settings']['keybindings'] rpc_channel = view.rpc_channel kb = KeyBindings() def do(key: str): if key not in kb_map: logging.debug("[KB] Unknown special key: {}".format(key)) return if kb_map[key][0] == '.': action = kb_map[key][1:] assert action[0] != '_' do_action(view, action, {}) else: rpc_channel.edit(kb_map[key]) @kb.add('escape', '[', '1', ';', '4', 'A', eager=True) def c_s_up(_): do('c-s-up') @kb.add('escape', '[', '1', ';', '4', 'B', eager=True) def c_s_down(_): do('c-s-down') @kb.add('escape', '[', '1', ';', '6', 'D', eager=True) def c_s_left(_): do('c-s-left') @kb.add('escape', '[', '1', ';', '6', 'C', eager=True) def c_s_right(_): do('c-s-right') @kb.add('escape', filter=Condition(lambda: len(view.current_view.undo_stack) > 0)) def kb_undo(_): (action, params) = view.current_view.undo_stack.pop() do_action(view, action, params) @kb.add('<any>') def _(event): for sequence in event.key_sequence: if sequence.key in SPECIAL_KEYS: do(sequence.key) else: rpc_channel.edit('insert', {'chars': sequence.key}) return ConditionalKeyBindings( kb, filter=Condition(lambda: view.current_view is not None))
def mainloop(self): self.key_bindings = KeyBindings() @Condition def is_logging_mode(): return self.mode == LOGGING_MODE @self.key_bindings.add('up') def _(event): self.clear_screen() self.logger.show_log(decrease=True) self.output.print_info("Log Mode") print_formatted_text(HTML( '<yellow>[+] Press <blue>↑</blue> or <blue>↓</blue> to turn pages or ' '<blue>Esc</blue> to quit log mode</yellow>'), style=self.style) print_formatted_text(FormattedText(self.analog_prompt), end="") @self.key_bindings.add('down') def _(event): self.clear_screen() self.logger.show_log(increase=True) self.output.print_info("Log Mode") print_formatted_text(HTML( '<yellow>[+] Press <blue>↑</blue> or <blue>↓</blue> to turn pages or ' '<blue>Esc</blue> to quit log mode</yellow>'), style=self.style) print_formatted_text(FormattedText(self.analog_prompt), end="") @self.key_bindings.add('escape') def _(event): self.mode = NORMAL_MODE self.logger.clear() print() self.output.print_info("Back to normal mode.") self.key_bindings = ConditionalKeyBindings( key_bindings=self.key_bindings, filter=is_logging_mode) while True: text = None try: text = self.session.prompt(self.analog_prompt, style=self.style, completer=self.analog_completer, key_bindings=self.key_bindings, refresh_interval=True) self.command_parser(text) except KeyboardInterrupt: if self.mode == NORMAL_MODE: self.output.print_info( "Are you wanna exit? Type 'exit' to quit the analog.") else: self.output.print_lastLine( "Press key Esc to quit log mode.") except AddCommandError: self.add_command_help() except CommandFormatError: self.output.print_error( "Unknown command: {}. Type \"help\" for help.".format( text if text else "(Failed to read command)")) except Exception as e: if self.debug: traceback.print_exc() raise e self.output.print_error("Error: %s" % str(e))
""" global waiting_for_confirmation global prompt_window # Return to normal state waiting_for_confirmation = False prompt_window = Window() @Condition def is_not_waiting_for_confirmation(): "Enable key bindings when not waiting for confirmation" return not waiting_for_confirmation kb = ConditionalKeyBindings(kb, is_not_waiting_for_confirmation) def load_tasks(): """ Load tasks of currently focused folder """ global focus_folder global focus_index_task global tasks global task2id task_data = auth.list_tasks(all_=False, folder=folder2id[focus_index_folder])
info = False layout.focus(input_field) @kb.add('/') def _(event): global searching searching = True @Condition def notSearching(): return not searching registry = ConditionalKeyBindings(kb, notSearching) # Build a main application object. application = Application(layout=layout, key_bindings=registry, full_screen=True) def pwdmgr(_getPasswords, *args, **kwargs): global getPasswords global pageSize pageSize = kwargs.get("pageSize", 30) getPasswords = _getPasswords reloadPasswords()
style="class:topbar", ) ], height=1, style="class:topbar", ) root_container = FloatContainer(HSplit([ titlebar, body, ]), floats=[]) application = Application( layout=Layout(root_container, focused_element=sidebar), key_bindings=merge_key_bindings([ kb, ConditionalKeyBindings( key_bindings=focus_bindings, filter=Condition(lambda: not state.is_float_displaying), ), ConditionalKeyBindings( key_bindings=sidebar_bindings, filter=Condition(lambda: state.focused_window == sidebar), ), ]), mouse_support=True, full_screen=True, style=style, refresh_interval=0.5, ) def execute(): async def main():