Preventing a GUI app from stealing stdin+stdout/the keyboard and console


#1

Greetings, people of Juce.

I'm continuing with my exploits in wrapping Juce in Cython - so far very successfully.    Cython is cool!

I'm starting to integrate it with the full application, and I've just realized that Juce grabs stdin and stdout when it starts operation, so I can no longer control my console application (which contains a Juce GUI application) from the keyboard.

I'm not entirely sure of the cause, but the results are that I no longer get any data from Python's sys.stdin.readline() - when a Juce application is running as a shared library loaded into Python.

I can run parts of Juce perfectly well - for example, I'm able to do audio stuff.  It's when the JUCEApplication starts up that stdin no longer responds.

 

(I'm running on OS/X but this will be working also on Linux and Windows...)

 

If that's not possible, is there a way to get keystrokes, even if there is no window showing - or even created?  Actually, I'm interested in how to do that, regardless.


#2

I'm starting to fear that the answer is "it's impossible" which would be catastrophic for me.

Let me spell out where I'm at.  

I'm working on a cross-platform console application called echomesh - for the "internet of things".  It's a console application.  As part of it, I have a visualizer for your lights - a simple GUI with a large number of regions representing lights changing color.  However, you might or might not even have that visualizer running - the program current works even on "headless" machines controlling hardware lights.

I originally used Python's Tk to do the visualizer, but it turned out to be very slow.  So I went to using Juce - in an external process.  And once I had that, I started using it for the audio too.

This sort of worked, but the socket connection between the two used a lot of mechanism, and having that second process just wasn't reliable.

So I started using Juce from within Python, as a shared library, using Cython.  I did a great deal of exploratory development to convince myself it was possible before I really put work into it, checking that I could do audio and pop up windows  - and of course I asked here - BUT the one thing I didn't check before I put the huge amount of work in was that I'd still be able to get familiar old keystrokes from my controlling console app in the terminal... and I'm only realizing this in the very last stages as I put the very last parts together.

It has to be doable in principle... Tk did it perfectly fine on multiple platforms and Tk is more or less the same thing as Juce.  If I run Tk, I continue to get keystrokes if the console is in the front, and Tk gets the keystrokes if its window is in the front.

 

But the hints I see on the forum are not encouraging.

Do let me know!

 

I'm really not picky.  I'd be perfectly happy with, e.g., an option to compile Juce so it simply never interacted with the keyboard at all...


#3

Quite a bit of progress on this.

 

I can in fact read stdin and out from Juce BUT something about calling the Juce application prevents the Python stdin and stdout from functioning.  I think this will work for the moment by reading and writing in C++ and shipping the results back to Python.  Longer term - curses...!


#4

It was all doing things I expected, I just didn't put it together.

The call to "my equivalent of main" didn't come back - as I expected.  But it was holding Python's GIL... so eventually everything ground to a halt!  Fixing that and it all worked...