nucleic / enaml

Declarative User Interfaces for Python
http://enaml.readthedocs.io/en/latest/
Other
1.54k stars 131 forks source link

image using base64 string #371

Closed K3nn3th2 closed 5 years ago

K3nn3th2 commented 5 years ago

when using a basestring to describe an images data attribute i get the following error:

Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/enaml/qt/qt_abstract_button.py", line 83, in on_clicked self.declaration.clicked(checked) File "/usr/lib/python2.7/site-packages/enaml/core/declarative_meta.py", line 68, in declarative_change_handler engine.write(owner, change['name'], change) File "/usr/lib/python2.7/site-packages/enaml/core/expression_engine.py", line 217, in write pair.writer(owner, name, change) File "/usr/lib/python2.7/site-packages/enaml/core/standard_handlers.py", line 82, in call call_func(func, (), {}, scope) File "ReggaeLoaderPC.enaml", line 263, in f clicked :: target.objects = results[' '.join(scraperSelect.selected_item.split(' ')[:-1])] File "/usr/lib/python2.7/site-packages/enaml/core/include.py", line 85, in _observe_objects self.parent.insert_children(self, newvalue) File "/usr/lib/python2.7/site-packages/enaml/core/object.py", line 228, in insert_children child_added(child) File "/usr/lib/python2.7/site-packages/enaml/widgets/toolkit_object.py", line 185, in child_added child.activate_proxy() File "/usr/lib/python2.7/site-packages/enaml/widgets/toolkit_object.py", line 213, in activate_proxy child.activate_proxy() File "/usr/lib/python2.7/site-packages/enaml/widgets/toolkit_object.py", line 213, in activate_proxy child.activate_proxy() File "/usr/lib/python2.7/site-packages/enaml/widgets/toolkit_object.py", line 214, in activate_proxy self.activate_bottom_up() File "/usr/lib/python2.7/site-packages/enaml/widgets/toolkit_object.py", line 236, in activate_bottom_up self.proxy.activate_bottom_up() File "/usr/lib/python2.7/site-packages/enaml/qt/qt_toolkit_object.py", line 82, in activate_bottom_up self.init_layout() File "/usr/lib/python2.7/site-packages/enaml/qt/qt_container.py", line 334, in init_layout self._setup_manager() File "/usr/lib/python2.7/site-packages/enaml/qt/qt_container.py", line 538, in _setup_manager manager.set_items(self._create_layout_items()) File "/usr/lib/python2.7/site-packages/enaml/layout/layout_manager.py", line 320, in set_items lc = child.layout_constraints() File "/usr/lib/python2.7/site-packages/enaml/layout/layout_manager.py", line 131, in layout_constraints return expand_constraints(self.constrainable(), self.constraints()) File "/usr/lib/python2.7/site-packages/enaml/qt/qt_container.py", line 139, in constraints return self.declaration.layout_constraints() File "/usr/lib/python2.7/site-packages/enaml/widgets/image_view.py", line 69, in layout_constraints ratio = self.proxy.get_aspect_ratio() File "/usr/lib/python2.7/site-packages/enaml/qt/qt_image_view.py", line 272, in get_aspect_ratio return pm_size.width()/pm_size.height() ZeroDivisionError: integer division or modulo by zero

i have tried setting raw_size but to no avail. does anyone have any ideas how to fix the error?

MatthieuDartiailh commented 5 years ago

This is I believe fixed on latest master and I need to cut a release.

K3nn3th2 commented 5 years ago

okay. thanks for the work! I tried installing the latest master but i still got the same error.

ive got an ImageView with a base64 image:

ImageView: imgView:

