def __init__(self, parent: tkinter.Misc, textwidget_of_tab: tkinter.Text) -> None: self.textwidget = textwidget_of_tab self.canvas = tkinter.Canvas(parent, width=40, highlightthickness=0) textwidget.use_pygments_theme(self.canvas, self._set_colors) utils.add_scroll_command(textwidget_of_tab, "yscrollcommand", self._do_update) textwidget_of_tab.bind( "<<ContentChanged>>", lambda event: textwidget_of_tab.after_idle(self._do_update), add=True, ) textwidget_of_tab.bind("<<UpdateLineNumbers>>", self._do_update, add=True) # TODO: document this? self._do_update() self.canvas.bind("<<SettingChanged:font_family>>", self._update_canvas_width, add=True) self.canvas.bind("<<SettingChanged:font_size>>", self._update_canvas_width, add=True) self._update_canvas_width() self._clicked_place: Optional[str] = None self.canvas.bind("<Button-1>", self._on_click, add=True) self.canvas.bind("<ButtonRelease-1>", self._on_unclick, add=True) self.canvas.bind("<Double-Button-1>", self._on_double_click, add=True) self.canvas.bind("<Button1-Motion>", self._on_drag, add=True)
def setup(self) -> None: utils.add_scroll_command(self.tab.textwidget, 'xscrollcommand', self.do_update) self.tab.bind('<<TabSettingChanged:max_line_length>>', self.do_update, add=True) self.tab.bind('<<SettingChanged:font_family>>', self.do_update, add=True) self.tab.bind('<<SettingChanged:font_size>>', self.do_update, add=True) self.tab.bind('<<SettingChanged:pygments_style>>', self.on_style_changed, add=True) self.tab.textwidget.bind('<Configure>', self.on_configure, add=True) self.do_update() self.on_style_changed()
def __init__(self, master: tkinter.BaseWidget, tab: tabs.FileTab) -> None: super().__init__(master) textwidget.create_peer_widget(tab.textwidget, self) self.config( width=25, exportselection=False, takefocus=False, yscrollcommand=self._update_vast, wrap='none', ) self._tab = tab self._tab.textwidget.config(highlightthickness=LINE_THICKNESS) self.tag_config('sel', foreground='', background='') # To indicate the area visible in tab.textwidget, we can't use a tag, # because tag configuration is the same for both widgets (except for # one tag that we are already abusing). Instead, we put a bunch of # frames on top of the text widget to make up a border. I call this # "vast" for "visible area showing thingies". self._vast = [ tkinter.Frame(self), tkinter.Frame(self), tkinter.Frame(self), tkinter.Frame(self), ] utils.add_scroll_command(tab.textwidget, 'yscrollcommand', self._scroll_callback) self.bind('<Button-1>', self._on_click_and_drag, add=True) self.bind('<Button1-Motion>', self._on_click_and_drag, add=True) # We want to prevent the user from selecting anything in self, because # of abusing the 'sel' tag. Binding <Button-1> and <Button1-Motion> # isn't quite enough. self.bind('<Button1-Enter>', self._on_click_and_drag, add=True) self.bind('<Button1-Leave>', self._on_click_and_drag, add=True) self.bind('<<SettingChanged:font_family>>', self.set_font, add=True) self.bind('<<SettingChanged:font_size>>', self.set_font, add=True) tab.bind('<<TabSettingChanged:indent_size>>', self.set_font, add=True) self.set_font() # Make sure that 'sel' tag stays added even when text widget becomes empty tab.textwidget.bind('<<ContentChanged>>', self._update_sel_tag, add=True) # don't know why after_idle doesn't work. Adding a timeout causes # issues with tests. if 'pytest' not in sys.modules: self.after(50, self._scroll_callback)
def on_new_tab(tab: tabs.Tab) -> None: if isinstance(tab, tabs.FileTab): # needed because pygments_lexer might change def on_lexer_changed(junk: object = None) -> None: assert isinstance(tab, tabs.FileTab) # f u mypy highlighter.set_lexer(tab.settings.get("pygments_lexer", LexerMeta)()) highlighter = Highlighter(tab.textwidget) tab.bind("<<TabSettingChanged:pygments_lexer>>", on_lexer_changed, add=True) on_lexer_changed() utils.bind_with_data(tab.textwidget, "<<ContentChanged>>", highlighter.on_change, add=True) utils.add_scroll_command( tab.textwidget, "yscrollcommand", debounce(tab, highlighter.highlight_visible, 100) ) highlighter.highlight_visible()
def __init__(self, textwidget: tkinter.Text) -> None: self.textwidget = textwidget self.textwidget.bind("<<CursorMoved>>", self._on_cursor_moved, add=True) self.textwidget.bind("<<UnderlinerHidePopup>>", self._hide_message_label, add=True) self.textwidget.tag_bind("underline_common", "<Enter>", self._on_mouse_enter) self.textwidget.tag_bind("underline_common", "<Leave>", self._hide_message_label) utils.add_scroll_command(textwidget, "yscrollcommand", self._hide_message_label) self._message_label: Optional[tkinter.Label] = None self._message_tag: Optional[str] = None self._tag2underline: Dict[str, Underline] = {}
def on_new_tab(tab: tabs.Tab) -> None: if isinstance(tab, tabs.FileTab): tab.textwidget.bind("<<ContentChanged>>", partial(update_url_underlines, tab), add=True) utils.add_scroll_command(tab.textwidget, "yscrollcommand", partial(update_url_underlines, tab)) update_url_underlines(tab) tab.textwidget.tag_bind( "underline:urls", "<<Urls:OpenWithMouse>>", partial(open_the_url, tab, "current"), add=True, ) tab.textwidget.bind("<<Urls:OpenWithKeyboard>>", partial(open_the_url, tab, "insert"), add=True)
def __init__(self, parent: tkinter.Misc, textwidget_of_tab: tkinter.Text) -> None: self.textwidget = textwidget_of_tab self.canvas = tkinter.Canvas(parent, width=40) textwidget.use_pygments_theme(self.canvas, self._set_colors) utils.add_scroll_command(textwidget_of_tab, 'yscrollcommand', self._do_update) textwidget_of_tab.bind('<<ContentChanged>>', self._do_update, add=True) self._do_update() self.canvas.bind('<<SettingChanged:font_family>>', self._update_canvas_width, add=True) self.canvas.bind('<<SettingChanged:font_size>>', self._update_canvas_width, add=True) self._update_canvas_width() self._clicked_place: Optional[str] = None self.canvas.bind('<Button-1>', self._on_click, add=True) self.canvas.bind('<ButtonRelease-1>', self._on_unclick, add=True) self.canvas.bind('<Double-Button-1>', self._on_double_click, add=True) self.canvas.bind('<Button1-Motion>', self._on_drag, add=True)