Esempio n. 1
0
    def initialize(self, mw):
        log.info("Pinyin Toolkit is initializing")

        # Build basic objects we use to interface with Anki
        thenotifier = notifier.AnkiNotifier()
        themediamanager = mediamanager.AnkiMediaManager(mw)

        # Open up the database
        if not self.tryCreateAndLoadDatabase(mw, thenotifier):
            # Eeek! Database building failed, so we better turn off the toolkit
            log.error("Database construction failed: disabling the Toolkit")
            return

        # Build the updaters
        updaters = {
            'expression':
            pinyin.updater.FieldUpdaterFromExpression(thenotifier,
                                                      themediamanager),
            'reading':
            pinyin.updater.FieldUpdaterFromReading(),
            'meaning':
            pinyin.updater.FieldUpdaterFromMeaning(),
            'audio':
            pinyin.updater.FieldUpdaterFromAudio(thenotifier, themediamanager)
        }

        # Finally, build the hooks.  Make sure you store a reference to these, because otherwise they
        # get garbage collected, causing garbage collection of the actions they contain
        self.hooks = [
            hookbuilder(mw, thenotifier, themediamanager, updaters)
            for hookbuilder in hookbuilders
        ]
        for hook in self.hooks:
            hook.install()

        # add hooks and menu items
        # use wrap() instead of addHook to ensure menu already created
        def ptkRebuildAddonsMenu(self):
            ptkMenu = None
            for menu in self._menus:
                if menu.title() == "Pinyin Toolkit":
                    ptkMenu = menu
                    break

            ptkMenu.addSeparator()
            config = getconfig()
            hooks.buildHooks(ptkMenu, mw, config, thenotifier, themediamanager,
                             updaters)

        aqt.addons.AddonManager.rebuildAddonsMenu = wrap(
            aqt.addons.AddonManager.rebuildAddonsMenu, ptkRebuildAddonsMenu)
Esempio n. 2
0
 def initialize(self, mw):
     log.info("Pinyin Toolkit is initializing")
     
     # Build basic objects we use to interface with Anki
     thenotifier = notifier.AnkiNotifier()
     themediamanager = mediamanager.AnkiMediaManager(mw)
     
     # Open up the database
     if not self.tryCreateAndLoadDatabase(mw, thenotifier):
         # Eeek! Database building failed, so we better turn off the toolkit
         log.error("Database construction failed: disabling the Toolkit")
         return
     
     # Try and load the settings from the Anki config database
     settings = mw.config.get("pinyintoolkit")
     if settings is None:
         # Initialize the configuration with default settings
         config = pinyin.config.Config()
         utils.persistconfig(mw, config)
         
         # TODO: first-run activities:
         #  1) Guide user around the interface and what they can do
         #  2) Link to getting started guide
     else:
         # Initialize the configuration with the stored settings
         config = pinyin.config.Config(settings)
     
     # Build the updaters
     updaters = {
         'expression' : pinyin.updater.FieldUpdaterFromExpression,
         'reading'    : lambda *args: pinyin.updater.FieldUpdater("reading", *args),
         'meaning'    : lambda *args: pinyin.updater.FieldUpdater("meaning", *args),
         'audio'      : lambda *args: pinyin.updater.FieldUpdater("audio", *args)
       }
     
     # Finally, build the hooks.  Make sure you store a reference to these, because otherwise they
     # get garbage collected, causing garbage collection of the actions they contain
     self.hooks = [hookbuilder(mw, thenotifier, themediamanager, config, updaters) for hookbuilder in hookbuilders]
     for hook in self.hooks:
         hook.install()
 
     # Tell Anki about the plugin
     mw.registerPlugin("Mandarin Chinese Pinyin Toolkit", 4)
     self.registerStandardModels()
Esempio n. 3
0
 def initialize(self, mw):
     log.info("Pinyin Toolkit is initializing")
     
     # Build basic objects we use to interface with Anki
     thenotifier = notifier.AnkiNotifier()
     themediamanager = mediamanager.AnkiMediaManager(mw)
     
     # Open up the database
     if not self.tryCreateAndLoadDatabase(mw, thenotifier):
         # Eeek! Database building failed, so we better turn off the toolkit
         log.error("Database construction failed: disabling the Toolkit")
         return
     
     # Try and load the settings from the Anki config database
     settings = mw.config.get("pinyintoolkit")
     if settings is None:
         # Initialize the configuration with default settings
         config = pinyin.config.Config()
         utils.persistconfig(mw, config)
         
         # TODO: first-run activities:
         #  1) Guide user around the interface and what they can do
         #  2) Link to getting started guide
     else:
         # Initialize the configuration with the stored settings
         config = pinyin.config.Config(settings)
     
     # Build the updaters
     updaters = {
         'expression' : pinyin.updater.FieldUpdaterFromExpression,
         'reading'    : lambda *args: pinyin.updater.FieldUpdater("reading", *args),
         'meaning'    : lambda *args: pinyin.updater.FieldUpdater("meaning", *args),
         'audio'      : lambda *args: pinyin.updater.FieldUpdater("audio", *args)
       }
     
     # Finally, build the hooks.  Make sure you store a reference to these, because otherwise they
     # get garbage collected, causing garbage collection of the actions they contain
     self.hooks = [hookbuilder(mw, thenotifier, themediamanager, config, updaters) for hookbuilder in hookbuilders]
     for hook in self.hooks:
         hook.install()
 
     # Tell Anki about the plugin
     mw.registerPlugin("Mandarin Chinese Pinyin Toolkit", 4)
     self.registerStandardModels()
Esempio n. 4
0
    def initialize(self, mw):
        log.info("Pinyin Toolkit is initializing")
        
        # Build basic objects we use to interface with Anki
        thenotifier = notifier.AnkiNotifier()
        themediamanager = mediamanager.AnkiMediaManager(mw)
        
        # Open up the database
        if not self.tryCreateAndLoadDatabase(mw, thenotifier):
            # Eeek! Database building failed, so we better turn off the toolkit
            log.error("Database construction failed: disabling the Toolkit")
            return

        # Build the updaters
        updaters = {
            'expression' : pinyin.updater.FieldUpdaterFromExpression(thenotifier, themediamanager),
            'reading'    : pinyin.updater.FieldUpdaterFromReading(),
            'meaning'    : pinyin.updater.FieldUpdaterFromMeaning(),
            'audio'      : pinyin.updater.FieldUpdaterFromAudio(thenotifier, themediamanager)
          }
        
        # Finally, build the hooks.  Make sure you store a reference to these, because otherwise they
        # get garbage collected, causing garbage collection of the actions they contain
        self.hooks = [hookbuilder(mw, thenotifier, themediamanager, updaters) for hookbuilder in hookbuilders]
        for hook in self.hooks:
            hook.install()

        # add hooks and menu items
        # use wrap() instead of addHook to ensure menu already created 
        def ptkRebuildAddonsMenu(self):
            ptkMenu = None
            for menu in self._menus:
                if menu.title() == "Pinyin Toolkit":
                    ptkMenu = menu
                    break

            ptkMenu.addSeparator()
            config = getconfig()
            hooks.buildHooks(ptkMenu, mw, config, thenotifier, themediamanager,
                               updaters)

        aqt.addons.AddonManager.rebuildAddonsMenu = wrap(aqt.addons.AddonManager.rebuildAddonsMenu, ptkRebuildAddonsMenu)