Delegator for syntax highlighting (text coloring). Instance variables: delegate: Delegator below this one in the stack, meaning the one this one delegates to. Used to track state: after_id: Identifier for scheduled after event, which is a
| 106 | |
| 107 | |
| 108 | class ColorDelegator(Delegator): |
| 109 | """Delegator for syntax highlighting (text coloring). |
| 110 | |
| 111 | Instance variables: |
| 112 | delegate: Delegator below this one in the stack, meaning the |
| 113 | one this one delegates to. |
| 114 | |
| 115 | Used to track state: |
| 116 | after_id: Identifier for scheduled after event, which is a |
| 117 | timer for colorizing the text. |
| 118 | allow_colorizing: Boolean toggle for applying colorizing. |
| 119 | colorizing: Boolean flag when colorizing is in process. |
| 120 | stop_colorizing: Boolean flag to end an active colorizing |
| 121 | process. |
| 122 | """ |
| 123 | |
| 124 | def __init__(self): |
| 125 | Delegator.__init__(self) |
| 126 | self.init_state() |
| 127 | self.prog = prog |
| 128 | self.idprog = idprog |
| 129 | self.LoadTagDefs() |
| 130 | |
| 131 | def init_state(self): |
| 132 | "Initialize variables that track colorizing state." |
| 133 | self.after_id = None |
| 134 | self.allow_colorizing = True |
| 135 | self.stop_colorizing = False |
| 136 | self.colorizing = False |
| 137 | |
| 138 | def setdelegate(self, delegate): |
| 139 | """Set the delegate for this instance. |
| 140 | |
| 141 | A delegate is an instance of a Delegator class and each |
| 142 | delegate points to the next delegator in the stack. This |
| 143 | allows multiple delegators to be chained together for a |
| 144 | widget. The bottom delegate for a colorizer is a Text |
| 145 | widget. |
| 146 | |
| 147 | If there is a delegate, also start the colorizing process. |
| 148 | """ |
| 149 | if self.delegate is not None: |
| 150 | self.unbind("<<toggle-auto-coloring>>") |
| 151 | Delegator.setdelegate(self, delegate) |
| 152 | if delegate is not None: |
| 153 | self.config_colors() |
| 154 | self.bind("<<toggle-auto-coloring>>", self.toggle_colorize_event) |
| 155 | self.notify_range("1.0", "end") |
| 156 | else: |
| 157 | # No delegate - stop any colorizing. |
| 158 | self.stop_colorizing = True |
| 159 | self.allow_colorizing = False |
| 160 | |
| 161 | def config_colors(self): |
| 162 | "Configure text widget tags with colors from tagdefs." |
| 163 | for tag, cnf in self.tagdefs.items(): |
| 164 | self.tag_configure(tag, **cnf) |
| 165 | self.tag_raise('sel') |
no outgoing calls
no test coverage detected
searching dependent graphs…