Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
try to fit 16 columns perfectly into font overview, resize window accordingly
from mojo.UI import CurrentFontWindow
from lib.tools.defaults import getDefault
'''
trying to perfectly fit 16 columns of cells across the font overview
'''
fo = CurrentFontWindow().fontOverview
gc = fo.getGlyphCollection()
v = gc.getGlyphCellView()
# get the width of the cell view
vw = v.frameSize().width
cells_across = 16
cw = vw / cells_across
print("frame width is ", vw)
print("and the amount of cells I want across is ", cells_across)
print("so: ")
print("desired cell size is ", cw)
# do it
v.setCellSize_([cw, cw])
new_cw = gc.getCellSize()[0]
print("but resulting cell size is ", new_cw)
print("so: ")
print("leftover padding on right side of font overview is ", ((cw - new_cw) * cells_across))
vw = new_cw * cells_across
print("new desired frame width is ", vw)
# set frame size
if getDefault("singleWindowMode") == 1:
v.recalculateFrame()
x, y, w, h = fo.getPosSize()
fo.setPosSize((x, y, vw, h))
else:
windows = NSApp().orderedWindows()
(x, y), (w, h) = windows[0].frame()
x_diff = w - vw
windows[0].setFrame_display_animate_(((x + x_diff, y), (vw, h)), True, False)
print("final frame width is ", v.frameSize().width)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.