Skip to content

Commit 821e6e2

Browse files
committed
Enhance font handling in configtools: add more monospace fonts and improve warning logic for missing fonts in offscreen mode
1 parent d693c88 commit 821e6e2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

guidata/configtools.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,17 @@ def font_is_installed(font: str) -> list[str]:
316316
"Cascadia Code",
317317
"Cascadia Mono",
318318
"Consolas",
319+
"Lucida Console",
320+
"Lucida Sans Typewriter",
319321
"Monospace",
320322
"Menlo",
321323
"Courier New",
324+
"Courier",
322325
"Bitstream Vera Sans Mono",
323326
"Andale Mono",
324327
"Liberation Mono",
325328
"Monaco",
326-
"Courier",
329+
"Fixedsys",
327330
"monospace",
328331
"Fixed",
329332
"Terminal",
@@ -345,8 +348,14 @@ def get_family(families: str | list[str]) -> str:
345348
if font_is_installed(family):
346349
return family
347350
else:
348-
warnings.warn("None of the following fonts is installed: %r" % families)
349-
return ""
351+
# On Windows, in offscreen/headless mode, Qt may not detect fonts properly
352+
# Don't warn in this case, just return the first family as a fallback
353+
is_windows_offscreen = (
354+
sys.platform == "win32" and os.environ.get("QT_QPA_PLATFORM") == "offscreen"
355+
)
356+
if not is_windows_offscreen:
357+
warnings.warn("None of the following fonts is installed: %r" % families)
358+
return families[0] if families else ""
350359

351360

352361
def get_font(conf: UserConfig, section: str, option: str = "") -> QG.QFont:

0 commit comments

Comments
 (0)