Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 04-18-2011, 01:08 PM   #1
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
Detecting complete sync of books from device

Is there a way to tell when a device is fully connected - in the sense that calibre knows the ids of the books on the device.

I occasionally get a condition where someone (ok, me mainly ) runs the plugin before all the books that are on the device are identified. This means when my plugin asks calibre for the data, it gets back 0 books on the device, until you run it a second time after the job is done.
meme is offline   Reply With Quote
Old 04-18-2011, 02:03 PM   #2
chaley
"chaley", not "charley"
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 5,055
Karma: 802238
Join Date: Jan 2010
Location: France
Device: Many android devices
No, there isn't. What would you do if you had something like this? Refuse to run?

We could add a signal that is fired when the ondevice calculations are done. I see two issues. 1) It would be best not to interact with the user in that signal handler, because the GUI would blocked at what appears to be a random time. 2) it would be signaled when books are added or deleted.

Kovid, I am thinking of emitting the signal after we call self.library_view.model().refresh_ondevice() at line 803 of device.py. Do you see any problem with this?
chaley is offline   Reply With Quote
Old 04-18-2011, 02:08 PM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,427
Karma: 4961459
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Why not do it at the end of metadata_downloaded? IIRC, that means the device is "fully connected"
kovidgoyal is online now   Reply With Quote
Old 04-18-2011, 02:13 PM   #4
chaley
"chaley", not "charley"
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 5,055
Karma: 802238
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by kovidgoyal View Post
Why not do it at the end of metadata_downloaded? IIRC, that means the device is "fully connected"
The last thing metadata_downloaded does is call refresh_ondevice().

My thought was that if we are adding this signal, something that connects to the signal might want to know if the booklists have changed. There are other methods that change the booklist, for example books_uploaded and books_deleted, and both of these call refresh_ondevice at the right time.
chaley is offline   Reply With Quote
Old 04-18-2011, 02:16 PM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,427
Karma: 4961459
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Best to have two signals in that case, it's not like they are a scarce resource metadata_downloaded and book list changed are very different things.
kovidgoyal is online now   Reply With Quote
Old 04-18-2011, 02:19 PM   #6
chaley
"chaley", not "charley"
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 5,055
Karma: 802238
Join Date: Jan 2010
Location: France
Device: Many android devices
Both of them result in the same thing -- telling the signal recipient that the ondevice information has (potentially) changed. But I don't care enough to argue. I will add the signal to the end of metadata_downloaded.
chaley is offline   Reply With Quote
Old 04-18-2011, 02:29 PM   #7
chaley
"chaley", not "charley"
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 5,055
Karma: 802238
Join Date: Jan 2010
Location: France
Device: Many android devices
Code pushed.

The signal is device_metadata_available, and is raised after all the connection processing is complete. It should be visible to a plugin as gui.device_metadata_available.

The sequence: gui.device_manager.is_device_connected will become True, then sometime later gui.device_metadata_available will be signaled. This does not mean that there are no more jobs running. Automatic metadata management might have kicked off a sync_booklists to write new metadata onto the device, and that job might still be running when the signal is emitted.
chaley is offline   Reply With Quote
Old 04-18-2011, 02:35 PM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,427
Karma: 4961459
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
merged .
kovidgoyal is online now   Reply With Quote
Old 04-18-2011, 02:56 PM   #9
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
Step away for a minute and look what happens

Just to be clear - my plugin does not have to be running and looking for a signal? It just has to test if gui.device_metadata_available is True before continuing - otherwise I will issue an error dialog to tell the user to wait and try again. (Actually I currently test if gui.device_manager.is_device_connected is True, and then I test if gui.device_manager.connected_device._main_prefix has a value because I think I used to test for just main_prefix but found that wasn't reset between connections so I test both - and now I'll add a 3rd test).

I understand it won't be perfect as there could be books to send to/sync with the device - but it will prevent the majority of issues that might happen.

Many thanks.
meme is offline   Reply With Quote
Old 04-18-2011, 04:18 PM   #10
chaley
"chaley", not "charley"
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 5,055
Karma: 802238
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by meme View Post
Just to be clear - my plugin does not have to be running and looking for a signal? It just has to test if gui.device_metadata_available is True before continuing - otherwise I will issue an error dialog to tell the user to wait and try again.
No. It is a signal, not a flag. You can't test it at random times.

Thinking about it, I understand one of the difficulties you are facing. You don't track connections and disconnections, so this one signal isn't sufficient. You need to know when the device connects and disconnects so you can know what this signal means.

Assuming Kovid accepts the change, I have added a second signal, gui.device_connected_changed.emit(connected). This signal is emitted whenever a device is connected or disconnected. The argument to the signal, connected, is True if a device has been connected, False otherwise.

In your init method, connect to these two signals. If you get device_connected_changed(False), mark the fact that there is no device and clear the device valid indication. If you get device_connected_changed(True), mark that fact, and prepare to receive the device_metadata_available signal. When you receive the device_metadata_available, note that fact, which the rest of your plugin will use to determine whether the info is available or not.

The initial condition is that there is no device.
chaley is offline   Reply With Quote
Old 04-18-2011, 04:42 PM   #11
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,427
Karma: 4961459
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Merged.
kovidgoyal is online now   Reply With Quote
Old 04-18-2011, 05:21 PM   #12
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
Got it. Of course the plugin is already live once calibre starts. Thanks.
meme is offline   Reply With Quote
Old 04-19-2011, 12:36 PM   #13
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
Ok, don't got it.

I'm running from the source with the signals, but I'm obviously missing something in the syntax/use as I'm getting an error.

I've put in my genesis routine in ui.py (testconnect1 just prints hello):

self.gui.device_metadata_available.connect(self.te stconnect1)

but I get this when I start calibre:

File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/main.py", line 253, in initialize
self.initialize_db()
File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/main.py", line 234, in initialize_db
self.initialize_db_stage2(db, None)
File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/main.py", line 203, in initialize_db_stage2
self.start_gui(db)
File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/main.py", line 159, in start_gui
main.initialize(self.library_path, db, self.listener, self.actions)
File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/ui.py", line 195, in initialize
ac.do_genesis()
File "/home/meme/Calibre-Source/calibre/src/calibre/gui2/actions/__init__.py", line 97, in do_genesis
self.genesis()
File "calibre_plugins.kindle_collections.ui", line 55, in genesis

TypeError: connect() failed between [] and unislot()
meme is offline   Reply With Quote
Old 04-19-2011, 12:53 PM   #14
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,224
Karma: 1334002
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
@meme - try hooking in initialization_complete rather than genesis?
kiwidude is online now   Reply With Quote
Old 04-19-2011, 01:00 PM   #15
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,427
Karma: 4961459
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
There was a bug with the way signals were implemented. Charles committed a fix a little while ago.

Use

self.gui.device_signals.signal_name.connect(...
kovidgoyal is online now   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calibre not detecting device Bureaucromancer Kobo Reader 3 09-19-2010 12:16 AM
Re-detecting a device such as iPad gandor62 Calibre 1 06-18-2010 08:21 PM
Calibre not detecting device prs500 Miri Calibre 10 06-13-2010 01:46 PM
Detecting device mpetry Calibre 3 04-16-2010 09:05 PM
Multi-Device Sync? Sonist Calibre 6 02-03-2010 03:49 PM


All times are GMT -4. The time now is 11:16 AM.


MobileRead.com is a privately owned, operated and funded community.