Example #1
0
    def setupTranslator(cls):
        lang = cls.cfg.get("general", "language")
        if lang == "inherited":
            ccfg = ts3client.Config()
            q = ccfg.query("SELECT * FROM application WHERE key='Language'")

            if q.next():
                lang = q.value("value")
            else:
                lang = "en_US"
                logprint(cls._tr("Error querying language from client config"),
                         ts3defines.LogLevel.LogLevel_ERROR,
                         "pyTSon.PluginHost.setupTranslator")
            del ccfg

        if cls.translator:
            if not QCoreApplication.removeTranslator(cls.translator):
                logprint(cls._tr("Error removing translator"),
                         ts3defines.LogLevel.LogLevel_ERROR,
                         "pyTSon.PluginHost.setupTranslator")
            cls.translator = None

        p = pytson.getPluginPath("ressources", "i18n", "pyTSon-%s.qm" % lang)

        if os.path.isfile(p):
            cls.verboseLog(
                cls._tr("Using translator from {file}").format(file=p),
                "pyTSon.PluginHost.setupTranslator")

            cls.translator = QTranslator()
            if not cls.translator.load(p):
                logprint("Error loading translator from %s" % p,
                         ts3defines.LogLevel.LogLevel_ERROR,
                         "pyTSon.PluginHost.setupTranslator")
                cls.translator = None
                return

            if not QCoreApplication.installTranslator(cls.translator):
                logprint("Error installing translator from %s" % p,
                         ts3defines.LogLevel.LogLevel_ERROR,
                         "pyTSon.PluginHost.setupTranslator")
                cls.translator = None
Example #2
0
    def setupTranslator(cls):
        lang = cls.cfg.get("general", "language")
        if lang == "inherited":
            ccfg = ts3client.Config()
            q = ccfg.query("SELECT * FROM application WHERE key='Language'")

            if q.next():
                lang = q.value("value")
            else:
                lang = "en_US"
                logprint(cls._tr("Error querying language from client config"),
                         ts3defines.LogLevel.LogLevel_ERROR,
                         "pyTSon.PluginHost.setupTranslator")
            del ccfg

        if cls.translator:
            if not QCoreApplication.removeTranslator(cls.translator):
                logprint(cls._tr("Error removing translator"),
                         ts3defines.LogLevel.LogLevel_ERROR,
                         "pyTSon.PluginHost.setupTranslator")
            cls.translator = None

        p = pytson.getPluginPath("ressources", "i18n", "pyTSon-%s.qm" % lang)

        if os.path.isfile(p):
            cls.verboseLog(cls._tr("Using translator from {file}").
                           format(file=p), "pyTSon.PluginHost.setupTranslator")

            cls.translator = QTranslator()
            if not cls.translator.load(p):
                logprint("Error loading translator from %s" % p,
                         ts3defines.LogLevel.LogLevel_ERROR,
                         "pyTSon.PluginHost.setupTranslator")
                cls.translator = None
                return

            if not QCoreApplication.installTranslator(cls.translator):
                logprint("Error installing translator from %s" % p,
                         ts3defines.LogLevel.LogLevel_ERROR,
                         "pyTSon.PluginHost.setupTranslator")
                cls.translator = None
Example #3
0
    def shutdown(cls):
        cls.verboseLog(cls._tr("Shutting down"), "pyTSon.PluginHost.shutdown")

        if cls.shell:
            cls.shell.delete()
        cls.shell = None
        if cls.confdlg:
            cls.confdlg.delete()
        cls.confdlg = None

        if cls.nwm:
            cls.nwm.delete()
        cls.nwm = None

        # store config
        with open(pytson.getConfigPath("pyTSon.conf"), "w") as f:
            cls.cfg.write(f)

        # stop all plugins
        for key, p in cls.active.items():
            try:
                p.stop()
            except:
                print(
                    cls._tr(
                        "Error stopping python plugin {name}: {trace}").format(
                            name=key, trace=traceback.format_exc()))

        cls.active = {}

        # save local menu ids
        for globid, (p, locid) in cls.menus.items():
            # previously reloaded?
            if not type(p) is str:
                cls.menus[globid] = (p.name, locid)

        # save local hotkeys
        for keyword, (p, lockey) in cls.hotkeys.items():
            if not type(p) is str:
                cls.hotkeys[keyword] = (p.name, lockey)

        if cls.translator:
            if not QCoreApplication.removeTranslator(cls.translator):
                logprint(cls._tr("Error removing translator"),
                         ts3defines.LogLevel.LogLevel_ERROR,
                         "pyTSon.PluginHost.shutdown")
Example #4
0
    def shutdown(cls):
        cls.verboseLog(cls._tr("Shutting down"), "pyTSon.PluginHost.shutdown")

        if cls.shell:
            cls.shell.delete()
        cls.shell = None
        if cls.confdlg:
            cls.confdlg.delete()
        cls.confdlg = None

        if cls.nwm:
            cls.nwm.delete()
        cls.nwm = None

        # store config
        with open(pytson.getConfigPath("pyTSon.conf"), "w") as f:
            cls.cfg.write(f)

        # stop all plugins
        for key, p in cls.active.items():
            try:
                p.stop()
            except:
                print(cls._tr("Error stopping python plugin {name}: {trace}").
                      format(name=key, trace=traceback.format_exc()))

        cls.active = {}

        # save local menu ids
        for globid, (p, locid) in cls.menus.items():
            # previously reloaded?
            if not type(p) is str:
                cls.menus[globid] = (p.name, locid)

        # save local hotkeys
        for keyword, (p, lockey) in cls.hotkeys.items():
            if not type(p) is str:
                cls.hotkeys[keyword] = (p.name, lockey)

        if cls.translator:
            if not QCoreApplication.removeTranslator(cls.translator):
                logprint(cls._tr("Error removing translator"),
                         ts3defines.LogLevel.LogLevel_ERROR,
                         "pyTSon.PluginHost.shutdown")