-
-
Save esprengle/dc9abd15df0fb826bb63e957575b9805 to your computer and use it in GitHub Desktop.
Import and export Pyto themes
This file contains hidden or 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
""" | |
A script for importing and exporting Pyto themes. | |
""" | |
from rubicon.objc import ObjCClass, at | |
from console import clear | |
import sys | |
import base64 | |
import sharing | |
NSUserDefaults = ObjCClass("NSUserDefaults") | |
NSData = ObjCClass("NSData") | |
NSString = ObjCClass("NSString") | |
print("1) Export theme") | |
print("2) Import theme") | |
r = input("Select option ") | |
export = None | |
if r == "1": | |
export = True | |
elif r == "2": | |
export = False | |
else: | |
raise ValueError("Invalid option") | |
themes = NSUserDefaults.standardUserDefaults.valueForKey("themes") | |
if export and (themes == None or len(themes) == 0): | |
print("\nNo custom theme") | |
sys.exit(1) | |
elif themes == None: | |
themes = [] | |
themes = list(themes) | |
decoded_themes = [] | |
for theme in themes: | |
decoded_themes.append(base64.b64decode(str(theme.base64EncodedStringWithOptions(0))).decode()) | |
if export: | |
print("\nSelect a theme\n") | |
i = 0 | |
for theme in decoded_themes: | |
i += 1 | |
print(str(i)+") "+theme.split("\n")[0]) | |
selected = int(input("Theme number... "))-1 | |
theme = decoded_themes[selected].replace("\n", "\\n") | |
sharing.share_items([theme]) | |
else: | |
theme = input("Paste theme here\n").replace("\\n", "\n") | |
clear() | |
theme_data = at(theme).dataUsingEncoding(4) | |
themes.append(theme_data) | |
NSUserDefaults.standardUserDefaults.setValue(themes, forKey="themes") | |
print("Installed theme") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment