davidfor/calibre-annotations

Add support for multiple libraries with different custom column assignments

GRiker opened this issue · 14 comments

(Generated from calibre plugins forum post)

The last thing is that I use several libraries. In my test library, I added a column called "Annotations" and selected it. Later, while using another library which doesn't have that column, I opened the Annotations configuration. And had the following error:

calibre, version 1.13.0
ERROR: Unhandled exception: TypeError:'NoneType' object has no attribute 'getitem'
calibre 1.13 isfrozen: True is64bit: False
Windows-7-6.1.7601-SP1 Windows ('32bit', 'WindowsPE')
('Windows', '7', '6.1.7601')
Python 2.7.5
Windows: ('7', '6.1.7601', 'SP1', 'Multiprocessor Free')
Traceback (most recent call last):
File "calibre_plugins.annotations.config", line 273, in annotations_destination_changed
File "calibre_plugins.annotations.common_utils", line 737, in existing_annotations
TypeError: 'NoneType' object has no attribute 'getitem'

After that, the configuration dialog is shown with no fields and calibre crashes. Windows shows the "calibre.exe has stopped working" error with the usual check online or close options.

I've posted a initial build with support for multiple libraries and other bug fixes. You can download version 1.2.901 of the plugin to test it. It hasn't been tested rigorously.

Unfortunately, that didn't work. When I opened the configuration dialog, it crashed calibre. This was with a library that I had been using for my testing. It already had a custom column created and configured.

The following was printed to the console window:

DEBUG:   45.7 AnnotationsAction:launch_library_scanner(updating library index)
DEBUG:   46.1 AnnotationsAction:library_index_complete()
DEBUG:   52.1 ConfigWidget:populate_annotations()
calibre 1.13*  isfrozen: True is64bit: False
Windows-7-6.1.7601-SP1 Windows ('32bit', 'WindowsPE')
('Windows', '7', '6.1.7601')
Python 2.7.5
Windows: ('7', '6.1.7601', 'SP1', 'Multiprocessor Free')
Traceback (most recent call last):
  File "calibre_plugins.annotations.config", line 483, in run
  File "calibre_plugins.annotations.config", line 501, in find_all_annotated_books
TypeError: 'NoneType' object has no attribute '__getitem__'

QObject::setParent: Cannot set parent, new parent is in a different thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QObject::setParent: Cannot set parent, new parent is in a different thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread

I also deleted the annotations.db and annotations.json from the calibre plugins directory. There was no change.

Please try the following:

  • Exit calibre
  • in annotations.json, set the debug flag to true: "cfg_plugin_debug_log_checkbox": true,
  • Run calibre in debug mode
  • Follow the steps to create the crash
  • Post the debug log in a new comment

I tried again and got it working. This time, I close calibre, deleted annotations.json, started calibre and closed it again. Then I edited annotations.json to set the debug flag.started calibre and restarted in debug mode. Then I was able to open the configuration without errors.

But, then I changed to a library that didn't have the custom column. Opening the configuration dialog produced the following error:

calibre, version 1.13.0
ERROR: Unhandled exception: <b>AttributeError</b>:'Struct' object has no attribute '_log_location'

calibre 1.13  isfrozen: True is64bit: False
Windows-7-6.1.7601-SP1 Windows ('32bit', 'WindowsPE')
('Windows', '7', '6.1.7601')
Python 2.7.5
Windows: ('7', '6.1.7601', 'SP1', 'Multiprocessor Free')
Traceback (most recent call last):
  File "calibre_plugins.annotations.config", line 250, in annotations_destination_changed
  File "calibre_plugins.annotations.common_utils", line 914, in move_annotations
AttributeError: 'Struct' object has no attribute '_log_location'

Pressing OK on the error window crashed calibre. Running in debug mode didn't help and didn't show the debug log after the crash.

I've updated to 1.2.902, I think it should fix that crash.

I know there are still problems, I'm trying to get things to a state where you can at least develop your Kobo driver.

