Last active
April 10, 2025 11:57
-
-
Save okay-type/cb086eaac45964815c7b258aaa435b51 to your computer and use it in GitHub Desktop.
replace the fuzzy cell size slider with a crispy number field
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
from mojo.UI import AllFontWindows, NumberEditText | |
from mojo.subscriber import Subscriber, registerFontOverviewSubscriber | |
from AppKit import NSColor, NSTextAlignmentRight | |
from mojo.UI import CurrentFontWindow, getDefault, setDefault | |
''' | |
[email protected] | |
for robofont | |
replace the fuzzy cell size slider with a crispy number field | |
set as a start up script | |
version zero point two | |
''' | |
class numeric_ice_cubes(Subscriber): | |
def build(self): | |
self.hold = False | |
size = int(getDefault('fontCollectionViewGlyphSize')) | |
for f in AllFonts(): | |
fw = f.fontWindow() | |
fo = fw.fontOverview | |
self.rebuild_ui(fo, size) | |
def rebuild_ui(self, fo, size=42): | |
# hide slider | |
slider = fo.views.sizeSlider | |
slider.show(False) | |
# add number | |
fsb = fo.statusBar | |
if hasattr(fsb, 'fit_button'): | |
del fsb.fit_button | |
fsb.fit_button = NumberEditText( | |
(-56, -18, 50, 18), | |
text=size, | |
callback=self.resize_cells, | |
sizeStyle='small', | |
allowFloat=False, | |
allowNegative=False, | |
allowEmpty=False, | |
minimum=10, | |
maximum=200, | |
decimals=0, | |
continuous=False | |
) | |
self.flat_edittext(fsb.fit_button) | |
def fontOverviewDidOpen(self, info): | |
size = int(getDefault('fontCollectionViewGlyphSize')) | |
self.rebuild_ui(info['fontOverview'], size) | |
def resize_cells(self, sender): | |
if self.hold == True: | |
return | |
size = int(sender.get()) | |
for f in AllFonts(): | |
fw = f.fontWindow() | |
fo = fw.fontOverview | |
# update cell sizes | |
gc = fo.getGlyphCollection() | |
v = gc.getGlyphCellView() | |
v.setCellSize_([size, size]) | |
# update text fields | |
self.hold = True | |
fo.statusBar.fit_button.set(size) | |
self.hold = False | |
# update pref | |
setDefault('fontCollectionViewGlyphSize', int(size)) | |
def flat_edittext(self, this): | |
ns = this.getNSTextField() | |
ns.setBordered_(False) | |
ns.setBackgroundColor_(NSColor.clearColor()) | |
ns.setFocusRingType_(1) | |
ns.setAlignment_(NSTextAlignmentRight) | |
registerFontOverviewSubscriber(numeric_ice_cubes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment