diff --git a/src/calibre/ebooks/lrf/fonts/__init__.py b/src/calibre/ebooks/lrf/fonts/__init__.py index 462762af1e..1f67a50f25 100644 --- a/src/calibre/ebooks/lrf/fonts/__init__.py +++ b/src/calibre/ebooks/lrf/fonts/__init__.py @@ -51,7 +51,7 @@ def get_font_path(name): font_mod = __import__('calibre.ebooks.lrf.fonts.prs500', {}, {}, [fname], -1) getattr(font_mod, fname) - except ImportError, AttributeError: + except (ImportError, AttributeError): font_mod = __import__('calibre.ebooks.lrf.fonts.liberation', {}, {}, [LIBERATION_FONT_MAP[name]], -1) p = PersistentTemporaryFile('.ttf', 'font_') @@ -81,4 +81,4 @@ def get_font(name, size, encoding='unic'): path = get_font_path(name) return ImageFont.truetype(path, size, encoding=encoding) elif name in FONT_FILE_MAP.keys(): - return ImageFont.truetype(FONT_FILE_MAP[name], size, encoding=encoding) \ No newline at end of file + return ImageFont.truetype(FONT_FILE_MAP[name], size, encoding=encoding) diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 279dab42aa..97ad934eeb 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -1424,9 +1424,14 @@ in which you want to store your books files. Any existing books will be automati self.memory_view.write_settings() def quit(self, checked, restart=False): - if self.shutdown(): - self.restart_after_quit = restart - QApplication.instance().quit() + if not self.confirm_quit(): + return + try: + self.shutdown() + except: + pass + self.restart_after_quit = restart + QApplication.instance().quit() def donate(self): BUTTON = ''' @@ -1457,22 +1462,26 @@ in which you want to store your books files. Any existing books will be automati QDesktopServices.openUrl(QUrl.fromLocalFile(pt.name)) - def shutdown(self): - msg = _('There are active jobs. Are you sure you want to quit?') - if self.job_manager.has_device_jobs(): - msg = '

'+__appname__ + _(''' is communicating with the device!
- 'Quitting may cause corruption on the device.
- 'Are you sure you want to quit?''')+'

' + def confirm_quit(self): if self.job_manager.has_jobs(): + msg = _('There are active jobs. Are you sure you want to quit?') + if self.job_manager.has_device_jobs(): + msg = '

'+__appname__ + _(''' is communicating with the device!
+ 'Quitting may cause corruption on the device.
+ 'Are you sure you want to quit?''')+'

' + d = QMessageBox(QMessageBox.Warning, _('WARNING: Active jobs'), msg, QMessageBox.Yes|QMessageBox.No, self) d.setIconPixmap(QPixmap(':/images/dialog_warning.svg')) d.setDefaultButton(QMessageBox.No) if d.exec_() != QMessageBox.Yes: return False + return True - self.job_manager.terminate_all_jobs() + + def shutdown(self): self.write_settings() + self.job_manager.terminate_all_jobs() self.device_manager.keep_going = False self.cover_cache.stop() self.hide() @@ -1498,7 +1507,11 @@ in which you want to store your books files. Any existing books will be automati self.hide() e.ignore() else: - if self.shutdown(): + if self.confirm_quit(): + try: + self.shutdown() + except: + pass e.accept() else: e.ignore() diff --git a/src/calibre/utils/fontconfig.py b/src/calibre/utils/fontconfig.py index d24ea0d4b1..2a5207c67c 100644 --- a/src/calibre/utils/fontconfig.py +++ b/src/calibre/utils/fontconfig.py @@ -22,7 +22,7 @@ match to a given font specification. The main functions in this module are: .. autofunction:: match ''' -import sys, os, locale, codecs +import sys, os, locale, codecs, subprocess, re from ctypes import cdll, c_void_p, Structure, c_int, POINTER, c_ubyte, c_char, util, \ pointer, byref, create_string_buffer, Union, c_char_p, c_double @@ -58,6 +58,13 @@ def load_library(): return cdll.LoadLibrary(lib) elif iswindows: return cdll.LoadLibrary('libfontconfig-1') + elif isbsd: + raw = subprocess.Popen('pkg-config --libs-only-L fontconfig'.split(), + stdout=subprocess.PIPE).stdout.read().strip() + match = re.search(r'-L([^\s,]+)', raw) + if not match: + return cdll.LoadLibrary('libfontconfig.so') + return cdll.LoadLibrary(match.group(1)+'/libfontconfig.so') else: try: return cdll.LoadLibrary(util.find_library('fontconfig'))