Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
napretep committed Jul 21, 2022
1 parent 3909af6 commit 5a71a19
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 100 deletions.
6 changes: 3 additions & 3 deletions lib/common_tools/configsModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
194 changes: 97 additions & 97 deletions lib/common_tools/handle_js.py
Original file line number Diff line number Diff line change
@@ -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:<br>" + url)
elif url.startswith("file://"):
matches = re.search("file:/{2,3}(?P<pdfpath>.*)#page=(?P<page>\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:<br>" + url)
elif url.startswith("file:/"):
matches = re.search("file:/{2,3}(?P<pdfpath>.*)#page=(?P<page>\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

0 comments on commit 5a71a19

Please sign in to comment.