Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError while pressing a ListItemButton #3078

Closed
alexkiro opened this issue Feb 25, 2015 · 8 comments
Closed

UnicodeEncodeError while pressing a ListItemButton #3078

alexkiro opened this issue Feb 25, 2015 · 8 comments

Comments

@alexkiro
Copy link

While having an unicode character in a ListItemButton's text is working ok, the application crashes when the button is pressed:

[INFO   ] [Base        ] Leaving application in progress...
 Traceback (most recent call last):
   File "list_composite.py", line 61, in <module>
     runTouchApp(MainView(width=800))
   File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 481, in runTouchApp
     EventLoop.window.mainloop()
   File "/usr/lib/python2.7/dist-packages/kivy/core/window/window_pygame.py", line 381, in mainloop
     self._mainloop()
   File "/usr/lib/python2.7/dist-packages/kivy/core/window/window_pygame.py", line 287, in _mainloop
     EventLoop.idle()
   File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 324, in idle
     self.dispatch_input()
   File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 309, in dispatch_input
     post_dispatch_input(*pop(0))
   File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 220, in post_dispatch_input
     listener.dispatch('on_motion', etype, me)
   File "kivy/_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4690)
   File "/usr/lib/python2.7/dist-packages/kivy/core/window/__init__.py", line 649, in on_motion
     self.dispatch('on_touch_up', me)
   File "kivy/_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4690)
   File "/usr/lib/python2.7/dist-packages/kivy/core/window/__init__.py", line 675, in on_touch_up
     if w.dispatch('on_touch_up', touch):
   File "kivy/_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4690)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 306, in on_touch_up
     if child.dispatch('on_touch_up', touch):
   File "kivy/_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4690)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 306, in on_touch_up
     if child.dispatch('on_touch_up', touch):
   File "kivy/_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4690)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/scrollview.py", line 697, in on_touch_up
     self.simulate_touch_down(touch)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/scrollview.py", line 508, in simulate_touch_down
     ret = super(ScrollView, self).on_touch_down(touch)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 284, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy/_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4690)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 284, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy/_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4690)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 284, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy/_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4690)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/behaviors.py", line 92, in on_touch_down
     self._do_press()
   File "/usr/lib/python2.7/dist-packages/kivy/uix/behaviors.py", line 75, in _do_press
     self.state = 'down'
   File "kivy/properties.pyx", line 345, in kivy.properties.Property.__set__ (kivy/properties.c:3654)
   File "kivy/properties.pyx", line 377, in kivy.properties.Property.set (kivy/properties.c:4169)
   File "kivy/properties.pyx", line 431, in kivy.properties.Property.dispatch (kivy/properties.c:4823)
   File "/usr/lib/python2.7/dist-packages/kivy/lang.py", line 1317, in call_fn
     element, key, value, rule.value))
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 23: ordinal not in range(128)

Kivy version:

$ pip freeze | grep -i kivy
Kivy==1.8.0
@alexkiro
Copy link
Author

The error can be replicate with this simple modified kivy example:

http://pastebin.com/dy0pWK6D

@victor-rene
Copy link
Contributor

@alexkiro Your pastebin example needs fixing. Can you make it runnable ? I get multiple python syntax errors.

@alexkiro
Copy link
Author

@victor-rene

Works fine for me :/

