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.
Reading Pythonistas/Apples plist file format?
-
Hi,
does anyone know how Pyhtonistas
plist
files are being encoded? I always assumed that plists are just XML files in UTF-8 encoding. I however do fail reading pythonistas plist files, specifically :private/var/mobile/Containers/Shared/AppGroup/{Pythonistas app hash}/Library/Preferences/group.pythonista.plist
I do keep getting encoding exceptions:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 8: invalid continuation byte
I did tryascii
,utf-8,
andutf-16
with no luck. -
Plists can be stored in different formats – ASCII (rare nowadays), XML, or binary. You might want to use the
plistlib
module from the standard library, it should be able to handle all formats. -
thanks, that did work (Python really has a lib for everything):
import plistlib path = '/private/var/mobile/Containers/Shared/AppGroup/CB0CD8AB-6A20-4ECC-8312-B0822DFFD9A1/Library/Preferences/group.pythonista.plist' with open(path, 'rb') as f: data = plistlib.load(f) print(data)
The file however does not contain what I did hope for. Any chance you could shed some light on where the currently active theme is being stored? I know where the theme json files are stored, but I am sort of stumped on how to get the active theme.
Ps: I am aware of the theme related
editor
functions, but these have it quirks, which is why I am trying to do it by hand. -
What quirks specifically? Anyway, you could look at the source code of the
editor
module, to see how it gets the current theme (Modules & Templates/Standard Library (3.5)/site-packages/editor.py). In short, it usesNSUserDefaults
viaobjc_util
. -
Thanks again, I'll see what I can figure out. About the quirks - This little setup shows what I consider quirky - not everything is being styled correctly.
import editor import ui import time class SomeUi(ui.View): def __init__(self): self.frame = (0, 0, 500, 470) self.table_view = ui.TableView(frame=(10, 10, 480, 400)) self.text_view = ui.TextField(frame=(10, 420, 480, 40)) self.add_subview(self.table_view) self.add_subview(self.text_view) editor.apply_ui_theme(self) def wait(dt=1.0): t = time.perf_counter() while time.perf_counter() - t < dt: pass op = SomeUi() op.present('sheet') wait(3) op.close() wait(1) editor.present_themed(op, style='sheet')
In a more complex setup I have also experieneced that when reading colors from an
ui
element styled with theeditor.apply_ui_theme()
before anyui.View.layout()
has ran can give you back a wrong color (-1, 1, 1, 1). -
Hi,
had some time to poke in
editor
around.editor.get_theme_dict()
does exactly what I want. It should be made officially public (as it is already not internal, but doesn't appear in the autocomplete for some reason). Some mentioning in the docs would also be nice.