Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

qt font family/size configurable

  • Loading branch information...
commit 2a72ea4020da3b7be679e2cce7776b67ac049b17 1 parent 6011408
@minrk authored
Showing with 32 additions and 7 deletions.
  1. +32 −7 IPython/frontend/qt/console/console_widget.py
View
39 IPython/frontend/qt/console/console_widget.py
@@ -19,7 +19,7 @@
from IPython.config.configurable import Configurable
from IPython.frontend.qt.rich_text import HtmlExporter
from IPython.frontend.qt.util import MetaQObjectHasTraits, get_font
-from IPython.utils.traitlets import Bool, Enum, Int
+from IPython.utils.traitlets import Bool, Enum, Int, Unicode
from ansi_code_processor import QtAnsiCodeProcessor
from completion_widget import CompletionWidget
from kill_ring import QtKillRing
@@ -89,6 +89,28 @@ class ConsoleWidget(Configurable, QtGui.QWidget):
'none' : The text is written directly to the console.
""")
+ font_family = Unicode(config=True,
+ help="""The font family to use for the console.
+ On OSX this defaults to Monaco, on Windows the default is
+ Consolas with fallback of Courier, and on other platforms
+ the default is Inconsolata with fallback of Monospace
+ """)
+ def _font_family_default(self):
+ if sys.platform == 'win32':
+ # Consolas ships with Vista/Win7, fallback to Courier if needed
+ return 'Consolas'
+ elif sys.platform == 'darwin':
+ # OSX always has Monaco, no need for a fallback
+ return 'Monaco'
+ else:
+ # A popular free mono font, will fallback to Monospace
+ return 'Anonymous Pro'
+
+ font_size = Int(config=True,
+ help="""The font size. If unconfigured, Qt will be entrusted
+ with the size of the font.
+ """)
+
# Whether to override ShortcutEvents for the keybindings defined by this
# widget (Ctrl+n, Ctrl+a, etc). Enable this if you want this widget to take
# priority (when it has focus) over, e.g., window-level menu shortcuts.
@@ -597,16 +619,19 @@ def reset_font(self):
"""
if sys.platform == 'win32':
# Consolas ships with Vista/Win7, fallback to Courier if needed
- family, fallback = 'Consolas', 'Courier'
+ fallback = 'Courier'
elif sys.platform == 'darwin':
- # OSX always has Monaco, no need for a fallback
- family, fallback = 'Monaco', None
+ # OSX always has Monaco
+ fallback = 'Monaco'
else:
# FIXME: remove Consolas as a default on Linux once our font
# selections are configurable by the user.
- family, fallback = 'Consolas', 'Monospace'
- font = get_font(family, fallback)
- font.setPointSize(QtGui.qApp.font().pointSize())
+ fallback = 'Monospace'
+ font = get_font(self.font_family, fallback)
+ if self.font_size:
+ font.setPointSize(self.font_size)
+ else:
+ font.setPointSize(QtGui.qApp.font().pointSize())
font.setStyleHint(QtGui.QFont.TypeWriter)
self._set_font(font)
Please sign in to comment.
Something went wrong with that request. Please try again.