image=Image(data='iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAflBMVEX///8AAAD39/fKysqJiYkhISEGBgbj4+P6+vo8PDwaGhrh4eHQ0NAvLy8UFBRBQUF+fn5VVVUmJiZaWlpKSkq6urpfX1/y8vKPj48kJCQWFhZoaGiioqK5ubk3NzdFRUV0dHR4eHiampqmpqawsLAyMjLr6+vExMTY2NiMjIz58fMdAAAJOElEQVR4nMVb13rqMAxOQxYrhBnKKquQvv8LnvqXR0KGBz1fdBUgWLK2ZNnzXCAf3LLlajgN0yhKw+lwtcxug9xpKWvw15fZ6KMRRrPL2v+vyJNnNoyakQuIhtkz+U/oB/u0G7mAdD/4e+xxsKjv9lf8pxNThNpPiyD+U/ST+Yuw99vjuCRuf3zc7l9UYz75M/SDVWndcHNo3Vx82ISlV1d/I4nBl1ry6zDWvT4+lN9/n4THRq42NZVrHEzlnzaP9/BvheJHG6vNDDZCMdPtG+gH3wL9Xsv6VxjvBQnfznLIBPqzKR+f36P5Xfihx1mQkDmhj2fCnoxNOt+B6dIPxcJ6Zw5eYb2j/34ezf/zkH5oy53E8ZO+2K1t8X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yN6ZlW0+vC4d31MxfmZfVufK/L3U+ZH7wHDL8X15gIGqbWTDMVWFO46vkCPe2qy/FdoGGEojHDz+oP8wJh5EAQ9cYs5aW1C3QesIR3mIhV6isRdhgCc5n5IxrmjLjhboGGIpj/Gs1diLNMBoKyfcntnR9RJD1xhPeZCJuj5p6ViNqeit+X8W0DnIVBnlonmHiFA+xZDo9E0vpBnlqgyz8cYTxZ9cGmCYvTHqph1mq4zzcZx7kvZRdWlmBoecjaAf56sONAYV9U+2O0mCy8Cn2UBjdaTzxicyudH6gbxl4zJvZDbSWR1q5YN4HzMu9/yHZyYO5mA61Fod6y245KNAMB2Xjab2IjAe630JQFL9xbT8L4V3By9kMdj8Otp9FNVQ6Kr8nuVo9+twey5rEefrU5bD7bXx/rtKgb8O9uK3H++vXXBQ0/JyUM4cXC44eLUrHmpa3mrky/mKh1e/5OJvhSDMJo4I3C+5NF3z4RcO9R1AucQ713y8potOyX2+M7529O5FJ6//q15e75fdvP6v+3m9X3gECf1e+WTQ86VXBj1f+wX0e/EZ0PPVb4JeL79L+MPr//8Ao6OGuLp5Hx4AAAAASUVORK5CYII=')

When trying to display it i get the above mentioned error.

MatthieuDartiailh commented 5 years ago

Thanks for posting a minimal reproduction example. I will try to have a look at it soon but do not hesitate to ping me.

MatthieuDartiailh commented 5 years ago

You need to decode the image to make it acceptable to qt as follows:

from enaml.widgets.api import Window, Container, ImageView
from enaml.image import Image
import base64

enamldef Main(Window):

    Container:
        ImageView:
            image=Image(data=base64.b64decode('iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAflBMVEX///8AAAD39/fKysqJiYkhISEGBgbj4+P6+vo8PDwaGhrh4eHQ0NAvLy8UFBRBQUF+fn5VVVUmJiZaWlpKSkq6urpfX1/y8vKPj48kJCQWFhZoaGiioqK5ubk3NzdFRUV0dHR4eHiampqmpqawsLAyMjLr6+vExMTY2NiMjIz58fMdAAAJOElEQVR4nMVb13rqMAxOQxYrhBnKKquQvv8Lnv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XppOwfsrFN33GZWrXpuqHcplONSkgcTkk1tv3yga9Fo1ID5UZlqVU7FRunkSTEqAGEwJsLxq1aHVRatapZvZUbp1PEQhL7MeULmzWrdVBtVqt2fZ6KjVNjm8yEWp4nkYIatOu18NKuVwcW2PiOWR0ddtLkAWVkqcjztQcWWng9sFBHNrTxTBJJR7n86EmR3H1ko4fXI5vSoRX8Azx5DlpGlHlzfCt1tN16aGUA9UOr0rEdNotQSB1/8oI5H85YVLfZcGxnAvVju9LBJR2swgBpoIFGfxJhf7O7Nb5XaDq4LB3dQh/IAEn9+UyRtL/F9c0B8qaj29LhNXn8b3hBYjxNIcgz0V97yN6ZlW0+vC4d31MxfmZfVufK/L3U+ZH7wHDL8X15gIGqbWTDMVWFO46vkCPe2qy/FdoGGEojHDz+oP8wJh5EAQ9cYs5aW1C3QesIR3mIhV6isRdhgCc5n5IxrmjLjhboGGIpj/Gs1diLNMBoKyfcntnR9RJD1xhPeZCJuj5p6ViNqeit+X8W0DnIVBnlonmHiFA+xZDo9E0vpBnlqgyz8cYTxZ9cGmCYvTHqph1mq4zzcZx7kvZRdWlmBoecjaAf56sONAYV9U+2O0mCy8Cn2UBjdaTzxicyudH6gbxl4zJvZDbSWR1q5YN4HzMu9/yHZyYO5mA61Fod6y245KNAMB2Xjab2IjAe630JQFL9xbT8L4V3By9kMdj8Otp9FNVQ6Kr8nuVo9+twey5rEefrU5bD7bXx/rtKgb8O9uK3H++vXXBQ0/JyUM4cXC44eLUrHmpa3mrky/mKh1e/5OJvhSDMJo4I3C+5NF3z4RcO9R1AucQ713y8potOyX2+M7529O5FJ6//q15e75fdvP6v+3m9X3gECf1e+WTQ86VXBj1f+wX0e/EZ0PPVb4JeL79L+MPr//8Ao6OGuLp5Hx4AAAAASUVORK5CYII='))

With this everything behaves as expected. I will clarify the documentation and sorry for the slow answer.