def set_not_saved(self, text: tk.Text) -> None: """ When you edit the file, this method registers that you have unsaved changes. :param text: The text object to edit :type text: tk.Text """ text.tag_remove('search', '1.0', tk.END) global saved saved = False
def code_color(text: tk.Text, style=None): """color_config(text) p = Percolator(text) d = ColorDelegator() p.insertfilter(d)""" code_color_object = get_style_by_name(style or highlight_name) text.config(bg=code_color_object.background_color, bd=0) try: if not code_color_object.highlight_color: raise AttributeError text.config(selectbackground=code_color_object.highlight_color) except AttributeError: text.config(selectbackground='blue') code_color_config = code_color_object.styles black_colors = ('#000000', '#202020', '#232629', '#111111', '#2f1e2e', '#1e1e27', '#272822', '#002b36') if text.cget('bg') in black_colors: text.config(insertbackground='white', fg='white') else: text.config(insertbackground='black', fg='black') for i in range(count): text.tag_remove(i, 0.0, tk.END) def colorize(*args): global count row1, col1 = args[0].start row1, col1 = str(row1), str(col1) row2, col2 = args[0].end row2, col2 = str(row2), str(col2) start = ".".join((row1, col1)) end = ".".join((row2, col2)) text.tag_add(str(count), start, end) try: try: text.tag_config(str(count), foreground=args[1].replace(':', ' ').split(' ')[-1], font=args[2]) except IndexError: text.tag_config(str(count), foreground=args[1].replace(':', ' ').split(' ')[-1]) except tk.TclError: try: text.tag_config(str(count), foreground=args[1].replace(':', ' ').split(' ')[0]) except tk.TclError: text.tag_config(str(count), font=(args[1].replace(':', ' ').split(' ')[-1], font_size + 1)) count += 1 try: for i in tokenize.tokenize( io.BytesIO(text.get(1.0, tk.END).encode("utf-8")).readline): if i.type == 1: if i.string in keyword.kwlist: colorize(i, code_color_config[Keyword]) elif i.string in dir(builtins): colorize(i, code_color_config[Name.Builtin]) elif i.string in ['self', 'cls']: colorize( i, code_color_config[Keyword.Type] or code_color_config[Keyword]) else: if text.cget('bg') not in black_colors: colorize(i, 'black') else: colorize(i, 'white') if i.type == tokenize.STRING: colorize(i, code_color_config[String]) elif i.type == tokenize.NUMBER: colorize(i, code_color_config[Number]) elif i.type == tokenize.COMMENT: if text.cget('bg') in black_colors: colorize( i, code_color_config[Comment.Special] or code_color_config[Comment]) else: colorize(i, code_color_config[Comment]) elif i.type == 53: if i.string == "," or i.string == "." or i.string == ":": colorize(i, code_color_config[Keyword]) elif i.string == "(" or i.string == ")" or i.string == "[" \ or i.string == "]" or i.string == "{" or i.string == "}": colorize(i, "darkred") else: colorize(i, "green") except (tokenize.TokenError, SyntaxError): pass