Merge branch 'kovidgoyal/master'

This commit is contained in:
Charles Haley 2013-07-11 09:52:26 +02:00
commit 8f221eecda
6 changed files with 31 additions and 20 deletions

View File

@ -279,7 +279,7 @@ class Convert(object):
self.styles.resolve_numbering(numbering) self.styles.resolve_numbering(numbering)
def write(self, doc): def write(self, doc):
toc = create_toc(doc, self.body, self.resolved_link_map, self.styles, self.object_map) toc = create_toc(doc, self.body, self.resolved_link_map, self.styles, self.object_map, self.log)
raw = html.tostring(self.html, encoding='utf-8', doctype='<!DOCTYPE html>') raw = html.tostring(self.html, encoding='utf-8', doctype='<!DOCTYPE html>')
with open(os.path.join(self.dest_dir, 'index.html'), 'wb') as f: with open(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
f.write(raw) f.write(raw)

View File

@ -21,7 +21,7 @@ class Count(object):
def __init__(self): def __init__(self):
self.val = 0 self.val = 0
def from_headings(body): def from_headings(body, log):
' Create a TOC from headings in the document ' ' Create a TOC from headings in the document '
headings = ('h1', 'h2', 'h3') headings = ('h1', 'h2', 'h3')
tocroot = TOC() tocroot = TOC()
@ -58,6 +58,7 @@ def from_headings(body):
level_prev[i] = None level_prev[i] = None
if len(tuple(tocroot.flat())) > 1: if len(tuple(tocroot.flat())) > 1:
log('Generating Table of Contents from headings')
return tocroot return tocroot
def structure_toc(entries): def structure_toc(entries):
@ -98,7 +99,7 @@ def link_to_txt(a, styles, object_map):
return tostring(a, method='text', with_tail=False, encoding=unicode).strip() return tostring(a, method='text', with_tail=False, encoding=unicode).strip()
def from_toc(docx, link_map, styles, object_map): def from_toc(docx, link_map, styles, object_map, log):
toc_level = None toc_level = None
level = 0 level = 0
TI = namedtuple('TI', 'text anchor indent') TI = namedtuple('TI', 'text anchor indent')
@ -132,9 +133,10 @@ def from_toc(docx, link_map, styles, object_map):
ml = 0 ml = 0
toc.append(TI(txt, href[1:], ml)) toc.append(TI(txt, href[1:], ml))
if toc: if toc:
log('Found Word Table of Contents, using it to generate the Table of Contents')
return structure_toc(toc) return structure_toc(toc)
def create_toc(docx, body, link_map, styles, object_map): def create_toc(docx, body, link_map, styles, object_map, log):
return from_toc(docx, link_map, styles, object_map) or from_headings(body) return from_toc(docx, link_map, styles, object_map, log) or from_headings(body, log)

View File

@ -1,8 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai # vim:fileencoding=utf-8
from __future__ import (unicode_literals, division, absolute_import,
print_function)
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog

View File

@ -1,6 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
# vim:fileencoding=utf-8
from __future__ import (unicode_literals, division, absolute_import,
print_function)
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __copyright__ = '2013, Kovid Goyal kovid@kovidgoyal.net'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
@ -158,7 +162,7 @@ class MatchBooks(QDialog, Ui_MatchBooks):
self.save_state() self.save_state()
def book_clicked(self, row, column): def book_clicked(self, row, column):
self.book_selected = True; self.book_selected = True
id_ = self.books_table.item(row, 0).data(Qt.UserRole).toInt()[0] id_ = self.books_table.item(row, 0).data(Qt.UserRole).toInt()[0]
self.current_library_book_id = id_ self.current_library_book_id = id_
@ -195,3 +199,4 @@ class MatchBooks(QDialog, Ui_MatchBooks):
def reject(self): def reject(self):
self.close() self.close()
QDialog.reject(self) QDialog.reject(self)

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>768</width> <width>751</width>
<height>342</height> <height>342</height>
</rect> </rect>
</property> </property>
@ -50,7 +50,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<widget class="QLabel"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Do a search to find the book you want to match</string> <string>Do a search to find the book you want to match</string>
</property> </property>
@ -64,19 +64,21 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="columnCount"> <property name="rowCount">
<number>0</number> <number>0</number>
</property> </property>
<property name="rowCount"> <property name="columnCount">
<number>0</number> <number>0</number>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<widget class="QLabel"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>&lt;p&gt;Be sure to update metadata on the device when you are <string>&lt;p&gt;Remember to update metadata on the device when you are done (Right click the device icon and select &lt;i&gt;Update cached metadata&lt;/i&gt;)&lt;/p&gt;</string>
finished matching books (Device -> Update Metadata)&lt;/p&gt;</string> </property>
<property name="wordWrap">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@ -109,7 +111,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<resources/>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>HistoryLineEdit</class> <class>HistoryLineEdit</class>
@ -117,6 +118,7 @@
<header>calibre/gui2/widgets.h</header> <header>calibre/gui2/widgets.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/>
<connections> <connections>
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>

View File

@ -61,7 +61,7 @@ class LocationManager(QObject): # {{{
a = m.addAction(QIcon(I('config.png')), _('Configure this device')) a = m.addAction(QIcon(I('config.png')), _('Configure this device'))
a.triggered.connect(self._configure_requested) a.triggered.connect(self._configure_requested)
self._mem.append(a) self._mem.append(a)
a = m.addAction(QIcon(I('sync.png')), _('Update metadata on device')) a = m.addAction(QIcon(I('sync.png')), _('Update cached metadata on device'))
a.triggered.connect(lambda x : self.update_device_metadata.emit()) a.triggered.connect(lambda x : self.update_device_metadata.emit())
self._mem.append(a) self._mem.append(a)