Skip to content

Commit

Permalink
qt font family/size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Jun 10, 2011
1 parent 6011408 commit 2a72ea4
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions IPython/frontend/qt/console/console_widget.py
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 2a72ea4

Please sign in to comment.