Last active
June 30, 2020 15:02
-
-
Save frankrolf/dea90f000dfe3b25c15c774847ae74a7 to your computer and use it in GitHub Desktop.
This file contains 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
''' | |
Open different space centers based on figure figure_suffixes given below | |
''' | |
from mojo import UI | |
from AppKit import NSApp, NSScreen, NSMakeRect | |
# figure_suffixes = ('', '.lf', '.tosf', '.osf', '.sc', '.sups') | |
figure_suffixes = ('', '.lf', '.tosf', '.osf') | |
def make_figure_string(suffix=None): | |
''' | |
Add suffixes to figures. | |
Could add some fanciness with slashed zeros here. | |
''' | |
figures = 'zero one two three four five six seven eight nine'.split() | |
if not suffix: | |
suffix = '' | |
# the two spaces at the end force RF to repeat the prefix character | |
return ' '.join([f'/{figure}{suffix}' for figure in figures]) + ' ' | |
def get_sc_nswindows(): | |
return [ | |
w for w in NSApp().orderedWindows() if w.windowName() == 'SpaceCenter'] | |
sc_content = [] | |
for suffix in figure_suffixes: | |
sc_content.append( | |
# prefix, content, suffix | |
(f'/zero{suffix}', make_figure_string(suffix), None) | |
) | |
# close existing space centers | |
space_center_nswindows = get_sc_nswindows() | |
for w in space_center_nswindows: | |
w.close() | |
# make new space centers | |
f = CurrentFont() | |
for prefix, content, suffix in sc_content: | |
sc = UI.OpenSpaceCenter(f, True) | |
sc.setPre(prefix) | |
sc.setRaw(content) | |
sc.setSuffix(suffix) | |
screen = NSScreen.mainScreen() | |
frame = screen.visibleFrame() | |
sc_width = frame.size.width | |
sc_height = frame.size.height / len(sc_content) | |
space_center_nswindows = get_sc_nswindows() | |
y = 0 | |
for w in space_center_nswindows: | |
w.setFrame_display_(NSMakeRect(0, y, sc_width, sc_height), False) | |
y += sc_height | |
# I don’t know how to get the same NSWindow object from UI.AllSpaceCenters() | |
# -- that might be faster. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment