mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-05 08:40:13 -04:00
Legacy listeners interface
This commit is contained in:
parent
e54625a320
commit
9548ad6206
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os
|
import os, traceback
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from calibre.db.backend import DB
|
from calibre.db.backend import DB
|
||||||
@ -30,6 +30,7 @@ class LibraryDatabase(object):
|
|||||||
progress_callback=lambda x, y:True, restore_all_prefs=False):
|
progress_callback=lambda x, y:True, restore_all_prefs=False):
|
||||||
|
|
||||||
self.is_second_db = is_second_db # TODO: Use is_second_db
|
self.is_second_db = is_second_db # TODO: Use is_second_db
|
||||||
|
self.listeners = set([])
|
||||||
|
|
||||||
backend = self.backend = DB(library_path, default_prefs=default_prefs,
|
backend = self.backend = DB(library_path, default_prefs=default_prefs,
|
||||||
read_only=read_only, restore_all_prefs=restore_all_prefs,
|
read_only=read_only, restore_all_prefs=restore_all_prefs,
|
||||||
@ -117,6 +118,22 @@ class LibraryDatabase(object):
|
|||||||
self.data.cache.refresh()
|
self.data.cache.refresh()
|
||||||
self.data.refresh(field=field, ascending=ascending)
|
self.data.refresh(field=field, ascending=ascending)
|
||||||
|
|
||||||
|
def add_listener(self, listener):
|
||||||
|
'''
|
||||||
|
Add a listener. Will be called on change events with two arguments.
|
||||||
|
Event name and list of affected ids.
|
||||||
|
'''
|
||||||
|
self.listeners.add(listener)
|
||||||
|
|
||||||
|
def notify(self, event, ids=[]):
|
||||||
|
'Notify all listeners'
|
||||||
|
for listener in self.listeners:
|
||||||
|
try:
|
||||||
|
listener(event, ids)
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
continue
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def path(self, index, index_is_id=False):
|
def path(self, index, index_is_id=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user