diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index 9163aac3..e4f8d0d8 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -148,7 +148,9 @@ class MAINUI() : return ss def textgetmethod(self,text,is_auto_run=True,embedcallback=None,onlytrans=False): _autolock(self.solvegottextlock) - + + returnandembedcallback = lambda : embedcallback('') if embedcallback else '' + if type(text)==str: if text.startswith(''): self.translation_ui.displayres.emit(dict(color=globalconfig['rawtextcolor'],res=text[len(''):],onlytrans=onlytrans)) @@ -167,9 +169,7 @@ class MAINUI() : self.translation_ui.displaystatus.emit(text[len(msg):],color,refresh,False) return if text=='' or len(text)>100000: - if embedcallback: - embedcallback('') - return + return returnandembedcallback() if onlytrans==False: self.currentsignature=time.time() try: @@ -185,9 +185,7 @@ class MAINUI() : return if text=='' or (is_auto_run and (text==self.currenttext or len(text)>(max(globalconfig['maxoriginlength'],globalconfig['maxlength'])))): - if embedcallback: - embedcallback('') - return + return returnandembedcallback() try: @@ -212,7 +210,8 @@ class MAINUI() : text_solved,optimization_params= self.solvebeforetrans(text) - skip=is_auto_run and (len(text_solved)globalconfig['maxlength'] ) + if is_auto_run and (len(text_solved)globalconfig['maxlength'] ): + return returnandembedcallback() self.premtalready=['premt'] self.usefultranslators=list(self.translators.keys()) @@ -242,7 +241,7 @@ class MAINUI() : #print(keys,usenum,self.lasttranslatorindex) for engine in keys: 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 self.lasttranslatorindex+=1 if(thistimeusednum>=usenum): diff --git a/LunaTranslator/LunaTranslator/textsource/texthook.py b/LunaTranslator/LunaTranslator/textsource/texthook.py index a6125ddb..9538df9e 100644 --- a/LunaTranslator/LunaTranslator/textsource/texthook.py +++ b/LunaTranslator/LunaTranslator/textsource/texthook.py @@ -215,13 +215,13 @@ class texthook(basetext ): def getembedtext(self,text,tp): if self.safeembedcheck(text)==False: self.embedcallback(text,text) - self.newline.put((text,False, lambda trans:1,True)) + self.newline.put((text,True, lambda trans:1,True)) return if globalconfig['autorun']==False: self.embedcallback(text,text) return 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): diff --git a/LunaTranslator/LunaTranslator/translator/basetranslator.py b/LunaTranslator/LunaTranslator/translator/basetranslator.py index 49eb0001..ba484799 100644 --- a/LunaTranslator/LunaTranslator/translator/basetranslator.py +++ b/LunaTranslator/LunaTranslator/translator/basetranslator.py @@ -223,7 +223,7 @@ class basetrans(commonbase): while True: _=self.queue.get() if _ is None:break - callback,contentraw,contentsolved,skip,embedcallback,is_auto_run=_ + callback,contentraw,contentsolved,embedcallback,is_auto_run=_ if embedcallback is not None: savelast.clear() @@ -232,12 +232,10 @@ class basetrans(commonbase): break if self.using==False:break 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: self.gettask(_) if embedcallback is None: - if skip: - continue if is_auto_run and self.onlymanual: continue