diff options
| -rw-r--r-- | equalize_sidebearings.py | 6 | ||||
| -rw-r--r-- | info.plist | 2 | ||||
| -rw-r--r-- | preferences.py | 33 | ||||
| -rw-r--r-- | preferences_window.py | 26 |
4 files changed, 57 insertions, 10 deletions
diff --git a/equalize_sidebearings.py b/equalize_sidebearings.py index 18515ad..5660330 100644 --- a/equalize_sidebearings.py +++ b/equalize_sidebearings.py @@ -1,6 +1,8 @@ from mojo.events import addObserver from lib.doodleMenus import SpaceCenterMenuForGlyph +from preferences import Preferences + class CustomSpaceCenterMenuForGlyph(SpaceCenterMenuForGlyph): @@ -10,13 +12,13 @@ class CustomSpaceCenterMenuForGlyph(SpaceCenterMenuForGlyph): class EqualizeSidebearings(object): - DEFAULT_ACTIVATION_KEY = 'e' def __init__(self): addObserver(self, 'equalize', 'spaceCenterKeyUp') + self.preferences = Preferences() def equalize(self, info): - if info['event'].characters() == self.DEFAULT_ACTIVATION_KEY: + if info['event'].characters() == self.preferences.activation_key: space_center_menu = CustomSpaceCenterMenuForGlyph( info['glyph'].naked()) space_center_menu.equalSideBearings_(self) @@ -6,7 +6,7 @@ <array> <dict> <key>path</key> - <string>preferences.py</string> + <string>preferences_window.py</string> <key>preferredName</key> <string>Preferences</string> <key>shortKey</key> diff --git a/preferences.py b/preferences.py index 7f6434c..637ad64 100644 --- a/preferences.py +++ b/preferences.py @@ -1,12 +1,31 @@ -import vanilla +from mojo.extensions import getExtensionDefault, setExtensionDefault +# from lib.doodlePreferences import HotKeyItem -class EqualizeSidebearingsPreferences(object): + +class Preferences(object): + DEFAULT_ACTIVATION_KEY = 'e' + PREFERENCES_DOMAIN = 'com.teddywing.EqualizeSidebearings' def __init__(self): - self.w = vanilla.Window((150, 50), 'Equalize Sidebearings') - self.w.activation_key_label = vanilla.TextBox((10, 15, -10, 22), 'Short Key:') - self.w.activation_key = vanilla.EditText((82, 12, -10, 25), 'e') - self.w.open() + self.load() + + def preference_key(self, key): + return '{0}.{1}'.format(self.PREFERENCES_DOMAIN, key) + + def load(self): + self._activation_key = getExtensionDefault( + self.preference_key('activation_key'), + self.DEFAULT_ACTIVATION_KEY) + + def save(self): + setExtensionDefault( + self.preference_key('activation_key'), + self.activation_key) + @property + def activation_key(self): + return self._activation_key -EqualizeSidebearingsPreferences() + @activation_key.setter + def activation_key(self, value): + self._activation_key = value diff --git a/preferences_window.py b/preferences_window.py new file mode 100644 index 0000000..11d3b52 --- /dev/null +++ b/preferences_window.py @@ -0,0 +1,26 @@ +import vanilla + +from preferences import Preferences + + +class PreferencesWindow(object): + + def __init__(self): + self.preferences = Preferences() + + self.w = vanilla.Window((150, 50), 'Equalize Sidebearings') + self.w.activation_key_label = vanilla.TextBox( + (10, 15, -10, 22), + 'Short Key:') + self.w.activation_key = vanilla.EditText( + posSize=(82, 12, -10, 25), + text=self.preferences.activation_key, + callback=self.edit_text_callback) + self.w.open() + + def edit_text_callback(self, sender): + self.preferences.activation_key = sender.get() + self.preferences.save() + + +PreferencesWindow() |
