mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-26 23:24:13 +08:00
...
This commit is contained in:
parent
8c7ceeb112
commit
615ba9691a
1
.gitignore
vendored
1
.gitignore
vendored
@ -43,3 +43,4 @@ LunaTranslator/run3832.bat
|
||||
LunaTranslator/logs
|
||||
LunaTranslator/LunaTranslator/.vscode/settings.json
|
||||
.vscode/settings.json
|
||||
LunaTranslator/translation_record
|
||||
|
@ -13,7 +13,13 @@ from myutils.utils import (
|
||||
makehtml,
|
||||
loadpostsettingwindowmethod_maybe,
|
||||
)
|
||||
from myutils.hwnd import mouseselectwindow, grabwindow, getExeIcon, getcurrexe
|
||||
from myutils.hwnd import (
|
||||
mouseselectwindow,
|
||||
grabwindow,
|
||||
getExeIcon,
|
||||
getcurrexe,
|
||||
hwndratex,
|
||||
)
|
||||
from gui.setting_about import doupdate
|
||||
from gui.dialog_memory import dialog_memory
|
||||
from gui.textbrowser import Textbrowser
|
||||
@ -252,8 +258,8 @@ class TranslatorWindow(resizableframeless):
|
||||
move_signal = pyqtSignal(QPoint)
|
||||
closesignal = pyqtSignal()
|
||||
hotkeyuse_selectprocsignal = pyqtSignal()
|
||||
changeshowhiderawsig=pyqtSignal()
|
||||
changeshowhidetranssig=pyqtSignal()
|
||||
changeshowhiderawsig = pyqtSignal()
|
||||
changeshowhidetranssig = pyqtSignal()
|
||||
|
||||
@threader
|
||||
def tracewindowposthread(self):
|
||||
@ -284,11 +290,12 @@ class TranslatorWindow(resizableframeless):
|
||||
if not rect:
|
||||
lastpos = None
|
||||
continue
|
||||
rate = hwndratex(hwnd)
|
||||
rect = QRect(
|
||||
int(rect[0] / self.devicePixelRatioF()),
|
||||
int(rect[1] / self.devicePixelRatioF()),
|
||||
int((rect[2] - rect[0]) / self.devicePixelRatioF()),
|
||||
int((rect[3] - rect[1]) / self.devicePixelRatioF()),
|
||||
int(rect[0] / rate),
|
||||
int(rect[1] / rate),
|
||||
int((rect[2] - rect[0]) / rate),
|
||||
int((rect[3] - rect[1]) / rate),
|
||||
)
|
||||
if not lastpos:
|
||||
lastpos = rect
|
||||
|
@ -266,11 +266,16 @@ def safepixmap(bs):
|
||||
return pixmap
|
||||
|
||||
|
||||
def hwndratex(hwnd):
|
||||
_dpi = windows.GetDpiForWindow(hwnd)
|
||||
mdpi = winsharedutils.GetMonitorDpiScaling(hwnd)
|
||||
return mdpi / _dpi
|
||||
|
||||
|
||||
def gdi_screenshot(x1, y1, x2, y2, hwnd=None):
|
||||
if hwnd:
|
||||
_r = QApplication.instance().devicePixelRatio()
|
||||
_dpi = windows.GetDpiForWindow(hwnd)
|
||||
x1, y1, x2, y2 = (int(_ * _dpi / 96 / _r) for _ in (x1, y1, x2, y2))
|
||||
rate = hwndratex(hwnd)
|
||||
x1, y1, x2, y2 = (int(_ / rate) for _ in (x1, y1, x2, y2))
|
||||
bs = winsharedutils.gdi_screenshot(x1, y1, x2, y2, hwnd)
|
||||
return safepixmap(bs)
|
||||
|
||||
|
@ -369,7 +369,7 @@ class basetrans(commonbase):
|
||||
if not checktutukufunction():
|
||||
# 检查请求队列是否空,请求队列有新的请求,则放弃当前请求。但对于内嵌翻译请求,不可以放弃。
|
||||
continue
|
||||
if self.using_gpt_dict:
|
||||
if self.transtype == "pre" or self.using_gpt_dict:
|
||||
gpt_dict = None
|
||||
contentraw = contentsolved
|
||||
for _ in optimization_params:
|
||||
|
@ -36,6 +36,9 @@ class TS(basetrans):
|
||||
)
|
||||
|
||||
def translate(self, content):
|
||||
query = json.loads(content)
|
||||
content = query["contentraw"]
|
||||
|
||||
self.checkfilechanged(
|
||||
self.unsafegetcurrentgameconfig(), self.config["sqlitefile"]
|
||||
)
|
||||
|
@ -115,6 +115,8 @@ class TS(basetrans):
|
||||
return "\n".join(collect)
|
||||
|
||||
def translate(self, content: str):
|
||||
query = json.loads(content)
|
||||
content = query["contentraw"]
|
||||
self.checkfilechanged(
|
||||
self.unsafegetcurrentgameconfig(), tuple(self.config["jsonfile"])
|
||||
)
|
||||
|
@ -57,20 +57,21 @@ class TS(basetrans):
|
||||
gpt_dict_raw_text = "\n".join(gpt_dict_text_list)
|
||||
return gpt_dict_raw_text
|
||||
|
||||
def appendcontext(self, message, contextnum):
|
||||
|
||||
for _i in range(min(len(self.context) // 2, contextnum)):
|
||||
i = len(self.context) // 2 - min(len(self.context) // 2, contextnum) + _i
|
||||
message.append(self.context[i * 2])
|
||||
message.append(self.context[i * 2 + 1])
|
||||
|
||||
def _gpt_common_parse_context_2(self, messages, context, contextnum):
|
||||
def _gpt_common_parse_context_2(self, messages, context, contextnum, ja=False):
|
||||
msgs = []
|
||||
self._gpt_common_parse_context(msgs, context, contextnum)
|
||||
__ja, __zh = [], []
|
||||
for i, _ in enumerate(msgs):
|
||||
[__ja, __zh][i % 2 == 0].append(_.strip())
|
||||
messages.append({"role": "assistant", "content": "\n".join(__zh)})
|
||||
[__zh, __ja][i % 2 == 0].append(_.strip())
|
||||
if __ja:
|
||||
if ja:
|
||||
messages.append(
|
||||
{
|
||||
"role": "user",
|
||||
"content": "将下面的日文文本翻译成中文:" + "\n".join(__ja),
|
||||
}
|
||||
)
|
||||
messages.append({"role": "assistant", "content": "\n".join(__zh)})
|
||||
|
||||
def make_messages(self, query, gpt_dict=None):
|
||||
contextnum = (
|
||||
@ -111,7 +112,7 @@ class TS(basetrans):
|
||||
"content": "你是一个轻小说翻译模型,可以流畅通顺地以日本轻小说的风格将日文翻译成简体中文,并联系上下文正确使用人称代词,不擅自添加原文中没有的代词。",
|
||||
}
|
||||
]
|
||||
self._gpt_common_parse_context_2(messages, self.context, contextnum)
|
||||
self._gpt_common_parse_context_2(messages, self.context, contextnum, True)
|
||||
gpt_dict_raw_text = self.make_gpt_dict_text(gpt_dict)
|
||||
if gpt_dict_raw_text:
|
||||
content = (
|
||||
|
@ -19,7 +19,7 @@ from ctypes import (
|
||||
CFUNCTYPE,
|
||||
c_long,
|
||||
)
|
||||
from ctypes.wintypes import WORD, HWND, DWORD, RECT
|
||||
from ctypes.wintypes import WORD, HWND, DWORD, RECT, UINT
|
||||
import gobject
|
||||
|
||||
utilsdll = CDLL(gobject.GetDllpath(("winsharedutils32.dll", "winsharedutils64.dll")))
|
||||
@ -354,3 +354,8 @@ def encodemp3(wav):
|
||||
if len(ret):
|
||||
return ret[0]
|
||||
return None
|
||||
|
||||
|
||||
GetMonitorDpiScaling = utilsdll.GetMonitorDpiScaling
|
||||
GetMonitorDpiScaling.argtypes = (HWND,)
|
||||
GetMonitorDpiScaling.restype = UINT
|
||||
|
@ -1121,7 +1121,7 @@
|
||||
"frequency_penalty": 0,
|
||||
"fix_degeneration": false,
|
||||
"流式输出": true,
|
||||
"prompt_version": 0,
|
||||
"prompt_version": 2,
|
||||
"s": ""
|
||||
},
|
||||
"argstype": {
|
||||
|
@ -28,8 +28,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version)
|
||||
include(generate_product_version)
|
||||
|
||||
set(VERSION_MAJOR 5)
|
||||
set(VERSION_MINOR 42)
|
||||
set(VERSION_PATCH 12)
|
||||
set(VERSION_MINOR 43)
|
||||
set(VERSION_PATCH 0)
|
||||
|
||||
add_library(pch pch.cpp)
|
||||
target_precompile_headers(pch PUBLIC pch.h)
|
||||
|
@ -13,7 +13,7 @@ generate_product_version(
|
||||
add_library(tinymp3 ../libs/tinymp3/shine_mp3.c)
|
||||
add_library(winsharedutils MODULE mp3enc.cpp webview2_extra.cpp AreoAcrylic.cpp screenshot.cpp ../implsapi.cpp hwnd.cpp globalmessagelistener.cpp theme.cpp version.cpp otsu.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp ${versioninfo})
|
||||
target_precompile_headers(winsharedutils REUSE_FROM pch)
|
||||
target_link_libraries(winsharedutils tinymp3)
|
||||
target_link_libraries(winsharedutils tinymp3 Shcore)
|
||||
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
|
||||
set_target_properties(winsharedutils PROPERTIES OUTPUT_NAME "winsharedutils64")
|
||||
else()
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "define.h"
|
||||
|
||||
#include <shellscalingapi.h>
|
||||
DECLARE void showintab(HWND hwnd, bool show, bool tool)
|
||||
{
|
||||
// WS_EX_TOOLWINDOW可以立即生效,WS_EX_APPWINDOW必须切换焦点才生效。但是WS_EX_TOOLWINDOW会改变窗口样式,因此只对无边框窗口使用。
|
||||
@ -95,4 +95,36 @@ DECLARE void getprocesses(void (*cb)(DWORD, const wchar_t *))
|
||||
cb(pe32.th32ProcessID, pe32.szExeFile);
|
||||
} while (Process32Next(hSnapshot, &pe32));
|
||||
}
|
||||
}
|
||||
}
|
||||
DECLARE UINT GetMonitorDpiScaling(HWND hwnd)
|
||||
{
|
||||
HMONITOR hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
if (!hMonitor)
|
||||
return 96;
|
||||
auto pGetDpiForMonitor = (HRESULT(*)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *))GetProcAddress(GetModuleHandleA("Shcore.dll"), "GetDpiForMonitor");
|
||||
if (pGetDpiForMonitor)
|
||||
{
|
||||
UINT dpiX = 0;
|
||||
UINT dpiY = 0;
|
||||
HRESULT hr = pGetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
|
||||
if (FAILED(hr))
|
||||
return 96;
|
||||
else
|
||||
return dpiX;
|
||||
}
|
||||
else
|
||||
{
|
||||
MONITORINFOEX info;
|
||||
info.cbSize = sizeof(MONITORINFOEX);
|
||||
if (!GetMonitorInfo(hMonitor, &info))
|
||||
return 96;
|
||||
HDC hdc = GetDC(NULL);
|
||||
HDC hdcMonitor = CreateCompatibleDC(hdc);
|
||||
HDC hdcMonitorScreen = CreateIC(TEXT("DISPLAY"), info.szDevice, NULL, 0);
|
||||
int dpiX = GetDeviceCaps(hdcMonitorScreen, LOGPIXELSX);
|
||||
DeleteDC(hdcMonitor);
|
||||
DeleteDC(hdcMonitorScreen);
|
||||
ReleaseDC(NULL, hdc);
|
||||
return dpiX;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user