Wednesday, 15 June 2011

python - Why does Tkinter text widget "lags" updates for increased window heights? -



python - Why does Tkinter text widget "lags" updates for increased window heights? -

i'm implementing sample ui neovim, , decided utilize tkinter/python due popularity/simplicity of platforms. problem i'm having tkinter seems "stack" ui updates when window height crosses threshold.

here video shows problem.

the right window terminal emulator running neovim, , left window tkinter ui programme connected it. thought tkinter ui should mirror neovim terminal screen, including dimensions. in video never take focus away terminal window, events tk has process come connection neovim(virtual 'nvim' events describe screen updates)

the first part of video shows works nicely when window height small, starts lag updates when increment height.

here code tkinter program. while neovim api new , still in heavy development(the code may not create sense readers), think problem i'm trying solve close implementing terminal emulator(using tk text widget): must handle big bursts of formatted text updates efficiently.

i'm inexperienced in gui programming. tkinter wise selection task? if yes, give me hint of i'm doing wrong?

to explain bit what's happening: neovim api thread-safe, , vim.next_event() method blocks(without busy waiting, uses libuv event loop underneath) until event received.

when the vim.next_event() phone call returns, notify tkinter thread using generate_event, actual event processing(it buffers events between redraw:start , redraw:stop optimize screen updates).

so there 2 event loops running in parallel, background event loop feeding tkinter event loop in thread-safe way(the generate_event method 1 of few can called other threads)

i double check is, in fact, tkinter that's hold up. way writing out terminal when event.

but take closer problem:

t = thread(target=get_nvim_events, args=(self.nvim_events, self.vim, self.root,))

threads not play nicely event loops - of tkinter has one. i'm not sure if neovim api setup utilize callbacks, that's typically how want propagate changes.

since you're unfamiliar gui programming i'm going assume you're unfamiliar thought of event loops. basically, imagine have code looks this:

while true: if something_to_do: do_it_now()

obviously that's busy loop , fire cpu, typically event loop going block or setup callbacks os, allows relinquish cpu , when interesting happens os like, "someone clicked here," or "someone pressed key," or "hey, told me wake now!"

so job gui developer jack event loop. don't care when happens - want respond it. tkinter can .after methods see "non-event callbacks". might selection .after_idle method:

registers callback called when scheme idle. callback called there no more events process in mainloop. callback called 1 time each phone call after_idle.

this means won't block key press or mouse click, , run 1 time tkinter has finished processing other stuff (e.g. drawing, calling callbacks, etc.)

i expect might happening thread , mainloop having issues (possibly gil). looked around didn't see obvious, want effect of:

def do_something(arg): # `arg` here def event_happened(event_args): #whatever args event generates root.after_idle(lambda: do_something(event_args)) vim.bind("did_something", event_happened)

of course, it's possible can bypass event loop altogether , have event want.

python user-interface tkinter tk neovim

No comments:

Post a Comment