コード例 #1
0
 def change_language(self, idx):
     prefs['language'] = str(
         self.language.itemData(self.language.currentIndex()).toString())
     import __builtin__
     __builtin__.__dict__['_'] = lambda (x): x
     from calibre.utils.localization import set_translators
     from calibre.gui2 import qt_app
     from calibre.ebooks.metadata.book.base import reset_field_metadata
     set_translators()
     qt_app.load_translations()
     self.retranslate.emit()
     self.init_languages()
     reset_field_metadata()
     try:
         lang = prefs['language'].lower()[:2]
         metadata_plugins = {
             'zh': ('Douban Books', ),
             'fr': ('Nicebooks', ),
             'ru': ('OZON.ru', ),
         }.get(lang, [])
         from calibre.customize.ui import enable_plugin
         for name in metadata_plugins:
             enable_plugin(name)
     except:
         pass
コード例 #2
0
ファイル: __init__.py プロジェクト: qykth-git/calibre-debian
 def change_language(self, idx):
     prefs['language'] = unicode_type(
         self.language.itemData(self.language.currentIndex()) or '')
     from polyglot.builtins import builtins
     builtins.__dict__['_'] = lambda x: x
     from calibre.ebooks.metadata.book.base import reset_field_metadata
     from calibre.gui2 import qt_app
     from calibre.utils.localization import set_translators
     set_translators()
     qt_app.load_translations()
     self.retranslate.emit()
     self.init_languages()
     reset_field_metadata()
     try:
         lang = prefs['language'].lower()[:2]
         metadata_plugins = {
             'zh': ('Douban Books', ),
             'fr': ('Nicebooks', ),
             'ru': ('OZON.ru', ),
         }.get(lang, [])
         from calibre.customize.ui import enable_plugin
         for name in metadata_plugins:
             enable_plugin(name)
     except:
         pass
     lp = self.location.text()
     if lp == self.initial_library_location:
         self.set_initial_library_location()
     for x in globals().values():
         if type(x) is type and hasattr(x, 'untranslated_name'):
             x.name = __builtins__['_'](x.untranslated_name)
コード例 #3
0
ファイル: __init__.py プロジェクト: yeyanchao/calibre
 def change_language(self, idx):
     prefs['language'] = str(self.language.itemData(self.language.currentIndex()).toString())
     import __builtin__
     __builtin__.__dict__['_'] = lambda(x): x
     from calibre.utils.localization import set_translators
     from calibre.gui2 import qt_app
     set_translators()
     qt_app.load_translations()
     self.retranslate.emit()
     self.init_languages()
     try:
         lang = prefs['language'].lower()[:2]
         metadata_plugins = {
                 'zh' : ('Douban Books',),
                 'fr' : ('Nicebooks',),
                 'ru' : ('OZON.ru',),
         }.get(lang, [])
         from calibre.customize.ui import enable_plugin
         for name in metadata_plugins:
             enable_plugin(name)
     except:
         pass
コード例 #4
0
ファイル: __init__.py プロジェクト: j-howell/calibre
 def change_language(self, idx):
     prefs['language'] = str(self.language.itemData(self.language.currentIndex()) or '')
     from polyglot.builtins import builtins
     builtins.__dict__['_'] = lambda x: x
     from calibre.utils.localization import set_translators
     from calibre.gui2 import qt_app
     from calibre.ebooks.metadata.book.base import reset_field_metadata
     set_translators()
     qt_app.load_translations()
     self.retranslate.emit()
     self.init_languages()
     reset_field_metadata()
     try:
         lang = prefs['language'].lower()[:2]
         metadata_plugins = {
                 'zh' : ('Douban Books',),
                 'fr' : ('Nicebooks',),
                 'ru' : ('OZON.ru',),
         }.get(lang, [])
         from calibre.customize.ui import enable_plugin
         for name in metadata_plugins:
             enable_plugin(name)
     except:
         pass
コード例 #5
0
ファイル: startup.py プロジェクト: oheil/calibre
        except:
            pass
    for i in range(1, len(sys.argv)):
        if not isinstance(sys.argv[i], unicode):
            sys.argv[i] = sys.argv[i].decode(enc, 'replace')

    ################################################################################
    # Setup resources
    import calibre.utils.resources as resources
    resources

    ################################################################################
    # Setup translations
    from calibre.utils.localization import set_translators

    set_translators()

    ################################################################################
    # Initialize locale
    # Import string as we do not want locale specific
    # string.whitespace/printable, on windows especially, this causes problems.
    # Before the delay load optimizations, string was loaded before this point
    # anyway, so we preserve the old behavior explicitly.
    import string
    string
    try:
        locale.setlocale(locale.LC_ALL, '')
    except:
        dl = locale.getdefaultlocale()
        try:
            if dl:
