2022-12-20

Non-blocking Python window only displaying a constantly updating image

I want to develop an application that uses multiple threads to read user input from the keyboard and translate that to an image on the screen, very quickly so that it can be updated quickly enough itll look like a smooth animation. The image generation will sometimes include algorithmic further processing so i need the program to update the image on the screen while at the same time retrieving input from the terminal.

All I need is a window with an image that updates itself based on user input and algorithms while the user is using the command line spawning other windows like a video playback window(opencv) while running image processing routines and database access in the background.

inputThread
imageGeneratorThread

while Running:
    if inputThread.inputEntered:
       userInput = inputThread.getUserInput()
       img = generateImage(userInput)
       imageGeneratorThread.updateImage(img) 

I need this loop running continuously while the worker threads gather input and output results from it. There'll be any number of windows and associated threads running, turned on and off from the command line, with its own keyboard listener thread running.

Thank you for reading

I Tried:

I used pynput for the keyboard thread and it works great, its always on collecting keystrokes even if another window has focus.

Initially I tried pygame for the keyboard and graphic animations which should've worked great, but updating the screens with the keystrokes was too slow to be usuable, not sure why my other pygame project was great but I think the font subsystem on it is to blame.

The pillow library was my next goto, but its just not good for smooth animations, best I could get was another window every frame, not good enough

Then I tried the opencv imshow function which is great for displaying video files and rapidly updating images, but hangs miserably when its waiting for an input so I keep getting window not responding when the image ceases to change

Im starting to see that windows on Python needs to be on the main thread and blocking. Is there another GUI API thats thread safe and fast? Is there some lower level python library I can use in its own thread?



No comments:

Post a Comment