Esempio n. 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
    def identify(plugins=None, **kwargs):
        """ Run an identify with the given options, and return the list of results. """
        # Enable the desired plugins and convert to the expected format.
        if plugins:
            for plugin in plugins:
                enable_plugin(plugin)
            kwargs['allowed_plugins'] = [p.name for p in plugins]

        # Create a log that both outputs to stdout as well as a capture.
        # capsys/capfs do not work, unfortunately.
        from calibre.utils.logging import FileStream
        log = create_log(sys.stdout)
        capture = StringIO()
        captures.append(capture)
        log.outputs.append(FileStream(capture))

        # Run the regular identify function.
        abort = Event()
        results = calibre_identify(log, abort, **kwargs)

        # Output the log. Pytest will swallow this output unless a test fails.
        log.close()

        # Log the results.
        print()
        print('Results:')
        print('-' * 40)
        for result in results:
            print(result)
            print('-' * 40)

        return results
Esempio n. 3
0
 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)
Esempio n. 4
0
    def modify_plugin(self, op=''):
        index = self.plugin_view.currentIndex()
        if index.isValid():
            if not index.parent().isValid():
                name = str(index.data() or '')
                return error_dialog(self, _('Error'), '<p>'+
                        _('Select an actual plugin under <b>%s</b> to customize')%name,
                        show=True, show_copy_button=False)

            plugin = self._plugin_model.index_to_plugin(index)
            if op == 'toggle':
                if not plugin.can_be_disabled:
                    info_dialog(self, _('Plugin cannot be disabled'),
                                 _('Disabling the plugin %s is not allowed')%plugin.name, show=True, show_copy_button=False)
                    return
                if is_disabled(plugin):
                    enable_plugin(plugin)
                else:
                    disable_plugin(plugin)
                self._plugin_model.refresh_plugin(plugin)
                self.changed_signal.emit()
            if op == 'customize':
                if not plugin.is_customizable():
                    info_dialog(self, _('Plugin not customizable'),
                        _('Plugin: %s does not need customization')%plugin.name).exec_()
                    return
                self.changed_signal.emit()
                from calibre.customize import InterfaceActionBase
                if isinstance(plugin, InterfaceActionBase) and not getattr(plugin,
                        'actual_iaction_plugin_loaded', False):
                    return error_dialog(self, _('Must restart'),
                            _('You must restart calibre before you can'
                                ' configure the <b>%s</b> plugin')%plugin.name, show=True)
                if plugin.do_user_config(self.gui):
                    self._plugin_model.refresh_plugin(plugin)
            elif op == 'remove':
                if not confirm('<p>' +
                    _('Are you sure you want to remove the plugin: %s?')%
                    '<b>{0}</b>'.format(plugin.name),
                    'confirm_plugin_removal_msg', parent=self):
                    return

                msg = _('Plugin <b>{0}</b> successfully removed. You will have'
                        ' to restart calibre for it to be completely removed.').format(plugin.name)
                if remove_plugin(plugin):
                    self._plugin_model.beginResetModel()
                    self._plugin_model.populate()
                    self._plugin_model.endResetModel()
                    self.changed_signal.emit()
                    info_dialog(self, _('Success'), msg, show=True,
                            show_copy_button=False)
                else:
                    error_dialog(self, _('Cannot remove builtin plugin'),
                         plugin.name + _(' cannot be removed. It is a '
                         'builtin plugin. Try disabling it instead.')).exec_()