コード例 #6
0
ファイル: startup.py プロジェクト: BerZek/calibre
        except:
            pass
    for i in range(1, len(sys.argv)):
        if not isinstance(sys.argv[i], unicode):
            sys.argv[i] = sys.argv[i].decode(enc, 'replace')

    #
    # Setup resources
    import calibre.utils.resources as resources
    resources

    #
    # Setup translations
    from calibre.utils.localization import set_translators

    set_translators()

    #
    # Initialize locale
    # Import string as we do not want locale specific
    # string.whitespace/printable, on windows especially, this causes problems.
    # Before the delay load optimizations, string was loaded before this point
    # anyway, so we preserve the old behavior explicitly.
    import string
    string
    try:
        locale.setlocale(locale.LC_ALL, '')  # set the locale to the user's default locale
    except:
        dl = locale.getdefaultlocale()
        try:
            if dl:
コード例 #7
0
def initialize_calibre():
    if hasattr(initialize_calibre, 'initialized'):
        return
    initialize_calibre.initialized = True

    # Ensure that all temp files/dirs are created under a calibre tmp dir
    from calibre.ptempfile import base_dir
    try:
        base_dir()
    except OSError:
        pass  # Ignore this error during startup, so we can show a better error message to the user later.

    #
    # Ensure that the max number of open files is at least 1024
    if iswindows:
        # See https://msdn.microsoft.com/en-us/library/6e3b887c.aspx
        from calibre_extensions import winutil
        winutil.setmaxstdio(max(1024, winutil.getmaxstdio()))
    else:
        import resource
        soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
        if soft < 1024:
            try:
                resource.setrlimit(resource.RLIMIT_NOFILE,
                                   (min(1024, hard), hard))
            except Exception:
                if DEBUG:
                    import traceback
                    traceback.print_exc()

    #
    # Fix multiprocessing
    from multiprocessing import spawn, util

    def get_command_line(**kwds):
        prog = 'from multiprocessing.spawn import spawn_main; spawn_main(%s)'
        prog %= ', '.join('%s=%r' % item for item in kwds.items())
        return get_debug_executable() + ['--fix-multiprocessing', '--', prog]

    spawn.get_command_line = get_command_line
    orig_spawn_passfds = util.spawnv_passfds

    def spawnv_passfds(path, args, passfds):
        try:
            idx = args.index('-c')
        except ValueError:
            return orig_spawn_passfds(args[0], args, passfds)
        patched_args = get_debug_executable() + [
            '--fix-multiprocessing', '--'
        ] + args[idx + 1:]
        return orig_spawn_passfds(patched_args[0], patched_args, passfds)

    util.spawnv_passfds = spawnv_passfds

    #
    # Setup resources
    import calibre.utils.resources as resources
    resources

    #
    # Setup translations
    from calibre.utils.localization import set_translators

    set_translators()

    #
    # Initialize locale
    # Import string as we do not want locale specific
    # string.whitespace/printable, on windows especially, this causes problems.
    # Before the delay load optimizations, string was loaded before this point
    # anyway, so we preserve the old behavior explicitly.
    import string
    string
    try:
        locale.setlocale(locale.LC_ALL,
                         '')  # set the locale to the user's default locale
    except:
        dl = locale.getdefaultlocale()
        try:
            if dl:
                locale.setlocale(locale.LC_ALL, dl[0])
        except:
            pass

    builtins.__dict__['lopen'] = open  # legacy compatibility
    from calibre.utils.icu import title_case, lower as icu_lower, upper as icu_upper
    builtins.__dict__['icu_lower'] = icu_lower
    builtins.__dict__['icu_upper'] = icu_upper
    builtins.__dict__['icu_title'] = title_case

    def connect_lambda(bound_signal, self, func, **kw):
        import weakref
        r = weakref.ref(self)
        del self
        num_args = func.__code__.co_argcount - 1
        if num_args < 0:
            raise TypeError('lambda must take at least one argument')

        def slot(*args):
            ctx = r()
            if ctx is not None:
                if len(args) != num_args:
                    args = args[:num_args]
                func(ctx, *args)

        bound_signal.connect(slot, **kw)

    builtins.__dict__['connect_lambda'] = connect_lambda

    if islinux or ismacos or isfreebsd:
        # Name all threads at the OS level created using the threading module, see
        # http://bugs.python.org/issue15500
        import threading
        from calibre_extensions import speedup

        orig_start = threading.Thread.start

        def new_start(self):
            orig_start(self)
            try:
                name = self.name
                if not name or name.startswith('Thread-'):
                    name = self.__class__.__name__
                    if name == 'Thread':
                        name = self.name
                if name:
                    if isinstance(name, str):
                        name = name.encode('ascii', 'replace').decode('ascii')
                    speedup.set_thread_name(name[:15])
            except Exception:
                pass  # Don't care about failure to set name

        threading.Thread.start = new_start