Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] – Please, allow the selected text in the PDF to be read with the normal xclip App. #200

Closed
joaocarvalhoopen opened this issue Apr 15, 2022 · 13 comments

Comments

@joaocarvalhoopen
Copy link

joaocarvalhoopen commented Apr 15, 2022

Hello Ahrm,

What I’m asking with this enhancement is simple I have one application that I made that in every previous PDF reader that I used on Linux Ubuntu 20.04 I selected a section text then I made a Key combination and my external program would run and use xclip to extract to a file the X11 system selected text from the PDF Reader and write to a txt file. Then my Python program would read that file (in the default RAM disk /dev/shm/ ) and send it to google to text-to-speach in EN or to translate from EN to PT or in PT or Spanish, German or other language. I use this when I’m late at night and I’m to tired to read, but I need to read, or to help my daughter read and understand long text’s in other languages.

The key application is xclips, and it use normal system selected text, so there should be some way to tell QT when you select a segment of text that the text is a string in Sioyek code.

# Save X text selection to a file.
# Runs clip to get the the selected text from the GUI in X, in any GUI program.
os.system('xclip -out > ' + TEXT_SOURCE_FILE) 

Just if you are curious, my program that does text to speech or text translate and to speech is here:

Linux Translation and Text to Speech with natural voice
https://github.com/joaocarvalhoopen/Linux_Translation_and_Text_to_Speech_with_natural_voice

Thank you,

The very best regards,
João

@ahrm
Copy link
Owner

ahrm commented Apr 15, 2022

I'm not very familiar with xclip. How is that different from using clipboard?

@joaocarvalhoopen
Copy link
Author

joaocarvalhoopen commented Apr 15, 2022

Hello Ahrm,

I don’t know clipboard and I couldn't find the program under Linux, but with xclip if you run the program in a terminal, the text that is currently selected under any QT or GNOME Window APP goes or is written directly to a file if you use the above command, and that is what I use in my Python program to make Text to Speech in any PDF Reader. I don’t have experience with the QT lib but there should be same method or API in QT where um can pass the selected text, from your GUI in a similar way to if it was a selected text inside a QT component Label or Edit Text component.

Thank you,

The very best regards,
João

@ahrm
Copy link
Owner

ahrm commented Apr 15, 2022

I am still a little confused. Isn't that the same as pressing C-c after selecting the text?

@joaocarvalhoopen
Copy link
Author

joaocarvalhoopen commented Apr 15, 2022

The objective is the same to pass the selected text to a file automatically and then to drive the program text to speech but it must work with the normal X11-window manager of GNOME and QT or other under linux, I don't know about QT but I think that your Widget class that I think hinerantes from QTWidget class Must implement something similar to a QLabel like this:

/*!
    Selects text from position \a start and for \a length characters.
    \sa selectedText()
    \bold{Note:} The textInteractionFlags set on the label need to include
    either TextSelectableByMouse or TextSelectableByKeyboard.
    \since 4.7
*/
void QLabel::setSelection(int start, int length)
{
    Q_D(QLabel);
    if (d->control) {
        d->ensureTextPopulated();
        QTextCursor cursor = d->control->textCursor();
        cursor.setPosition(start);
        cursor.setPosition(start + length, QTextCursor::KeepAnchor);
        d->control->setTextCursor(cursor);
    }
}

line 812 from the file https://github.com/openwebos/qt/blob/master/src/gui/widgets/qlabel.cpp

Thank you,

@joaocarvalhoopen
Copy link
Author

What I think is happenning is that QTWidget doesn't know you have selected some text with the mouse and the X11 that is underneath doesn't know you have a text selected and so xclips can't get the text.

But you are wright it should work like a selection before a Ctrl + C, but one that communicates the selected text to QTWidget and it will communicate to X11 where xclips will get the text. I think QTextCursor class is the key, but I don't know QT.

Thank you,

@ahrm
Copy link
Owner

ahrm commented Apr 15, 2022

I seached a little bit and I think you can solve the problem by using this command instead:

xclip -selection clipboard -o

instead of

xclip -out

I will still look to see if I can set the normal xclip value.

@ahrm
Copy link
Owner

ahrm commented Apr 15, 2022

Should be fixed in 561e8d9. I haven't tested it though, because I am on windows and this seems to be a linux-specific thing.

@ahrm
Copy link
Owner

ahrm commented Apr 15, 2022

Okay I tested it on linux and it seems to be working. I issued a build command for the other repository, a new build should be available in about 20 minutes if there are no errors.

@joaocarvalhoopen
Copy link
Author

Thank you very much, I will test it when the build is ready and give you my feedback.

@joaocarvalhoopen
Copy link
Author

joaocarvalhoopen commented Apr 15, 2022

Hello Ahrm,

I tested it on Linux Ubuntu 20.04 and it’s working 100%.

Ahrm, you are one of the fastest developers I have ever seen.

Congratulations.

Thank you very much,

The very best regards,
João

@ahrm
Copy link
Owner

ahrm commented Apr 15, 2022

Thank you. By the way, in that build there is a super experimental new feature which you might interesting. I have explained it in detail here:
https://ahrm.github.io/jekyll/update/2022/04/14/using-languge-models-to-read-faster.html

You need a beefy GPU to run it though (unless you use the heuristic mode which doesn't require running the server at all).

@ahrm ahrm closed this as completed Apr 15, 2022
@joaocarvalhoopen
Copy link
Author

Thank you Ahrm,

I downloaded the script,
I installed the transforms on Anaconda conda,
Run the Python script for the server and it downloaded the 570 MB Transformer model,
and I run it and it runned quite fast on a 1080TI to render one page,
It only takes a little longer if I press page down and it speeds the page downs quickly but the prediction model puts every page on the queue, I think it should only start putting the page text of each page inside the fetching queue of the server, when we stop at a page after 200ms of no Page Down or Page UP movement, that will skip the fast page downs.

In terms of final result, I tested on a book of electronics and I think your language model isn’t the best and I currently prefer the simple Visual one line with toogle_custom_color with my dyslexic mode colors settings.

Currently I tested with 3 dyslexic persons and all are of the opinion that Sioyek is a really, really good for dyslexic people, really the best, currently those 3 persons have Sioyek installed by me on there computer. Linux and Windows.

I tested also the three simultaneous modes with fast_read, custom color and visual one line, and it all worked well.

Then I took the language model server down, and activated the the fast_read mode again to activate the heuristic mode and it worked well for the at least the pages of the book that I tried, it worker better then the language model. One could more easily read it then the transformer model, one. Which indicates that possibly the specific language model isn’t the best for general texts on electronics. But this is just my humble opinion, and not very knowledgeable in text models for Neural Networks with Transforms.

All tested on Linux Ubuntu 20.04 LTS.

Thank you Ahrm,

Like I said, you are doing a fantastic work!

The very best regards,
João

@ahrm
Copy link
Owner

ahrm commented Apr 15, 2022

Thanks you for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants