mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
top
This commit is contained in:
parent
f5d7fd5764
commit
aeb551e360
@ -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()
|
||||||
|
|
||||||
|
@ -702,29 +702,16 @@ class QUnFrameWindow(resizableframeless):
|
|||||||
self.setontopthread()
|
self.setontopthread()
|
||||||
|
|
||||||
def canceltop(self):
|
def canceltop(self):
|
||||||
windows.SetWindowPos(
|
if self.istopmost():
|
||||||
self.winid,
|
windows.SetWindowPos(
|
||||||
windows.HWND_NOTOPMOST,
|
self.winid,
|
||||||
0,
|
windows.HWND_NOTOPMOST,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
windows.SWP_NOACTIVATE | windows.SWP_NOSIZE | windows.SWP_NOMOVE,
|
0,
|
||||||
)
|
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,22 +732,25 @@ class QUnFrameWindow(resizableframeless):
|
|||||||
|
|
||||||
@threader
|
@threader
|
||||||
def setontopthread(self):
|
def setontopthread(self):
|
||||||
self.settop()
|
|
||||||
while globalconfig["keepontop"]:
|
|
||||||
|
|
||||||
try:
|
with self.setontopthread_lock:
|
||||||
hwnd = windows.GetForegroundWindow()
|
if not globalconfig["keepontop"]:
|
||||||
pid = windows.GetWindowThreadProcessId(hwnd)
|
return self.canceltop()
|
||||||
if pid == os.getpid():
|
self.settop()
|
||||||
pass
|
while globalconfig["keepontop"]:
|
||||||
elif globalconfig["focusnotop"] and self.thistimenotsetop:
|
|
||||||
pass
|
try:
|
||||||
else:
|
hwnd = windows.GetForegroundWindow()
|
||||||
self.settop()
|
pid = windows.GetWindowThreadProcessId(hwnd)
|
||||||
except:
|
if pid == os.getpid():
|
||||||
print_exc()
|
pass
|
||||||
time.sleep(0.5)
|
elif globalconfig["focusnotop"] and self.thistimenotsetop:
|
||||||
self.canceltop()
|
pass
|
||||||
|
else:
|
||||||
|
self.settop()
|
||||||
|
except:
|
||||||
|
print_exc()
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
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)
|
||||||
|
@ -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 _focusp == os.getpid():
|
if not (globalconfig["keepontop"] and globalconfig["focusnotop"]):
|
||||||
pass
|
return
|
||||||
else:
|
if _focusp == os.getpid():
|
||||||
hwndmagpie = windows.FindWindow(
|
return
|
||||||
"Window_Magpie_967EB565-6F73-4E94-AE53-00CC42592A22", None
|
|
||||||
)
|
if windows.FindWindow(
|
||||||
if (
|
"Window_Magpie_967EB565-6F73-4E94-AE53-00CC42592A22", None
|
||||||
len(gobject.baseobject.textsource.pids) == 0
|
):
|
||||||
or _focusp in gobject.baseobject.textsource.pids
|
return
|
||||||
or hwnd == hwndmagpie
|
if (
|
||||||
):
|
len(gobject.baseobject.textsource.pids) == 0
|
||||||
gobject.baseobject.translation_ui.thistimenotsetop = False
|
or _focusp in gobject.baseobject.textsource.pids
|
||||||
gobject.baseobject.translation_ui.settop()
|
):
|
||||||
else:
|
gobject.baseobject.translation_ui.thistimenotsetop = False
|
||||||
gobject.baseobject.translation_ui.thistimenotsetop = True
|
gobject.baseobject.translation_ui.settop()
|
||||||
if gobject.baseobject.translation_ui.istopmost():
|
else:
|
||||||
gobject.baseobject.translation_ui.canceltop()
|
gobject.baseobject.translation_ui.thistimenotsetop = True
|
||||||
|
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()
|
||||||
|
@ -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,
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user