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.


    Syntax inside the Custom Attributes section

    Pythonista
    ui editor
    7
    14
    11437
    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.
    • ywangd
      ywangd last edited by

      You must use double quotes for JSON, i.e.:

      {"background_color": "#f4dbff"}
      
      marcus67 2 Replies Last reply Reply Quote 1
      • marcus67
        marcus67 @ywangd last edited by

        @ywangd Thanks for your advice, but this does not work for me. Same error.

        1 Reply Last reply Reply Quote 0
        • marcus67
          marcus67 @ywangd last edited by marcus67

          @ywangd Sorry, mea maxima culpa. This time I forgot the curly braces altogether. It even works like this: { "background_color" : defaults.COLOR_LIGHT_PURPLE }. :-) I just have to make sure I import my module defaults in the module reading the pyui file.

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

            @ywangd Custom attributes are not JSON, they're interpreted as a Python dictionary literal.

            marcus67 1 Reply Last reply Reply Quote 0
            • marcus67
              marcus67 @omz last edited by

              @omz What is the reason that single quotes are not excepted? Thanks!

              Phuket2 1 Reply Last reply Reply Quote 0
              • omz
                omz last edited by omz

                @marcus67 Single quotes should work fine. In your example, it looks like the first quotation mark is misplaced though, it should be after the opening brace ({'background_color': ...} not '{background_color': ...})

                Edit: Just noticed that this was already pointed out by @Webmaster4o and @dgelessus

                @dgelessus The use of eval instead of ast.literal_eval is intentional. This allows you to calculate attribute values dynamically.

                marcus67 1 Reply Last reply Reply Quote 2
                • Phuket2
                  Phuket2 @marcus67 last edited by

                  @marcus67 , I have seen this error before. To me it seems intermittent. Assuming your the syntax is correct. But if you call a function or method, it appears you always get that message unless you return an INT.
                  Eg
                  {
                  custom_attr : func_work_it_out(),
                  }

                  func_work_it_out() needs to return a INT from what I can see, otherwise you get the warnings. I know it's not 100% the same issue, but guessing it's connected

                  1 Reply Last reply Reply Quote 0
                  • marcus67
                    marcus67 @omz last edited by

                    @omz You are right: it also works with single quotes. So, I guess it must have been due to the switched characters. Sorry about the confusion...

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

                      I found that my iPad Pro with the Apple external keyboard case was inserting slanted quotes instead of the UTF-8 quote characters expected by the Python interpreter for string literals. This was causing me to get the error:

                      Warning: could not load custom attributes of view "xyz": invalid character in identifier

                      I had to detach the keyboard and use the on-screen keyboard to get the correct string literal characters inserted. Note this applies to the IOS keyboard that pops up when editing custom attributes in the UI designer.

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

                        This could be because of iOS 11's "smart punctuation" feature, which messes up quotes, dashes, and other punctuation. (Well, in normal text it's nice, but when programming it's annoying.) Maybe you've already disabled it for the onscreen keyboard, but you may have to disable it again for the hardware keyboard. (Since iOS 10, some keyboard settings are tracked separately for onscreen and hardware keyboards. The "smart punctuation" setting might be one of them.)

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