diff options
| author | Teddy Wing | 2015-12-06 03:13:40 -0500 |
|---|---|---|
| committer | Teddy Wing | 2015-12-06 03:22:23 -0500 |
| commit | 2180b298ff7fbee1df2d69c4552266c13d40c57c (patch) | |
| tree | 638e44281e562cf0482297b01d4074d3f8f00046 /equalize_sidebearings.py | |
| parent | 385ba95ce64661a773af2a7f28191a768149c572 (diff) | |
| download | RoboFont-Equalize-Sidebearings-Key-2180b298ff7fbee1df2d69c4552266c13d40c57c.tar.bz2 | |
equalize_sidebearings.py: Call RoboFont implementation instead of copy
Comment out the copied RoboFont implementation and call the existing
implementation instead.
We do this by subclassing `SpaceCenterMenuForGlyph` and overriding the
`__init__` method. This allows us to bypass `SpaceCenterMenuForGlyph`'s
`__init__` method (notice that we call its super `__init__` but not its
`__init__`), allowing us to create an instance without needing to
specify the required `event`, `view`, and `callback` parameters that the
original class requires.
This also allows us to not include proprietary code in the project.
Undo functionality _still_ doesn't work. Can't figure out what the
problem is.
This change is really from shortly after the last commit, but I didn't
bother committing because I wanted to resolve the undo problems first.
Since it's been a while, deciding now to commit what's here and continue
working.
Diffstat (limited to 'equalize_sidebearings.py')
| -rw-r--r-- | equalize_sidebearings.py | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/equalize_sidebearings.py b/equalize_sidebearings.py index 7f7f5cc..14526ca 100644 --- a/equalize_sidebearings.py +++ b/equalize_sidebearings.py @@ -1,7 +1,7 @@ from AppKit import NSUserDefaults from mojo.events import addObserver -# from lib.doodleMenus import SpaceCenterMenuForGlyph +from lib.doodleMenus import SpaceCenterMenuForGlyph # from tools.defaults import getDefault def getDefault(key, defaultValue = None, defaultClass = None): @@ -11,6 +11,14 @@ def getDefault(key, defaultValue = None, defaultClass = None): return defaultClass(value) return value + +class CustomSpaceCenterMenuForGlyph(SpaceCenterMenuForGlyph): + + def __init__(self, glyph): + self._glyph = glyph + super(SpaceCenterMenuForGlyph, self).__init__() + + class EqualizeSidebearings(object): def __init__(self): addObserver(self, 'center', 'spaceCenterKeyUp') @@ -18,8 +26,16 @@ class EqualizeSidebearings(object): def center(self, info): if info['event'].characters() == 'a': # g = info['glyph'] - self.equalize_sidebearings(info['glyph']) - # SpaceCenterMenuForGlyph(info['event'], self, g) + # self.equalize_sidebearings(info['glyph']) + # space_center_menu = SpaceCenterMenuForGlyph(info['event'], self, g, None) + # space_center_menu.equalSideBearings_(self) + space_center_menu = CustomSpaceCenterMenuForGlyph(info['glyph']) + space_center_menu.equalSideBearings_(self) + + # import vanilla + # self.w = vanilla.Window((400, 400, 1000, 900)) + # self.w.text = vanilla.ObjectBrowser((0, 0, -0, -0), space_center_menu) + # self.w.open() # # g.prepareUndo('Equalize Sidebearings') # @@ -27,20 +43,20 @@ class EqualizeSidebearings(object): # # g.performUndo() - def equalize_sidebearings(self, glyph): - useItalicAngleForDisplay = getDefault('glyphViewShouldUseItalicAngleForDisplay') - leftMarginAttribute = 'leftMargin' - rightMarginAttribute = 'rightMargin' - if useItalicAngleForDisplay: - leftMarginAttribute = 'angledLeftMargin' - rightMarginAttribute = 'angledRightMargin' - left = getattr(glyph, leftMarginAttribute) - right = getattr(glyph, rightMarginAttribute) - margin = int(round((left + right) / 2.0)) - glyph.prepareUndo('Equalize sidebearings') - setattr(glyph, leftMarginAttribute, margin) - setattr(glyph, rightMarginAttribute, margin) - glyph.selection.resetSelectionPath() - glyph.performUndo() + # def equalize_sidebearings(self, glyph): + # useItalicAngleForDisplay = getDefault('glyphViewShouldUseItalicAngleForDisplay') + # leftMarginAttribute = 'leftMargin' + # rightMarginAttribute = 'rightMargin' + # if useItalicAngleForDisplay: + # leftMarginAttribute = 'angledLeftMargin' + # rightMarginAttribute = 'angledRightMargin' + # left = getattr(glyph, leftMarginAttribute) + # right = getattr(glyph, rightMarginAttribute) + # margin = int(round((left + right) / 2.0)) + # glyph.prepareUndo('Equalize sidebearings') + # setattr(glyph, leftMarginAttribute, margin) + # setattr(glyph, rightMarginAttribute, margin) + # glyph.selection.resetSelectionPath() + # glyph.performUndo() EqualizeSidebearings()
\ No newline at end of file |
