mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
fix
Update LunaTranslator.py Update LunaTranslator.py
This commit is contained in:
parent
58ade2661f
commit
d4a715316c
@ -148,7 +148,9 @@ class MAINUI() :
|
|||||||
return ss
|
return ss
|
||||||
def textgetmethod(self,text,is_auto_run=True,embedcallback=None,onlytrans=False):
|
def textgetmethod(self,text,is_auto_run=True,embedcallback=None,onlytrans=False):
|
||||||
_autolock(self.solvegottextlock)
|
_autolock(self.solvegottextlock)
|
||||||
|
|
||||||
|
returnandembedcallback = lambda : embedcallback('') if embedcallback else ''
|
||||||
|
|
||||||
if type(text)==str:
|
if type(text)==str:
|
||||||
if text.startswith('<notrans>'):
|
if text.startswith('<notrans>'):
|
||||||
self.translation_ui.displayres.emit(dict(color=globalconfig['rawtextcolor'],res=text[len('<notrans>'):],onlytrans=onlytrans))
|
self.translation_ui.displayres.emit(dict(color=globalconfig['rawtextcolor'],res=text[len('<notrans>'):],onlytrans=onlytrans))
|
||||||
@ -167,9 +169,7 @@ class MAINUI() :
|
|||||||
self.translation_ui.displaystatus.emit(text[len(msg):],color,refresh,False)
|
self.translation_ui.displaystatus.emit(text[len(msg):],color,refresh,False)
|
||||||
return
|
return
|
||||||
if text=='' or len(text)>100000:
|
if text=='' or len(text)>100000:
|
||||||
if embedcallback:
|
return returnandembedcallback()
|
||||||
embedcallback('')
|
|
||||||
return
|
|
||||||
if onlytrans==False:
|
if onlytrans==False:
|
||||||
self.currentsignature=time.time()
|
self.currentsignature=time.time()
|
||||||
try:
|
try:
|
||||||
@ -185,9 +185,7 @@ class MAINUI() :
|
|||||||
return
|
return
|
||||||
|
|
||||||
if text=='' or (is_auto_run and (text==self.currenttext or len(text)>(max(globalconfig['maxoriginlength'],globalconfig['maxlength'])))):
|
if text=='' or (is_auto_run and (text==self.currenttext or len(text)>(max(globalconfig['maxoriginlength'],globalconfig['maxlength'])))):
|
||||||
if embedcallback:
|
return returnandembedcallback()
|
||||||
embedcallback('')
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -212,7 +210,8 @@ class MAINUI() :
|
|||||||
|
|
||||||
text_solved,optimization_params= self.solvebeforetrans(text)
|
text_solved,optimization_params= self.solvebeforetrans(text)
|
||||||
|
|
||||||
skip=is_auto_run and (len(text_solved)<globalconfig['minlength'] or len(text_solved)>globalconfig['maxlength'] )
|
if is_auto_run and (len(text_solved)<globalconfig['minlength'] or len(text_solved)>globalconfig['maxlength'] ):
|
||||||
|
return returnandembedcallback()
|
||||||
|
|
||||||
self.premtalready=['premt']
|
self.premtalready=['premt']
|
||||||
self.usefultranslators=list(self.translators.keys())
|
self.usefultranslators=list(self.translators.keys())
|
||||||
@ -242,7 +241,7 @@ class MAINUI() :
|
|||||||
#print(keys,usenum,self.lasttranslatorindex)
|
#print(keys,usenum,self.lasttranslatorindex)
|
||||||
for engine in keys:
|
for engine in keys:
|
||||||
if engine not in self.premtalready:
|
if engine not in self.premtalready:
|
||||||
self.translators[engine].gettask((partial(self.GetTranslationCallback,onlytrans,engine,self.currentsignature, optimization_params,_showrawfunction,_showrawfunction_sig,text),text,text_solved,skip,embedcallback,is_auto_run))
|
self.translators[engine].gettask((partial(self.GetTranslationCallback,onlytrans,engine,self.currentsignature, optimization_params,_showrawfunction,_showrawfunction_sig,text),text,text_solved,embedcallback,is_auto_run))
|
||||||
thistimeusednum+=1
|
thistimeusednum+=1
|
||||||
self.lasttranslatorindex+=1
|
self.lasttranslatorindex+=1
|
||||||
if(thistimeusednum>=usenum):
|
if(thistimeusednum>=usenum):
|
||||||
|
@ -215,13 +215,13 @@ class texthook(basetext ):
|
|||||||
def getembedtext(self,text,tp):
|
def getembedtext(self,text,tp):
|
||||||
if self.safeembedcheck(text)==False:
|
if self.safeembedcheck(text)==False:
|
||||||
self.embedcallback(text,text)
|
self.embedcallback(text,text)
|
||||||
self.newline.put((text,False, lambda trans:1,True))
|
self.newline.put((text,True, lambda trans:1,True))
|
||||||
return
|
return
|
||||||
if globalconfig['autorun']==False:
|
if globalconfig['autorun']==False:
|
||||||
self.embedcallback(text,text)
|
self.embedcallback(text,text)
|
||||||
return
|
return
|
||||||
if self.checkisusingembed(tp.addr,tp.ctx,tp.ctx2):
|
if self.checkisusingembed(tp.addr,tp.ctx,tp.ctx2):
|
||||||
self.newline.put((text,False, functools.partial(self.embedcallback,text),True))
|
self.newline.put((text,True, functools.partial(self.embedcallback,text),True))
|
||||||
|
|
||||||
def embedcallback(self,text,trans):
|
def embedcallback(self,text,trans):
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ class basetrans(commonbase):
|
|||||||
while True:
|
while True:
|
||||||
_=self.queue.get()
|
_=self.queue.get()
|
||||||
if _ is None:break
|
if _ is None:break
|
||||||
callback,contentraw,contentsolved,skip,embedcallback,is_auto_run=_
|
callback,contentraw,contentsolved,embedcallback,is_auto_run=_
|
||||||
if embedcallback is not None:
|
if embedcallback is not None:
|
||||||
savelast.clear()
|
savelast.clear()
|
||||||
|
|
||||||
@ -232,12 +232,10 @@ class basetrans(commonbase):
|
|||||||
break
|
break
|
||||||
if self.using==False:break
|
if self.using==False:break
|
||||||
if savelast[0][4] is not None:
|
if savelast[0][4] is not None:
|
||||||
callback,contentraw,contentsolved,skip,embedcallback,is_auto_run=savelast.pop(0)
|
callback,contentraw,contentsolved,embedcallback,is_auto_run=savelast.pop(0)
|
||||||
for _ in savelast:
|
for _ in savelast:
|
||||||
self.gettask(_)
|
self.gettask(_)
|
||||||
if embedcallback is None:
|
if embedcallback is None:
|
||||||
if skip:
|
|
||||||
continue
|
|
||||||
if is_auto_run and self.onlymanual:
|
if is_auto_run and self.onlymanual:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user