Pythonista 3.3 and theme access
Hey all you Pythonisters, I just upgraded one of my devices to Pythonista 3.3 to test what has changed or broken from 3.2 in my project.
There's a few things, mostly minor. The biggest one is actually that the theme-management code I was using, which was cobbled together from threads in this forum, is no longer working.
I have this code:
def currentThemeName(self): if self._NSUserDefaults is None: self._NSUserDefaults = objc_util.ObjCClass('NSUserDefaults') defaults = self._NSUserDefaults.standardUserDefaults() name = str(defaults.stringForKey_('ThemeName')) if not name: name = 'Default' return name
that used to return the currently selected theme but is now, I believe, always returning the theme setting from Pythonista 3.2, which implies the user default key has changed?
Anyone know (@omz if you have a spare moment)? Perhaps there's now a better way to access this info?
Well look at me, being all fancy and figuring this one out myself!
Ok, so first step was looking at all the NSUserDefaults key/value pairs to see what held the theme:
import objc_util nsd = objc_util.ObjCClass("NSUserDefaults") standard = nsd.standardUserDefaults() defaults = standard.dictionaryRepresentation() print(defaults)
Then, just scanning through the output, I see:
ThemeName = ...
ThemeNameDarkMode = ...
ThemeNameLightMode = ...
so, obviously in retrospect, we've got new keys for the theme settings for light and dark modes. Et, voila.
Now then...anyone know how we find out which mode we are in from a script?
I should probably do the research first before asking questions: to get which theme mode we are in, light or dark, there is a new ui module function:
So there you go.
Now...how do I find out the pythonista version to special case this situation since we'll be running some Pythonista 3.2 and some Pythonista 3.3, and some iOS 12 and some iOS 13, for a little while at least?
Shows examples of getting pythonista build version, along with iOS platform/version in a mostly robust way.
@JonB thanks so much, that's perfect.
@omz can I request that some future minor update to pythonista put the ability to check the build version and the iOS version into some globally available module?