This commit is contained in:
恍兮惚兮 2024-06-05 00:23:41 +08:00
parent a35e284312
commit 3c16f053c5
3 changed files with 27 additions and 11 deletions

View File

@ -108,11 +108,6 @@ class edittrans(QMainWindow):
def __init__(self, parent): def __init__(self, parent):
super().__init__(parent, Qt.WindowType.FramelessWindowHint) super().__init__(parent, Qt.WindowType.FramelessWindowHint)
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
self.setStyleSheet(
"background-color: %s"
% str2rgba(globalconfig["backcolor"], globalconfig["transparent"])
)
self.setupUi() self.setupUi()
self.rssignal.connect(self.resize) self.rssignal.connect(self.resize)
@ -142,8 +137,7 @@ class edittrans(QMainWindow):
def setupUi(self): def setupUi(self):
self.setWindowIcon(qtawesome.icon("fa.edit")) self.setWindowIcon(qtawesome.icon("fa.edit"))
self.textOutput = QLineEdit(self) self.textOutput = QPlainTextEdit(self)
qv = QHBoxLayout() qv = QHBoxLayout()
w = QWidget() w = QWidget()
self.setCentralWidget(w) self.setCentralWidget(w)
@ -160,11 +154,10 @@ class edittrans(QMainWindow):
) )
) )
qv.addWidget(submit) qv.addWidget(submit)
submit.clicked.connect(self.submitfunction) submit.clicked.connect(self.submitfunction)
def submitfunction(self): def submitfunction(self):
text = self.textOutput.text() text = self.textOutput.toPlainText()
if len(text) == 0: if len(text) == 0:
return return
try: try:

View File

@ -241,6 +241,8 @@ class basetrans(commonbase):
return res return res
def cachesetatend(self, contentsolved, res): def cachesetatend(self, contentsolved, res):
if self.transtype == "pre":
return
if globalconfig["uselongtermcache"]: if globalconfig["uselongtermcache"]:
self.longtermcacheset(contentsolved, res) self.longtermcacheset(contentsolved, res)
self.shorttermcacheset(contentsolved, res) self.shorttermcacheset(contentsolved, res)
@ -290,6 +292,7 @@ class basetrans(commonbase):
pass pass
else: else:
collectiterres.append(_) collectiterres.append(_)
if all([_ is not None for _ in collectiterres]):
callback("".join(collectiterres), embedcallback, is_iter_res) callback("".join(collectiterres), embedcallback, is_iter_res)
def reinitandtrans(self, contentraw, contentsolved, is_auto_run): def reinitandtrans(self, contentraw, contentsolved, is_auto_run):
@ -345,6 +348,7 @@ class basetrans(commonbase):
else: else:
__callback(res, 0) __callback(res, 0)
if all([_ is not None for _ in collectiterres]):
self.cachesetatend(contentsolved, "".join(collectiterres)) self.cachesetatend(contentsolved, "".join(collectiterres))
except Exception as e: except Exception as e:
if self.using and globalconfig["showtranexception"]: if self.using and globalconfig["showtranexception"]:

View File

@ -0,0 +1,19 @@
import json, gobject
from translator.basetranslator import basetrans
class TS(basetrans):
def translate(self, content):
try:
sql = gobject.baseobject.textsource.sqlwrite2
except:
return None
(ret,) = sql.execute(
"SELECT machineTrans FROM artificialtrans WHERE source = ?", (content,)
).fetchone()
if ret is None:
return None
ret = json.loads(ret)
return ret.get("realtime_edit", None)