Some questions about Pythonista
- Is theoretically possible to present a ui in the extension without breaking apple rules?
- Can you please reinsert the icloud drive implementation?
- Is it possible to change theme with objc_util?
- In editorial there is editor.get_theme(). Why not adding it in Pythonista?
Thanks in advance
omz last edited by
Is theoretically possible to present a ui in the extension without breaking apple rules?
I don't see why not. There are a couple of technical limitations though – e.g. your UI can't cover the entire screen, it's restricted to the size of the Pythonista extension (to my knowledge, it is technically impossible to work around this).
Can you please reinsert the icloud drive implementation?
Probably not in this update.
Is it possible to change theme with objc_util?
Yes, here's an example:
# Utility functions for setting the UI/syntax highlighting theme in Pythonista (1.6 beta) using objc_util. # WARNING: This relies on some internals that may change in the future. # When run as a script, it toggles between the default (light) theme and Tomorrow-Dark. from objc_util import * import os from glob import glob def get_theme_names(): res_path = str(ObjCClass('NSBundle').mainBundle().resourcePath()) theme_paths = glob(os.path.join(res_path, 'Themes2/*.json')) theme_names = [os.path.split(p).split('.') for p in theme_paths] return theme_names def get_current_theme_name(): defaults = ObjCClass('NSUserDefaults').standardUserDefaults() return str(defaults.objectForKey_('ThemeName')) @on_main_thread def set_theme(name): if name not in get_theme_names(): raise ValueError('Theme not found') # Save new setting and load the theme: defaults = ObjCClass('NSUserDefaults').standardUserDefaults() defaults.setObject_forKey_(name, 'ThemeName') ui_theme = ObjCClass('PA2UITheme').sharedTheme() ui_theme.loadThemeNamed_(name) # Reset the thumbnail cache for the script library: renderer = ObjCClass('PAScriptThumbnailRenderer').sharedThumbnailRenderer() renderer.reset() # Hide the keyboard (switching between light/dark doesn't look right otherwise): UIApp = ObjCClass('UIApplication') UIApp.sharedApplication().keyWindow().endEditing_(True) def main(): # Toggle between a light and a dark theme: current = get_current_theme_name() theme_name = 'Default' if current != 'Default' else 'Theme07_TomorrowNight' set_theme(theme_name) if __name__ == '__main__': main()
In editorial there is editor.get_theme(). Why not adding it in Pythonista?
get_current_theme_name()function in the code above. This is pretty straightforward and it's the part that's least likely to break in the future.
Thanks for your replies :-)
Dunno why i thought uis weren't possible in extensions 😊 thanks
Another question about objc_utils:
I tried just for fun to get generalPasteboard.string()
It works but it is returned as NSCFString. How can i convert it into normal python string?
omz last edited by
This should work:
ns_string = ObjCClass('UIPasteboard').generalPasteboard().string() py_string = str(ns_string) # alternatively: py_unicode = unicode(ns_string)