コード例 #1
0
 def onShowRequest(self):
     if self.window:
         self.window.setVisible(True)
         self.window.activateWindow()
     else:
         self.window = MainWindowReader(
             self.parent,
             self.languages,
             None,
             self.preferences,
             self.anki,
             self.onWindowClose,
             self.onWindowUpdate
         )
         self.window.show()
コード例 #2
0
class YomichanPlugin:
    def __init__(self):
        self.languages = {'Japanese': japanese.initLanguage()}
        self.preferences = Preferences()
        self.preferences.load()
        self.toolIconVisible = False
        self.window = None

        self.anki = anki_host.Anki()
        self.parent = self.anki.window()
        self.separator = QtGui.QAction(self.parent)
        self.separator.setSeparator(True)
        self.action = QtGui.QAction(QtGui.QIcon(':/logos/logos/logo32x32.png'), '&Yomichan...', self.parent)
        self.action.setIconVisibleInMenu(True)
        self.parent.connect(self.action, QtCore.SIGNAL('triggered()'), self.onShowRequest)

        self.anki.addHook('loadDeck', self.onDeckLoad)
        self.anki.addHook('deckClosed', self.onDeckClose)


    def onShowRequest(self):
        if self.window:
            self.window.setVisible(True)
            self.window.activateWindow()
        else:
            self.window = MainWindowReader(
                self.parent,
                self.languages,
                None,
                self.preferences,
                self.anki,
                self.onWindowClose,
                self.onWindowUpdate
            )
            self.window.show()


    def onWindowClose(self):
        self.window = None


    def onWindowUpdate(self):
        if self.preferences.ankiShowIcon:
            self.showToolIcon()
        else:
            self.hideToolIcon()


    def onDeckLoad(self):
        self.anki.toolsMenu().addAction(self.separator)
        self.anki.toolsMenu().addAction(self.action)

        if self.preferences.ankiShowIcon:
            self.showToolIcon()


    def onDeckClose(self):
        self.anki.toolsMenu().removeAction(self.action)
        self.anki.toolsMenu().removeAction(self.separator)

        self.hideToolIcon()

        if self.window:
            self.window.close()
            self.window = None


    def hideToolIcon(self):
        if self.toolIconVisible:
            self.anki.toolBar().removeAction(self.action)
            self.toolIconVisible = False


    def showToolIcon(self):
        if not self.toolIconVisible:
            self.anki.toolBar().addAction(self.action)
            self.toolIconVisible = True