class YomichanPlugin(Yomichan): def __init__(self): Yomichan.__init__(self) self.toolIconVisible = False self.window = None self.anki = anki_bridge.Anki() self.parent = self.anki.window() self.ankiConnect = AnkiConnect(self.anki, self.preferences) separator = QtGui.QAction(self.parent) separator.setSeparator(True) self.anki.addUiAction(separator) action = QtGui.QAction(QtGui.QIcon(':/img/img/icon_logo_32.png'), '&Yomichan...', self.parent) action.setIconVisibleInMenu(True) action.setShortcut('Ctrl+Y') action.triggered.connect(self.onShowRequest) self.anki.addUiAction(action) def onShowRequest(self): if self.window: self.window.setVisible(True) self.window.activateWindow() else: self.window = MainWindowReader(self.parent, self.preferences, self.language, None, self.anki, self.onWindowClose) self.window.show() def onWindowClose(self): self.window = None
def onShowRequest(self): if self.window: self.window.setVisible(True) self.window.activateWindow() else: self.window = MainWindowReader(self.parent, self.preferences, self.language, None, self.anki, self.onWindowClose) self.window.show()
def __init__(self): Yomichan.__init__(self) self.application = QtGui.QApplication(sys.argv) self.window = MainWindowReader( None, self.preferences, self.language, filename=sys.argv[1] if len(sys.argv) >= 2 else None) self.window.show() self.application.exec_()
class YomichanStandalone(Yomichan): def __init__(self): Yomichan.__init__(self) self.application = QtGui.QApplication(sys.argv) self.window = MainWindowReader( None, self.preferences, self.language, filename=sys.argv[1] if len(sys.argv) >= 2 else None ) self.window.show() self.application.exec_()
class YomichanPlugin(Yomichan): def __init__(self): Yomichan.__init__(self) self.toolIconVisible = False self.window = None self.anki = anki_bridge.Anki() self.parent = self.anki.window() self.ankiConnect = AnkiConnect(self.anki, self.preferences) separator = QtGui.QAction(self.parent) separator.setSeparator(True) self.anki.addUiAction(separator) action = QtGui.QAction(QtGui.QIcon(':/img/img/icon_logo_32.png'), '&Yomichan...', self.parent) action.setIconVisibleInMenu(True) action.setShortcut('Ctrl+Y') action.triggered.connect(self.onShowRequest) self.anki.addUiAction(action) def onShowRequest(self): if self.window: self.window.setVisible(True) self.window.activateWindow() else: self.window = MainWindowReader( self.parent, self.preferences, self.language, None, self.anki, self.onWindowClose ) self.window.show() def onWindowClose(self): self.window = None
def onShowRequest(self): if self.window: self.window.setVisible(True) self.window.activateWindow() else: self.window = MainWindowReader( self.parent, self.preferences, self.language, None, self.anki, self.onWindowClose ) self.window.show()
class YomichanPlugin(Yomichan): def __init__(self): Yomichan.__init__(self) self.toolIconVisible = False self.window = None self.anki = Anki() self.fileCache = dict() self.ankiConnect = AnkiConnect(self, self.preferences) self.parent = None #self.anki.window() separator = QtGui.QAction(self.anki.window()) separator.setSeparator(True) self.anki.addUiAction(separator) self.profiles = profiles.getAllProfileClasses() self.preventReload = False action = QtGui.QAction(QtGui.QIcon(':/img/img/icon_logo_32.png'), '&Yomichan...', self.anki.window()) action.setIconVisibleInMenu(True) action.setShortcut('Ctrl+Y') action.triggered.connect(self.onShowRequest) self.anki.addUiAction(action) def onShowRequest(self): if self.window: self.window.setVisible(True) self.window.activateWindow() else: self.window = MainWindowReader( self, self.parent, self.preferences, self.languages, self.anki, self.onWindowClose ) self.window.show() def fetchAllCards(self): if self.anki is None: return None allCards = dict() for p in self.profiles: profile = self.preferences['profiles'].get(p) d = dict() if profile is None: continue for cid,value,nid in self.anki.getCards(profile["model"]): if value not in d: d[value] = self.anki.collection().getCard(cid) allCards[p] = d return allCards def loadAllTexts(self,rootDir=None): if not hasattr(self,'i'): self.i = 0 self.i += 1 if rootDir is None: rootDir = u"Yomichan" oldCache = self.fileCache self.fileCache = dict() self.allCards = self.fetchAllCards() if self.allCards is not None: mediadir = self.anki.collection().media.dir() yomimedia = os.path.join(mediadir,rootDir) def processFile(file,relDir): if file[-4:] in extensions['text']: path = os.path.join(relDir,file) fullPath = u'::'.join(unicode(path).split(os.sep)) if fullPath in oldCache: fileState = oldCache[fullPath] fileState.load() else: fileState = FileState(os.path.join(mediadir,path),self.preferences['stripReadings'],profiles=self.profiles) self.fileCache[fullPath] = fileState # create deck if necessary self.anki.collection().decks.id(fullPath,create=True) fileState.findVocabulary(self.anki.collection().sched,self.allCards,needContent=False) if os.path.isdir(yomimedia): for root,dirs,files in os.walk(yomimedia): relDir = os.path.relpath(root,mediadir) for file in files: processFile(file,relDir) for dir in dirs: path = os.path.join(relDir,dir) self.fileCache[u'::'.join(unicode(path).split(os.sep))] = None elif os.path.isfile(yomimedia): processFile(os.path.basename(yomimedia),os.path.dirname(rootDir)) def onWindowClose(self): self.window = None ### this becomes obsolote due to onAfterStateChange #if not sum(list(aqt.mw.col.sched.counts())): # aqt.mw.moveToState('deckBrowser') def getFileCache(self): return self.fileCache