texstudio-org / texstudio

TeXstudio is a fully featured LaTeX editor. Our goal is to make writing LaTeX documents as easy and comfortable as possible.
http://www.texstudio.org/
GNU General Public License v3.0
2.83k stars 345 forks source link

set a stdin other than keyboard #923

Closed Mattia541993 closed 4 years ago

Mattia541993 commented 4 years ago

I'd like to pipe the output of process to the stdin of texstudio. Is it possible? My aim is substitute the keyboard to type in the editor. Is it possible? I tried with this simple python script (time.py)

import time

while 1:
    print("foo")
    time.sleep(2)

and in the bash I run python3 time.py | texstudio but nothing happens in the editor where I open a new file with the cursor blinking on it. Is there any way?

Thank you!

Environment

MeanSquaredError commented 4 years ago

TXS (actually the underlying Qt library) does not read its input from stdin. Instead it accepts events from the corresponding windowing manager, so you have to send TXS keyboard events in the form of window events (in your case X11 events).

I just tested xdotool by sending keyboard events to TXS and it simulates keyboard input just fine. You have to send the events to the corresponding input control, though. Sending events to the main TXS window does not work. In my test I had to send it to the main edit control that holds the main document text.

xdotool type --window 90177646 --delay 100 testing

In my case 90177646 is the ID of the edit control.

Mattia541993 commented 4 years ago

Thank you for your answer, I installed xdotool, but I'm trying to figure out why I had this error: Error: Can't open display: (null). Failed creating new xdo instance. I'm looking for solutions but with no success. Which OS do you have? Have you experienced the same issue? Temporarily I solved with the pynput python library throwing a similar command after some delay.

Thank you again for your help!

MeanSquaredError commented 4 years ago

The error means that xdotool does not know which xserver to connect to and more specifically that it does not find the DISPLAY environment variable.. All modern Linux distributions with an X11 GUI set the DISPLAY variable, so you are either running xdotool from a non-gui terminal or there is something misconfigured in the startup scripts on your computer or I am just missing some other option :-)

You can solve this problem by setting the DISPLAY environment variable before calling xdotool. If your xserver is on the same computer as xdotool and you have only one screen, then you can set it via: export DISPLAY=:0 For detailed explanation on the meaning of DISPLAY you can see https://askubuntu.com/a/432257

By the way I checked the pynput library and on Linux it does pretty much the same as xdotool so there is no point in getting xdotool to work if pynput works correctly for you.

Mattia541993 commented 4 years ago

Sorry for my delay, thank you very much! I'll try and I'll let you know