Exemple #1
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        # the '#' character seems to be a 'numbersign' in tk
        tab.textwidget.bind('<numbersign>',
                            functools.partial(comment_or_uncomment, tab),
                            add=True)
Exemple #2
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        get_config_and_apply_to_tab(tab)
        tab.bind('<<PathChanged>>',
                 partial(get_config_and_apply_to_tab, tab),
                 add=True)
Exemple #3
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if not isinstance(tab, tabs.FileTab):
        return

    overview = Overview(tab.right_frame, tab)
    textwidget.use_pygments_theme(overview, overview.set_colors)
    overview.pack(fill='y', expand=True)
Exemple #4
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        underliner = _Underliner(tab.textwidget)
        utils.bind_with_data(tab,
                             '<<SetUnderlines>>',
                             underliner.set_underlines,
                             add=True)
Exemple #5
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):

        def bind_callback(event: 'tkinter.Event[tkinter.Misc]') -> None:
            assert isinstance(tab, tabs.FileTab)  # because mypy is awesome
            tab.textwidget.after_idle(after_enter, tab.textwidget)

        tab.textwidget.bind('<Return>', bind_callback, add=True)
Exemple #6
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        tab.settings.add_option('langserver',
                                None,
                                type=Optional[LangServerConfig])

        tab.bind('<<TabSettingChanged:langserver>>',
                 partial(switch_langservers, tab, False),
                 add=True)
        tab.bind('<<PathChanged>>',
                 partial(switch_langservers, tab, True),
                 add=True)
        switch_langservers(tab, False)
Exemple #7
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        tab.textwidget.bind('<<ContentChanged>>',
                            partial(update_url_underlines, tab),
                            add=True)
        update_url_underlines(tab)

        tab.textwidget.tag_bind('underline:urls',
                                '<Control-Button-1>',
                                partial(open_the_url, tab, 'current'),
                                add=True)
        tab.textwidget.bind('<Control-Return>',
                            partial(open_the_url, tab, 'insert'),
                            add=True)
Exemple #8
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        # needed because pygments_lexer might change
        def get_lexer_class() -> pygments.lexer.LexerMeta:
            assert isinstance(tab, tabs.FileTab)  # f u mypy
            return tab.settings.get('pygments_lexer', pygments.lexer.LexerMeta)

        highlighter = Highlighter(tab.textwidget, get_lexer_class)
        tab.bind('<<TabSettingChanged:pygments_lexer>>',
                 highlighter.highlight_all,
                 add=True)
        tab.textwidget.bind('<<ContentChanged>>',
                            highlighter.highlight_all,
                            add=True)
        tab.bind('<Destroy>', highlighter.on_destroy, add=True)
        highlighter.highlight_all()
Exemple #9
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if not isinstance(tab, tabs.FileTab):
        return

    tab.settings.add_option('autocomplete_chars', [], type=List[str])

    completer = AutoCompleter(tab)

    # no idea why backspace has to be bound separately
    utils.bind_with_data(tab.textwidget,
                         '<Key>',
                         completer.on_any_key,
                         add=True)
    tab.textwidget.bind('<BackSpace>', completer.on_any_key, add=True)

    utils.bind_tab_key(tab.textwidget, completer.on_tab, add=True)
    tab.textwidget.bind('<Return>', completer.on_enter, add=True)
    tab.textwidget.bind('<Escape>', completer.on_escape, add=True)
    tab.textwidget.bind('<Prior>', completer.popup.on_page_up_down, add=True)
    tab.textwidget.bind('<Next>', completer.popup.on_page_up_down, add=True)
    tab.textwidget.bind('<Up>', completer.popup.on_arrow_key_up_down, add=True)
    tab.textwidget.bind('<Down>',
                        completer.popup.on_arrow_key_up_down,
                        add=True)
    completer.popup.treeview.bind('<Button-1>',
                                  (lambda event: completer._accept()),
                                  add=True)

    # avoid weird corner cases
    tab.winfo_toplevel().bind('<FocusOut>',
                              (lambda event: completer._reject()),
                              add=True)
    tab.textwidget.bind(
        # any mouse button
        '<Button>',
        (lambda event: completer._reject()),
        add=True)

    tab.bind('<Destroy>', (lambda event: completer.popup.toplevel.destroy()),
             add=True)
Exemple #10
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        utils.bind_tab_key(tab.textwidget, on_tab_key, add=True)
Exemple #11
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        tab.settings.add_option('commands', CommandsConfig())
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        textwidget.use_pygments_theme(
            tab, partial(on_pygments_theme_changed, tab.textwidget))
        tab.textwidget.bind('<<CursorMoved>>', on_cursor_moved, add=True)
Exemple #13
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        tab.settings.add_option('insert_final_newline', True)
        tab.bind('<<Save>>', on_save, add=True)
Exemple #14
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        on_path_changed(tab)
        tab.bind('<<PathChanged>>', partial(on_path_changed, tab), add=True)
Exemple #15
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        linenumbers = LineNumbers(tab.left_frame, tab.textwidget)
        linenumbers.canvas.pack(side='left', fill='y')
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    if isinstance(tab, tabs.FileTab):
        # raymond hettinger says 90-ish
        tab.settings.add_option('max_line_length', 90)
        LongLineMarker(tab).setup()
Exemple #17
0
def on_new_tab(event: utils.EventWithData) -> None:
    tab = event.data_widget()
    assert isinstance(tab, tabs.Tab)
    StatusBar(tab.bottom_frame, tab).pack(side='bottom', fill='x')
Exemple #18
0
 def on_new_tab(self, event: utils.EventWithData) -> None:
     self._frame.pack_forget()
     event.data_widget().bind('<Destroy>', self._on_tab_closed, add=True)