2019-02-05 04:59:03 +01:00
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
2012-12-21 08:51:59 +01:00
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2021-03-22 09:23:56 +01:00
|
|
|
|
2020-02-08 23:59:29 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-01-26 01:48:49 +01:00
|
|
|
import html
|
2019-12-20 10:19:03 +01:00
|
|
|
from copy import deepcopy
|
2020-02-17 16:26:21 +01:00
|
|
|
from dataclasses import dataclass
|
2021-10-03 10:59:42 +02:00
|
|
|
from typing import Any
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
import aqt
|
2022-02-13 04:40:47 +01:00
|
|
|
import aqt.operations
|
2023-12-10 03:33:43 +01:00
|
|
|
from anki.collection import Collection, OpChanges
|
2021-05-31 08:24:51 +02:00
|
|
|
from anki.decks import DeckCollapseScope, DeckId, DeckTreeNode
|
2020-01-22 01:46:35 +01:00
|
|
|
from aqt import AnkiQt, gui_hooks
|
2021-05-27 05:11:20 +02:00
|
|
|
from aqt.deckoptions import display_options_for_deck_id
|
2021-05-08 08:20:10 +02:00
|
|
|
from aqt.operations import QueryOp
|
2021-04-03 08:26:10 +02:00
|
|
|
from aqt.operations.deck import (
|
|
|
|
add_deck_dialog,
|
|
|
|
remove_decks,
|
|
|
|
rename_deck,
|
|
|
|
reparent_decks,
|
2021-04-06 13:37:31 +02:00
|
|
|
set_current_deck,
|
2021-04-05 02:21:50 +02:00
|
|
|
set_deck_collapsed,
|
2021-04-03 08:26:10 +02:00
|
|
|
)
|
2019-12-20 10:19:03 +01:00
|
|
|
from aqt.qt import *
|
2020-01-20 11:10:38 +01:00
|
|
|
from aqt.sound import av_player
|
2020-01-22 01:46:35 +01:00
|
|
|
from aqt.toolbar import BottomBar
|
2021-05-06 10:50:24 +02:00
|
|
|
from aqt.utils import getOnlyText, openLink, shortcut, showInfo, tr
|
2019-12-20 10:19:03 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-02-08 23:59:29 +01:00
|
|
|
class DeckBrowserBottomBar:
|
2021-02-01 14:28:21 +01:00
|
|
|
def __init__(self, deck_browser: DeckBrowser) -> None:
|
2020-02-08 23:59:29 +01:00
|
|
|
self.deck_browser = deck_browser
|
|
|
|
|
|
|
|
|
2023-12-10 03:33:43 +01:00
|
|
|
@dataclass
|
|
|
|
class RenderData:
|
|
|
|
"""Data from collection that is required to show the page."""
|
|
|
|
|
|
|
|
tree: DeckTreeNode
|
|
|
|
current_deck_id: DeckId
|
|
|
|
studied_today: str
|
|
|
|
sched_upgrade_required: bool
|
|
|
|
|
|
|
|
|
2020-02-17 16:26:21 +01:00
|
|
|
@dataclass
|
|
|
|
class DeckBrowserContent:
|
|
|
|
"""Stores sections of HTML content that the deck browser will be
|
|
|
|
populated with.
|
2020-08-31 05:29:28 +02:00
|
|
|
|
2020-02-17 16:26:21 +01:00
|
|
|
Attributes:
|
|
|
|
tree {str} -- HTML of the deck tree section
|
|
|
|
stats {str} -- HTML of the stats section
|
|
|
|
"""
|
|
|
|
|
|
|
|
tree: str
|
|
|
|
stats: str
|
2020-02-16 19:29:01 +01:00
|
|
|
|
|
|
|
|
2020-05-16 02:52:14 +02:00
|
|
|
@dataclass
|
|
|
|
class RenderDeckNodeContext:
|
2021-03-27 12:38:20 +01:00
|
|
|
current_deck_id: DeckId
|
2020-05-16 02:52:14 +02:00
|
|
|
|
|
|
|
|
2017-02-06 23:21:33 +01:00
|
|
|
class DeckBrowser:
|
2023-12-10 03:33:43 +01:00
|
|
|
_render_data: RenderData
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-01-22 01:46:35 +01:00
|
|
|
def __init__(self, mw: AnkiQt) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
self.mw = mw
|
|
|
|
self.web = mw.web
|
2020-01-22 01:46:35 +01:00
|
|
|
self.bottom = BottomBar(mw, mw.bottomWeb)
|
2014-02-17 03:04:36 +01:00
|
|
|
self.scrollPos = QPoint(0, 0)
|
2021-03-14 15:03:41 +01:00
|
|
|
self._refresh_needed = False
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-02-01 14:28:21 +01:00
|
|
|
def show(self) -> None:
|
2020-01-20 11:10:38 +01:00
|
|
|
av_player.stop_and_clear_queue()
|
2020-02-08 23:59:29 +01:00
|
|
|
self.web.set_bridge_command(self._linkHandler, self)
|
2020-01-31 04:31:31 +01:00
|
|
|
# redraw top bar for theme change
|
2020-06-02 05:23:01 +02:00
|
|
|
self.mw.toolbar.redraw()
|
2021-03-14 13:08:37 +01:00
|
|
|
self.refresh()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-02-01 14:28:21 +01:00
|
|
|
def refresh(self) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
self._renderPage()
|
2021-03-14 15:03:41 +01:00
|
|
|
self._refresh_needed = False
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-03-14 13:08:37 +01:00
|
|
|
def refresh_if_needed(self) -> None:
|
2021-03-14 15:03:41 +01:00
|
|
|
if self._refresh_needed:
|
2021-03-14 13:08:37 +01:00
|
|
|
self.refresh()
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
|
2021-04-06 02:14:11 +02:00
|
|
|
def op_executed(
|
2021-10-03 10:59:42 +02:00
|
|
|
self, changes: OpChanges, handler: object | None, focused: bool
|
2021-04-06 02:14:11 +02:00
|
|
|
) -> bool:
|
2021-06-08 04:09:35 +02:00
|
|
|
if changes.study_queues and handler is not self:
|
2021-03-14 15:03:41 +01:00
|
|
|
self._refresh_needed = True
|
2021-03-14 13:08:37 +01:00
|
|
|
|
|
|
|
if focused:
|
|
|
|
self.refresh_if_needed()
|
more reset refactoring
'card modified' covers the common case where we need to rebuild the
study queue, but is also set when changing the card flags. We want to
avoid a queue rebuild in that case, as it causes UI flicker, and may
result in a different card being shown. Note marking doesn't trigger
a queue build, but still causes flicker, and may return the user back
to the front side when they were looking at the answer.
I still think entity-based change tracking is the simplest in the
common case, but to solve the above, I've introduced an enum describing
the last operation that was taken. This currently is not trying to list
out all possible operations, and just describes the ones we want to
special-case.
Other changes:
- Fire the old 'state_did_reset' hook after an operation is performed,
so legacy code can refresh itself after an operation is performed.
- Fire the new `operation_did_execute` hook when mw.reset() is called,
so that as the UI is updated to the use the new hook, it will still
be able to refresh after legacy code calls mw.reset()
- Update the deck browser, overview and review screens to listen to
the new hook, instead of relying on the main window to call moveToState()
- Add a 'set flag' backend action, so we can distinguish it from a
normal card update.
- Drop the separate added/modified entries in the change list in
favour of a single entry per entity.
- Add typing to mw.state
- Tweak perform_op()
- Convert a few more actions to use perform_op()
2021-03-14 10:54:15 +01:00
|
|
|
|
2021-03-14 15:03:41 +01:00
|
|
|
return self._refresh_needed
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
# Event handlers
|
|
|
|
##########################################################################
|
|
|
|
|
2021-01-30 11:37:29 +01:00
|
|
|
def _linkHandler(self, url: str) -> Any:
|
2012-12-21 08:51:59 +01:00
|
|
|
if ":" in url:
|
2021-01-25 16:33:18 +01:00
|
|
|
(cmd, arg) = url.split(":", 1)
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
|
|
|
cmd = url
|
|
|
|
if cmd == "open":
|
2021-04-06 13:37:31 +02:00
|
|
|
self.set_current_deck(DeckId(int(arg)))
|
2012-12-21 08:51:59 +01:00
|
|
|
elif cmd == "opts":
|
|
|
|
self._showOptions(arg)
|
|
|
|
elif cmd == "shared":
|
|
|
|
self._onShared()
|
|
|
|
elif cmd == "import":
|
|
|
|
self.mw.onImport()
|
|
|
|
elif cmd == "create":
|
2021-02-24 13:59:38 +01:00
|
|
|
self._on_create()
|
2012-12-21 08:51:59 +01:00
|
|
|
elif cmd == "drag":
|
2021-01-30 11:37:29 +01:00
|
|
|
source, target = arg.split(",")
|
2021-03-27 12:38:20 +01:00
|
|
|
self._handle_drag_and_drop(DeckId(int(source)), DeckId(int(target or 0)))
|
2012-12-21 08:51:59 +01:00
|
|
|
elif cmd == "collapse":
|
2021-03-27 12:38:20 +01:00
|
|
|
self._collapse(DeckId(int(arg)))
|
2021-02-21 06:50:41 +01:00
|
|
|
elif cmd == "v2upgrade":
|
|
|
|
self._confirm_upgrade()
|
|
|
|
elif cmd == "v2upgradeinfo":
|
2023-09-16 08:09:26 +02:00
|
|
|
if self.mw.col.sched_ver() == 1:
|
|
|
|
openLink("https://faqs.ankiweb.net/the-anki-2.1-scheduler.html")
|
|
|
|
else:
|
|
|
|
openLink("https://faqs.ankiweb.net/the-2021-scheduler.html")
|
2023-02-28 03:09:40 +01:00
|
|
|
elif cmd == "select":
|
|
|
|
set_current_deck(
|
|
|
|
parent=self.mw, deck_id=DeckId(int(arg))
|
|
|
|
).run_in_background()
|
2016-05-31 10:51:40 +02:00
|
|
|
return False
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-04-06 13:37:31 +02:00
|
|
|
def set_current_deck(self, deck_id: DeckId) -> None:
|
|
|
|
set_current_deck(parent=self.mw, deck_id=deck_id).success(
|
|
|
|
lambda _: self.mw.onOverview()
|
|
|
|
).run_in_background(initiator=self)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# HTML generation
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
_body = """
|
|
|
|
<center>
|
2022-11-24 11:18:57 +01:00
|
|
|
<table cellspacing=0 cellpadding=3>
|
2012-12-21 08:51:59 +01:00
|
|
|
%(tree)s
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<br>
|
|
|
|
%(stats)s
|
|
|
|
</center>
|
|
|
|
"""
|
|
|
|
|
2021-02-02 15:00:29 +01:00
|
|
|
def _renderPage(self, reuse: bool = False) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
if not reuse:
|
2018-06-12 05:46:15 +02:00
|
|
|
|
2023-12-10 03:33:43 +01:00
|
|
|
def get_data(col: Collection) -> RenderData:
|
|
|
|
return RenderData(
|
|
|
|
tree=col.sched.deck_due_tree(),
|
|
|
|
current_deck_id=col.decks.get_current_id(),
|
|
|
|
studied_today=col.studied_today(),
|
|
|
|
sched_upgrade_required=not col.v3_scheduler(),
|
|
|
|
)
|
|
|
|
|
|
|
|
def success(output: RenderData) -> None:
|
|
|
|
self._render_data = output
|
2023-09-30 07:38:11 +02:00
|
|
|
self.__renderPage(None)
|
|
|
|
|
|
|
|
QueryOp(
|
|
|
|
parent=self.mw,
|
2023-12-10 03:33:43 +01:00
|
|
|
op=get_data,
|
2023-09-30 07:38:11 +02:00
|
|
|
success=success,
|
|
|
|
).run_in_background()
|
|
|
|
else:
|
|
|
|
self.web.evalWithCallback("window.pageYOffset", self.__renderPage)
|
|
|
|
|
|
|
|
def __renderPage(self, offset: int | None) -> None:
|
2023-12-10 03:33:43 +01:00
|
|
|
data = self._render_data
|
2020-02-17 16:26:21 +01:00
|
|
|
content = DeckBrowserContent(
|
2023-12-10 03:33:43 +01:00
|
|
|
tree=self._renderDeckTree(data.tree),
|
2023-12-14 01:57:50 +01:00
|
|
|
stats=self._renderStats(),
|
2020-02-16 19:29:01 +01:00
|
|
|
)
|
2020-02-17 16:26:21 +01:00
|
|
|
gui_hooks.deck_browser_will_render_content(self, content)
|
2019-12-23 01:34:10 +01:00
|
|
|
self.web.stdHtml(
|
2023-12-10 03:33:43 +01:00
|
|
|
self._v1_upgrade_message(data.sched_upgrade_required)
|
|
|
|
+ self._body % content.__dict__,
|
2020-11-01 05:26:58 +01:00
|
|
|
css=["css/deckbrowser.css"],
|
2020-12-21 04:20:55 +01:00
|
|
|
js=[
|
2020-12-28 14:18:07 +01:00
|
|
|
"js/vendor/jquery.min.js",
|
2020-12-30 12:07:02 +01:00
|
|
|
"js/vendor/jquery-ui.min.js",
|
2020-12-21 04:20:55 +01:00
|
|
|
"js/deckbrowser.js",
|
|
|
|
],
|
2020-02-12 22:00:13 +01:00
|
|
|
context=self,
|
2019-12-23 01:34:10 +01:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
self._drawButtons()
|
2019-04-29 08:46:13 +02:00
|
|
|
if offset is not None:
|
|
|
|
self._scrollToOffset(offset)
|
2020-04-09 05:40:19 +02:00
|
|
|
gui_hooks.deck_browser_did_render(self)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-02-02 15:00:29 +01:00
|
|
|
def _scrollToOffset(self, offset: int) -> None:
|
2021-04-13 20:26:06 +02:00
|
|
|
self.web.eval("window.scrollTo(0, %d, 'instant');" % offset)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2023-12-14 01:57:50 +01:00
|
|
|
def _renderStats(self) -> str:
|
|
|
|
return '<div id="studiedToday"><span>{}</span></div>'.format(
|
|
|
|
self._render_data.studied_today
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2020-05-16 02:52:14 +02:00
|
|
|
def _renderDeckTree(self, top: DeckTreeNode) -> str:
|
|
|
|
buf = """
|
2021-10-03 10:59:42 +02:00
|
|
|
<tr><th colspan=5 align=start>{}</th>
|
|
|
|
<th class=count>{}</th>
|
2022-02-16 01:23:57 +01:00
|
|
|
<th class=count>{}</th>
|
2021-10-03 10:59:42 +02:00
|
|
|
<th class=count>{}</th>
|
|
|
|
<th class=optscol></th></tr>""".format(
|
2023-10-26 05:15:00 +02:00
|
|
|
tr.decks_deck(),
|
2021-03-26 04:48:26 +01:00
|
|
|
tr.actions_new(),
|
2023-10-26 05:15:00 +02:00
|
|
|
tr.decks_learn_header(),
|
2023-11-02 12:15:02 +01:00
|
|
|
tr.decks_review_header(),
|
2020-05-16 02:52:14 +02:00
|
|
|
)
|
|
|
|
buf += self._topLevelDragRow()
|
|
|
|
|
2023-12-10 03:33:43 +01:00
|
|
|
ctx = RenderDeckNodeContext(current_deck_id=self._render_data.current_deck_id)
|
2020-05-16 02:52:14 +02:00
|
|
|
|
|
|
|
for child in top.children:
|
|
|
|
buf += self._render_deck_node(child, ctx)
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
return buf
|
|
|
|
|
2020-05-16 02:52:14 +02:00
|
|
|
def _render_deck_node(self, node: DeckTreeNode, ctx: RenderDeckNodeContext) -> str:
|
|
|
|
if node.collapsed:
|
2012-12-21 08:51:59 +01:00
|
|
|
prefix = "+"
|
2020-05-16 02:02:08 +02:00
|
|
|
else:
|
|
|
|
prefix = "-"
|
2020-05-16 02:52:14 +02:00
|
|
|
|
2021-02-01 14:28:21 +01:00
|
|
|
def indent() -> str:
|
2020-05-16 02:52:14 +02:00
|
|
|
return " " * 6 * (node.level - 1)
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2020-05-16 02:52:14 +02:00
|
|
|
if node.deck_id == ctx.current_deck_id:
|
2019-12-23 01:34:10 +01:00
|
|
|
klass = "deck current"
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
2019-12-23 01:34:10 +01:00
|
|
|
klass = "deck"
|
2020-05-16 02:52:14 +02:00
|
|
|
|
2023-02-28 03:09:40 +01:00
|
|
|
buf = (
|
|
|
|
"<tr class='%s' id='%d' onclick='if(event.shiftKey) return pycmd(\"select:%d\")'>"
|
|
|
|
% (
|
|
|
|
klass,
|
|
|
|
node.deck_id,
|
|
|
|
node.deck_id,
|
|
|
|
)
|
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
# deck link
|
2020-05-16 02:52:14 +02:00
|
|
|
if node.children:
|
2019-12-23 01:34:10 +01:00
|
|
|
collapse = (
|
|
|
|
"<a class=collapse href=# onclick='return pycmd(\"collapse:%d\")'>%s</a>"
|
2020-05-16 02:52:14 +02:00
|
|
|
% (node.deck_id, prefix)
|
2019-12-23 01:34:10 +01:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
else:
|
|
|
|
collapse = "<span class=collapse></span>"
|
2020-05-16 02:52:14 +02:00
|
|
|
if node.filtered:
|
2012-12-21 08:51:59 +01:00
|
|
|
extraclass = "filtered"
|
|
|
|
else:
|
|
|
|
extraclass = ""
|
|
|
|
buf += """
|
|
|
|
|
2016-05-31 10:51:40 +02:00
|
|
|
<td class=decktd colspan=5>%s%s<a class="deck %s"
|
2019-12-23 01:34:10 +01:00
|
|
|
href=# onclick="return pycmd('open:%d')">%s</a></td>""" % (
|
|
|
|
indent(),
|
|
|
|
collapse,
|
|
|
|
extraclass,
|
2020-05-16 02:52:14 +02:00
|
|
|
node.deck_id,
|
2023-01-26 01:48:49 +01:00
|
|
|
html.escape(node.name),
|
2019-12-23 01:34:10 +01:00
|
|
|
)
|
2023-03-31 06:02:40 +02:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
# due counts
|
2021-02-01 14:28:21 +01:00
|
|
|
def nonzeroColour(cnt: int, klass: str) -> str:
|
2012-12-21 08:51:59 +01:00
|
|
|
if not cnt:
|
2020-01-23 06:08:10 +01:00
|
|
|
klass = "zero-count"
|
|
|
|
return f'<span class="{klass}">{cnt}</span>'
|
2019-12-23 01:34:10 +01:00
|
|
|
|
2021-05-16 10:26:01 +02:00
|
|
|
review = nonzeroColour(node.review_count, "review-count")
|
|
|
|
learn = nonzeroColour(node.learn_count, "learn-count")
|
|
|
|
|
2022-12-08 13:29:56 +01:00
|
|
|
buf += ("<td align=end>%s</td>" * 3) % (
|
2020-05-16 02:52:14 +02:00
|
|
|
nonzeroColour(node.new_count, "new-count"),
|
2021-05-16 10:26:01 +02:00
|
|
|
learn,
|
|
|
|
review,
|
2019-12-23 01:34:10 +01:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
# options
|
2019-12-23 01:34:10 +01:00
|
|
|
buf += (
|
|
|
|
"<td align=center class=opts><a onclick='return pycmd(\"opts:%d\");'>"
|
2020-05-16 02:52:14 +02:00
|
|
|
"<img src='/_anki/imgs/gears.svg' class=gears></a></td></tr>" % node.deck_id
|
2019-12-23 01:34:10 +01:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
# children
|
2020-05-16 02:52:14 +02:00
|
|
|
if not node.collapsed:
|
|
|
|
for child in node.children:
|
|
|
|
buf += self._render_deck_node(child, ctx)
|
2012-12-21 08:51:59 +01:00
|
|
|
return buf
|
|
|
|
|
2021-02-01 14:28:21 +01:00
|
|
|
def _topLevelDragRow(self) -> str:
|
2012-12-21 08:51:59 +01:00
|
|
|
return "<tr class='top-level-drag-row'><td colspan='6'> </td></tr>"
|
|
|
|
|
|
|
|
# Options
|
|
|
|
##########################################################################
|
|
|
|
|
2020-05-22 02:53:20 +02:00
|
|
|
def _showOptions(self, did: str) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
m = QMenu(self.mw)
|
2021-03-26 04:48:26 +01:00
|
|
|
a = m.addAction(tr.actions_rename())
|
2021-03-27 12:38:20 +01:00
|
|
|
qconnect(a.triggered, lambda b, did=did: self._rename(DeckId(int(did))))
|
2021-03-26 04:48:26 +01:00
|
|
|
a = m.addAction(tr.actions_options())
|
2021-03-27 12:38:20 +01:00
|
|
|
qconnect(a.triggered, lambda b, did=did: self._options(DeckId(int(did))))
|
2021-03-26 04:48:26 +01:00
|
|
|
a = m.addAction(tr.actions_export())
|
2021-03-27 12:38:20 +01:00
|
|
|
qconnect(a.triggered, lambda b, did=did: self._export(DeckId(int(did))))
|
2021-03-26 04:48:26 +01:00
|
|
|
a = m.addAction(tr.actions_delete())
|
2021-03-27 12:38:20 +01:00
|
|
|
qconnect(a.triggered, lambda b, did=did: self._delete(DeckId(int(did))))
|
2020-05-22 03:27:40 +02:00
|
|
|
gui_hooks.deck_browser_will_show_options_menu(m, int(did))
|
2022-02-18 08:18:29 +01:00
|
|
|
m.popup(QCursor.pos())
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-03-27 12:38:20 +01:00
|
|
|
def _export(self, did: DeckId) -> None:
|
2014-06-20 02:13:12 +02:00
|
|
|
self.mw.onExport(did=did)
|
|
|
|
|
2021-03-27 12:38:20 +01:00
|
|
|
def _rename(self, did: DeckId) -> None:
|
2021-05-31 08:24:51 +02:00
|
|
|
def prompt(name: str) -> None:
|
|
|
|
new_name = getOnlyText(tr.decks_new_deck_name(), default=name)
|
|
|
|
if not new_name or new_name == name:
|
2021-04-03 16:15:25 +02:00
|
|
|
return
|
|
|
|
else:
|
2021-04-06 06:36:13 +02:00
|
|
|
rename_deck(
|
|
|
|
parent=self.mw, deck_id=did, new_name=new_name
|
|
|
|
).run_in_background()
|
2021-04-03 16:15:25 +02:00
|
|
|
|
2021-05-08 08:20:10 +02:00
|
|
|
QueryOp(
|
2021-05-31 08:24:51 +02:00
|
|
|
parent=self.mw, op=lambda col: col.decks.name(did), success=prompt
|
2021-05-08 08:20:10 +02:00
|
|
|
).run_in_background()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-03-27 12:38:20 +01:00
|
|
|
def _options(self, did: DeckId) -> None:
|
2021-05-27 05:11:20 +02:00
|
|
|
display_options_for_deck_id(did)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-03-27 12:38:20 +01:00
|
|
|
def _collapse(self, did: DeckId) -> None:
|
2023-12-10 03:33:43 +01:00
|
|
|
node = self.mw.col.decks.find_deck_in_tree(self._render_data.tree, did)
|
2020-05-16 05:05:20 +02:00
|
|
|
if node:
|
2020-05-16 02:52:14 +02:00
|
|
|
node.collapsed = not node.collapsed
|
2021-04-05 02:21:50 +02:00
|
|
|
set_deck_collapsed(
|
2021-04-06 06:36:13 +02:00
|
|
|
parent=self.mw,
|
2021-04-05 02:21:50 +02:00
|
|
|
deck_id=did,
|
|
|
|
collapsed=node.collapsed,
|
|
|
|
scope=DeckCollapseScope.REVIEWER,
|
2021-04-06 06:36:13 +02:00
|
|
|
).run_in_background()
|
2021-04-05 02:21:50 +02:00
|
|
|
self._renderPage(reuse=True)
|
2020-05-16 02:52:14 +02:00
|
|
|
|
2021-03-27 12:38:20 +01:00
|
|
|
def _handle_drag_and_drop(self, source: DeckId, target: DeckId) -> None:
|
2021-04-06 06:36:13 +02:00
|
|
|
reparent_decks(
|
|
|
|
parent=self.mw, deck_ids=[source], new_parent=target
|
|
|
|
).run_in_background()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-03-27 12:38:20 +01:00
|
|
|
def _delete(self, did: DeckId) -> None:
|
2021-04-06 06:36:13 +02:00
|
|
|
remove_decks(parent=self.mw, deck_ids=[did]).run_in_background()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
# Top buttons
|
|
|
|
######################################################################
|
|
|
|
|
2017-07-15 15:39:01 +02:00
|
|
|
drawLinks = [
|
2021-03-26 04:48:26 +01:00
|
|
|
["", "shared", tr.decks_get_shared()],
|
|
|
|
["", "create", tr.decks_create_deck()],
|
|
|
|
["Ctrl+Shift+I", "import", tr.decks_import_file()],
|
2017-07-15 15:39:01 +02:00
|
|
|
]
|
|
|
|
|
2021-02-01 14:28:21 +01:00
|
|
|
def _drawButtons(self) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
buf = ""
|
2017-08-06 17:03:11 +02:00
|
|
|
drawLinks = deepcopy(self.drawLinks)
|
|
|
|
for b in drawLinks:
|
2012-12-21 08:51:59 +01:00
|
|
|
if b[0]:
|
2021-03-26 05:21:04 +01:00
|
|
|
b[0] = tr.actions_shortcut_key(val=shortcut(b[0]))
|
2012-12-21 08:51:59 +01:00
|
|
|
buf += """
|
2019-12-23 01:34:10 +01:00
|
|
|
<button title='%s' onclick='pycmd(\"%s\");'>%s</button>""" % tuple(
|
|
|
|
b
|
|
|
|
)
|
2020-02-12 22:00:13 +01:00
|
|
|
self.bottom.draw(
|
|
|
|
buf=buf,
|
|
|
|
link_handler=self._linkHandler,
|
|
|
|
web_context=DeckBrowserBottomBar(self),
|
2020-02-08 23:59:29 +01:00
|
|
|
)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2021-02-01 14:28:21 +01:00
|
|
|
def _onShared(self) -> None:
|
2021-02-11 01:09:06 +01:00
|
|
|
openLink(f"{aqt.appShared}decks/")
|
2021-02-21 06:50:41 +01:00
|
|
|
|
2021-02-24 13:59:38 +01:00
|
|
|
def _on_create(self) -> None:
|
2023-02-28 03:09:40 +01:00
|
|
|
if op := add_deck_dialog(
|
|
|
|
parent=self.mw, default_text=self.mw.col.decks.current()["name"]
|
|
|
|
):
|
2021-04-06 06:36:13 +02:00
|
|
|
op.run_in_background()
|
2021-02-24 13:59:38 +01:00
|
|
|
|
2021-02-21 06:50:41 +01:00
|
|
|
######################################################################
|
|
|
|
|
2023-12-10 03:33:43 +01:00
|
|
|
def _v1_upgrade_message(self, required: bool) -> str:
|
|
|
|
if not required:
|
2021-02-21 06:50:41 +01:00
|
|
|
return ""
|
|
|
|
|
2023-09-16 08:09:26 +02:00
|
|
|
update_required = tr.scheduling_update_required().replace("V2", "v3")
|
|
|
|
|
2021-02-21 06:50:41 +01:00
|
|
|
return f"""
|
|
|
|
<center>
|
|
|
|
<div class=callout>
|
|
|
|
<div>
|
2023-09-16 08:09:26 +02:00
|
|
|
{update_required}
|
2021-02-21 06:50:41 +01:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<button onclick='pycmd("v2upgrade")'>
|
2021-03-26 04:48:26 +01:00
|
|
|
{tr.scheduling_update_button()}
|
2021-02-21 06:50:41 +01:00
|
|
|
</button>
|
|
|
|
<button onclick='pycmd("v2upgradeinfo")'>
|
2021-03-26 04:48:26 +01:00
|
|
|
{tr.scheduling_update_more_info_button()}
|
2021-02-21 06:50:41 +01:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</center>
|
|
|
|
"""
|
|
|
|
|
|
|
|
def _confirm_upgrade(self) -> None:
|
2023-09-16 08:09:26 +02:00
|
|
|
if self.mw.col.sched_ver() == 1:
|
|
|
|
self.mw.col.mod_schema(check=True)
|
|
|
|
self.mw.col.upgrade_to_v2_scheduler()
|
|
|
|
self.mw.col.set_v3_scheduler(True)
|
2021-02-21 06:50:41 +01:00
|
|
|
|
2021-03-26 04:48:26 +01:00
|
|
|
showInfo(tr.scheduling_update_done())
|
2021-02-21 06:50:41 +01:00
|
|
|
self.refresh()
|