Esempio n. 5
0
    def modify_plugin(self, op=''):
        index = self.plugin_view.currentIndex()
        if index.isValid():
            if not index.parent().isValid():
                name = unicode(index.data() or '')
                return error_dialog(self, _('Error'), '<p>'+
                        _('Select an actual plugin under <b>%s</b> to customize')%name,
                        show=True, show_copy_button=False)

            plugin = self._plugin_model.index_to_plugin(index)
            if op == 'toggle':
                if not plugin.can_be_disabled:
                    info_dialog(self, _('Plugin cannot be disabled'),
                                 _('Disabling the plugin %s is not allowed')%plugin.name, show=True, show_copy_button=False)
                    return
                if is_disabled(plugin):
                    enable_plugin(plugin)
                else:
                    disable_plugin(plugin)
                self._plugin_model.refresh_plugin(plugin)
                self.changed_signal.emit()
            if op == 'customize':
                if not plugin.is_customizable():
                    info_dialog(self, _('Plugin not customizable'),
                        _('Plugin: %s does not need customization')%plugin.name).exec_()
                    return
                self.changed_signal.emit()
                from calibre.customize import InterfaceActionBase
                if isinstance(plugin, InterfaceActionBase) and not getattr(plugin,
                        'actual_iaction_plugin_loaded', False):
                    return error_dialog(self, _('Must restart'),
                            _('You must restart calibre before you can'
                                ' configure the <b>%s</b> plugin')%plugin.name, show=True)
                if plugin.do_user_config(self.gui):
                    self._plugin_model.refresh_plugin(plugin)
            elif op == 'remove':
                if not confirm('<p>' +
                    _('Are you sure you want to remove the plugin: %s?')%
                    '<b>{0}</b>'.format(plugin.name),
                    'confirm_plugin_removal_msg', parent=self):
                    return

                msg = _('Plugin <b>{0}</b> successfully removed. You will have'
                        ' to restart calibre for it to be completely removed.').format(plugin.name)
                if remove_plugin(plugin):
                    self._plugin_model.beginResetModel()
                    self._plugin_model.populate()
                    self._plugin_model.endResetModel()
                    self.changed_signal.emit()
                    info_dialog(self, _('Success'), msg, show=True,
                            show_copy_button=False)
                else:
                    error_dialog(self, _('Cannot remove builtin plugin'),
                         plugin.name + _(' cannot be removed. It is a '
                         'builtin plugin. Try disabling it instead.')).exec_()
Esempio n. 6
0
 def _toggle_enabled_clicked(self):
     display_plugin = self._selected_display_plugin()
     plugin = display_plugin.plugin
     if not plugin.can_be_disabled:
         return error_dialog(self,_('Plugin cannot be disabled'),
                      _('The plugin: %s cannot be disabled')%plugin.name, show=True)
     if is_disabled(plugin):
         enable_plugin(plugin)
     else:
         disable_plugin(plugin)
     self.model.refresh_plugin(display_plugin)
Esempio n. 7
0
 def setData(self, index, data, role):
     if not index.isValid():
         return False
     row, col = index.row(), index.column()
     if col == 0:
         if data.toBool():
             enable_plugin(self.get_plugin(index))
         else:
             disable_plugin(self.get_plugin(index))
     self.dataChanged.emit(self.index(index.row(), 0), self.index(index.row(), self.columnCount() - 1))
     return True
Esempio n. 8
0
 def _toggle_enabled_clicked(self):
     display_plugin = self._selected_display_plugin()
     plugin = display_plugin.plugin
     if not plugin.can_be_disabled:
         return error_dialog(self,_('Plugin cannot be disabled'),
                      _('The plugin: %s cannot be disabled')%plugin.name, show=True)
     if is_disabled(plugin):
         enable_plugin(plugin)
     else:
         disable_plugin(plugin)
     self.model.refresh_plugin(display_plugin)
Esempio n. 9
0
 def setData(self, index, data, role):
     if not index.isValid():
         return False
     col = index.column()
     if col == 0:
         if bool(data):
             enable_plugin(self.get_plugin(index))
         else:
             disable_plugin(self.get_plugin(index))
     self.dataChanged.emit(self.index(index.row(), 0), self.index(index.row(), self.columnCount() - 1))
     return True
Esempio n. 10
0
    def commit(self):
        for plugin, val in self.enabled_overrides.iteritems():
            if val == Qt.Checked:
                enable_plugin(plugin)
            elif val == Qt.Unchecked:
                disable_plugin(plugin)

        if self.cover_overrides:
            cp = msprefs['cover_priorities']
            for plugin, val in self.cover_overrides.iteritems():
                if val == 1:
                    cp.pop(plugin.name, None)
                else:
                    cp[plugin.name] = val
            msprefs['cover_priorities'] = cp

        self.enabled_overrides = {}
        self.cover_overrides = {}
