diff --git a/src/calibre/customize/profiles.py b/src/calibre/customize/profiles.py index 3844ab43a5..8434773515 100644 --- a/src/calibre/customize/profiles.py +++ b/src/calibre/customize/profiles.py @@ -242,9 +242,9 @@ class KindleDXOutput(OutputProfile): description = _('This profile is intended for the Amazon Kindle DX.') # Screen size is a best guess - screen_size = (1200, 824) + screen_size = (824, 1200) dpi = 150.0 - comic_screen_size = (1180, 800) + comic_screen_size = (775, 1128) @classmethod def tags_to_string(cls, tags): diff --git a/src/calibre/devices/bebook/driver.py b/src/calibre/devices/bebook/driver.py index a3e8db917a..2fb756b532 100644 --- a/src/calibre/devices/bebook/driver.py +++ b/src/calibre/devices/bebook/driver.py @@ -1,9 +1,12 @@ __license__ = 'GPL v3' __copyright__ = '2009, Tijmen Ruizendaal ' + ''' Device driver for BeBook ''' +import re + from calibre.devices.usbms.driver import USBMS class BEBOOK(USBMS): @@ -24,8 +27,8 @@ class BEBOOK(USBMS): WINDOWS_MAIN_MEM = 'FILE-STOR_GADGET' WINDOWS_CARD_A_MEM = 'FILE-STOR_GADGET' - OSX_MAIN_MEM = 'BeBook Internal Memory' - OSX_CARD_A_MEM = 'BeBook Storage Card' + OSX_MAIN_MEM = 'Linux File-Stor Gadget Media' + OSX_CARD_A_MEM = 'Linux File-Stor Gadget Media' MAIN_MEMORY_VOLUME_LABEL = 'BeBook Internal Memory' STORAGE_CARD_VOLUME_LABEL = 'BeBook Storage Card' @@ -41,8 +44,35 @@ class BEBOOK(USBMS): drives['main'] = card drives['carda'] = main + if card and not main: + drives['main'] = card + drives['carda'] = None + return drives + def osx_sort_names(self, names): + main = names.get('main', None) + card = names.get('carda', None) + + try: + main_num = int(re.findall('\d+', main)[0]) if main else None + except: + main_num = None + try: + card_num = int(re.findall('\d+', card)[0]) if card else None + except: + card_num = None + + if card_num is not None and main_num is not None and card_num < main_num: + names['main'] = card + names['carda'] = main + + if card and not main: + names['main'] = card + names['carda'] = None + + return names + def linux_swap_drives(self, drives): if len(drives) < 2: return drives drives = list(drives) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 98ba781b0b..e1e8f3890c 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -235,12 +235,13 @@ class Device(DeviceConfig, DevicePlugin): wmi = __import__('wmi', globals(), locals(), [], -1) c = wmi.WMI(find_classes=False) for drive in c.Win32_DiskDrive(): - if self.windows_match_device(drive, 'WINDOWS_CARD_A_MEM'): + if self.windows_match_device(drive, 'WINDOWS_CARD_A_MEM') and not drives.get('carda', None): drives['carda'] = self.windows_get_drive_prefix(drive) - elif self.windows_match_device(drive, 'WINDOWS_CARD_B_MEM'): + elif self.windows_match_device(drive, 'WINDOWS_CARD_B_MEM') and not drives.get('cardb', None): drives['cardb'] = self.windows_get_drive_prefix(drive) - elif self.windows_match_device(drive, 'WINDOWS_MAIN_MEM'): + elif self.windows_match_device(drive, 'WINDOWS_MAIN_MEM') and not drives.get('main', None): drives['main'] = self.windows_get_drive_prefix(drive) + if 'main' in drives.keys() and 'carda' in drives.keys() and \ 'cardb' in drives.keys(): break @@ -265,6 +266,8 @@ class Device(DeviceConfig, DevicePlugin): return subprocess.Popen((ioreg+' -w 0 -S -c IOMedia').split(), stdout=subprocess.PIPE).communicate()[0] + def osx_sort_names(self, names): + return names def get_osx_mountpoints(self, raw=None): raw = self.run_ioreg(raw) @@ -290,7 +293,7 @@ class Device(DeviceConfig, DevicePlugin): get_dev_node(lines[i+1:], 'cardb') if len(names.keys()) == 3: break - return names + return self.osx_sort_names(names) def open_osx(self): mount = subprocess.Popen('mount', shell=True, stdout=subprocess.PIPE).stdout.read() diff --git a/src/calibre/ebooks/conversion/preprocess.py b/src/calibre/ebooks/conversion/preprocess.py index 2dc404e586..816dd54ade 100644 --- a/src/calibre/ebooks/conversion/preprocess.py +++ b/src/calibre/ebooks/conversion/preprocess.py @@ -21,7 +21,7 @@ _span_pat = re.compile('', re.DOTALL|re.IGNORECASE) def sanitize_head(match): x = match.group(1) x = _span_pat.sub('', x) - return '\n'+x+'\n' + return '\n%s\n' % x def chap_head(match): chap = match.group('chap') @@ -84,7 +84,7 @@ class HTMLPreProcessor(object): PREPROCESS = [ # Some idiotic HTML generators (Frontpage I'm looking at you) # Put all sorts of crap into . This messes up lxml - (re.compile(r']*>(.*?)', re.IGNORECASE|re.DOTALL), + (re.compile(r']*>\n*(.*?)\n*', re.IGNORECASE|re.DOTALL), sanitize_head), # Convert all entities, since lxml doesn't handle them well (re.compile(r'&(\S+?);'), convert_entities), @@ -130,7 +130,11 @@ class HTMLPreProcessor(object): # Have paragraphs show better (re.compile(r''), lambda match : '

