diff --git a/src/calibre/gui2/actions/tweak_epub.py b/src/calibre/gui2/actions/tweak_epub.py index 67ec34c12b..212aff8019 100755 --- a/src/calibre/gui2/actions/tweak_epub.py +++ b/src/calibre/gui2/actions/tweak_epub.py @@ -40,8 +40,7 @@ class TweakEpubAction(InterfaceAction): _('No ePub available. First convert the book to ePub.'), show=True) - - # Launch a modal dialog waiting for user to complete or cancel + # Launch modal dialog waiting for user to tweak or cancel dlg = TweakEpub(self.gui, path_to_epub) if dlg.exec_() == dlg.Accepted: self.update_db(book_id, dlg._output) diff --git a/src/calibre/gui2/dialogs/tweak_epub.py b/src/calibre/gui2/dialogs/tweak_epub.py index fb3643884b..db6e93fd7a 100755 --- a/src/calibre/gui2/dialogs/tweak_epub.py +++ b/src/calibre/gui2/dialogs/tweak_epub.py @@ -21,8 +21,6 @@ class TweakEpub(QDialog, Ui_Dialog): ''' Display controls for tweaking ePubs - To do: - - need way to kill file browser proc in cleanup() ''' def __init__(self, parent, epub): @@ -30,7 +28,6 @@ class TweakEpub(QDialog, Ui_Dialog): self._epub = epub self._exploded = None - #self._file_browser_proc = None self._output = None # Run the dialog setup generated from tweak_epub.ui diff --git a/src/calibre/gui2/dialogs/tweak_epub.ui b/src/calibre/gui2/dialogs/tweak_epub.ui index 9daa5a8f67..ccd33f44ab 100644 --- a/src/calibre/gui2/dialogs/tweak_epub.ui +++ b/src/calibre/gui2/dialogs/tweak_epub.ui @@ -32,7 +32,7 @@ &Explode ePub - + :/images/wizard.png:/images/wizard.png @@ -49,7 +49,7 @@ &Rebuild ePub - + :/images/exec.png:/images/exec.png @@ -63,7 +63,7 @@ &Cancel - + :/images/window-close.png:/images/window-close.png @@ -71,7 +71,7 @@ - First, explode the epub. Then edit is contents by right clicking on the individual files and selecting the editor of your choice. When you are done, click rebuild epub and the epub in your calibre library will be updated with the changes you have made. + Explode the ePub to display contents in a file browser window. To tweak individual files, right-click, then 'Open with...' your editor of choice. When tweaks are complete, close the file browser window. Rebuild the ePub, updating your calibre library. true diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index d310a0e6fe..42feb6f8fa 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import re, itertools +import re, itertools, time from itertools import repeat from datetime import timedelta from threading import Thread, RLock @@ -38,7 +38,6 @@ class CoverCache(Thread): self.keep_running = False def _image_for_id(self, id_): - import time time.sleep(0.050) # Limit 20/second to not overwhelm the GUI img = self.cover_func(id_, index_is_id=True, as_image=True) if img is None: diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 1fdacfc09f..205d2f894a 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -437,7 +437,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): if current_path and os.path.exists(spath): # Migrate existing files cdata = self.cover(id, index_is_id=True) if cdata is not None: - open(os.path.join(tpath, 'cover.jpg'), 'wb').write(cdata) + with open(os.path.join(tpath, 'cover.jpg'), 'wb') as f: + f.write(cdata) for format in formats: # Get data as string (can't use file as source and target files may be the same) f = self.format(id, format, index_is_id=True, as_file=False) @@ -447,7 +448,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.add_format(id, format, stream, index_is_id=True, path=tpath, notify=False) self.conn.execute('UPDATE books SET path=? WHERE id=?', (path, id)) - self.conn.commit() self.data.set(id, self.FIELD_MAP['path'], path, row_is_id=True) # Delete not needed directories if current_path and os.path.exists(spath): @@ -551,10 +551,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): return self.field_metadata.sortable_field_keys() def searchable_fields(self): - return self.field_metadata.searchable_fields() + return self.field_metadata.searchable_field_keys() def search_term_to_field_key(self, term): - return self.field_metadata.search_term_to_field_key(term) + return self.field_metadata.search_term_to_key(term) def metadata_for_field(self, key): return self.field_metadata[key] @@ -1211,7 +1211,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): result.append(r) return ' & '.join(result).replace('|', ',') - def set_authors(self, id, authors, notify=True): + def set_authors(self, id, authors, notify=True, commit=True): ''' `authors`: A list of authors. ''' @@ -1239,7 +1239,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): ss = self.author_sort_from_book(id, index_is_id=True) self.conn.execute('UPDATE books SET author_sort=? WHERE id=?', (ss, id)) - self.conn.commit() + if commit: + self.conn.commit() self.data.set(id, self.FIELD_MAP['authors'], ','.join([a.replace(',', '|') for a in authors]), row_is_id=True) @@ -1248,7 +1249,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): if notify: self.notify('metadata', [id]) - def set_title(self, id, title, notify=True): + def set_title(self, id, title, notify=True, commit=True): if not title: return if not isinstance(title, unicode): @@ -1260,7 +1261,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): else: self.data.set(id, self.FIELD_MAP['sort'], title, row_is_id=True) self.set_path(id, index_is_id=True) - self.conn.commit() + if commit: + self.conn.commit() if notify: self.notify('metadata', [id])