def translate(self, text, engine): # I should not hardcode fr and to languages here # Force async import settings, trman lang = settings.reader().userLanguage() return trman.manager().translate( text, engine=engine, fr='ja', to=lang, async=True)[0] or ''
def getSpeed(self, key): """ @param key str @return int """ try: return int(settings.reader().ttsSpeeds().get(key) or 0) except (ValueError, TypeError): return 0
def zunkoEngine(self): if not self._zunkoEngine: ss = settings.reader() eng = self._zunkoEngine = _ttsman.ZunkoEngine( path=ss.zunkoLocation()) ss.zunkoLocationChanged.connect(eng.setPath) growl.msg(' '.join(( i18n.tr("Load TTS"), eng.name, ))) return self._zunkoEngine
def jlpManager(self): dprint("create jlp manager") import jlpman ret = jlpman.manager() reader = settings.reader() ret.setRubyType(reader.rubyType()) dic = 'unidic' if reader.isMeCabEnabled() else '' # always unidic ret.setMeCabDicType(dic) return ret
def setSpeed(self, key, v): """ @param key str @param v int """ ss = settings.reader() m = ss.ttsSpeeds() if v != m.get(key): m[key] = v ss.setTtsSpeeds(m) eng = self._sapiEngines.get(key) if eng: eng.setSpeed(v)
def ttsManager(self): dprint("create tts manager") import ttsman ret = ttsman.manager() ret.setParent(self.q) #ret.setParentWidget(self.mainWindow) ss = settings.global_() if ss.isTtsEnabled() and not ret.isAvailable(): ss.setTtsEnabled(False) ret.setEnabled(ss.isTtsEnabled()) ss.ttsEnabledChanged.connect(ret.setEnabled) #ret.setOnline(self.networkManager.isOnline()) #self.networkManager.onlineChanged.connect(ret.setOnline) reader = settings.reader() ret.setDefaultEngine(reader.ttsEngine()) reader.ttsEngineChanged.connect(ret.setDefaultEngine) return ret
def html_data(url): # QUrl|str -> unicode|None if isinstance(url, QUrl): url = url.toString() ret = HTML_DATA.get(url) if not ret: key = URL_TEMPLATE.get(url) if key: from sakurakit.sktr import tr_ params = { 'cache': cacheman.CacheApi, 'tr': tr_, 'rc': sys.modules[__name__], } if key == 'about': import i18nutil, settings t = settings.global_().version() params['version'] = i18nutil.timestamp2datetime(t) elif key == 'settings': import settings params['settings'] = settings.global_() params['reader'] = settings.reader() ret = HTML_DATA[url] = jinja_template(key).render( params) # unicode html return ret
def main(): # Use UTF-8 encoding for Qt from PySide.QtCore import QTextCodec #sys_codec = QTextCodec.codecForLocale() u8codec = QTextCodec.codecForName("UTF-8") QTextCodec.setCodecForCStrings(u8codec) QTextCodec.setCodecForTr(u8codec) import config from sakurakit import skdebug #skdebug.DEBUG = config.APP_DEBUG or '--debug' in sys.argv skdebug.DEBUG = '--debug' in sys.argv print "browser: debug = %s" % skdebug.DEBUG from sakurakit.skdebug import dprint, dwarn dprint("enter") if '--help' in sys.argv: print_help() dprint("leave: help") return dprint("python = %s" % sys.executable) #dprint("rootdir = %s" % rootdir) #dprint("mecabrc = %s" % mecabrc_path) from sakurakit import skos if skos.WIN: dprint("set app id") from sakurakit import skwin skwin.set_app_id("org.sakurakit.browser") import rc for it in ( rc.DIR_CACHE_DATA, rc.DIR_CACHE_HISTORY, rc.DIR_CACHE_NETMAN, rc.DIR_CACHE_WEBKIT, ): if not os.path.exists(it): try: os.makedirs(it) except OSError: dwarn("warning: failed to create directory: %s" % it) dprint("init opencc") from opencc import opencc opencc.setdicpaths(config.OPENCC_DICS) dprint("create app") import app a = app.Application(sys.argv) dprint("load translations") a.loadTranslations() # Take the ownership of sakurakit translation from sakurakit import sktr sktr.manager().setParent(a) dprint("load settings") import settings ss = settings.global_() ss.setParent(a) reader = settings.reader() #reader.setParent(a) # reader does NOT have a app parent dprint("update settings") ss_version = ss.version() if ss_version != config.VERSION_TIMESTAMP: dprint("app update detected, migrate settings") if ss_version: from sakurakit import skfileio if ss_version <= 1417339268: for it in ( #rc.DIR_CACHE_DATA, rc.DIR_CACHE_HISTORY, rc.DIR_CACHE_NETMAN, rc.DIR_CACHE_WEBKIT, ): if os.path.exists(it): skfileio.removetree(it) try: os.makedirs(it) except OSError: dwarn("warning: failed to create directory: %s" % it) if ss_version <= 1396371158: skfileio.removefile(rc.COOKIES_LOCATION) ss.setVersion(config.VERSION_TIMESTAMP) ss.sync() if reader.isCursorThemeEnabled(): dprint("load cursor theme") import curtheme curtheme.load() from sakurakit import skpaths skpaths.append_paths(( #reader.localeEmulatorLocation(), reader.jbeijingLocation(), reader.ezTransLocation(), reader.atlasLocation(), os.path.join(reader.lecLocation(), r"Nova\JaEn") if reader.lecLocation() else "", os.path.join(reader.dreyeLocation(), r"DreyeMT\SDK\bin") if reader.dreyeLocation() else "", )) path = reader.fastaitLocation() if path: path = os.path.join(path, "GTS") if os.path.exists(path): from sakurakit import skfileio dllpaths = skfileio.listdirs(path) if dllpaths: skpaths.append_paths(dllpaths) dprint("set max thread count") from PySide.QtCore import QThreadPool if QThreadPool.globalInstance().maxThreadCount() < config.QT_THREAD_COUNT: QThreadPool.globalInstance().setMaxThreadCount(config.QT_THREAD_COUNT) dprint("load web settings") import webrc webrc.update_web_settings() if reader.isMainlandChina(): dprint("set up proxy") from google import googletts googletts.setapi(config.PROXY_GOOGLE_TTS) import googleman googleman.setapi(config.PROXY_GOOGLE_TRANS) dprint("create main object") import main m = main.MainObject() m.run(a.arguments()) dprint("exec") sys.exit(a.exec_())
def translatorManager(self): dprint("create translator manager") import trman ret = trman.manager() ret.setParent(self.q) ss = settings.global_() reader = settings.reader() if not reader.jbeijingLocation() and ss.isJBeijingEnabled(): ss.setJBeijingEnabled(False) if not reader.fastaitLocation() and ss.isFastaitEnabled(): ss.setFastaitEnabled(False) if not reader.ezTransLocation() and ss.isEzTransEnabled(): ss.setEzTransEnabled(False) if not reader.dreyeLocation() and ss.isDreyeEnabled(): ss.setDreyeEnabled(False) if not reader.atlasLocation() and ss.isAtlasEnabled(): ss.setAtlasEnabled(False) if not reader.lecLocation() and ss.isLecEnabled(): ss.setLecEnabled(False) ret.setInfoseekEnabled(ss.isInfoseekEnabled()) ss.infoseekEnabledChanged.connect(ret.setInfoseekEnabled) ret.setExciteEnabled(ss.isExciteEnabled()) ss.exciteEnabledChanged.connect(ret.setExciteEnabled) ret.setBingEnabled(ss.isBingEnabled()) ss.bingEnabledChanged.connect(ret.setBingEnabled) ret.setGoogleEnabled(ss.isGoogleEnabled()) ss.googleEnabledChanged.connect(ret.setGoogleEnabled) ret.setTransruEnabled(ss.isTransruEnabled()) ss.transruEnabledChanged.connect(ret.setTransruEnabled) ret.setBaiduEnabled(ss.isBaiduEnabled()) ss.baiduEnabledChanged.connect(ret.setBaiduEnabled) ret.setLecOnlineEnabled(ss.isLecOnlineEnabled()) ss.lecOnlineEnabledChanged.connect(ret.setLecOnlineEnabled) #ret.setYoudaoEnabled(ss.isYoudaoEnabled()) #ss.youdaoEnabledChanged.connect(ret.setYoudaoEnabled) ret.setHanVietEnabled(ss.isHanVietEnabled()) ss.hanVietEnabledChanged.connect(ret.setHanVietEnabled) ret.setJBeijingEnabled(ss.isJBeijingEnabled()) ss.jbeijingEnabledChanged.connect(ret.setJBeijingEnabled) ret.setFastaitEnabled(ss.isFastaitEnabled()) ss.fastaitEnabledChanged.connect(ret.setFastaitEnabled) ret.setDreyeEnabled(ss.isDreyeEnabled()) ss.dreyeEnabledChanged.connect(ret.setDreyeEnabled) ret.setEzTransEnabled(ss.isEzTransEnabled()) ss.ezTransEnabledChanged.connect(ret.setEzTransEnabled) ret.setAtlasEnabled(ss.isAtlasEnabled()) ss.atlasEnabledChanged.connect(ret.setAtlasEnabled) ret.setLecEnabled(ss.isLecEnabled()) ss.lecEnabledChanged.connect(ret.setLecEnabled) #ret.setEnabled(ss.isTranslationEnabled()) #ss.translationEnabledChanged.connect(ret.setEnabled) return ret
def applicationLocale(): import settings lang = settings.reader().userLanguage() locale = config.language2locale(lang) return locale
def wallpaper_url(): import settings return settings.reader().wallpaperUrl() or image_url('wallpaper')
# coding: utf8 # proxy.py # 3/25/2014 jichi import re from PySide.QtCore import QUrl import config import settings _MAINLAND = settings.reader().isMainlandChina() #_MAINLAND = True def _normalize_host(url): # str -> str url = url.lower() if not url.startswith('www.'): url = 'www.' + url return url _PROXY_DOMAINS = { _normalize_host(host): ip for host, ip in config.PROXY_DOMAINS.iteritems() } # {string host: string ip} _PROXY_IPS = {ip: host for host, ip in config.PROXY_DOMAINS.iteritems() } # {string ip: string host} _PROXY_SITES = { _normalize_host(host): key