Esempio n. 11
0
    def commit(self):
        for plugin, val in self.enabled_overrides.iteritems():
            if val == Qt.Checked:
                enable_plugin(plugin)
            elif val == Qt.Unchecked:
                disable_plugin(plugin)

        if self.cover_overrides:
            cp = msprefs['cover_priorities']
            for plugin, val in self.cover_overrides.iteritems():
                if val == 1:
                    cp.pop(plugin.name, None)
                else:
                    cp[plugin.name] = val
            msprefs['cover_priorities'] = cp

        self.enabled_overrides = {}
        self.cover_overrides = {}
Esempio n. 12
0
    def commit(self):
        devs = {}
        for i in xrange(0, self.devices.count()):
            e = self.devices.item(i)
            dev, uid = e.data(Qt.UserRole)
            if dev not in devs:
                devs[dev] = []
            if e.checkState() == Qt.Checked:
                devs[dev].append(uid)

        for dev, bl in devs.iteritems():
            dev.set_user_blacklisted_devices(bl)

        for i in xrange(self.device_plugins.count()):
            e = self.device_plugins.item(i)
            dev = e.data(Qt.UserRole)
            if e.checkState() == Qt.Unchecked:
                enable_plugin(dev)

        return True  # Restart required
Esempio n. 13
0
    def commit(self):
        devs = {}
        for i in range(0, self.devices.count()):
            e = self.devices.item(i)
            dev, uid = e.data(Qt.UserRole)
            if dev not in devs:
                devs[dev] = []
            if e.checkState() == Qt.Checked:
                devs[dev].append(uid)

        for dev, bl in iteritems(devs):
            dev.set_user_blacklisted_devices(bl)

        for i in range(self.device_plugins.count()):
            e = self.device_plugins.item(i)
            dev = e.data(Qt.UserRole)
            if e.checkState() == Qt.Unchecked:
                enable_plugin(dev)

        return True  # Restart required
Esempio n. 14
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
     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
Esempio n. 15
0
 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
Esempio n. 16
0
    def modify_plugin(self, op=""):
        index = self.plugin_view.currentIndex()
        if index.isValid():
            if not index.parent().isValid():
                name = unicode(index.data().toString())
                return error_dialog(
                    self,
                    _("Error"),
                    "<p>" + _("Select an actual plugin under <b>%s</b> to customize") % name,
                    show=True,
                    show_copy_button=False,
                )

            plugin = self._plugin_model.index_to_plugin(index)
            if op == "toggle":
                if not plugin.can_be_disabled:
                    info_dialog(
                        self,
                        _("Plugin cannot be disabled"),
                        _("Disabling the plugin %s is not allowed") % plugin.name,
                        show=True,
                        show_copy_button=False,
                    )
                    return
                if is_disabled(plugin):
                    enable_plugin(plugin)
                else:
                    disable_plugin(plugin)
                self._plugin_model.refresh_plugin(plugin)
                self.changed_signal.emit()
            if op == "customize":
                if not plugin.is_customizable():
                    info_dialog(
                        self, _("Plugin not customizable"), _("Plugin: %s does not need customization") % plugin.name
                    ).exec_()
                    return
                self.changed_signal.emit()
                from calibre.customize import InterfaceActionBase

                if isinstance(plugin, InterfaceActionBase) and not getattr(
                    plugin, "actual_iaction_plugin_loaded", False
                ):
                    return error_dialog(
                        self,
                        _("Must restart"),
                        _("You must restart calibre before you can" " configure the <b>%s</b> plugin") % plugin.name,
                        show=True,
                    )
                if plugin.do_user_config(self.gui):
                    self._plugin_model.refresh_plugin(plugin)
            elif op == "remove":
                if not confirm(
                    "<p>" + _("Are you sure you want to remove the plugin: %s?") % "<b>{0}</b>".format(plugin.name),
                    "confirm_plugin_removal_msg",
                    parent=self,
                ):
                    return

                msg = _("Plugin <b>{0}</b> successfully removed").format(plugin.name)
                if remove_plugin(plugin):
                    self._plugin_model.populate()
                    self._plugin_model.reset()
                    self.changed_signal.emit()
                    info_dialog(self, _("Success"), msg, show=True, show_copy_button=False)
                else:
                    error_dialog(
                        self,
                        _("Cannot remove builtin plugin"),
                        plugin.name + _(" cannot be removed. It is a " "builtin plugin. Try disabling it instead."),
                    ).exec_()