Skip to content

Instantly share code, notes, and snippets.

@typemytype
typemytype / addMeasurement.py
Created December 10, 2014 20:48
add a measurement line in RoboFont
from AppKit import NSPoint
from mojo.events import MeasurementTool
measurement = MeasurementTool.measurementClass()
measurement.startPoint = NSPoint(100, 100)
measurement.endPoint = NSPoint(200, 200)
g = CurrentGlyph()
g.naked().measurements.append(measurement)
g.update()
@typemytype
typemytype / embedGroupInScrollview.py
Created December 15, 2014 13:57
proposal for vanilla.ScrollView to support embedded vanilla.Group
from vanilla import *
import vanilla
from vanilla.vanillaBase import VanillaError
class ScrollView(vanilla.ScrollView):
def __init__(self, posSize, nsView, hasHorizontalScroller=True, hasVerticalScroller=True,
autohidesScrollers=False, backgroundColor=None, clipView=None,
drawsBackground=True):
@typemytype
typemytype / pinkyfier.py
Last active August 29, 2015 14:12
creates a pink app icon
from AppKit import *
icon = NSApp().applicationIconImage()
w, h = icon.size()
new = NSImage.alloc().initWithSize_((w, h))
imageRect = NSMakeRect(0, 0, w, h)
new.lockFocus()
@typemytype
typemytype / testURLhandler.py
Created January 15, 2015 13:52
RoboFont url handler
f = CurrentFont()
print f
@typemytype
typemytype / defaultFontInfoChanger.py
Created February 22, 2015 20:40
Change default font info values
from lib.settings import defaultFontInfoAttributes
defaultFontInfoAttributes["descender"] = -200
defaultFontInfoAttributes["ascender"] = 800
@typemytype
typemytype / fixStrikeout.py
Created April 17, 2015 08:49
fix Strikeout
import os
from fontTools.ttLib import TTFont
from mojo.events import addObserver
from ufo2fdk.fontInfoData import getAttrWithFallback
from ufo2fdk.outlineOTF import _roundInt
class FixBinaryOutput(object):
def __init__(self):
@typemytype
typemytype / extendedSliderVariable.py
Created June 22, 2015 13:31
DrawBot Variable slider example
Variable([
dict(name="myVariable", ui="Slider",
args=dict( # add some vanilla Slider specific attributes
value=10,
minValue=0,
maxValue=100,
tickMarkCount=11,
stopOnTickMarks=True)),
], globals())
@typemytype
typemytype / searchImage.py
Last active August 29, 2015 14:24
get image from google search and draw it
# DrawBot example
import urllib2
import json
searchTerm = 'DrawBot app is AWESOME'
## get data from google
fetcher = urllib2.build_opener()
startIndex = "0"
@typemytype
typemytype / baseGlyphJumper.py
Last active August 29, 2015 14:25
Open the selected component base glyph in a separate glyph window
from mojo.UI import OpenGlyphWindow
from mojo.events import addObserver
class BaseGlyphJumper(object):
def __init__(self):
# add observer on key down
addObserver(self, "keyDown", "keyDown")
from mojo.events import addObserver
from AppKit import NSSound, NSURL
path = u"http://soundbible.com/grab.php?id=1995&type=mp3"
url = NSURL.URLWithString_(path)
sound = NSSound.alloc().initWithContentsOfURL_byReference_(url, False)
class SomeMotivation(object):