From 8778928a0989ea938fb06f0dd4c6639a6f9148ca Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 24 Dec 2015 18:26:03 -0800 Subject: Make hotkey preference work Separate preference handling into a new class and have the previous preferences class handle only the preferences window. We rename the old file to `preferences_window.py` and adjust the `info.plist` key for the menu item accordingly. Our new `Preference` class can now be imported from both `equalize_sidebearings.py` and `preferences_window.py` without causing confusion. I extracted it because asking for the `DEFAULT_ACTIVATION_KEY` from `preferences_window.py` from `equalize_sidebearings.py` would open the preferences window (bad). We now save the preferred key using RoboFont's extension preferences API. When the text input in the preferences window is modified, the new key preference gets saved. BUG: There's an issue with this implementation where the preferred key doesn't become active until the next launch of RoboFont because `EqualizeSidebearings` has its own instance of `Preferences` which has a stale `activation_key`. --- preferences_window.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 preferences_window.py (limited to 'preferences_window.py') 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() -- cgit v1.2.3