This commit is contained in:
Kovid Goyal 2010-01-19 08:43:52 -07:00
parent e8d1e03f73
commit 0e0863103a
3 changed files with 18 additions and 6 deletions

View File

@ -20,6 +20,10 @@ class Font(object):
class Column(object): class Column(object):
# A column contains an element is the element bulges out to
# the left or the right by at most HFUZZ*col width.
HFUZZ = 0.2
def __init__(self): def __init__(self):
self.left = self.right = self.top = self.bottom = 0 self.left = self.right = self.top = self.bottom = 0
self.width = self.height = 0 self.width = self.height = 0
@ -41,6 +45,10 @@ class Column(object):
for x in self.elements: for x in self.elements:
yield x yield x
def contains(self, elem):
return elem.left > self.left - self.HFUZZ*self.width and \
elem.right < self.right + self.HFUZZ*self.width
class Element(object): class Element(object):
def __eq__(self, other): def __eq__(self, other):
@ -238,11 +246,10 @@ class Page(object):
return columns return columns
def find_elements_in_row_of(self, x): def find_elements_in_row_of(self, x):
interval = Interval(x.top - self.YFUZZ * self.average_text_height, interval = Interval(x.top,
x.top + self.YFUZZ*(1+self.average_text_height)) x.top + self.YFUZZ*(1+self.average_text_height))
h_interval = Interval(x.left, x.right) h_interval = Interval(x.left, x.right)
m = max(0, x.idx-15) for y in self.elements[x.idx:x.idx+15]:
for y in self.elements[m:x.idx+15]:
if y is not x: if y is not x:
y_interval = Interval(y.top, y.bottom) y_interval = Interval(y.top, y.bottom)
x_interval = Interval(y.left, y.right) x_interval = Interval(y.left, y.right)

View File

@ -1361,7 +1361,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
def generate_catalog(self): def generate_catalog(self):
rows = self.library_view.selectionModel().selectedRows() rows = self.library_view.selectionModel().selectedRows()
if not rows: if not rows or len(rows) < 3:
rows = xrange(self.library_view.model().rowCount(QModelIndex())) rows = xrange(self.library_view.model().rowCount(QModelIndex()))
ids = map(self.library_view.model().id, rows) ids = map(self.library_view.model().id, rows)
dbspec = None dbspec = None

View File

@ -1634,13 +1634,15 @@ class LibraryDatabase2(LibraryDatabase):
for i in iter(self): for i in iter(self):
yield i[x] yield i[x]
def get_data_as_dict(self, prefix=None, authors_as_string=False): def get_data_as_dict(self, prefix=None, authors_as_string=False, ids=None):
''' '''
Return all metadata stored in the database as a dict. Includes paths to Return all metadata stored in the database as a dict. Includes paths to
the cover and each format. the cover and each format.
:param prefix: The prefix for all paths. By default, the prefix is the absolute path :param prefix: The prefix for all paths. By default, the prefix is the absolute path
to the library folder. to the library folder.
:param ids: Set of ids to return the data for. If None return data for
all entries in database.
''' '''
if prefix is None: if prefix is None:
prefix = self.library_path prefix = self.library_path
@ -1649,12 +1651,15 @@ class LibraryDatabase2(LibraryDatabase):
'isbn', 'uuid', 'pubdate']) 'isbn', 'uuid', 'pubdate'])
data = [] data = []
for record in self.data: for record in self.data:
db_id = record[FIELD_MAP['id']]
if ids is not None and db_id not in ids:
continue
if record is None: continue if record is None: continue
x = {} x = {}
for field in FIELDS: for field in FIELDS:
x[field] = record[FIELD_MAP[field]] x[field] = record[FIELD_MAP[field]]
data.append(x) data.append(x)
x['id'] = record[FIELD_MAP['id']] x['id'] = db_id
x['formats'] = [] x['formats'] = []
if not x['authors']: if not x['authors']:
x['authors'] = _('Unknown') x['authors'] = _('Unknown')