I'm currently implementing a sample UI for neovim, and decided to use Tkinter/python due to the popularity/simplicity of the platforms. The problem I'm having is that tkinter seems to "stack" UI updates when the window height crosses a certain threshold.
Here is a video that shows the problem.
The right window is a terminal emulator running neovim, and the left window is the Tkinter UI program connected to it. The idea is that the tkinter UI should mirror neovim terminal screen, including dimensions. In this video never take focus away from the terminal window, so the only events Tk has to process come from the connection to neovim(virtual 'nvim' events which describe screen updates)
The first part of the video shows that everything works nicely when the window height is small, but starts to lag updates when I increase the height.
Here is the code for the Tkinter program. While neovim API is very new and still in heavy development(the code may not make sense to some readers), I think the problem I'm trying to solve is close to implementing terminal emulator(using Tk text widget): it must handle large bursts of formatted text updates efficiently.
I'm very inexperienced in GUI programming. Is Tkinter a wise choice for this task? If yes, then could someone give me a hint of what I'm doing wrong?
To explain a bit what's happening: Neovim API is thread-safe, and the vim.next_event()
method blocks(without busy waiting, it uses a libuv event loop underneath) until an event is received.
When the the vim.next_event()
call returns, it will notify Tkinter thread using generate_event
, which will do the actual event processing(it also buffers events between redraw:start
and redraw:stop
to optimize screen updates).
So there are actually two event loops running in parallel, with the background event loop feeding the Tkinter event loop in a thread-safe way(the generate_event
method is one of the few that can be called from other threads)