This commit is contained in:
恍兮惚兮 2024-08-09 16:37:59 +08:00
parent f5d7fd5764
commit aeb551e360
5 changed files with 74 additions and 72 deletions

View File

@ -1248,7 +1248,10 @@ class MAINUI:
self.__count += 1 self.__count += 1
elif msg == 1: elif msg == 1:
if bool(param): if bool(param):
windows.BringWindowToTop(int(self.translation_ui.winid)) self.translation_ui.settop()
else:
if not globalconfig['keepontop']:
self.translation_ui.canceltop()
elif msg == 2: elif msg == 2:
self.translation_ui.closesignal.emit() self.translation_ui.closesignal.emit()

View File

@ -702,6 +702,7 @@ class QUnFrameWindow(resizableframeless):
self.setontopthread() self.setontopthread()
def canceltop(self): def canceltop(self):
if self.istopmost():
windows.SetWindowPos( windows.SetWindowPos(
self.winid, self.winid,
windows.HWND_NOTOPMOST, windows.HWND_NOTOPMOST,
@ -711,20 +712,6 @@ class QUnFrameWindow(resizableframeless):
0, 0,
windows.SWP_NOACTIVATE | windows.SWP_NOSIZE | windows.SWP_NOMOVE, windows.SWP_NOACTIVATE | windows.SWP_NOSIZE | windows.SWP_NOMOVE,
) )
HWNDStyleEx = windows.GetWindowLong(self.winid, windows.GWL_EXSTYLE)
windows.SetWindowLong(
self.winid, windows.GWL_EXSTYLE, HWNDStyleEx & ~windows.WS_EX_TOPMOST
)
windows.SetWindowPos(
self.winid,
windows.GetForegroundWindow(),
0,
0,
0,
0,
windows.SWP_NOACTIVATE | windows.SWP_NOSIZE | windows.SWP_NOMOVE,
)
def istopmost(self): def istopmost(self):
return bool( return bool(
@ -733,12 +720,6 @@ class QUnFrameWindow(resizableframeless):
) )
def settop(self): def settop(self):
if not self.istopmost():
self.canceltop()
HWNDStyleEx = windows.GetWindowLong(self.winid, windows.GWL_EXSTYLE)
windows.SetWindowLong(
self.winid, windows.GWL_EXSTYLE, HWNDStyleEx | windows.WS_EX_TOPMOST
)
windows.SetWindowPos( windows.SetWindowPos(
self.winid, self.winid,
windows.HWND_TOPMOST, windows.HWND_TOPMOST,
@ -751,6 +732,10 @@ class QUnFrameWindow(resizableframeless):
@threader @threader
def setontopthread(self): def setontopthread(self):
with self.setontopthread_lock:
if not globalconfig["keepontop"]:
return self.canceltop()
self.settop() self.settop()
while globalconfig["keepontop"]: while globalconfig["keepontop"]:
@ -766,7 +751,6 @@ class QUnFrameWindow(resizableframeless):
except: except:
print_exc() print_exc()
time.sleep(0.5) time.sleep(0.5)
self.canceltop()
def seteffect(self): def seteffect(self):
if globalconfig["WindowEffect"] == 0: if globalconfig["WindowEffect"] == 0:
@ -792,6 +776,7 @@ class QUnFrameWindow(resizableframeless):
self.processismuteed = False self.processismuteed = False
self.thistimenotsetop = False self.thistimenotsetop = False
self.isbindedwindow = False self.isbindedwindow = False
self.setontopthread_lock = threading.Lock()
def displayglobaltooltip_f(self, string): def displayglobaltooltip_f(self, string):
QToolTip.showText(QCursor.pos(), string, self) QToolTip.showText(QCursor.pos(), string, self)

View File

@ -430,25 +430,35 @@ def minmaxmoveobservefunc(self):
return return
_focusp = windows.GetWindowThreadProcessId(hwnd) _focusp = windows.GetWindowThreadProcessId(hwnd)
if event == windows.EVENT_SYSTEM_FOREGROUND: if event != windows.EVENT_SYSTEM_FOREGROUND:
if globalconfig["keepontop"] and globalconfig["focusnotop"]: return
if not (globalconfig["keepontop"] and globalconfig["focusnotop"]):
return
if _focusp == os.getpid(): if _focusp == os.getpid():
pass return
else:
hwndmagpie = windows.FindWindow( if windows.FindWindow(
"Window_Magpie_967EB565-6F73-4E94-AE53-00CC42592A22", None "Window_Magpie_967EB565-6F73-4E94-AE53-00CC42592A22", None
) ):
return
if ( if (
len(gobject.baseobject.textsource.pids) == 0 len(gobject.baseobject.textsource.pids) == 0
or _focusp in gobject.baseobject.textsource.pids or _focusp in gobject.baseobject.textsource.pids
or hwnd == hwndmagpie
): ):
gobject.baseobject.translation_ui.thistimenotsetop = False gobject.baseobject.translation_ui.thistimenotsetop = False
gobject.baseobject.translation_ui.settop() gobject.baseobject.translation_ui.settop()
else: else:
gobject.baseobject.translation_ui.thistimenotsetop = True gobject.baseobject.translation_ui.thistimenotsetop = True
if gobject.baseobject.translation_ui.istopmost():
gobject.baseobject.translation_ui.canceltop() gobject.baseobject.translation_ui.canceltop()
windows.SetWindowPos(
hwnd,
windows.HWND_TOP,
0,
0,
0,
0,
windows.SWP_NOACTIVATE | windows.SWP_NOSIZE | windows.SWP_NOMOVE,
)
except: except:
print_exc() print_exc()

View File

@ -113,7 +113,7 @@ class TS(basetrans):
content += ( content += (
"将下面的日文文本根据上述术语表的对应关系和备注翻译成中文:" + query "将下面的日文文本根据上述术语表的对应关系和备注翻译成中文:" + query
) )
print(content) # print(content)
messages.append({"role": "user", "content": content}) messages.append({"role": "user", "content": content})
return messages return messages
@ -185,12 +185,15 @@ class TS(basetrans):
for o in output.iter_lines(): for o in output.iter_lines():
try: try:
res = o.decode("utf-8").strip()[6:] # .replace("data: ", "") res = o.decode("utf-8").strip()[6:] # .replace("data: ", "")
print(res) # print(res)
if res != "": if res == "":
yield json.loads(res) continue
res = json.loads(res)
except: except:
raise Exception(o) raise Exception(o)
yield res
def translate(self, query): def translate(self, query):
query = json.loads(query) query = json.loads(query)
gpt_dict = query["gpt_dict"] gpt_dict = query["gpt_dict"]
@ -223,13 +226,13 @@ class TS(basetrans):
if bool(self.config["fix_degeneration"]): if bool(self.config["fix_degeneration"]):
cnt = 0 cnt = 0
print(completion_tokens) # print(completion_tokens)
while completion_tokens == int(self.config["max_new_token"]): while completion_tokens == int(self.config["max_new_token"]):
# detect degeneration, fixing # detect degeneration, fixing
frequency_penalty += 0.1 frequency_penalty += 0.1
yield "\0" yield "\0"
yield "[检测到退化,重试中]" yield "[检测到退化,重试中]"
print("------------------清零------------------") # print("------------------清零------------------")
if bool(self.config["流式输出"]) == True: if bool(self.config["流式输出"]) == True:
output = self.send_request_stream( output = self.send_request_stream(
query, query,
@ -307,12 +310,12 @@ class TS(basetrans):
if bool(self.config["fix_degeneration"]): if bool(self.config["fix_degeneration"]):
cnt = 0 cnt = 0
print(completion_tokens) # print(completion_tokens)
while completion_tokens == int(self.config["max_new_token"]): while completion_tokens == int(self.config["max_new_token"]):
frequency_penalty += 0.1 frequency_penalty += 0.1
yield "\0" yield "\0"
yield "[检测到退化,重试中]" yield "[检测到退化,重试中]"
print("------------------清零------------------") # print("------------------清零------------------")
if bool(self.config["流式输出"]) == True: if bool(self.config["流式输出"]) == True:
output = self.send_request_stream( output = self.send_request_stream(
query, query,

View File

@ -87,6 +87,7 @@ SW_MAX = 11
WS_MINIMIZE = 536870912 WS_MINIMIZE = 536870912
HWND_TOPMOST = -1 HWND_TOPMOST = -1
HWND_NOTOPMOST = -2 HWND_NOTOPMOST = -2
HWND_TOP = 0
SW_HIDE = 0 SW_HIDE = 0
SWP_NOACTIVATE = 16 SWP_NOACTIVATE = 16
SWP_NOMOVE = 2 SWP_NOMOVE = 2