]> granicus.if.org Git - python/commitdiff
[2.7] bpo-30310: tkFont now supports unicode options (e.g. font family). (#1567)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 26 May 2017 05:15:51 +0000 (08:15 +0300)
committerGitHub <noreply@github.com>
Fri, 26 May 2017 05:15:51 +0000 (08:15 +0300)
Lib/lib-tk/test/test_tkinter/test_font.py
Lib/lib-tk/tkFont.py
Misc/NEWS

index 4cbf82e8d8bac2be666865df1872ae1b959163d0..830c5a691aa568ce0c6b54aff956ed9c12b03fad 100644 (file)
@@ -1,7 +1,7 @@
 import unittest
 import Tkinter as tkinter
 import tkFont as font
-from test.test_support import requires, run_unittest
+from test.test_support import requires, run_unittest, gc_collect
 from test_ttk.support import AbstractTkTest
 
 requires('gui')
@@ -35,6 +35,16 @@ class FontTest(AbstractTkTest, unittest.TestCase):
             self.assertIsInstance(self.font.cget(key), sizetype)
             self.assertIsInstance(self.font[key], sizetype)
 
+    def test_unicode_family(self):
+        family = u'MS \u30b4\u30b7\u30c3\u30af'
+        try:
+            f = font.Font(root=self.root, family=family, exists=True)
+        except tkinter.TclError:
+            f = font.Font(root=self.root, family=family, exists=False)
+        self.assertEqual(f.cget('family'), family)
+        del f
+        gc_collect()
+
     def test_actual(self):
         options = self.font.actual()
         self.assertGreaterEqual(set(options),
index 113c983b015990294e181909f930db78de6d5ebc..b245623e30eed1d83f0d875111b13c18744556fa 100644 (file)
@@ -47,8 +47,10 @@ class Font:
     def _set(self, kw):
         options = []
         for k, v in kw.items():
+            if not isinstance(v, basestring):
+                v = str(v)
             options.append("-"+k)
-            options.append(str(v))
+            options.append(v)
         return tuple(options)
 
     def _get(self, args):
index ba5d5d17828890ea8d5089848900a411080b2254..e56af3a60c849bab6639abe3b58090ca4a7dd291 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -49,6 +49,8 @@ Extension Modules
 Library
 -------
 
+- bpo-30310: tkFont now supports unicode options (e.g. font family).
+
 - bpo-30414: multiprocessing.Queue._feed background running
   thread do not break from main loop on exception.