mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make quitting hopefully more robust on windows. Add code for loading fontconfig on BSD systems.
This commit is contained in:
parent
cb6599bbc1
commit
d3bd57de6e
@ -51,7 +51,7 @@ def get_font_path(name):
|
|||||||
font_mod = __import__('calibre.ebooks.lrf.fonts.prs500', {}, {},
|
font_mod = __import__('calibre.ebooks.lrf.fonts.prs500', {}, {},
|
||||||
[fname], -1)
|
[fname], -1)
|
||||||
getattr(font_mod, fname)
|
getattr(font_mod, fname)
|
||||||
except ImportError, AttributeError:
|
except (ImportError, AttributeError):
|
||||||
font_mod = __import__('calibre.ebooks.lrf.fonts.liberation', {}, {},
|
font_mod = __import__('calibre.ebooks.lrf.fonts.liberation', {}, {},
|
||||||
[LIBERATION_FONT_MAP[name]], -1)
|
[LIBERATION_FONT_MAP[name]], -1)
|
||||||
p = PersistentTemporaryFile('.ttf', 'font_')
|
p = PersistentTemporaryFile('.ttf', 'font_')
|
||||||
@ -81,4 +81,4 @@ def get_font(name, size, encoding='unic'):
|
|||||||
path = get_font_path(name)
|
path = get_font_path(name)
|
||||||
return ImageFont.truetype(path, size, encoding=encoding)
|
return ImageFont.truetype(path, size, encoding=encoding)
|
||||||
elif name in FONT_FILE_MAP.keys():
|
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)
|
||||||
|
@ -1424,9 +1424,14 @@ in which you want to store your books files. Any existing books will be automati
|
|||||||
self.memory_view.write_settings()
|
self.memory_view.write_settings()
|
||||||
|
|
||||||
def quit(self, checked, restart=False):
|
def quit(self, checked, restart=False):
|
||||||
if self.shutdown():
|
if not self.confirm_quit():
|
||||||
self.restart_after_quit = restart
|
return
|
||||||
QApplication.instance().quit()
|
try:
|
||||||
|
self.shutdown()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.restart_after_quit = restart
|
||||||
|
QApplication.instance().quit()
|
||||||
|
|
||||||
def donate(self):
|
def donate(self):
|
||||||
BUTTON = '''
|
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))
|
QDesktopServices.openUrl(QUrl.fromLocalFile(pt.name))
|
||||||
|
|
||||||
|
|
||||||
def shutdown(self):
|
def confirm_quit(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>'
|
|
||||||
if self.job_manager.has_jobs():
|
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,
|
d = QMessageBox(QMessageBox.Warning, _('WARNING: Active jobs'), msg,
|
||||||
QMessageBox.Yes|QMessageBox.No, self)
|
QMessageBox.Yes|QMessageBox.No, self)
|
||||||
d.setIconPixmap(QPixmap(':/images/dialog_warning.svg'))
|
d.setIconPixmap(QPixmap(':/images/dialog_warning.svg'))
|
||||||
d.setDefaultButton(QMessageBox.No)
|
d.setDefaultButton(QMessageBox.No)
|
||||||
if d.exec_() != QMessageBox.Yes:
|
if d.exec_() != QMessageBox.Yes:
|
||||||
return False
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
self.job_manager.terminate_all_jobs()
|
|
||||||
|
def shutdown(self):
|
||||||
self.write_settings()
|
self.write_settings()
|
||||||
|
self.job_manager.terminate_all_jobs()
|
||||||
self.device_manager.keep_going = False
|
self.device_manager.keep_going = False
|
||||||
self.cover_cache.stop()
|
self.cover_cache.stop()
|
||||||
self.hide()
|
self.hide()
|
||||||
@ -1498,7 +1507,11 @@ in which you want to store your books files. Any existing books will be automati
|
|||||||
self.hide()
|
self.hide()
|
||||||
e.ignore()
|
e.ignore()
|
||||||
else:
|
else:
|
||||||
if self.shutdown():
|
if self.confirm_quit():
|
||||||
|
try:
|
||||||
|
self.shutdown()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
e.accept()
|
e.accept()
|
||||||
else:
|
else:
|
||||||
e.ignore()
|
e.ignore()
|
||||||
|
@ -22,7 +22,7 @@ match to a given font specification. The main functions in this module are:
|
|||||||
.. autofunction:: match
|
.. 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, \
|
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
|
pointer, byref, create_string_buffer, Union, c_char_p, c_double
|
||||||
|
|
||||||
@ -58,6 +58,13 @@ def load_library():
|
|||||||
return cdll.LoadLibrary(lib)
|
return cdll.LoadLibrary(lib)
|
||||||
elif iswindows:
|
elif iswindows:
|
||||||
return cdll.LoadLibrary('libfontconfig-1')
|
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:
|
else:
|
||||||
try:
|
try:
|
||||||
return cdll.LoadLibrary(util.find_library('fontconfig'))
|
return cdll.LoadLibrary(util.find_library('fontconfig'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user