Skip to content

Commit 3719e57

Browse files
committed
Settings: fall back to sensible default font
1 parent fa7cecc commit 3719e57

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pyqt_code_editor/_settings.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,23 @@ def set_font_family(self):
228228
if self.font_family != 'default':
229229
return
230230
from .utils import get_first_available_font
231+
231232
self.font_family = get_first_available_font(
232233
['Ubuntu Mono', 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New',
233234
'monospace'])
235+
236+
# Fallback if no font was found
237+
if self.font_family is None:
238+
import platform
239+
system = platform.system()
240+
if system == 'Windows':
241+
self.font_family = 'Consolas' # Available on Windows Vista+
242+
elif system == 'Darwin': # macOS
243+
self.font_family = 'Menlo' # Default monospace on macOS
244+
else: # Linux and other Unix-like systems
245+
self.font_family = 'monospace' # Generic monospace fallback
246+
234247
logger.info(f'setting font family to {self.font_family}')
235248

236-
237249
# Create the singleton instance
238250
settings = Settings()

0 commit comments

Comments
 (0)