From 5a71a1956882f7c2231b175ec315df1e3d4eb5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E4=BA=94?= Date: Thu, 21 Jul 2022 12:26:09 +0800 Subject: [PATCH] bug fixes --- lib/common_tools/configsModel.py | 6 +- lib/common_tools/handle_js.py | 194 +++++++++++++++---------------- 2 files changed, 100 insertions(+), 100 deletions(-) diff --git a/lib/common_tools/configsModel.py b/lib/common_tools/configsModel.py index 4480d3b..190f854 100644 --- a/lib/common_tools/configsModel.py +++ b/lib/common_tools/configsModel.py @@ -184,11 +184,11 @@ class Widget: @staticmethod def pdfurl_default_system_cmd(): """因为不同的系统需要的命令不同,所以要这个东西来确定""" - url = f"file:///{{{terms.PDFLink.url}}}#page={{{terms.PDFLink.page}}}" + url = f""" file:///{{{terms.PDFLink.url}}}#page={{{terms.PDFLink.page}}} """ if isMac: - return f'open -a Safari {url}' + return f'''open -a Safari "{url}" ''' if isWin: - return f"start msedge {url}" + return f""" start msedge "{url}" """ return "" gview_admin_default_display: ConfigModelItem = field(default_factory=lambda: ConfigModelItem( diff --git a/lib/common_tools/handle_js.py b/lib/common_tools/handle_js.py index a67ed67..61fc868 100644 --- a/lib/common_tools/handle_js.py +++ b/lib/common_tools/handle_js.py @@ -1,97 +1,97 @@ -import os -import platform -import re -import sys -from urllib.parse import quote, unquote - -from aqt import mw -# from ..dialogs.DialogCardPrev import external_card_dialog -from aqt.browser.previewer import BrowserPreviewer -from aqt.editor import Editor -from aqt.reviewer import Reviewer -from aqt.utils import showInfo, tooltip - -from . import funcs, terms - -CardId = funcs.Compatible.CardId() - -# print, _ = clipper_imports.funcs.logger(__name__) -ankilink = funcs.G.src.ankilink - - -def find_card_from_context(context): - from ..bilink.dialogs.custom_cardwindow import SingleCardPreviewerMod - if isinstance(context, Editor): - return context.card.id - if isinstance(context, SingleCardPreviewerMod): - return context.card().id - if isinstance(context, BrowserPreviewer): - return context.card().id - return None - - -def on_js_message(handled, url: str, context): - """onAppMsgWrapper 这个函数也控制一些读取, 这里搞不懂的去那看看""" - if url.startswith("hjp-bilink-cid:"): - cid: "CardId" = CardId(int(url.split(":")[-1])) - - if funcs.CardOperation.exists(cid): - card = mw.col.getCard(cid) - funcs.Dialogs.open_custom_cardwindow(card).activateWindow() - else: - showInfo(f"""卡片不存在,id={str(cid)}""") - return True, None - # elif url.startswith("hjp-bilink-clipuuid:"): - # pdfuuid, pagenum = url.split(":")[-1].split("_") - # funcs.Dialogs.open_PDFprev(pdfuuid, pagenum, context) - elif url.startswith(f"{ankilink.protocol}://"): - if url.startswith(f"{ankilink.protocol}://{ankilink.cmd.opengview}="): - mode = funcs.GraphMode - uuid = url[-8:] - funcs.Utils.print(str(context.__class__.__name__)) - if funcs.GviewOperation.exists(uuid=uuid): - data = funcs.GviewOperation.load(uuid=uuid) - funcs.Dialogs.open_grapher(mode=mode.view_mode, gviewdata=data) - else: - showInfo(f"""视图不存在,id={uuid}""") - elif url.startswith(f"{ankilink.protocol}://{ankilink.cmd.opencard}="): - card_id = url[-13:] - if funcs.CardOperation.exists(card_id): - funcs.Dialogs.open_custom_cardwindow(card_id).activateWindow() - else: - showInfo(f"""卡片不存在,card_id={card_id}""") - elif url.startswith(f"{ankilink.protocol}://{ankilink.cmd.openbrowser_search}="): - s_len = len(f"{ankilink.protocol}://{ankilink.cmd.openbrowser_search}=") - searchstring = unquote(url[s_len + 1:]) - funcs.BrowserOperation.search(searchstring).activateWindow() - elif url.startswith(f"{ankilink.protocol}://{ankilink.Cmd.open}?{ankilink.Key.card}="): - card_id = url[-13:] - if funcs.CardOperation.exists(card_id): - funcs.Dialogs.open_custom_cardwindow(card_id).activateWindow() - else: - showInfo(f"""卡片不存在,card_id={card_id}""") - elif url.startswith(f"{ankilink.protocol}://{ankilink.Cmd.open}?{ankilink.Key.gview}="): - gview_id = url[-8:] - if funcs.GviewOperation.exists(uuid=gview_id): - data = funcs.GviewOperation.load(uuid=gview_id) - funcs.Dialogs.open_grapher(gviewdata=data, mode=funcs.GraphMode.view_mode) - elif url.startswith(f"{ankilink.protocol}://{ankilink.Cmd.open}?{ankilink.Key.browser_search}="): - searchstring = unquote(url.split("=")[-1]) - funcs.BrowserOperation.search(searchstring).activateWindow() - else: - showInfo("未知指令/unknown command:
" + url) - elif url.startswith("file://"): - matches = re.search("file:/{2,3}(?P.*)#page=(?P\d+)$", url) - pdfpath = matches.group("pdfpath") - pdfurl = quote(pdfpath) - pagenum = matches.group("page") - cmd: "str" = funcs.G.CONFIG.PDFUrlLink_cmd.value - if cmd.__contains__(terms.PDFLink.url): - cmd = re.sub(f"{{{terms.PDFLink.url}}}", pdfurl, cmd) - else: - cmd = re.sub(f"{{{terms.PDFLink.path}}}", pdfpath, cmd) - cmd = re.sub(f"{{{terms.PDFLink.page}}}", pagenum, cmd) - print(cmd) - # tooltip(cmd) - os.system(cmd) - return handled +import os +import platform +import re +import sys +from urllib.parse import quote, unquote + +from aqt import mw +# from ..dialogs.DialogCardPrev import external_card_dialog +from aqt.browser.previewer import BrowserPreviewer +from aqt.editor import Editor +from aqt.reviewer import Reviewer +from aqt.utils import showInfo, tooltip + +from . import funcs, terms + +CardId = funcs.Compatible.CardId() + +# print, _ = clipper_imports.funcs.logger(__name__) +ankilink = funcs.G.src.ankilink + + +def find_card_from_context(context): + from ..bilink.dialogs.custom_cardwindow import SingleCardPreviewerMod + if isinstance(context, Editor): + return context.card.id + if isinstance(context, SingleCardPreviewerMod): + return context.card().id + if isinstance(context, BrowserPreviewer): + return context.card().id + return None + + +def on_js_message(handled, url: str, context): + """onAppMsgWrapper 这个函数也控制一些读取, 这里搞不懂的去那看看""" + if url.startswith("hjp-bilink-cid:"): + cid: "CardId" = CardId(int(url.split(":")[-1])) + + if funcs.CardOperation.exists(cid): + card = mw.col.getCard(cid) + funcs.Dialogs.open_custom_cardwindow(card).activateWindow() + else: + showInfo(f"""卡片不存在,id={str(cid)}""") + return True, None + # elif url.startswith("hjp-bilink-clipuuid:"): + # pdfuuid, pagenum = url.split(":")[-1].split("_") + # funcs.Dialogs.open_PDFprev(pdfuuid, pagenum, context) + elif url.startswith(f"{ankilink.protocol}://"): + if url.startswith(f"{ankilink.protocol}://{ankilink.cmd.opengview}="): + mode = funcs.GraphMode + uuid = url[-8:] + funcs.Utils.print(str(context.__class__.__name__)) + if funcs.GviewOperation.exists(uuid=uuid): + data = funcs.GviewOperation.load(uuid=uuid) + funcs.Dialogs.open_grapher(mode=mode.view_mode, gviewdata=data) + else: + showInfo(f"""视图不存在,id={uuid}""") + elif url.startswith(f"{ankilink.protocol}://{ankilink.cmd.opencard}="): + card_id = url[-13:] + if funcs.CardOperation.exists(card_id): + funcs.Dialogs.open_custom_cardwindow(card_id).activateWindow() + else: + showInfo(f"""卡片不存在,card_id={card_id}""") + elif url.startswith(f"{ankilink.protocol}://{ankilink.cmd.openbrowser_search}="): + s_len = len(f"{ankilink.protocol}://{ankilink.cmd.openbrowser_search}=") + searchstring = unquote(url[s_len + 1:]) + funcs.BrowserOperation.search(searchstring).activateWindow() + elif url.startswith(f"{ankilink.protocol}://{ankilink.Cmd.open}?{ankilink.Key.card}="): + card_id = url[-13:] + if funcs.CardOperation.exists(card_id): + funcs.Dialogs.open_custom_cardwindow(card_id).activateWindow() + else: + showInfo(f"""卡片不存在,card_id={card_id}""") + elif url.startswith(f"{ankilink.protocol}://{ankilink.Cmd.open}?{ankilink.Key.gview}="): + gview_id = url[-8:] + if funcs.GviewOperation.exists(uuid=gview_id): + data = funcs.GviewOperation.load(uuid=gview_id) + funcs.Dialogs.open_grapher(gviewdata=data, mode=funcs.GraphMode.view_mode) + elif url.startswith(f"{ankilink.protocol}://{ankilink.Cmd.open}?{ankilink.Key.browser_search}="): + searchstring = unquote(url.split("=")[-1]) + funcs.BrowserOperation.search(searchstring).activateWindow() + else: + showInfo("未知指令/unknown command:
" + url) + elif url.startswith("file:/"): + matches = re.search("file:/{2,3}(?P.*)#page=(?P\d+)$", url) + pdfpath = matches.group("pdfpath") + pdfurl = quote(pdfpath) + pagenum = matches.group("page") + cmd: "str" = funcs.G.CONFIG.PDFUrlLink_cmd.value + if cmd.__contains__(terms.PDFLink.url): + cmd = re.sub(f"{{{terms.PDFLink.url}}}", pdfurl, cmd) + else: + cmd = re.sub(f"{{{terms.PDFLink.path}}}", pdfpath, cmd) + cmd = re.sub(f"{{{terms.PDFLink.page}}}", pagenum, cmd) + print(cmd) + # tooltip(cmd) + os.system(cmd) + return handled