Switched from xclip to pyperclip for import from x.
This commit is contained in:
parent
4966b87ba1
commit
73206ce393
@ -5,9 +5,10 @@
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
import subprocess, os
|
||||
from subprocess import Popen, PIPE
|
||||
import _thread
|
||||
import pyperclip
|
||||
import os
|
||||
|
||||
class command():
|
||||
def __init__(self):
|
||||
pass
|
||||
@ -22,33 +23,40 @@ class command():
|
||||
_thread.start_new_thread(self._threadRun , ())
|
||||
def _threadRun(self):
|
||||
try:
|
||||
# Find xclip path
|
||||
xclip_paths = ['/usr/bin/xclip', '/bin/xclip', '/usr/local/bin/xclip']
|
||||
xclip_path = None
|
||||
for path in xclip_paths:
|
||||
if os.path.isfile(path) and os.access(path, os.X_OK):
|
||||
xclip_path = path
|
||||
# Remember original display environment variable if it exists
|
||||
originalDisplay = os.environ.get('DISPLAY', '')
|
||||
clipboardContent = None
|
||||
|
||||
# Try different display options
|
||||
for i in range(10):
|
||||
display = f":{i}"
|
||||
try:
|
||||
# Set display environment variable
|
||||
os.environ['DISPLAY'] = display
|
||||
# Attempt to get clipboard content
|
||||
clipboardContent = pyperclip.paste()
|
||||
# If we get here without exception, we found a working display
|
||||
if clipboardContent:
|
||||
break
|
||||
if not xclip_path:
|
||||
self.env['runtime']['outputManager'].presentText('xclip not found in common locations', interrupt=True)
|
||||
return
|
||||
xClipboard = ''
|
||||
for display in range(10):
|
||||
p = Popen('su ' + self.env['general']['currUser'] + ' -p -c "' + xclip_path + ' -d :' + str(display) + ' -o"', stdout=PIPE, stderr=PIPE, shell=True)
|
||||
stdout, stderr = p.communicate()
|
||||
self.env['runtime']['outputManager'].interruptOutput()
|
||||
stderr = stderr.decode('utf-8')
|
||||
xClipboard = stdout.decode('utf-8')
|
||||
if (stderr == ''):
|
||||
break
|
||||
if stderr != '':
|
||||
self.env['runtime']['outputManager'].presentText(stderr , soundIcon='', interrupt=False)
|
||||
except Exception:
|
||||
# Failed for this display, try next one
|
||||
continue
|
||||
|
||||
# Restore original display setting
|
||||
if originalDisplay:
|
||||
os.environ['DISPLAY'] = originalDisplay
|
||||
else:
|
||||
self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', xClipboard)
|
||||
os.environ.pop('DISPLAY', None)
|
||||
|
||||
# Process the clipboard content if we found any
|
||||
if clipboardContent and isinstance(clipboardContent, str):
|
||||
self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', clipboardContent)
|
||||
self.env['runtime']['outputManager'].presentText('Import to Clipboard', soundIcon='CopyToClipboard', interrupt=True)
|
||||
self.env['runtime']['outputManager'].presentText(xClipboard, soundIcon='', interrupt=False)
|
||||
self.env['runtime']['outputManager'].presentText(clipboardContent, soundIcon='', interrupt=False)
|
||||
else:
|
||||
self.env['runtime']['outputManager'].presentText('No text found in clipboard or no accessible display', interrupt=True)
|
||||
except Exception as e:
|
||||
self.env['runtime']['outputManager'].presentText(e , soundIcon='', interrupt=False)
|
||||
self.env['runtime']['outputManager'].presentText(str(e), soundIcon='', interrupt=False)
|
||||
|
||||
def setCallback(self, callback):
|
||||
pass
|
||||
|
@ -4,5 +4,5 @@
|
||||
# Fenrir TTY screen reader
|
||||
# By Chrys, Storm Dragon, and contributers.
|
||||
|
||||
version = "2025.02.26"
|
||||
version = "2025.03.02"
|
||||
codeName = "testing"
|
||||
|
Loading…
x
Reference in New Issue
Block a user