From 953c8e939558ed380ae0a817cd89303a6fc959f7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 12 May 2011 15:05:55 -0600 Subject: [PATCH] Allow the use of condensed/expanded fonts as interface fonts --- src/calibre/gui2/__init__.py | 6 +++++- src/calibre/gui2/preferences/look_feel.py | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 1dfe1d8d14..28504f2a31 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -620,7 +620,11 @@ class Application(QApplication): self.original_font = QFont(QApplication.font()) fi = gprefs['font'] if fi is not None: - QApplication.setFont(QFont(*fi)) + font = QFont(*(fi[:4])) + s = gprefs.get('font_stretch', None) + if s is not None: + font.setStretch(s) + QApplication.setFont(font) def _send_file_open_events(self): with self._file_open_lock: diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 620113cc3f..ee2d7a5428 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -161,7 +161,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): def initialize(self): ConfigWidgetBase.initialize(self) - self.current_font = self.initial_font = gprefs['font'] + font = gprefs['font'] + if font is not None: + font = list(font) + font.append(gprefs.get('font_stretch', QFont.Unstretched)) + self.current_font = self.initial_font = font self.update_font_display() self.display_model.initialize() @@ -178,7 +182,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): def build_font_obj(self): font_info = self.current_font if font_info is not None: - font = QFont(*font_info) + font = QFont(*(font_info[:4])) + font.setStretch(font_info[4]) else: font = qt_app.original_font return font @@ -215,15 +220,18 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): if fd.exec_() == fd.Accepted: font = fd.selectedFont() fi = QFontInfo(font) - self.current_font = (unicode(fi.family()), fi.pointSize(), - fi.weight(), fi.italic()) + self.current_font = [unicode(fi.family()), fi.pointSize(), + fi.weight(), fi.italic(), font.stretch()] self.update_font_display() self.changed_signal.emit() def commit(self, *args): rr = ConfigWidgetBase.commit(self, *args) if self.current_font != self.initial_font: - gprefs['font'] = self.current_font + gprefs['font'] = (self.current_font[:4] if self.current_font else + None) + gprefs['font_stretch'] = (self.current_font[4] if self.current_font + is not None else QFont.Unstretched) QApplication.setFont(self.font_display.font()) rr = True self.display_model.commit()