Last active
August 29, 2015 14:08
-
-
Save zeffii/3e4783af5a739818dcd6 to your computer and use it in GitHub Desktop.
saving text editor theme to dict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import bpy | |
from mathutils import Color, Vector | |
current_theme = bpy.context.user_preferences.themes.items()[0][0] | |
texed = bpy.context.user_preferences.themes[current_theme].text_editor | |
theme_options = { | |
'space.text', | |
'space.back', | |
'cursor', | |
'syntax_builtin', # import, return, for, in.. | |
'syntax_comment', | |
'syntax_numbers', | |
'syntax_special', # def, class.. | |
'syntax_string', | |
'syntax_symbols', # = ()[] . , > < == etc. | |
'syntax_reserved', | |
'syntax_preprocessor', | |
'line_numbers_background', | |
'selected_text' | |
} | |
theme_dict = {} | |
for opt in theme_options: | |
if '.' in opt: | |
# assume only one dot. | |
prime, subprime = opt.split('.') | |
val = getattr(getattr(texed, prime), subprime) | |
else: | |
val = getattr(texed, opt) | |
# cant round a colour, convert to vector first. | |
regular_vec = Vector(val[:]) | |
# rounds the value after 7th decimal | |
theme_dict[opt] = regular_vec.to_tuple(7) | |
m = json.dumps(theme_dict, sort_keys=True, indent=2) | |
print(m) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment