omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    ui textfield escape-sequences

    Pythonista
    2
    8
    3476
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • drpaul
      drpaul last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        if the escape is always the same, how about

        data.split('\x1b[19~')
        
        1 Reply Last reply Reply Quote 0
        • drpaul
          drpaul last edited by 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)

          1 Reply Last reply Reply Quote 0
          • drpaul
            drpaul last edited by 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???

            1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by

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

              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • drpaul
                    drpaul last edited by

                    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?

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors