Widget for displaying code in CTk
| 53 | self.set_colors() |
| 54 | |
| 55 | class CTkCodeBox(customtkinter.CTkTextbox): |
| 56 | """ |
| 57 | Widget for displaying code in CTk |
| 58 | """ |
| 59 | def __init__(self, |
| 60 | master, |
| 61 | language, |
| 62 | height=200, |
| 63 | theme:str="solarized-light", |
| 64 | line_numbering:bool=True, |
| 65 | numbering_color:str=None, |
| 66 | undo:bool=True, |
| 67 | menu:bool=True, |
| 68 | menu_fg_color:str=None, |
| 69 | menu_text_color:str=None, |
| 70 | menu_hover_color:str=None, |
| 71 | wrap:bool=True, |
| 72 | select_color:str=None, |
| 73 | cursor_color:str=None, |
| 74 | **kwargs): |
| 75 | |
| 76 | super().__init__(master, undo=undo, height=height, **kwargs) |
| 77 | |
| 78 | if wrap: |
| 79 | self.configure(wrap="word") |
| 80 | if line_numbering: |
| 81 | AddLineNums(self, text_color=numbering_color) |
| 82 | if menu: |
| 83 | TextMenu(self, fg_color=menu_fg_color, text_color=menu_text_color, hover_color=menu_hover_color) |
| 84 | |
| 85 | self.select_color = select_color |
| 86 | if select_color: |
| 87 | self._textbox.config(selectbackground=self.select_color) |
| 88 | self.cursor_color = cursor_color |
| 89 | |
| 90 | if self.cursor_color: |
| 91 | self._textbox.config(insertbackground=self.cursor_color) |
| 92 | |
| 93 | self.bind('<KeyRelease>', self.update_code) # When a key is released, update the code |
| 94 | self.bind('<<ContentChanged>>', self.update_code) |
| 95 | self.bind("<Control-a>", lambda e: self.after(200, self._select_all), add=True) |
| 96 | |
| 97 | self.theme_name = theme |
| 98 | self.all_themes = list(get_all_styles()) |
| 99 | |
| 100 | self.common_langs = { |
| 101 | "python": python.PythonLexer, |
| 102 | "c": c_cpp.CLexer, |
| 103 | "cpp": c_cpp.CppLexer, |
| 104 | "c++": c_cpp.CppLexer, |
| 105 | "c#": dotnet.CSharpLexer, |
| 106 | "html": html.HtmlLexer, |
| 107 | "javascript": javascript.JavascriptLexer, |
| 108 | "xml": html.XmlLexer, |
| 109 | "css": css.CssLexer, |
| 110 | "json": data.JsonLexer, |
| 111 | "yaml": data.YamlLexer, |
| 112 | "go": go.GoLexer, |
no outgoing calls
no test coverage detected