Forum Archive

ui textfield escape-sequences

drpaul

Hello,

in pythonista ui I use a textfield to obtain the input of an barcode scanner:

class TextFieldDelegate(object):
    def textfield_did_end_editing(self, textfield):
        barcode = textfield.text
    return True

This works very well for barcodes without escape-sequences. But in my usecase the scanner sends a "\x1b[19~" as delimeter between data-fields.
The ui textfield apparently ignors the escape-sequences. For example:

Barcode is "12345\x1b[19~6789"
textfield.text provides "12345678989". I need the delimeter to set apart the data-fields in the barcode.

barcode = textfield.text.encode() provides b'123456789'

Any ideas? Thank you!

JonB

if the escape is always the same, how about

data.split('\x1b[19~')
drpaul

@JonB said:

data.split('\x1b[19~')

thank you for your quick answer, but this does not help, because the textfield.text does NOT deliver the escape-code, it seems to be filtered in the ui textfield-routine(?)
(the barcode scanner works as a external keyboard an sends the scanned data direct in the textfield)

drpaul

this is really strange. Maybe its not a "textfield" issue, but a Pythonista behaviour?
Test-Code:

barcode = input("Barcode = ")
print(barcode.encode('utf-8'))

When scanning into input prompt:
Output python 3.6 on macOS:

Barcode = 12345^[[19~6789
b'12345\x1b[19~6789'

Output Pythonista 3 on ios
Barcode = 123456789
b'123456789'

Why is Pythonista suppressing the escape-sequences???

JonB

i meant use split before setting into the textfield...

JonB

oh, are you using a physical barcode scanner?
you might need to use a textfield_should_change delegate, which i think gives you the replacement text. once it goes into the textfield, no printables are stripped, i think.

JonB

have you tried oy 2.7, or input(b'Barcode =') to force bytes input?

drpaul

I did some further research... obviously the non printable escape sequences are filtert by ios keyboard driver.
When I scan directly into an Raspberry-Shell the escape sequences are displayed but when I opened a shell via ios (for example "shelly") non printable characters are filtert.
So its not a problem of pythonista! Should I delete the threat?