chirila@chirila-notebook:~/workspace/android$ curl -ks http://pastebin.com/raw.php?i=dy0pWK6D > test_list.py
chirila@chirila-notebook:~/workspace/android$ python test_list.py 
[INFO   ] Kivy v1.8.0
[INFO   ] [Logger      ] Record log in /home/chirila/.kivy/logs/kivy_15-02-25_43.txt
[INFO   ] [Factory     ] 157 symbols loaded
[DEBUG  ] [Cache       ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG  ] [Cache       ] register <kv.image> with limit=None, timeout=60s
[DEBUG  ] [Cache       ] register <kv.atlas> with limit=None, timeout=Nones
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pygame, img_pil, img_gif 
[DEBUG  ] [Cache       ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG  ] [Cache       ] register <kv.shader> with limit=1000, timeout=3600s
[INFO   ] [Text        ] Provider: pygame
[DEBUG  ] [Window      ] Ignored <egl_rpi> (import error)
[INFO   ] [Window      ] Provider: pygame(['window_egl_rpi'] ignored)
[DEBUG  ] [Window      ] Display driver x11
[DEBUG  ] [Window      ] Actual window size: 800x600
[DEBUG  ] [Window      ] Actual color bits r8 g8 b8 a8
[DEBUG  ] [Window      ] Actual depth bits: 24
[DEBUG  ] [Window      ] Actual stencil bits: 8
[DEBUG  ] [Window      ] Actual multisampling samples: 4
[INFO   ] [GL          ] OpenGL version <3.0 Mesa 10.3.2>
[INFO   ] [GL          ] OpenGL vendor <Intel Open Source Technology Center>
[INFO   ] [GL          ] OpenGL renderer <Mesa DRI Intel(R) Ivybridge Mobile >
[INFO   ] [GL          ] OpenGL parsed version: 3, 0
[INFO   ] [GL          ] Shading version <1.30>
[INFO   ] [GL          ] Texture max size <8192>
[INFO   ] [GL          ] Texture max units <16>
[DEBUG  ] [Shader      ] Fragment compiled successfully

@victor-rene
Copy link
Contributor

@alexkiro

Should not work though. What I did to fix it is add

 #!/usr/bin/env python

at the top of your script. Then remove u"_______" before "chérie" and "Middle-{0}"
You must be more precise / careful before opening an issue =).

Aside from this it works for me on Windows with 1.8.0. No problem clicking a list item. Should be closed.

@alexkiro
Copy link
Author

Should not work though. What I did to fix it is add

#!/usr/bin/env python

It should work just fine without the shebang if you pass it trough python yourself.

Then remove u"_______" before "chérie" and "Middle-{0}"
You must be more precise / careful before opening an issue =).

This was just a simple example to replicate the issue. I received the data I want to present in the list as unicode. Removing the u is not a solution here.

I can encode the data before setting it to the ListItemButton, but the button should be able to handle unicode strings just fine. For example the documentation for Label states that (http://kivy.org/docs/api-kivy.uix.label.html).

I still believe this is an issue that requires fixing. Or at least clean-up what kind of string does the Widget accept.

@victor-rene
Copy link
Contributor

@alexkiro

What I am saying is if you wish the issue to be fixed, provide a better example. As such I am not able to reproduce it, without modifying your pastebin. Secondly, there was a lot of work done to fix unicode issues in the dev version (1.9.0). I would like to investigate this further but your example isn't clear enough for me at this point. It would make things easier for everyone if you reworked it, so we can test on stable / dev and other platforms to confirm if there is an issue or if it's solved by 1.9.0-dev implementation.

@alexkiro
Copy link
Author

Hmm, sorry, I'm still not sure what is not clear here :(

I'll install the dev version and checked if this has been already fixed. The traceback also point to this part of the code (in kivy.lang):

def call_fn(*args):
    if __debug__:
        trace('Builder: call_fn %s, key=%s, value=%r, %r' % (
           element, key, value, rule.value))

This suggests that the issue only occurs when -O flag is not used. And indeed running the app with -O avoids this problem:

$ python -O test_list.py 

@alexkiro
Copy link
Author

Update, this has been indeed fixed in the latest dev version:

chirila@chirila-notebook:~/workspace/android$ python test_list.py 
[INFO   ] [Logger      ] Record log in /home/chirila/.kivy/logs/kivy_15-02-25_68.txt
[INFO   ] [Kivy        ] v1.9.0-dev
[INFO   ] [Python      ] v2.7.8 (default, Oct 18 2014, 12:50:18) 
[GCC 4.9.1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants