omz / Pythonista-Issues

Issue tracker for Pythonista (iOS)
169 stars 14 forks source link

Editor.present_themed > does not work for a users custom themes #127

Open 1dancook opened 8 years ago

1dancook commented 8 years ago

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.

>>> editor.get_theme_dict()['name']
'mytest'
>>> import ui
>>> import editor
>>> v = ui.View()
>>> editor.present_themed(v, theme_name=editor.get_theme_dict()['name'])
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/var/containers/Bundle/Application/BFFB50DA-BF68-427B-A5E1-2DA994A786BA/Pythonista3.app/Frameworks/PythonistaKit3.framework/pylib/site-packages/editor.py", line 197, in present_themed
    apply_ui_theme(v, theme_name)
  File "/var/containers/Bundle/Application/BFFB50DA-BF68-427B-A5E1-2DA994A786BA/Pythonista3.app/Frameworks/PythonistaKit3.framework/pylib/site-packages/editor.py", line 176, in apply_ui_theme
    t = get_theme_dict(theme_name)
  File "/var/containers/Bundle/Application/BFFB50DA-BF68-427B-A5E1-2DA994A786BA/Pythonista3.app/Frameworks/PythonistaKit3.framework/pylib/site-packages/editor.py", line 163, in get_theme_dict
    with open(theme_path, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/var/containers/Bundle/Application/BFFB50DA-BF68-427B-A5E1-2DA994A786BA/Pythonista3.app/Themes2/mytest.json'
jsbain commented 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')
1dancook commented 8 years ago

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.

Phuket2 commented 8 years ago

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')
controversial commented 8 years ago

https://github.com/controversial/Pythonista-theme-utils works with custom themes.