Callable for original tk command that has been redirected. Returned by .register; can be used in the function registered. redir = WidgetRedirector(text) def my_insert(*args): print("insert", args) original_insert(*args) original_insert = redir.register("insert", my_i
| 118 | |
| 119 | |
| 120 | class OriginalCommand: |
| 121 | '''Callable for original tk command that has been redirected. |
| 122 | |
| 123 | Returned by .register; can be used in the function registered. |
| 124 | redir = WidgetRedirector(text) |
| 125 | def my_insert(*args): |
| 126 | print("insert", args) |
| 127 | original_insert(*args) |
| 128 | original_insert = redir.register("insert", my_insert) |
| 129 | ''' |
| 130 | |
| 131 | def __init__(self, redir, operation): |
| 132 | '''Create .tk_call and .orig_and_operation for .__call__ method. |
| 133 | |
| 134 | .redir and .operation store the input args for __repr__. |
| 135 | .tk and .orig copy attributes of .redir (probably not needed). |
| 136 | ''' |
| 137 | self.redir = redir |
| 138 | self.operation = operation |
| 139 | self.tk = redir.tk # redundant with self.redir |
| 140 | self.orig = redir.orig # redundant with self.redir |
| 141 | # These two could be deleted after checking recipient code. |
| 142 | self.tk_call = redir.tk.call |
| 143 | self.orig_and_operation = (redir.orig, operation) |
| 144 | |
| 145 | def __repr__(self): |
| 146 | return f"{self.__class__.__name__,}({self.redir!r}, {self.operation!r})" |
| 147 | |
| 148 | def __call__(self, *args): |
| 149 | return self.tk_call(self.orig_and_operation + args) |
| 150 | |
| 151 | |
| 152 | def _widget_redirector(parent): # htest # |
no outgoing calls
no test coverage detected
searching dependent graphs…