diff --git a/src/libprs500/gui2/dialogs/lrf_single.py b/src/libprs500/gui2/dialogs/lrf_single.py index 93a641e1ae..7ae39e3d92 100644 --- a/src/libprs500/gui2/dialogs/lrf_single.py +++ b/src/libprs500/gui2/dialogs/lrf_single.py @@ -22,6 +22,7 @@ from libprs500.gui2.dialogs.lrf_single_ui import Ui_LRFSingleDialog from libprs500.gui2.dialogs.choose_format import ChooseFormatDialog from libprs500.gui2 import qstring_to_unicode, error_dialog, \ pixmap_to_data, choose_images +from libprs500.gui2.widgets import FontFamilyModel from libprs500.ebooks.lrf import option_parser from libprs500.ptempfile import PersistentTemporaryFile from libprs500 import __appname__ @@ -64,6 +65,11 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog): self.cover_changed = False self.cpixmap = None self.changed = False + self.font_family_model = FontFamilyModel() + self.gui_serif_family.setModel(self.font_family_model) + self.gui_sans_family.setModel(self.font_family_model) + self.gui_mono_family.setModel(self.font_family_model) + self.read_saved_options() self.initialize_metadata() formats = self.db.formats(self.row) @@ -116,8 +122,17 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog): ops = prepro.get_opt_string() if ops in cmdline: self.preprocess.setCurrentIndex(self.preprocess.findText(ops[2:])) - break - + break + + for opt in ('--serif-family', '--sans-family', '--mono-family'): + if opt in cmdline: + print 'in' + family = cmdline[cmdline.index(opt)+1].split(',')[1].strip() + obj = getattr(self, 'gui_'+opt[2:].replace('-', '_')) + try: + obj.setCurrentIndex(self.font_family_model.index_of(family)) + except: + continue def select_cover(self, checked): files = choose_images(self, 'change cover dialog', @@ -284,6 +299,17 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog): if text != 'No preprocessing': cmd.append(u'--'+text) cmd.extend([u'--profile', qstring_to_unicode(self.gui_profile.currentText())]) + + for opt in ('--serif-family', '--sans-family', '--mono-family'): + obj = getattr(self, 'gui_'+opt[2:].replace('-', '_')) + family = qstring_to_unicode(obj.itemText(obj.currentIndex())).strip() + try: + path = self.font_family_model.path_of(family) + except KeyError: + continue + if path: + cmd.extend([opt, os.path.dirname(path)+', '+family]) + return cmd def title(self): @@ -319,6 +345,7 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog): self.cover_file.write(cover) self.cover_file.close() self.db.set_conversion_options(self.id, self.output_format.lower(), cmdline) + if self.cover_file: cmdline.extend([u'--cover', self.cover_file.name]) self.cmdline = [unicode(i) for i in cmdline] diff --git a/src/libprs500/gui2/dialogs/lrf_single.ui b/src/libprs500/gui2/dialogs/lrf_single.ui index fe2d8f127f..e23b1e8bb1 100644 --- a/src/libprs500/gui2/dialogs/lrf_single.ui +++ b/src/libprs500/gui2/dialogs/lrf_single.ui @@ -146,7 +146,7 @@ - 0 + 1 @@ -469,7 +469,7 @@ - + Base &font size: @@ -479,7 +479,7 @@ - + QAbstractSpinBox::PlusMinus @@ -504,7 +504,62 @@ - + + + + Embedded Fonts + + + + + + &Serif: + + + gui_serif_family + + + + + + + + 0 + 0 + + + + + + + + S&ans-serif: + + + gui_sans_family + + + + + + + + + + &Monospace: + + + gui_mono_family + + + + + + + + + + &Word spacing: @@ -517,7 +572,7 @@ - + QAbstractSpinBox::PlusMinus @@ -542,7 +597,28 @@ - + + + + Enable auto &rotation of images + + + + + + + Insert &blank lines between paragraphs + + + + + + + Ignore &tables + + + + &Preprocess: @@ -552,10 +628,10 @@ - + - + @@ -590,35 +666,14 @@ - - - - Enable auto &rotation of images - - - - - - - Insert &blank lines between paragraphs - - - - - - - Ignore &tables - - - - + Override<br>CSS - + diff --git a/src/libprs500/gui2/widgets.py b/src/libprs500/gui2/widgets.py index 2c5defeaa5..136aa22d99 100644 --- a/src/libprs500/gui2/widgets.py +++ b/src/libprs500/gui2/widgets.py @@ -19,7 +19,7 @@ from PyQt4.QtGui import QListView, QIcon, QFont, QLabel from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QSize, SIGNAL, QObject from libprs500.gui2 import human_readable, NONE, TableView -from libprs500 import fit_image +from libprs500 import fit_image, get_font_families class ImageView(QLabel): @@ -99,4 +99,38 @@ class LocationView(QListView): class JobsView(TableView): pass +class FontFamilyModel(QAbstractListModel): + + def __init__(self, *args): + QAbstractListModel.__init__(self, *args) + self.family_map = get_font_families() + self.families = self.family_map.keys() + self.families.sort() + self.families[:0] = ['None'] + + def rowCount(self, *args): + return len(self.families) + + def data(self, index, role): + try: + family = self.families[index.row()] + except: + import traceback + traceback.print_exc() + return NONE + if role == Qt.DisplayRole: + return QVariant(family) + if role == Qt.FontRole: + return QVariant(QFont(family)) + return NONE + + def path_of(self, family): + if family != None: + return self.family_map[family] + return None + + def index_of(self, family): + return self.families.index(family.strip()) + +