Open 1dancook opened 8 years ago
Do you mean one defined in the app? or one defined programatically? For in app themes, User: is supposed to work, but does not seem to
if name.startswith('User:'):
home_dir = os.environ.get('CFFIXED_USER_HOME')
user_themes_path = os.path.join(home_dir, 'Library/Application Support/Themes')
theme_path = os.path.join(user_themes_path, name[5:] + '.json')
I think we're not able to do use a custom theme as made in the theme settings. So we can't do this:
editor.present_themed(view, theme_name='Better Than Luke Taylors Theme' )
I didn't know that you could just prepend 'User:' and get the custom themes. But yes, it doesn't work. Maybe because my theme in that themes folder is name 343B239A-E9AD-4571-A6E5-52F0541FCD80.json
!!
So, backtracking a bit. We just can't get custom themes working. Will change the title.
I think the other problem is here, until there are user themes if ever, the below code does not work. The editor.get_theme will return the theme set as per the settings. Whether or not is a user theme or not. Which makes sense. But there is no straight forward elegant way to stop editor.present_themed from failing. I know you can compre against a list of theme names. But that's not elegant. Seems to me that the present should be checking theme name and defaulting to None if the theme can not be found.
I thought editor.get_theme... Was going to fail. It does not. Which makes sense
try:
theme = editor.get_theme_dict()['name']
print(theme)
except FileExistsError:
theme = 'Cool Glow'
editor.present_themed(fs, theme_name=theme, style='panel')
https://github.com/controversial/Pythonista-theme-utils works with custom themes.
This only checks the Themes2 directory for themes (maybe there's a reason that you have it that way @omz... I'm not sure), but it would be nice if it could load someone's custom theme as well.