'), # Clean up spaces - (re.compile(u'(?<=[\.,:;\?!”"\'])[\s^ ]*(?=<)'), lambda match: ' '), + (re.compile(u'(?<=[\.,;\?!”"\'])[\s^ ]*(?=<)'), lambda match: ' '), + # Connect paragraphs split by - + (re.compile(u'(?<=[^\s][-–])[\s]*(

)*[\s]*(

)*\s*(?=[^\s])'), lambda match: ''), + # Remove - that splits words + (re.compile(u'(?<=[^\s])[-–]+(?=[^\s])'), lambda match: ''), # Add space before and after italics (re.compile(u'(?'), lambda match: ' '), (re.compile(r'(?=\w)'), lambda match: ' '), diff --git a/src/calibre/ebooks/mobi/output.py b/src/calibre/ebooks/mobi/output.py index c5f94b5c28..625bd7ff0a 100644 --- a/src/calibre/ebooks/mobi/output.py +++ b/src/calibre/ebooks/mobi/output.py @@ -29,11 +29,7 @@ class MOBIOutput(OutputFormatPlugin): ), OptionRecommendation(name='mobi_periodical', recommended_value=False, level=OptionRecommendation.LOW, - help=_('When present, generate a periodical rather than a book.') - ), - OptionRecommendation(name='no_mobi_index', - recommended_value=False, level=OptionRecommendation.LOW, - help=_('Disable generation of MOBI index.') + help=_('Generate a periodical rather than a book.') ), OptionRecommendation(name='dont_compress', recommended_value=False, level=OptionRecommendation.LOW, diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py index 1ecee65410..cd38ebe5d5 100644 --- a/src/calibre/ebooks/mobi/writer.py +++ b/src/calibre/ebooks/mobi/writer.py @@ -639,7 +639,6 @@ class MobiWriter(object): self._text_nrecords = nrecords def _generate_indxt(self, ctoc): - if self.opts.mobi_periodical: raise NotImplementedError('Indexing for periodicals not implemented') toc = self._oeb.toc diff --git a/src/calibre/ebooks/pdb/header.py b/src/calibre/ebooks/pdb/header.py index 0d626b98f6..c012110a62 100644 --- a/src/calibre/ebooks/pdb/header.py +++ b/src/calibre/ebooks/pdb/header.py @@ -30,7 +30,7 @@ class PdbHeaderReader(object): def name(self): self.stream.seek(0) - return self.stream.read(32).replace('\x00', '') + return re.sub('[^-A-Za-z0-9]+', '', self.stream.read(32).replace('\x00', '')) def full_section_info(self, number): if number not in range(0, self.num_sections): @@ -66,7 +66,7 @@ class PdbHeaderBuilder(object): def __init__(self, identity, title): self.identity = identity.ljust(3, '\x00')[:8] - self.title = re.sub('[^-A-Za-z0-9]+', '_', title).ljust(32, '\x00')[:32] + self.title = re.sub('[^-A-Za-z0-9]+', '_', title).ljust(32, '\x00')[:32].encode('ascii', 'replace') def build_header(self, section_lengths, out_stream): ''' diff --git a/src/calibre/gui2/convert/bulk.py b/src/calibre/gui2/convert/bulk.py index 23336037a1..0b48f2521b 100644 --- a/src/calibre/gui2/convert/bulk.py +++ b/src/calibre/gui2/convert/bulk.py @@ -95,14 +95,13 @@ class BulkConfig(Config): self.stack.setCurrentIndex(idx) def setup_output_formats(self, db, preferred_output_format): - available_formats = '' - available_formats = set([x.lower() for x in - available_formats.split(',')]) + if preferred_output_format: + preferred_output_format = preferred_output_format.lower() output_formats = sorted(available_output_formats()) output_formats.remove('oeb') preferred_output_format = preferred_output_format if \ - preferred_output_format in output_formats else \ - sort_formats_by_preference(output_formats, + preferred_output_format and preferred_output_format \ + in output_formats else sort_formats_by_preference(output_formats, OUTPUT_FORMAT_PREFERENCES)[0] self.output_formats.addItems(list(map(QString, [x.upper() for x in output_formats]))) diff --git a/src/calibre/gui2/convert/mobi_output.py b/src/calibre/gui2/convert/mobi_output.py index 797ab31493..8fa27dcef1 100644 --- a/src/calibre/gui2/convert/mobi_output.py +++ b/src/calibre/gui2/convert/mobi_output.py @@ -18,7 +18,8 @@ class PluginWidget(Widget, Ui_Form): def __init__(self, parent, get_option, get_help, db=None, book_id=None): Widget.__init__(self, parent, 'mobi_output', - ['prefer_author_sort', 'rescale_images', 'toc_title'] + ['prefer_author_sort', 'rescale_images', 'toc_title', + 'dont_compress', 'mobi_periodical'] ) self.db, self.book_id = db, book_id self.initialize_options(get_option, get_help, db, book_id) diff --git a/src/calibre/gui2/convert/mobi_output.ui b/src/calibre/gui2/convert/mobi_output.ui index a91f48d592..bc1cd45714 100644 --- a/src/calibre/gui2/convert/mobi_output.ui +++ b/src/calibre/gui2/convert/mobi_output.ui @@ -41,7 +41,7 @@ - + Qt::Vertical @@ -54,6 +54,20 @@ + + + + Disable compression of the file contents + + + + + + + Generate a periodical rather than a book + + + diff --git a/src/calibre/gui2/convert/single.py b/src/calibre/gui2/convert/single.py index 8aaa9de7cd..4f91d848d8 100644 --- a/src/calibre/gui2/convert/single.py +++ b/src/calibre/gui2/convert/single.py @@ -153,7 +153,7 @@ class Config(ResizableDialog, Ui_Dialog): except ImportError: pass input_widget = None - name = 'calibre.gui2.convert.%s' % self.plumber.input_plugin.name.lower().replace(' ', '_') + name = self.plumber.input_plugin.name.lower().replace(' ', '_') try: input_widget = __import__('calibre.gui2.convert.'+name, fromlist=[1]) diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index 17c166099d..bf153ba932 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -1,16 +1,19 @@ -from __future__ import with_statement __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ' + ''' The dialog used to edit meta information for a book as well as add/remove formats ''' -import os, time, traceback + +import os +import re +import time +import traceback from PyQt4.QtCore import SIGNAL, QObject, QCoreApplication, Qt, QTimer, QThread from PyQt4.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog, QCompleter - from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \ choose_files, pixmap_to_data, choose_images, ResizableDialog from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog @@ -422,7 +425,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): def fetch_metadata(self): - isbn = qstring_to_unicode(self.isbn.text()) + isbn = re.sub(r'[^0-9a-zA-Z]', '', unicode(self.isbn.text())) title = qstring_to_unicode(self.title.text()) author = string_to_authors(unicode(self.authors.text()))[0] publisher = qstring_to_unicode(self.publisher.currentText()) diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index 9c62f53d3f..ff21a8f67e 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -344,8 +344,6 @@ class DetailView(QDialog, Ui_Dialog): self.next_pos = f.tell() if more: self.log.appendPlainText(more.decode('utf-8', 'replace')) - vbar = self.log.verticalScrollBar() - vbar.setValue(vbar.maximum()) class JobsView(TableView):