Make quitting hopefully more robust on windows. Add code for loading fontconfig on BSD systems.

This commit is contained in:
Kovid Goyal 2009-01-05 13:51:31 -08:00
parent cb6599bbc1
commit d3bd57de6e
3 changed files with 34 additions and 14 deletions

View File

@ -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)
return ImageFont.truetype(FONT_FILE_MAP[name], size, encoding=encoding)

View File

@ -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 = '<p>'+__appname__ + _(''' is communicating with the device!<br>
'Quitting may cause corruption on the device.<br>
'Are you sure you want to quit?''')+'</p>'
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 = '<p>'+__appname__ + _(''' is communicating with the device!<br>
'Quitting may cause corruption on the device.<br>
'Are you sure you want to quit?''')+'</p>'
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()

View File

@ -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'))