Last active
September 19, 2019 16:43
-
-
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
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
# 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