Skip to content

chore(textedit): add fastwrap#615

Draft
ceccopierangiolieugenio wants to merge 7 commits intomainfrom
602-ttktextwrap-has-very-slow-performance-for-large-documents
Draft

chore(textedit): add fastwrap#615
ceccopierangiolieugenio wants to merge 7 commits intomainfrom
602-ttktextwrap-has-very-slow-performance-for-large-documents

Conversation

@ceccopierangiolieugenio
Copy link
Copy Markdown
Owner

No description provided.

@slook
Copy link
Copy Markdown
Contributor

slook commented Apr 2, 2026

It works, but after when Quit Nicotine+ always crash IndexError exception...

user@ThinkPadT420:~/Git/slook/nicotine-plus$ ./nicotine --tui
Using TTk executable: /home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk
Loaded TTk 0.49.0-a0


                                   Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkCore/ttk.py", line 189, in mainloop
    self._mainloop()
  File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkCore/ttk.py", line 236, in _mainloop
    raise e
  File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkCore/timer_unix.py", line 68, in run
    self.timeout.emit()
  File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkCore/signal.py", line 187, in emit
    slot(*args[sl], **kwargs)
  File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkCore/ttk.py", line 362, in _time_event
    total = TTkHelper.paintAll()
            ^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkCore/helper.py", line 205, in paintAll
    widget.paintEvent(canvas)
  File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkWidgets/texedit.py", line 1063, in paintEvent
    subLines = self._textWrap.screenRows(oy, h, prefetch=h)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkGui/textwrap1.py", line 371, in screenRows
    ranges = self._wrapLine(line, self._textDocument._dataLines[line])
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
IndexError: list index out of range

I think this happens because I have destroy() method in my Chatter() module which calls self.chat_view.document().clear() on program quit event.

@ceccopierangiolieugenio ceccopierangiolieugenio marked this pull request as draft April 2, 2026 08:50
@ceccopierangiolieugenio
Copy link
Copy Markdown
Owner Author

I added a quick fix, anyway, I am still reviewing the PR.

@slook
Copy link
Copy Markdown
Contributor

slook commented Apr 2, 2026

No even after applying fix 0726665 the crash happen after exit because of document().clear()

