Skip to content

Instantly share code, notes, and snippets.

@ryanbugden
Created May 19, 2020 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanbugden/6c4048f3199fba63204df6eb357d9e00 to your computer and use it in GitHub Desktop.
Save ryanbugden/6c4048f3199fba63204df6eb357d9e00 to your computer and use it in GitHub Desktop.
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