(s, tags=(), write=editwin.write)
| 243 | # Replace the PyShell instance's write method with a wrapper, |
| 244 | # which inserts an ExpandingButton instead of a long text. |
| 245 | def mywrite(s, tags=(), write=editwin.write): |
| 246 | # Only auto-squeeze text which has just the "stdout" tag. |
| 247 | if tags != "stdout": |
| 248 | return write(s, tags) |
| 249 | |
| 250 | # Only auto-squeeze text with at least the minimum |
| 251 | # configured number of lines. |
| 252 | auto_squeeze_min_lines = self.auto_squeeze_min_lines |
| 253 | # First, a very quick check to skip very short texts. |
| 254 | if len(s) < auto_squeeze_min_lines: |
| 255 | return write(s, tags) |
| 256 | # Now the full line-count check. |
| 257 | numoflines = self.count_lines(s) |
| 258 | if numoflines < auto_squeeze_min_lines: |
| 259 | return write(s, tags) |
| 260 | |
| 261 | # Create an ExpandingButton instance. |
| 262 | expandingbutton = ExpandingButton(s, tags, numoflines, self) |
| 263 | |
| 264 | # Insert the ExpandingButton into the Text widget. |
| 265 | text.mark_gravity("iomark", tk.RIGHT) |
| 266 | text.window_create("iomark", window=expandingbutton, |
| 267 | padx=3, pady=5) |
| 268 | text.see("iomark") |
| 269 | text.update() |
| 270 | text.mark_gravity("iomark", tk.LEFT) |
| 271 | |
| 272 | # Add the ExpandingButton to the Squeezer's list. |
| 273 | self.expandingbuttons.append(expandingbutton) |
| 274 | |
| 275 | editwin.write = mywrite |
| 276 |
nothing calls this directly
no test coverage detected