summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-07-31 04:48:14 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-07-31 04:48:14 (GMT)
commit04fa704161358bd656ab8b85966efb00f6620f2a (patch)
tree5d1328b0fec8a50d7a657465bf9f94e6d8c8c6d6 /Lib
parent19b7a75abf97e2d609bbbff49e145e6b8d254cbf (diff)
downloadcpython-04fa704161358bd656ab8b85966efb00f6620f2a.zip
cpython-04fa704161358bd656ab8b85966efb00f6620f2a.tar.gz
cpython-04fa704161358bd656ab8b85966efb00f6620f2a.tar.bz2
Issue #21580: Now Tkinter correctly handles binary "data" and "maskdata"
configure options of tkinter.PhotoImage. Added private Tkapp method _createbytearray().
Diffstat (limited to 'Lib')
-rw-r--r--Lib/lib-tk/Tkinter.py4
-rw-r--r--Lib/lib-tk/test/test_tkinter/test_images.py11
2 files changed, 8 insertions, 7 deletions
diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py
index ee49ed7..aade649 100644
--- a/Lib/lib-tk/Tkinter.py
+++ b/Lib/lib-tk/Tkinter.py
@@ -3282,6 +3282,8 @@ class Image:
for k, v in cnf.items():
if hasattr(v, '__call__'):
v = self._register(v)
+ elif k in ('data', 'maskdata'):
+ v = self.tk._createbytearray(v)
options = options + ('-'+k, v)
self.tk.call(('image', 'create', imgtype, name,) + options)
self.name = name
@@ -3305,6 +3307,8 @@ class Image:
if k[-1] == '_': k = k[:-1]
if hasattr(v, '__call__'):
v = self._register(v)
+ elif k in ('data', 'maskdata'):
+ v = self.tk._createbytearray(v)
res = res + ('-'+k, v)
self.tk.call((self.name, 'config') + res)
config = configure
diff --git a/Lib/lib-tk/test/test_tkinter/test_images.py b/Lib/lib-tk/test/test_tkinter/test_images.py
index a27b763..b3c5b75 100644
--- a/Lib/lib-tk/test/test_tkinter/test_images.py
+++ b/Lib/lib-tk/test/test_tkinter/test_images.py
@@ -151,7 +151,8 @@ class PhotoImageTest(unittest.TestCase):
self.assertEqual(image.type(), 'photo')
self.assertEqual(image.width(), 16)
self.assertEqual(image.height(), 16)
- self.assertEqual(image['data'], data)
+ self.assertEqual(image['data'], data if self.wantobjects
+ else data.decode('latin1'))
self.assertEqual(image['file'], '')
self.assertIn('::img::test', self.root.image_names())
del image
@@ -160,21 +161,18 @@ class PhotoImageTest(unittest.TestCase):
def test_create_from_ppm_file(self):
self.check_create_from_file('ppm')
- @unittest.skip('issue #21580')
def test_create_from_ppm_data(self):
self.check_create_from_data('ppm')
def test_create_from_pgm_file(self):
self.check_create_from_file('pgm')
- @unittest.skip('issue #21580')
def test_create_from_pgm_data(self):
self.check_create_from_data('pgm')
def test_create_from_gif_file(self):
self.check_create_from_file('gif')
- @unittest.skip('issue #21580')
def test_create_from_gif_data(self):
self.check_create_from_data('gif')
@@ -182,19 +180,18 @@ class PhotoImageTest(unittest.TestCase):
def test_create_from_png_file(self):
self.check_create_from_file('png')
- @unittest.skip('issue #21580')
@requires_tcl(8, 6)
def test_create_from_png_data(self):
self.check_create_from_data('png')
- @unittest.skip('issue #21580')
def test_configure_data(self):
image = tkinter.PhotoImage('::img::test', master=self.root)
self.assertEqual(image['data'], '')
with open(self.testfile, 'rb') as f:
data = f.read()
image.configure(data=data)
- self.assertEqual(image['data'], data)
+ self.assertEqual(image['data'], data if self.wantobjects
+ else data.decode('latin1'))
self.assertEqual(image.width(), 16)
self.assertEqual(image.height(), 16)