rework ignore screen detection; detect user of current TTY

This commit is contained in:
chrys
2017-02-22 23:48:37 +01:00
parent ef006fb423
commit abb3823606
9 changed files with 135 additions and 52 deletions

View File

@@ -0,0 +1,56 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributers.
from core import debug
import subprocess, os
from subprocess import Popen, PIPE
import _thread
class command():
def __init__(self):
pass
def initialize(self, environment, scriptPath=''):
self.env = environment
self.scriptPath = scriptPath
def shutdown(self):
pass
def getDescription(self):
return 'export the current fenrir clipboard to X clipboard'
def run(self):
_thread.start_new_thread(self._threadRun , ())
def _threadRun(self):
try:
currClipboard = self.env['commandBuffer']['currClipboard']
if currClipboard < 0:
self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True)
return
if not self.env['commandBuffer']['clipboard']:
self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True)
return
if not self.env['commandBuffer']['clipboard'][currClipboard]:
self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True)
return
if self.env['commandBuffer']['clipboard'][currClipboard] == '':
self.env['runtime']['outputManager'].presentText('clipboard empty', interrupt=True)
return
p = Popen('su -c "echo -n \"' + self.env['commandBuffer']['clipboard'][currClipboard] +'\" | xclip -selection c' + self.env['generalInformation']['currUser'] , stdout=PIPE, stderr=PIPE, shell=True)
stdout, stderr = p.communicate()
self.env['runtime']['outputManager'].interruptOutput()
screenEncoding = self.env['runtime']['settingsManager'].getSetting('screen', 'encoding')
stderr = stderr.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
stdout = stdout.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
if stderr != '':
self.env['runtime']['outputManager'].presentText(stdout , soundIcon='', interrupt=False)
else:
self.env['runtime']['outputManager'].presentText('export clipboard', soundIcon='PasteClipboardOnScreen', interrupt=True)
except Exception as e:
print(e)
self.env['runtime']['outputManager'].presentText(e , soundIcon='', interrupt=False)
def setCallback(self, callback):
pass