I will continue working on this later today.

Sorry, that didn't help. I am still getting the crash. I have just updated to 1.14.0, but had the crash with 1.13.0 and when running from source. And just to check, I deleted the plugin and the json file and the database and installed the plugin again. Same problem.

In case it helps, here is the details that Windows shows

Problem signature:
  Problem Event Name:   APPCRASH
  Application Name: calibre.exe
  Application Version:  1.14.0.0
  Application Timestamp:    52a15354
  Fault Module Name:    QtGui4.dll
  Fault Module Version: 4.8.4.0
  Fault Module Timestamp:   51a1e64f
  Exception Code:   c0000005
  Exception Offset: 00165acd
  OS Version:   6.1.7601.2.1.0.256.48
  Locale ID:    3081
  Additional Information 1: 0a9e
  Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
  Additional Information 3: 0a9e
  Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

Running from source, I get:

DEBUG:    2.5 rebuild_menus - self.supports_ratings=False
Started up in 4.86 seconds with 29 books
calibre 1.14*  isfrozen: True is64bit: False
Windows-7-6.1.7601-SP1 Windows ('32bit', 'WindowsPE')
('Windows', '7', '6.1.7601')
Python 2.7.5
Windows: ('7', '6.1.7601', 'SP1', 'Multiprocessor Free')
Traceback (most recent call last):
  File "calibre_plugins.annotations.config", line 483, in run
  File "calibre_plugins.annotations.config", line 501, in find_all_annotated_books
TypeError: 'NoneType' object has no attribute '__getitem__'

QObject::setParent: Cannot set parent, new parent is in a different thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QObject::setParent: Cannot set parent, new parent is in a different thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QObject::startTimer: timers cannot be started from another thread
QObject::startTimer: timers cannot be started from another thread
QObject::startTimer: timers cannot be started from another thread
QObject::startTimer: timers cannot be started from another thread
QObject::startTimer: timers cannot be started from another thread
QApplication: Object event filter cannot be in a different thread.

And that keeps repeating.

The problem is in the following code at the end of the init method of ConfigWidget.. Why do you need to do this when opening the ConfigWidget?

        # Launch the annotated_books_scanner
        field = get_cc_mapping('annotations', 'field', None)
        self.annotated_books_scanner = InventoryAnnotatedBooks(self.gui, field)
        self.connect(self.annotated_books_scanner, self.annotated_books_scanner.signal,
            self.inventory_complete)
        QTimer.singleShot(1, self.start_inventory)

Please update to 1.2.903 which resolves the crash at #501 in config. This was an error left over from the change to supporting multiple libraries.

The call to InventoryAnnotatedBooks builds a list of annotated books in the current library, which is referenced throughout the plugin. This class not cause of the crash - I was passing an empty field to it.

I believe that this should resolve all the multi-library issues.

That and 1.2.904 didn't help. But, I did some debugging.

The error is in ConfigWidget::init and is in the line:

field = get_cc_mapping('annotations', 'field', 'Comment')

That should be 'Comments' as the default.

When you compare the field name used in InventoryAnnotatedBooks::find_all_annotated_books, it returns false and tries to fetch an unknown column from the metadata. I didn't track through to the actual crash as fixing the field names solved it.

Good eye. 1.2.905 resolves that problem. Thanks for spotting it.

You wouldn't say "Good eye" if you knew how long I stared at it :)

Tested and it works fine. And so does the new dialog.

Whew. I've been making the multi-library changes in two other related plugins and committing hundreds of changes. Apologies for the putting you through this.

I need some time to finish the multi-library changes on my other plugins while it's fresh in my mind. If you're now able to develop your Kobo module without crashes, I'd like to finish up what I'm doing before coming back to your other design-related questions.

That's OK. I can continue with what I am doing. Plus, I need to return to my own plugin. I have a beta that should be thrown to the wolves.

I'm closing this issue. If you find any problems with handling multiple libraries, please reopen it.