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
-
You must use double quotes for JSON, i.e.:
{"background_color": "#f4dbff"}
-
@ywangd Thanks for your advice, but this does not work for me. Same error.
-
@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 moduledefaults
in the module reading the pyui file. -
@ywangd Custom attributes are not JSON, they're interpreted as a Python dictionary literal.
-
@omz What is the reason that single quotes are not excepted? Thanks!
-
@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 ofast.literal_eval
is intentional. This allows you to calculate attribute values dynamically. -
@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
-
@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...
-
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.
-
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.)