示例#1
0
 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,
     )
示例#2
0
    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)
示例#3
0
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))
示例#4
0
文件: interface.py 项目: kiblee/tod0
    """
    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()
示例#6
0
文件: list.py 项目: jarvis394/notty
            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():