" % node.deck_id
)
# children
if not node.collapsed:
for child in node.children:
buf += self._render_deck_node(child, ctx)
return buf
def _topLevelDragRow(self) -> str:
return "
"
# Options
##########################################################################
def _showOptions(self, did: str) -> None:
m = QMenu(self.mw)
a = m.addAction(tr(TR.ACTIONS_RENAME))
qconnect(a.triggered, lambda b, did=did: self._rename(int(did)))
a = m.addAction(tr(TR.ACTIONS_OPTIONS))
qconnect(a.triggered, lambda b, did=did: self._options(did))
a = m.addAction(tr(TR.ACTIONS_EXPORT))
qconnect(a.triggered, lambda b, did=did: self._export(int(did)))
a = m.addAction(tr(TR.ACTIONS_DELETE))
qconnect(a.triggered, lambda b, did=did: self._delete(int(did)))
gui_hooks.deck_browser_will_show_options_menu(m, int(did))
m.exec_(QCursor.pos())
def _export(self, did: int) -> None:
self.mw.onExport(did=did)
def _rename(self, did: int) -> None:
deck = self.mw.col.decks.get(did)
oldName = deck["name"]
newName = getOnlyText(tr(TR.DECKS_NEW_DECK_NAME), default=oldName)
newName = newName.replace('"', "")
if not newName or newName == oldName:
return
try:
self.mw.col.decks.rename(deck, newName)
gui_hooks.sidebar_should_refresh_decks()
except DeckIsFilteredError as err:
showWarning(str(err))
return
self.mw.update_undo_actions()
self.show()
def _options(self, did: str) -> None:
# select the deck first, because the dyn deck conf assumes the deck
# we're editing is the current one
self.mw.col.decks.select(int(did))
self.mw.onDeckConf()
def _collapse(self, did: int) -> None:
self.mw.col.decks.collapse(did)
node = self.mw.col.decks.find_deck_in_tree(self._dueTree, did)
if node:
node.collapsed = not node.collapsed
self._renderPage(reuse=True)
def _handle_drag_and_drop(self, source: int, target: int) -> None:
def process() -> None:
self.mw.col.decks.drag_drop_decks([source], target)
def on_done(fut: Future) -> None:
try:
fut.result()
except Exception as e:
showWarning(str(e))
return
self.mw.update_undo_actions()
gui_hooks.sidebar_should_refresh_decks()
self.show()
self.mw.taskman.with_progress(process, on_done)
def _delete(self, did: int) -> None:
def do_delete() -> int:
return self.mw.col.decks.remove([did])
def on_done(fut: Future) -> None:
self.mw.reset()
self.mw.update_undo_actions()
self.show()
tooltip(tr(TR.BROWSING_CARDS_DELETED, count=fut.result()))
self.mw.taskman.with_progress(do_delete, on_done)
# Top buttons
######################################################################
drawLinks = [
["", "shared", tr(TR.DECKS_GET_SHARED)],
["", "create", tr(TR.DECKS_CREATE_DECK)],
["Ctrl+Shift+I", "import", tr(TR.DECKS_IMPORT_FILE)],
]
def _drawButtons(self) -> None:
buf = ""
drawLinks = deepcopy(self.drawLinks)
for b in drawLinks:
if b[0]:
b[0] = tr(TR.ACTIONS_SHORTCUT_KEY, val=shortcut(b[0]))
buf += """
""" % tuple(
b
)
self.bottom.draw(
buf=buf,
link_handler=self._linkHandler,
web_context=DeckBrowserBottomBar(self),
)
def _onShared(self) -> None:
openLink(f"{aqt.appShared}decks/")
def _on_create(self) -> None:
deck = getOnlyText(tr(TR.DECKS_NAME_FOR_DECK))
if deck:
try:
self.mw.col.decks.id(deck)
except DeckIsFilteredError as err:
showWarning(str(err))
return
gui_hooks.sidebar_should_refresh_decks()
self.refresh()
######################################################################
def _v1_upgrade_message(self) -> str:
if self.mw.col.schedVer() == 2:
return ""
if (intTime() - self._v1_message_dismissed_at) < 86_400:
return ""
return f"""
{tr(TR.SCHEDULING_UPDATE_SOON)}
"""
def _confirm_upgrade(self) -> None:
self.mw.col.modSchema(check=True)
self.mw.col.upgrade_to_v2_scheduler()
# not translated, as 2.15 should not be too far off
if askUser(
"Do you use AnkiDroid <= 2.14, or plan to use it in the near future? If unsure, choose No. You can adjust the setting later in the preferences screen.",
defaultno=True,
):
prefs = self.mw.col.get_preferences()
prefs.scheduling.new_timezone = False
self.mw.col.set_preferences(prefs)
showInfo(tr(TR.SCHEDULING_UPDATE_DONE))
self.refresh()