def init_JxPlugin(): """Initialises the Anki GUI to present an option to invoke the plugin.""" from PyQt4 import QtGui, QtCore # put JxWindow at the left of the main window widg ={} n = mw.mainWin.hboxlayout.count() for a in reversed(range(0,n)): widg[a+1]=mw.mainWin.hboxlayout.takeAt(a).widget() mw.mainWin.hboxlayout.removeWidget(widg[a+1]) widg[0]=JxWindow for a in range(0,n+1): mw.mainWin.hboxlayout.addWidget(widg[a]) # creates menu entry mw.mainWin.actionJxMenu = QtGui.QAction('JxMenu', mw) mw.mainWin.actionJxMenu.setStatusTip('Stats, Tools ans Settings for Japanese') mw.mainWin.actionJxMenu.setEnabled(not not mw.deck) mw.connect(mw.mainWin.actionJxMenu, QtCore.SIGNAL('triggered()'), onJxMenu) # creates graph entry mw.mainWin.actionJxGraphs = QtGui.QAction('JxGraphs', mw) mw.mainWin.actionJxGraphs.setStatusTip('Graphs for Japanese') mw.mainWin.actionJxGraphs.setEnabled(not not mw.deck) mw.connect(mw.mainWin.actionJxGraphs, QtCore.SIGNAL('triggered()'), onJxGraphs) # adds the plugin icons in the Anki Toolbar mw.mainWin.toolBar.addAction(mw.mainWin.actionJxMenu) mw.mainWin.toolBar.addAction(mw.mainWin.actionJxGraphs) # to enable or disable Jstats whenever a deck is opened/closed mw.deckRelatedMenuItems = mw.deckRelatedMenuItems + ("JxMenu","JxGraphs",) # Adding features through hooks ! mw.addHook('drawAnswer', append_JxPlugin) # additional info in answer cards mw.addHook('deckClosed', JxWindow.hide) # hides the main Jxplugin window when the current deck is closed # this is needed for people who open Anki by double clicking on an Anki deck (it bypasses newLoadDeck) if (mw.deck): from database import build_JxDeck build_JxDeck()
def newLoadDeck(deckPath, sync=True, interactive=True, uprecent=True,media=None): code = oldLoadDeck(deckPath, sync, interactive, uprecent,media) if code and mw.deck: from database import build_JxDeck build_JxDeck() return code