Skip to content

Instantly share code, notes, and snippets.

@okay-type
Last active September 19, 2019 16:43
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 okay-type/6e36bfd93e938f5f98253ab31a27f24e to your computer and use it in GitHub Desktop.
Save okay-type/6e36bfd93e938f5f98253ab31a27f24e to your computer and use it in GitHub Desktop.
Go to the previous line of Input Text in Robofont's Space Center
# Go to the previous line of Input Text in Robofont's Space Center
from mojo.UI import CurrentSpaceCenter
from difflib import get_close_matches
class SpacecenterPrevious(object):
def __init__(self):
sp = CurrentSpaceCenter()
tgli = sp.top.glyphLineInput
items = tgli.getItems()
current = tgli.getRaw()
if current in items:
count = len(items)
index = items.index(current)
nextitem = index-1
if nextitem < 0:
nextitem = count-1
nextline = items[nextitem]
sp.setRaw(nextline)
else:
x = get_close_matches(current, items)
try:
index = items.index(x[0])
sp.setRaw(items[index])
except:
tempcurrent = [item[:5] for item in items]
x = get_close_matches(current, tempcurrent)
try:
index = tempcurrent.index(x[0])
sp.setRaw(items[index])
except:
restart = 0
sp.setRaw(items[restart])
SpacecenterPrevious()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment