jenkins-bot has submitted this change and it was merged.
Change subject: win32_unicode: force truetype font in console
......................................................................
win32_unicode: force truetype font in console
This will automatically turn the terminal into one that supports unicode
for Windows Vista+ (i.e. any supported version of Windows). I have removed
the warning, as it is now no longer necessary to follow any steps for
a useful console.
Change-Id: I6fb1b418eae9b995e390de34639a6c3fc110dd32
---
M pywikibot/config2.py
M pywikibot/userinterfaces/win32_unicode.py
2 files changed, 59 insertions(+), 17 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 16c01ba..996228d 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -373,7 +373,7 @@
# transliteration_target = console_encoding
# After emitting the warning, this last option will be set.
-transliteration_target = 'not set'
+transliteration_target = None
# The encoding in which textfiles are stored, which contain lists of page
# titles. The most used is: 'utf-8'. 'utf-8-sig' recognizes BOM but it
is
@@ -973,19 +973,6 @@
console_encoding = 'cp850'
else:
console_encoding = 'iso-8859-1'
-
-# Fix up transliteration_target
-if transliteration_target == 'not set':
- if sys.platform == 'win32':
- transliteration_target = console_encoding
- print("WARNING: Running on Windows and transliteration_target is not "
- "set.")
- print("Please see "
-
"https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Pywikibot/Windows")
- else:
- transliteration_target = None
-elif transliteration_target in ('None', 'none'):
- transliteration_target = None
if sys.platform == 'win32' and editor is None:
diff --git a/pywikibot/userinterfaces/win32_unicode.py
b/pywikibot/userinterfaces/win32_unicode.py
index ebb83a0..4ea2560 100755
--- a/pywikibot/userinterfaces/win32_unicode.py
+++ b/pywikibot/userinterfaces/win32_unicode.py
@@ -22,6 +22,7 @@
from __future__ import print_function, unicode_literals
from io import UnsupportedOperation
import sys
+
stdin = sys.stdin
stdout = sys.stdout
stderr = sys.stderr
@@ -35,13 +36,65 @@
if sys.platform == "win32":
import codecs
- from ctypes import WINFUNCTYPE, windll, POINTER
- from ctypes import byref, c_int, create_unicode_buffer
- from ctypes.wintypes import BOOL, HANDLE, DWORD, LPWSTR, LPCWSTR
+ from ctypes import WINFUNCTYPE, windll, POINTER, WinError
+ from ctypes import Structure, byref, c_int, create_unicode_buffer, sizeof
+ from ctypes.wintypes import (BOOL, DWORD, HANDLE, LPCWSTR, LPWSTR,
+ SHORT, ULONG, UINT, WCHAR)
try:
from ctypes.wintypes import LPVOID
except ImportError:
from ctypes import c_void_p as LPVOID
+
+ def force_truetype_console(h_stdout):
+ """Force the console to use a TrueType font
(Vista+)."""
+ TMPF_TRUETYPE = 0x04
+ LF_FACESIZE = 32
+
+ class COORD(Structure):
+ _fields_ = [('X', SHORT),
+ ('Y', SHORT)]
+
+ class CONSOLE_FONT_INFOEX(Structure):
+ _fields_ = [('cbSize', ULONG),
+ ('nFont', DWORD),
+ ('dwFontSize', COORD),
+ ('FontFamily', UINT),
+ ('FontWeight', UINT),
+ ('FaceName', WCHAR * LF_FACESIZE)]
+
+ try:
+ GetCurrentConsoleFontEx = WINFUNCTYPE(
+ BOOL,
+ HANDLE, # hConsoleOutput
+ BOOL, # bMaximumWindow
+ POINTER(CONSOLE_FONT_INFOEX), # lpConsoleCurrentFontEx
+ )(("GetCurrentConsoleFontEx", windll.kernel32))
+
+ SetCurrentConsoleFontEx = WINFUNCTYPE(
+ BOOL,
+ HANDLE, # hConsoleOutput
+ BOOL, # bMaximumWindow
+ POINTER(CONSOLE_FONT_INFOEX), # lpConsoleCurrentFontEx
+ )(("SetCurrentConsoleFontEx", windll.kernel32))
+ except AttributeError:
+ # pre Windows Vista. Return without doing anything.
+ return
+
+ current_font = CONSOLE_FONT_INFOEX()
+ current_font.cbSize = sizeof(CONSOLE_FONT_INFOEX)
+
+ if not GetCurrentConsoleFontEx(h_stdout, True, byref(current_font)):
+ WinError()
+
+ truetype_font = (current_font.FontFamily & TMPF_TRUETYPE)
+
+ if not truetype_font:
+ new_font = CONSOLE_FONT_INFOEX()
+ new_font.cbSize = sizeof(CONSOLE_FONT_INFOEX)
+ new_font.FaceName = u'Lucida Console'
+
+ if not SetCurrentConsoleFontEx(h_stdout, True, byref(new_font)):
+ WinError()
original_stderr = sys.stderr
@@ -115,11 +168,13 @@
if real_stdout:
hStdout = GetStdHandle(STD_OUTPUT_HANDLE)
+ force_truetype_console(hStdout)
if not_a_console(hStdout):
real_stdout = False
if real_stderr:
hStderr = GetStdHandle(STD_ERROR_HANDLE)
+ force_truetype_console(hStderr)
if not_a_console(hStderr):
real_stderr = False
--
To view, visit
https://gerrit.wikimedia.org/r/270491
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6fb1b418eae9b995e390de34639a6c3fc110dd32
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: 2.0
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>