INFO:(TTk (Draw)) ttk.py:182 FPS: 0 (29 Bps)
INFO:(Thread-1 (_sigWinChThreaded)) ttk.py:373 Resize: w:238, h:61
DEBUG:(Thread-2 (mainloop)) ttk.py:194 
DEBUG:(Thread-2 (mainloop)) ttk.py:195          β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—            β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—    
DEBUG:(Thread-2 (mainloop)) ttk.py:196          β•šβ•β•β–ˆβ–ˆβ•”β•β•β•            β•šβ•β•β–ˆβ–ˆβ•”β•β•β•    
DEBUG:(Thread-2 (mainloop)) ttk.py:197             β–ˆβ–ˆβ•‘  β–„β–„  β–„ β–„β–„ β–„β–„β––β–„β––  β–ˆβ–ˆβ•‘ β–ˆ β–—β––  
DEBUG:(Thread-2 (mainloop)) ttk.py:198     β–žβ–€β–š β––β–—  β–ˆβ–ˆβ•‘ β–ˆβ–„β–„β–ˆ β–ˆβ–€β–˜  β–ˆ β–ˆ β–ˆ  β–ˆβ–ˆβ•‘ β–ˆβ–Ÿβ–˜   
DEBUG:(Thread-2 (mainloop)) ttk.py:199     β–™β–„β–žβ–β–„β–Ÿ  β–ˆβ–ˆβ•‘ β–€β–„β–„β–– β–ˆ    β–ˆ ▝ β–ˆ  β–ˆβ–ˆβ•‘ β–ˆ β–€β–„  
DEBUG:(Thread-2 (mainloop)) ttk.py:200     β–Œ    ▐  β•šβ•β•                  β•šβ•β•       
DEBUG:(Thread-2 (mainloop)) ttk.py:201       β–šβ–„β–„β–˜                                 
DEBUG:(Thread-2 (mainloop)) ttk.py:202 
DEBUG:(Thread-2 (mainloop)) ttk.py:203   Version: 0.49.0-a0
DEBUG:(Thread-2 (mainloop)) ttk.py:204 
DEBUG:(Thread-2 (mainloop)) ttk.py:205 Starting Main Loop...
DEBUG:(Thread-2 (mainloop)) ttk.py:206 screen = (os.terminal_size(columns=238, lines=61))
INFO:(TTk (Draw)) ttk.py:182 FPS: 10 (1928 Bps)
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54 Traceback (most recent call last):
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/./nicotine", line 24, in <module>
ERROR:(MainThread) ttk.py:54 sys.exit(load_module())
ERROR:(MainThread) ttk.py:54 ^^^^^^^^^^^^^^^^^^^^^^^
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/./nicotine", line 20, in load_module
ERROR:(MainThread) ttk.py:54 return pynicotine.run()
ERROR:(MainThread) ttk.py:54 ^^^^^^^^^^^^^^^^^^^^^^^
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/__init__.py", line 224, in run
ERROR:(MainThread) ttk.py:54 exit_code = application.run(ci_mode, isolated_mode)
ERROR:(MainThread) ttk.py:54 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/ttktui/__init__.py", line 45, in run
ERROR:(MainThread) ttk.py:54 return Application(ci_mode, isolated_mode).run()
ERROR:(MainThread) ttk.py:54 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/ttktui/application.py", line 92, in run
ERROR:(MainThread) ttk.py:54 while events.process_thread_events():
ERROR:(MainThread) ttk.py:54 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/events.py", line 333, in process_thread_events
ERROR:(MainThread) ttk.py:54 self.emit(event.event_name, *event.args, **event.kwargs)
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/events.py", line 276, in emit
ERROR:(MainThread) ttk.py:54 raise error
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/events.py", line 268, in emit
ERROR:(MainThread) ttk.py:54 function(*args, **kwargs)
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/ttktui/privatechat.py", line 93, in quit
ERROR:(MainThread) ttk.py:54 super().destroy()
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/ttktui/widgets/pages.py", line 61, in destroy
ERROR:(MainThread) ttk.py:54 page.destroy()
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/ttktui/widgets/chatter.py", line 191, in destroy
ERROR:(MainThread) ttk.py:54 self.chat_view.document().clear()
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkGui/textdocument.py", line 242, in clear
ERROR:(MainThread) ttk.py:54 self.setText(self._default_init_text)
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkGui/textdocument.py", line 254, in setText
ERROR:(MainThread) ttk.py:54 self.contentsChanged.emit()
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkCore/signal.py", line 187, in emit
ERROR:(MainThread) ttk.py:54 slot(*args[sl], **kwargs)
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkWidgets/texedit.py", line 765, in _documentChanged
ERROR:(MainThread) ttk.py:54 self.viewChanged.emit()
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkCore/signal.py", line 187, in emit
ERROR:(MainThread) ttk.py:54 slot(*args[sl], **kwargs)
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkWidgets/texedit.py", line 815, in _pushCursor
ERROR:(MainThread) ttk.py:54 x,y = self._textWrap.dataToScreenPosition(
ERROR:(MainThread) ttk.py:54       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54   File "/home/user/Git/slook/nicotine-plus/pynicotine/external/pyTermTk/TermTk/TTkGui/textwrap1.py", line 379, in dataToScreenPosition
ERROR:(MainThread) ttk.py:54 ranges = self._wrapLine(line, self._textDocument._dataLines[line])
ERROR:(MainThread) ttk.py:54 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
ERROR:(MainThread) ttk.py:54 
ERROR:(MainThread) ttk.py:54 IndexError
ERROR:(MainThread) ttk.py:54 : 
ERROR:(MainThread) ttk.py:54 list index out of range

It looks like it could also happen any time document().clear() is called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TTkTextWrap has very slow performance for large documents

2 participants