Label Rendering Crash (GBP Sign)

28 views
Skip to first unread message

Lord Xelous

unread,
Sep 14, 2015, 8:28:17 AM9/14/15
to Kivy users support
Hi,

I'm pulling my hair out here, and I have precious little hair remaining... When compiled for Android I'm having the following problem (PC/Linux/Mac all work fine, this only affects Android)

When one sets the text field of a Label to contain the £ sign (that's the Great British Pound Sterling sign), the application immediately, and without any messages, closes.

I've tried to catch errors, but it seems none are thrown in the user frame, it all happens as you leave the user code and re-enter Kivy.

I've tried to encode the strings variously as UTF-8, Unicode, ISO-8859-1, all to no avail.

You can enter the £ sign either in your kv file or through python into the label directly, both instantly result in the application closing.

Help
Message has been deleted

Lord Xelous

unread,
Sep 14, 2015, 8:43:51 AM9/14/15
to Kivy users support
To include example code, here is an example from Alex Taylors excellent series, I've simply tried it "as it" and then added "£10" to the label... Without the £ works fine, with crash....


buildozer.spec
main.py

Lord Xelous

unread,
Sep 14, 2015, 9:13:24 AM9/14/15
to Kivy users support
Digging through what I've done in the example "main.py" given below, I'm not even sure now it's Kivy, it seems it's something with Python itself on Android (least the build I have), for if I have:

print ('Hello World')
some_string = "$100"
print (some_string)
some_string = some_string.replace('$', '£')
print ("New: " + some_string)

I never see the "New" message print out, it crashes the moment something (the interpreter) see's the '£' symbol.

I've therefore tried to tell it the encoding of my code file at the top, but that's made no difference... Surely Python can ruin a £ symbol?... There are examples out there for the Euro € symbol... But they don't seem to work for the £..

Either-way, this appears not to be a Kivy specific problem, as I had thought.

ZenCODE

unread,
Sep 14, 2015, 9:53:45 AM9/14/15
to Kivy users support

Lord Xelous

unread,
Sep 14, 2015, 9:55:35 AM9/14/15
to Kivy users support
HI, thanks for the reply, unfortunately, I've already tried that: 

    "I've therefore tried to tell it the encoding of my code file at the top, but that's made no difference"

Lord Xelous

unread,
Sep 14, 2015, 10:00:16 AM9/14/15
to Kivy users support
This is a platform issue I'm sure of it, or rather the python running on Android, if I create a kivy app with just a text input field, and a button, the button presslinks to this function:

def OnButton(self, instance):
    len(text_field.text)

So I'm just looking at the length of the string, and I enter, from the Android virtual keyboard a single £ sign, it displays the symbol in the Kivy widget, so Kivy all is forgiven, however, the moment it calls "len" the application is closed no explanation why anywhere, it just closes len can't handle the string containing a £.

However, if I change my code to do this:

def OnButton(self, instance):
    for char in text_field.text:
        print (ord(char))

I get the ordinals of the characters out, and the £ symbol is correctly, 194 163.  Double byte encoded correctly.  Just the moment any of the str object functions see this 194 they go mental.

I tried with:  text = u'£' too, same results with a unicode string :(

ZenCODE

unread,
Sep 14, 2015, 11:48:28 AM9/14/15
to Kivy users support
Yeah, it's a b***** when it's only misbehaving on 1 platform. You say you've tried the various encodings, but even 1 character can break things. If you can post your latest code (the last post had no headers), I can test and play on my side.....

Trust the pommes to break stuff...;-)

Lord Xelous

unread,
Sep 14, 2015, 8:01:10 PM9/14/15
to Kivy users support
I've satisfied myself this is a problem with python on Android, not Kivy specifically at all, the problem is shown up with the following pseudo code:

l_string = "£100"

So, now l_string is a str object type in python:

for char in l_string:
    l_ord = ord(char)

Just getting the ordinal is fine!  But you will find you get 4 outputs, not 3, the pound sign gets translated into two bytes, 194 163; whilst the other charcters remain as single bytes, this will happen a lot with extended characters or accented characters too.  Interestingly, the ordinals I get are valid for the sign, just the str object works in single bytes and in the sys default encoding, or whatever you've set as sys.setdefaultencoding.

To hack over this problem and get my project at least working, whilst I look for a deeper solution to this strange problem I have implemented this function:

def NormalisePoundString(p_Source):
   l_result = ''
   for char in p_Source:
       if ord(char) != 194:
          l_result = l_result + char
    return l_result

And this then gives a valid str object, with 3 bytes, on which functions like "len" will operate, and which can be put into your Kivy labels & Controls.


Reply all
Reply to author
Forward
0 new messages