From 49f04da8001c0111deec986f654504bfea7154e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Fri, 31 May 2024 16:53:16 +0800 Subject: [PATCH] ... --- LunaTranslator/LunaTranslator/gui/usefulwidget.py | 4 +++- LunaTranslator/LunaTranslator/myutils/config.py | 7 ++++--- LunaTranslator/LunaTranslator/winsharedutils.py | 10 +++++++++- plugins/winsharedutils/SimpleBrowser.cpp | 4 ++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 00790273..4f0b4564 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -599,6 +599,8 @@ class mshtmlWidget(QWidget): def __init__(self, parent=None) -> None: super().__init__(parent) + if HTMLBrowser.version() < 10001: # ie10之前,sethtml会乱码 + self.html_limit = 0 self.browser = HTMLBrowser(int(self.winId())) threading.Thread(target=self.__getcurrenturl).start() @@ -625,7 +627,7 @@ class mshtmlWidget(QWidget): self.browser.set_html(html) def parsehtml(self, html): - html = """{}""".format( + html = """{}""".format( QFontDatabase.systemFont(QFontDatabase.GeneralFont).family(), html ) return html diff --git a/LunaTranslator/LunaTranslator/myutils/config.py b/LunaTranslator/LunaTranslator/myutils/config.py index 6cf08aa5..786cc931 100644 --- a/LunaTranslator/LunaTranslator/myutils/config.py +++ b/LunaTranslator/LunaTranslator/myutils/config.py @@ -247,7 +247,10 @@ thisapppath = os.path.normpath(os.getcwd()) if lastapppath is None: lastapppath = thisapppath -lastapppath = os.path.normpath(lastapppath) +else: + lastapppath = os.path.normpath(lastapppath) + +globalconfig["lastapppath"] = thisapppath def dynamicrelativepath(abspath): @@ -316,8 +319,6 @@ def _TRL(kk): def saveallconfig(): - globalconfig["lastapppath"] = thisapppath - def safesave(fname, js): # 有时保存时意外退出,会导致config文件被清空 with open(fname + ".tmp", "w", encoding="utf-8") as ff: diff --git a/LunaTranslator/LunaTranslator/winsharedutils.py b/LunaTranslator/LunaTranslator/winsharedutils.py index ade38d05..4c7a5032 100644 --- a/LunaTranslator/LunaTranslator/winsharedutils.py +++ b/LunaTranslator/LunaTranslator/winsharedutils.py @@ -149,13 +149,15 @@ class mecabwrap: surface = POINTER(c_char_p)() feature = POINTER(c_char_p)() num = c_uint() - _mecab_parse( + succ = _mecab_parse( self.kks, text.encode(codec), pointer(surface), pointer(feature), pointer(num), ) + if not succ: + raise Exception # failed res = [] for i in range(num.value): f = feature[i] @@ -185,6 +187,8 @@ def clipboard_get(): return "" +html_version = utilsdll.html_version +html_version.restype = DWORD html_new = utilsdll.html_new html_new.argtypes = (c_void_p,) html_new.restype = c_void_p @@ -204,6 +208,10 @@ html_set_html.argtypes = ( class HTMLBrowser: + @staticmethod + def version(): + return html_version() + def __init__(self, parent) -> None: self.html = html_new(parent) diff --git a/plugins/winsharedutils/SimpleBrowser.cpp b/plugins/winsharedutils/SimpleBrowser.cpp index 52f2fab6..4cdf0fda 100644 --- a/plugins/winsharedutils/SimpleBrowser.cpp +++ b/plugins/winsharedutils/SimpleBrowser.cpp @@ -106,6 +106,10 @@ BOOL DoSetBrowserEmulation(DWORD dwValue) return bOK; } +extern "C" __declspec(dllexport) DWORD html_version() +{ + return getemulation(); +} extern "C" __declspec(dllexport) void *html_new(HWND parent) { DoSetBrowserEmulation(getemulation());