Last active
October 22, 2019 15:37
-
-
Save okay-type/ce122159565cbeab320b069010fb011b to your computer and use it in GitHub Desktop.
Testing saving/loading preferences in robofont
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
from vanilla import Window, EditText, Button | |
from mojo.extensions import setExtensionDefault, getExtensionDefault, registerExtensionDefaults, removeExtensionDefault | |
class preferenceTest(object): | |
def __init__(self): | |
self.windowname = 'pref save / load test' | |
self.prefKey = 'com.okaytype.toolName' | |
self.makeWindow() | |
def makeWindow(self): | |
self.w = Window((333, 88), self.windowname) | |
self.w.t = EditText((0, 0, 0, 22), 'Placeholder') | |
self.w.b = Button((0, 22, 0, 22), 'Save Text', callback=self.prefSave) | |
self.w.x = Button((0, 44, 0, 22), 'Report Saved Value', callback=self.prefGet) | |
self.w.c = Button((0, 66, 0, 22), 'Clear Saved Preferences', callback=self.prefClear) | |
self.prefLoad() | |
self.w.open() | |
@property | |
def pref(self): | |
return self.prefKey + '.' + 'savedEditText' | |
def prefLoad(self): | |
initialDefaults = { | |
self.pref: 'Initial Default', | |
} | |
registerExtensionDefaults(initialDefaults) | |
v = getExtensionDefault(self.pref) | |
self.w.t.set(v) | |
print('load', v) | |
def prefSave(self, sender): | |
setExtensionDefault(self.prefKey+'.savedEditText', self.w.t.get()) | |
v = getExtensionDefault(self.pref) | |
print('set', v) | |
def prefGet(self, sender): | |
v = getExtensionDefault(self.pref) | |
print('get', v) | |
def prefClear(self, sender): | |
removeExtensionDefault(self.pref) | |
v = getExtensionDefault(self.pref) | |
self.w.t.set(v) | |
print('cleared', v) | |
preferenceTest() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment